You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
984 B

1 year ago
  1. /* global HTMLHint */
  2. /* eslint no-magic-numbers: ["error", { "ignore": [0, 1] }] */
  3. HTMLHint.addRule({
  4. id: 'kses',
  5. description: 'Element or attribute cannot be used.',
  6. init: function( parser, reporter, options ) {
  7. 'use strict';
  8. var self = this;
  9. parser.addListener( 'tagstart', function( event ) {
  10. var attr, col, attrName, allowedAttributes, i, len, tagName;
  11. tagName = event.tagName.toLowerCase();
  12. if ( ! options[ tagName ] ) {
  13. reporter.error( 'Tag <' + event.tagName + '> is not allowed.', event.line, event.col, self, event.raw );
  14. return;
  15. }
  16. allowedAttributes = options[ tagName ];
  17. col = event.col + event.tagName.length + 1;
  18. for ( i = 0, len = event.attrs.length; i < len; i++ ) {
  19. attr = event.attrs[ i ];
  20. attrName = attr.name.toLowerCase();
  21. if ( ! allowedAttributes[ attrName ] ) {
  22. reporter.error( 'Tag attribute [' + attr.raw + ' ] is not allowed.', event.line, col + attr.index, self, attr.raw );
  23. }
  24. }
  25. });
  26. }
  27. });