do11y 0.2.11 → 0.2.12

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/README.md CHANGED
@@ -84,16 +84,49 @@ interface Options {
84
84
  /**
85
85
  * The code highlighter.
86
86
  * - Markdown code blocks
87
- * - `.vue?highlight` & `.vue?highlight&lang=css` imports
87
+ * - `.vue?highlight`, `.vue?highlight&lang=css` & `.vue?highlight&styleless` imports
88
88
  * - `highlightedSource` and `highlightedCssSource` props in SandboxIframe
89
89
  *
90
90
  * If using multiple themes - you can set the `data-theme` attribute
91
91
  * to switch between them, e.g. `data-theme="vitesse-light"`.
92
92
  */
93
93
  highlighter?: {
94
+ /**
95
+ * The available themes.
96
+ * The default shiki themes are always included.
97
+ */
94
98
  themes: (ThemeInput | StringLiteralUnion<BundledTheme, string>)[];
99
+
100
+ /**
101
+ * What the default theme should be.
102
+ * @default "The first theme in the array"
103
+ */
95
104
  defaultTheme?: string | StringLiteralUnion<BundledTheme, string>;
105
+
106
+ /**
107
+ * Custom transformers.
108
+ *
109
+ * These Shiki's default transformers are always included:
110
+ * - transformerNotationHighlight
111
+ * - transformerNotationDiff
112
+ * - transformerNotationErrorLevel
113
+ */
96
114
  transformers?: ShikiTransformer[];
115
+
116
+ /**
117
+ * If comments should be filtered.
118
+ * - Passing `true` removes all comments
119
+ * - While `string[]` acts as a filter - removing comments that `include` any of these strings in them
120
+ * - `false` keeps all comments
121
+ *
122
+ * @default ["prettier-ignore"]
123
+ */
124
+ removeComments?: boolean | string[];
125
+
126
+ /**
127
+ * If any postprocessing should be done.
128
+ * The element is a JSDOM HTMLPreElement.
129
+ */
97
130
  postprocess?: (pre: HTMLPreElement) => void;
98
131
  };
99
132
 
@@ -25,6 +25,7 @@ const resolveOptions = async () => {
25
25
  themesInput,
26
26
  transformers: options.highlighter?.transformers || [],
27
27
  postprocess: options.highlighter?.postprocess,
28
+ removeComments: options.highlighter?.removeComments ?? ["prettier-ignore"],
28
29
  },
29
30
  };
30
31
  };
@@ -30,6 +30,52 @@ export const highlightCode = (code, lang) => {
30
30
  }
31
31
  },
32
32
  },
33
+ {
34
+ name: "remove-unwanted-comments",
35
+ tokens(tokens) {
36
+ const filter = do11yOptions.highlighter.removeComments;
37
+ if (filter === false) {
38
+ return tokens;
39
+ }
40
+ const result = [];
41
+ let previousLineWasRemoved = false;
42
+ for (const line of tokens) {
43
+ previousLineWasRemoved = false;
44
+ const filteredLine = [];
45
+ let hasComment = false;
46
+ for (const token of line) {
47
+ const isUnwantedComment = token.explanation?.some((exp) => {
48
+ const isComment = exp.scopes.some((s) => s.scopeName.startsWith("comment"));
49
+ if (!isComment) {
50
+ return false;
51
+ }
52
+ return typeof filter === "boolean"
53
+ ? true
54
+ : filter.some((query) => exp.content.includes(query));
55
+ });
56
+ if (isUnwantedComment) {
57
+ hasComment = true;
58
+ }
59
+ else {
60
+ filteredLine.push(token);
61
+ }
62
+ }
63
+ /**
64
+ * Remove lines that become empty after removing comments.
65
+ * Additionally, if the next line after a removed comment line is empty too - remove it.
66
+ */
67
+ if (hasComment || previousLineWasRemoved) {
68
+ const isAllWhitespace = filteredLine.every((token) => !token.content.trim());
69
+ previousLineWasRemoved = isAllWhitespace;
70
+ if (isAllWhitespace) {
71
+ continue;
72
+ }
73
+ }
74
+ result.push(filteredLine);
75
+ }
76
+ return result;
77
+ },
78
+ },
33
79
  ],
34
80
  });
35
81
  };
@@ -38,9 +38,38 @@ export interface Options extends MarkdownPluginOptions {
38
38
  * to switch between them, e.g. `data-theme="vitesse-light"`.
39
39
  */
40
40
  highlighter?: {
41
+ /**
42
+ * The available themes.
43
+ * The default shiki themes are always included.
44
+ */
41
45
  themes: (ThemeInput | StringLiteralUnion<BundledTheme, string>)[];
46
+ /**
47
+ * What the default theme should be.
48
+ * @default "The first theme in the array"
49
+ */
42
50
  defaultTheme?: string | StringLiteralUnion<BundledTheme, string>;
51
+ /**
52
+ * Custom transformers.
53
+ *
54
+ * These Shiki's default transformers are always included:
55
+ * - transformerNotationHighlight
56
+ * - transformerNotationDiff
57
+ * - transformerNotationErrorLevel
58
+ */
43
59
  transformers?: ShikiTransformer[];
60
+ /**
61
+ * If comments should be filtered.
62
+ * - Passing `true` removes all comments
63
+ * - While `string[]` acts as a filter - removing comments that `include` any of these strings in them
64
+ * - `false` keeps all comments
65
+ *
66
+ * @default ["prettier-ignore"]
67
+ */
68
+ removeComments?: boolean | string[];
69
+ /**
70
+ * If any postprocessing should be done.
71
+ * The element is a JSDOM HTMLPreElement.
72
+ */
44
73
  postprocess?: (pre: HTMLPreElement) => void;
45
74
  };
46
75
  }
@@ -50,6 +79,7 @@ export interface ResolvedOptions extends Omit<Options, "highlighter"> {
50
79
  themesInput: Record<string, string>;
51
80
  defaultTheme: string;
52
81
  transformers: ShikiTransformer[];
82
+ removeComments: boolean | string[];
53
83
  postprocess?: (pre: HTMLPreElement) => void;
54
84
  };
55
85
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "do11y",
3
- "version": "0.2.11",
3
+ "version": "0.2.12",
4
4
  "description": "A bare-bones tool to document Vue components.",
5
5
  "keywords": [
6
6
  "docs-generator",