@shikijs/transformers 1.0.0-beta.2 → 1.0.0-beta.4
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/index.mjs +21 -4
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -332,16 +332,33 @@ function transformerMetaWordHighlight(options = {}) {
|
|
|
332
332
|
} = options;
|
|
333
333
|
return {
|
|
334
334
|
name: "@shikijs/transformers:meta-word-highlight",
|
|
335
|
-
|
|
335
|
+
preprocess(code, options2) {
|
|
336
336
|
if (!this.options.meta?.__raw)
|
|
337
337
|
return;
|
|
338
338
|
const words = parseMetaHighlightWords(this.options.meta.__raw);
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
339
|
+
options2.decorations || (options2.decorations = []);
|
|
340
|
+
for (const word of words) {
|
|
341
|
+
const indexes = findAllSubstringIndexes(code, word);
|
|
342
|
+
for (const index of indexes) {
|
|
343
|
+
options2.decorations.push({
|
|
344
|
+
start: index,
|
|
345
|
+
end: index + word.length,
|
|
346
|
+
properties: {
|
|
347
|
+
class: className
|
|
348
|
+
}
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
}
|
|
342
352
|
}
|
|
343
353
|
};
|
|
344
354
|
}
|
|
355
|
+
function findAllSubstringIndexes(str, substr) {
|
|
356
|
+
const indexes = [];
|
|
357
|
+
let i = -1;
|
|
358
|
+
while ((i = str.indexOf(substr, i + 1)) !== -1)
|
|
359
|
+
indexes.push(i);
|
|
360
|
+
return indexes;
|
|
361
|
+
}
|
|
345
362
|
|
|
346
363
|
function transformerNotationDiff(options = {}) {
|
|
347
364
|
const {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@shikijs/transformers",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.0-beta.
|
|
4
|
+
"version": "1.0.0-beta.4",
|
|
5
5
|
"description": "Collective of common transformers transformers for Shiki",
|
|
6
6
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"dist"
|
|
31
31
|
],
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"shiki": "1.0.0-beta.
|
|
33
|
+
"shiki": "1.0.0-beta.4"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
36
|
"build": "unbuild",
|