home *** CD-ROM | disk | FTP | other *** search
/ HTML Examples / WP.iso / wordpress / wp-includes / js / codemirror / htmlhint-kses.js < prev    next >
Encoding:
JavaScript  |  2017-09-12  |  984 b   |  31 lines

  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.  
  9.         var self = this;
  10.         parser.addListener( 'tagstart', function( event ) {
  11.             var attr, col, attrName, allowedAttributes, i, len, tagName;
  12.  
  13.             tagName = event.tagName.toLowerCase();
  14.             if ( ! options[ tagName ] ) {
  15.                 reporter.error( 'Tag <' + event.tagName + '> is not allowed.', event.line, event.col, self, event.raw );
  16.                 return;
  17.             }
  18.  
  19.             allowedAttributes = options[ tagName ];
  20.             col = event.col + event.tagName.length + 1;
  21.             for ( i = 0, len = event.attrs.length; i < len; i++ ) {
  22.                 attr = event.attrs[ i ];
  23.                 attrName = attr.name.toLowerCase();
  24.                 if ( ! allowedAttributes[ attrName ] ) {
  25.                     reporter.error( 'Tag attribute [' + attr.raw + ' ] is not allowed.', event.line, col + attr.index, self, attr.raw );
  26.                 }
  27.             }
  28.         });
  29.     }
  30. });
  31.