html-validate 6.1.2 → 6.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/es/core.d.ts CHANGED
@@ -51,10 +51,11 @@ declare enum TokenType {
51
51
  TEXT = 11,
52
52
  TEMPLATING = 12,
53
53
  SCRIPT = 13,
54
- COMMENT = 14,
55
- CONDITIONAL = 15,
56
- DIRECTIVE = 16,
57
- EOF = 17
54
+ STYLE = 14,
55
+ COMMENT = 15,
56
+ CONDITIONAL = 16,
57
+ DIRECTIVE = 17,
58
+ EOF = 18
58
59
  }
59
60
  interface Token {
60
61
  type: TokenType;
package/dist/es/core.js CHANGED
@@ -1230,12 +1230,14 @@ var State;
1230
1230
  State[State["ATTR"] = 5] = "ATTR";
1231
1231
  State[State["CDATA"] = 6] = "CDATA";
1232
1232
  State[State["SCRIPT"] = 7] = "SCRIPT";
1233
+ State[State["STYLE"] = 8] = "STYLE";
1233
1234
  })(State || (State = {}));
1234
1235
 
1235
1236
  var ContentModel;
1236
1237
  (function (ContentModel) {
1237
1238
  ContentModel[ContentModel["TEXT"] = 1] = "TEXT";
1238
1239
  ContentModel[ContentModel["SCRIPT"] = 2] = "SCRIPT";
1240
+ ContentModel[ContentModel["STYLE"] = 3] = "STYLE";
1239
1241
  })(ContentModel || (ContentModel = {}));
1240
1242
  class Context {
1241
1243
  constructor(source) {
@@ -2915,7 +2917,7 @@ var TRANSFORMER_API;
2915
2917
  /** @public */
2916
2918
  const name = "html-validate";
2917
2919
  /** @public */
2918
- const version = "6.1.2";
2920
+ const version = "6.1.3";
2919
2921
  /** @public */
2920
2922
  const homepage = "https://html-validate.org";
2921
2923
  /** @public */
@@ -3601,10 +3603,11 @@ var TokenType;
3601
3603
  TokenType[TokenType["TEXT"] = 11] = "TEXT";
3602
3604
  TokenType[TokenType["TEMPLATING"] = 12] = "TEMPLATING";
3603
3605
  TokenType[TokenType["SCRIPT"] = 13] = "SCRIPT";
3604
- TokenType[TokenType["COMMENT"] = 14] = "COMMENT";
3605
- TokenType[TokenType["CONDITIONAL"] = 15] = "CONDITIONAL";
3606
- TokenType[TokenType["DIRECTIVE"] = 16] = "DIRECTIVE";
3607
- TokenType[TokenType["EOF"] = 17] = "EOF";
3606
+ TokenType[TokenType["STYLE"] = 14] = "STYLE";
3607
+ TokenType[TokenType["COMMENT"] = 15] = "COMMENT";
3608
+ TokenType[TokenType["CONDITIONAL"] = 16] = "CONDITIONAL";
3609
+ TokenType[TokenType["DIRECTIVE"] = 17] = "DIRECTIVE";
3610
+ TokenType[TokenType["EOF"] = 18] = "EOF";
3608
3611
  })(TokenType || (TokenType = {}));
3609
3612
 
3610
3613
  /* eslint-disable no-useless-escape */
@@ -3627,6 +3630,8 @@ const MATCH_CDATA_BEGIN = /^<!\[CDATA\[/;
3627
3630
  const MATCH_CDATA_END = /^[^]*?]]>/;
3628
3631
  const MATCH_SCRIPT_DATA = /^[^]*?(?=<\/script)/;
3629
3632
  const MATCH_SCRIPT_END = /^<(\/)(script)/;
3633
+ const MATCH_STYLE_DATA = /^[^]*?(?=<\/style)/;
3634
+ const MATCH_STYLE_END = /^<(\/)(style)/;
3630
3635
  const MATCH_DIRECTIVE = /^<!--\s*\[html-validate-(.*?)]\s*-->/;
