do11y 0.2.11 → 0.2.13
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
|
|
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
|
|
package/dist/docs/options.js
CHANGED
|
@@ -14,6 +14,7 @@ export const highlightCode = (code, lang) => {
|
|
|
14
14
|
lang,
|
|
15
15
|
themes: do11yOptions.highlighter.themesInput,
|
|
16
16
|
defaultColor: do11yOptions.highlighter.defaultTheme,
|
|
17
|
+
includeExplanation: true,
|
|
17
18
|
transformers: [
|
|
18
19
|
transformerNotationHighlight(),
|
|
19
20
|
transformerNotationDiff(),
|
|
@@ -30,6 +31,52 @@ export const highlightCode = (code, lang) => {
|
|
|
30
31
|
}
|
|
31
32
|
},
|
|
32
33
|
},
|
|
34
|
+
{
|
|
35
|
+
name: "remove-unwanted-comments",
|
|
36
|
+
tokens(tokens) {
|
|
37
|
+
const filter = do11yOptions.highlighter.removeComments;
|
|
38
|
+
if (filter === false) {
|
|
39
|
+
return tokens;
|
|
40
|
+
}
|
|
41
|
+
const result = [];
|
|
42
|
+
let previousLineWasRemoved = false;
|
|
43
|
+
for (const line of tokens) {
|
|
44
|
+
previousLineWasRemoved = false;
|
|
45
|
+
const filteredLine = [];
|
|
46
|
+
let hasComment = false;
|
|
47
|
+
for (const token of line) {
|
|
48
|
+
const isUnwantedComment = token.explanation?.some((exp) => {
|
|
49
|
+
const isComment = exp.scopes.some((s) => s.scopeName.startsWith("comment"));
|
|
50
|
+
if (!isComment) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
return typeof filter === "boolean"
|
|
54
|
+
? true
|
|
55
|
+
: filter.some((query) => exp.content.includes(query));
|
|
56
|
+
});
|
|
57
|
+
if (isUnwantedComment) {
|
|
58
|
+
hasComment = true;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
filteredLine.push(token);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Remove lines that become empty after removing comments.
|
|
66
|
+
* Additionally, if the next line after a removed comment line is empty too - remove it.
|
|
67
|
+
*/
|
|
68
|
+
if (hasComment || previousLineWasRemoved) {
|
|
69
|
+
const isAllWhitespace = filteredLine.every((token) => !token.content.trim());
|
|
70
|
+
previousLineWasRemoved = isAllWhitespace;
|
|
71
|
+
if (isAllWhitespace) {
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
result.push(filteredLine);
|
|
76
|
+
}
|
|
77
|
+
return result;
|
|
78
|
+
},
|
|
79
|
+
},
|
|
33
80
|
],
|
|
34
81
|
});
|
|
35
82
|
};
|
|
@@ -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
|
}
|