@shikijs/transformers 1.0.0-beta.1 → 1.0.0-beta.2
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 +10 -13
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import { addClassToHast } from 'shiki';
|
|
2
|
-
import { addClassToHast as addClassToHast$1 } from 'shiki/core';
|
|
3
|
-
|
|
4
1
|
function separateContinuousSpaces(inputs) {
|
|
5
2
|
const result = [];
|
|
6
3
|
let current = "";
|
|
@@ -102,7 +99,7 @@ function transformerRenderWhitespace(options = {}) {
|
|
|
102
99
|
};
|
|
103
100
|
clone.children = [{ type: "text", value: part }];
|
|
104
101
|
if (keys.includes(part)) {
|
|
105
|
-
addClassToHast(clone, classMap[part]);
|
|
102
|
+
this.addClassToHast(clone, classMap[part]);
|
|
106
103
|
delete clone.properties.style;
|
|
107
104
|
}
|
|
108
105
|
return clone;
|
|
@@ -129,7 +126,7 @@ function transformerCompactLineOptions(lineOptions = []) {
|
|
|
129
126
|
line(node, line) {
|
|
130
127
|
const lineOption = lineOptions.find((o) => o.line === line);
|
|
131
128
|
if (lineOption?.classes)
|
|
132
|
-
addClassToHast(node, lineOption.classes);
|
|
129
|
+
this.addClassToHast(node, lineOption.classes);
|
|
133
130
|
return node;
|
|
134
131
|
}
|
|
135
132
|
};
|
|
@@ -192,10 +189,10 @@ function transformerNotationMap(options = {}, name = "@shikijs/transformers:nota
|
|
|
192
189
|
function([_, match, range = ":1"], _line, _comment, lines, index) {
|
|
193
190
|
const lineNum = Number.parseInt(range.slice(1), 10);
|
|
194
191
|
lines.slice(index, index + lineNum).forEach((line) => {
|
|
195
|
-
addClassToHast(line, classMap[match]);
|
|
192
|
+
this.addClassToHast(line, classMap[match]);
|
|
196
193
|
});
|
|
197
194
|
if (classActivePre)
|
|
198
|
-
addClassToHast(this.pre, classActivePre);
|
|
195
|
+
this.addClassToHast(this.pre, classActivePre);
|
|
199
196
|
return true;
|
|
200
197
|
}
|
|
201
198
|
);
|
|
@@ -238,7 +235,7 @@ function highlightWordInLine(line, ignoredElement, word, className) {
|
|
|
238
235
|
const content = getTextContent(line);
|
|
239
236
|
let index = content.indexOf(word);
|
|
240
237
|
while (index !== -1) {
|
|
241
|
-
highlightRange(line.children, ignoredElement, index, word.length, className);
|
|
238
|
+
highlightRange.call(this, line.children, ignoredElement, index, word.length, className);
|
|
242
239
|
index = content.indexOf(word, index + 1);
|
|
243
240
|
}
|
|
244
241
|
}
|
|
@@ -264,7 +261,7 @@ function highlightRange(elements, ignoredElement, index, len, className) {
|
|
|
264
261
|
if (length === 0)
|
|
265
262
|
continue;
|
|
266
263
|
const separated = separateToken(element, textNode, start, length);
|
|
267
|
-
addClassToHast
|
|
264
|
+
this.addClassToHast(separated[1], className);
|
|
268
265
|
const output = separated.filter(Boolean);
|
|
269
266
|
elements.splice(i, 1, ...output);
|
|
270
267
|
i += output.length - 1;
|
|
@@ -313,9 +310,9 @@ function transformerNotationWordHighlight(options = {}) {
|
|
|
313
310
|
function([_, word, range], _line, comment, lines, index) {
|
|
314
311
|
const lineNum = range ? Number.parseInt(range.slice(1), 10) : lines.length;
|
|
315
312
|
word = word.replace(/\\(.)/g, "$1");
|
|
316
|
-
lines.slice(index + 1, index + 1 + lineNum).forEach((line) => highlightWordInLine(line, comment, word, classActiveWord));
|
|
313
|
+
lines.slice(index + 1, index + 1 + lineNum).forEach((line) => highlightWordInLine.call(this, line, comment, word, classActiveWord));
|
|
317
314
|
if (classActivePre)
|
|
318
|
-
addClassToHast(this.pre, classActivePre);
|
|
315
|
+
this.addClassToHast(this.pre, classActivePre);
|
|
319
316
|
return true;
|
|
320
317
|
},
|
|
321
318
|
true
|
|
@@ -340,7 +337,7 @@ function transformerMetaWordHighlight(options = {}) {
|
|
|
340
337
|
return;
|
|
341
338
|
const words = parseMetaHighlightWords(this.options.meta.__raw);
|
|
342
339
|
for (const word of words)
|
|
343
|
-
highlightWordInLine(node, null, word, className);
|
|
340
|
+
highlightWordInLine.call(this, node, null, word, className);
|
|
344
341
|
return node;
|
|
345
342
|
}
|
|
346
343
|
};
|
|
@@ -410,7 +407,7 @@ function transformerMetaHighlight(options = {}) {
|
|
|
410
407
|
(_a = this.meta)[symbol] || (_a[symbol] = parseMetaHighlightString(this.options.meta.__raw));
|
|
411
408
|
const lines = this.meta[symbol] || [];
|
|
412
409
|
if (lines.includes(line))
|
|
413
|
-
addClassToHast(node, className);
|
|
410
|
+
this.addClassToHast(node, className);
|
|
414
411
|
return node;
|
|
415
412
|
}
|
|
416
413
|
};
|
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.2",
|
|
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.2"
|
|
34
34
|
},
|
|
35
35
|
"scripts": {
|
|
36
36
|
"build": "unbuild",
|