3631
3636
  const MATCH_COMMENT = /^<!--([^]*?)-->/;
3632
3637
  const MATCH_CONDITIONAL = /^<!\[([^\]]*?)\]>/;
@@ -3666,6 +3671,9 @@ class Lexer {
3666
3671
  case State.SCRIPT:
3667
3672
  yield* this.tokenizeScript(context);
3668
3673
  break;
3674
+ case State.STYLE:
3675
+ yield* this.tokenizeStyle(context);
3676
+ break;
3669
3677
  /* istanbul ignore next: sanity check: should not happen unless adding new states */
3670
3678
  default:
3671
3679
  this.unhandled(context);
@@ -3734,11 +3742,14 @@ class Lexer {
3734
3742
  * Called when entering a new state.
3735
3743
  */
3736
3744
  enter(context, state, data) {
3737
- /* script tags require a different content model */
3745
+ /* script/style tags require a different content model */
3738
3746
  if (state === State.TAG && data && data[0][0] === "<") {
3739
3747
  if (data[0] === "<script") {
3740
3748
  context.contentModel = ContentModel.SCRIPT;
3741
3749
  }
3750
+ else if (data[0] === "<style") {
3751
+ context.contentModel = ContentModel.STYLE;
3752
+ }
3742
3753
  else {
3743
3754
  context.contentModel = ContentModel.TEXT;
3744
3755
  }
@@ -3764,6 +3775,7 @@ class Lexer {
3764
3775
  ], "expected doctype name");
3765
3776
  }
3766
3777
  *tokenizeTag(context) {
3778
+ /* eslint-disable-next-line consistent-return -- exhaustive switch handled by typescript */
3767
3779
  function nextState(token) {
3768
3780
  switch (context.contentModel) {
3769
3781
  case ContentModel.TEXT:
@@ -3775,11 +3787,14 @@ class Lexer {
3775
3787
  else {
3776
3788
  return State.TEXT; /* <script/> (not legal but handle it anyway so the lexer doesn't choke on it) */
3777
3789
  }
3790
+ case ContentModel.STYLE:
3791
+ if (token && token.data[0][0] !== "/") {
3792
+ return State.STYLE;
3793
+ }
3794
+ else {
3795
+ return State.TEXT; /* <style/> */
3796
+ }
3778
3797
  }
3779
- /* istanbul ignore next: not covered by a test as there is currently no
3780
- * way to trigger this unless new content models are added but this will
3781
- * add a saner default if anyone ever does */
3782
- return context.contentModel !== ContentModel.SCRIPT ? State.TEXT : State.SCRIPT;
3783
3798
  }
3784
3799
  yield* this.match(context, [
3785
3800
  [MATCH_TAG_CLOSE, nextState, TokenType.TAG_CLOSE],
@@ -3817,6 +3832,12 @@ class Lexer {
3817
3832
  [MATCH_SCRIPT_DATA, State.SCRIPT, TokenType.SCRIPT],
3818
3833
  ], "expected </script>");
3819
3834
  }
3835
+ *tokenizeStyle(context) {
3836
+ yield* this.match(context, [
3837
+ [MATCH_STYLE_END, State.TAG, TokenType.TAG_OPEN],
3838
+ [MATCH_STYLE_DATA, State.STYLE, TokenType.STYLE],
3839
+ ], "expected </style>");
3840
+ }
3820
3841
  }
3821
3842
 
3822
3843
  const whitespace = /(\s+)/;
@@ -6067,7 +6088,7 @@ function getCSSDeclarations(value) {
6067
6088
  .filter(Boolean)
6068
6089
  .map((it) => {
6069
6090
  const [property, value] = it.split(":", 2);
6070
- return { property: property.trim(), value: value.trim() };
6091
+ return { property: property.trim(), value: value ? value.trim() : undefined };
6071
6092
  });
6072
6093
  }
6073
6094
  class NoInlineStyle extends Rule {