[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/js/codemirror/ -> htmlhint-kses.js (source)

   1  /* global HTMLHint */
   2  /* eslint no-magic-numbers: ["error", { "ignore": [1] }] */
   3  HTMLHint.addRule( {
   4      id: 'kses',
   5      description: 'Element or attribute cannot be used.',
   6  
   7      /**
   8       * Initialize.
   9       *
  10       * @this {import('htmlhint/types').Rule}
  11       * @param {import('htmlhint').HTMLParser} parser - Parser.
  12       * @param {import('htmlhint').Reporter} reporter - Reporter.
  13       * @param {Record<string, Record<string, boolean>>} options - KSES options.
  14       * @return {void}
  15       */
  16      init: function ( parser, reporter, options ) {
  17          'use strict';
  18  
  19          parser.addListener( 'tagstart', ( event ) => {
  20              const tagName = event.tagName.toLowerCase();
  21              if ( ! options[ tagName ] ) {
  22                  reporter.error(
  23                      `Tag <${ event.tagName }> is not allowed.`,
  24                      event.line,
  25                      event.col,
  26                      this,
  27                      event.raw
  28                  );
  29                  return;
  30              }
  31  
  32              const allowedAttributes = options[ tagName ];
  33              const column = event.col + event.tagName.length + 1;
  34              for ( const attribute of event.attrs ) {
  35                  if ( ! allowedAttributes[ attribute.name.toLowerCase() ] ) {
  36                      reporter.error(
  37                          `Tag attribute [${ attribute.raw }] is not allowed.`,
  38                          event.line,
  39                          column + attribute.index,
  40                          this,
  41                          attribute.raw
  42                      );
  43                  }
  44              }
  45          } );
  46      },
  47  } );


Generated : Sat Jun 13 09:38:55 2026 Cross-referenced by PHPXref