@tamagui/code-to-html 2.7.7 → 3.0.0-beta.643.1
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/cjs/highlightLine.cjs +97 -105
- package/dist/cjs/highlightLine.native.cjs +129 -0
- package/dist/cjs/highlightLine.native.js +102 -109
- package/dist/cjs/highlightLine.native.js.map +1 -1
- package/dist/cjs/highlightWord.cjs +25 -33
- package/dist/cjs/highlightWord.native.cjs +47 -0
- package/dist/cjs/highlightWord.native.js +27 -34
- package/dist/cjs/highlightWord.native.js.map +1 -1
- package/dist/cjs/index.cjs +25 -33
- package/dist/cjs/index.native.cjs +49 -0
- package/dist/cjs/index.native.js +26 -33
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/esm/highlightLine.mjs +81 -79
- package/dist/esm/highlightLine.mjs.map +1 -1
- package/dist/esm/highlightLine.native.js +86 -84
- package/dist/esm/highlightLine.native.js.map +1 -1
- package/dist/esm/highlightWord.mjs +9 -7
- package/dist/esm/highlightWord.mjs.map +1 -1
- package/dist/esm/highlightWord.native.js +11 -9
- package/dist/esm/highlightWord.native.js.map +1 -1
- package/dist/esm/index.mjs +9 -7
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/index.native.js +10 -8
- package/dist/esm/index.native.js.map +1 -1
- package/package.json +13 -4
- package/src/index.ts +2 -2
- package/dist/esm/index.js +0 -18
- package/dist/esm/index.js.map +0 -1
|
@@ -1,94 +1,96 @@
|
|
|
1
1
|
import { toHtml } from "hast-util-to-html";
|
|
2
2
|
import parse from "rehype-parse";
|
|
3
3
|
import { unified } from "unified";
|
|
4
|
+
|
|
4
5
|
const lineNumberify = function lineNumberify2(ast, lineNum = 1) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
6
|
+
let lineNumber = lineNum;
|
|
7
|
+
return ast.reduce((result, node) => {
|
|
8
|
+
if (node.type === "text") {
|
|
9
|
+
if (node.value.indexOf("\n") === -1) {
|
|
10
|
+
node.lineNumber = lineNumber;
|
|
11
|
+
result.nodes.push(node);
|
|
12
|
+
return result;
|
|
13
|
+
}
|
|
14
|
+
const lines = node.value.split("\n");
|
|
15
|
+
for (let i = 0; i < lines.length; i++) {
|
|
16
|
+
if (i !== 0) ++lineNumber;
|
|
17
|
+
if (i === lines.length - 1 && lines[i].length === 0) continue;
|
|
18
|
+
result.nodes.push({
|
|
19
|
+
type: "text",
|
|
20
|
+
value: i === lines.length - 1 ? lines[i] : `${lines[i]}
|
|
20
21
|
`,
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
22
|
+
lineNumber
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
result.lineNumber = lineNumber;
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
if (node.children) {
|
|
29
|
+
node.lineNumber = lineNumber;
|
|
30
|
+
const processed = lineNumberify2(node.children, lineNumber);
|
|
31
|
+
node.children = processed.nodes;
|
|
32
|
+
result.lineNumber = processed.lineNumber;
|
|
33
|
+
result.nodes.push(node);
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
36
|
+
result.nodes.push(node);
|
|
37
|
+
return result;
|
|
38
|
+
}, {
|
|
39
|
+
nodes: [],
|
|
40
|
+
lineNumber
|
|
41
|
+
});
|
|
41
42
|
};
|
|
42
43
|
const wrapLines = function wrapLines2(ast, linesToHighlight) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
44
|
+
const highlightAll = linesToHighlight.length === 1 && linesToHighlight[0] === 0;
|
|
45
|
+
const allLines = Array.from(new Set(ast.map((x) => x.lineNumber)));
|
|
46
|
+
let i = 0;
|
|
47
|
+
const wrapped = allLines.reduce((nodes, marker) => {
|
|
48
|
+
const line = marker;
|
|
49
|
+
const children = [];
|
|
50
|
+
for (; i < ast.length; i++) {
|
|
51
|
+
if (ast[i].lineNumber < line) {
|
|
52
|
+
nodes.push(ast[i]);
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
if (ast[i].lineNumber === line) {
|
|
56
|
+
children.push(ast[i]);
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
if (ast[i].lineNumber > line) {
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
nodes.push({
|
|
64
|
+
type: "element",
|
|
65
|
+
tagName: "div",
|
|
66
|
+
properties: {
|
|
67
|
+
dataLine: line,
|
|
68
|
+
className: "highlight-line",
|
|
69
|
+
dataHighlighted: linesToHighlight.includes(line) || highlightAll ? "true" : "false"
|
|
70
|
+
},
|
|
71
|
+
children,
|
|
72
|
+
lineNumber: line
|
|
73
|
+
});
|
|
74
|
+
return nodes;
|
|
75
|
+
}, []);
|
|
76
|
+
return wrapped;
|
|
76
77
|
};
|
|
77
78
|
const MULTILINE_TOKEN_SPAN = /<span class="token ([^"]+)">[^<]*\n[^<]*<\/span>/g;
|
|
78
|
-
const applyMultilineFix = ast => {
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
const applyMultilineFix = (ast) => {
|
|
80
|
+
let html = toHtml(ast);
|
|
81
|
+
html = html.replace(MULTILINE_TOKEN_SPAN, (match, token) => match.replace(/\n/g, `</span>
|
|
81
82
|
<span class="token ${token}">`));
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
83
|
+
const hast = unified().use(parse, {
|
|
84
|
+
emitParseErrors: true,
|
|
85
|
+
fragment: true
|
|
86
|
+
}).parse(html);
|
|
87
|
+
return hast["children"];
|
|
87
88
|
};
|
|
88
89
|
function highlightLine(ast, lines) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
90
|
+
const formattedAst = applyMultilineFix(ast);
|
|
91
|
+
const numbered = lineNumberify(formattedAst).nodes;
|
|
92
|
+
return wrapLines(numbered, lines);
|
|
92
93
|
}
|
|
94
|
+
|
|
93
95
|
export { highlightLine };
|
|
94
96
|
//# sourceMappingURL=highlightLine.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"highlightLine.js","names":[],"sources":["esm/highlightLine.js"],"sourcesContent":["import { toHtml } from \"hast-util-to-html\";\nimport parse from \"rehype-parse\";\nimport { unified } from \"unified\";\nconst lineNumberify = function lineNumberify2(ast, lineNum = 1) {\n let lineNumber = lineNum;\n return ast.reduce(\n (result, node) => {\n if (node.type === \"text\") {\n if (node.value.indexOf(\"\\n\") === -1) {\n node.lineNumber = lineNumber;\n result.nodes.push(node);\n return result;\n }\n const lines = node.value.split(\"\\n\");\n for (let i = 0; i < lines.length; i++) {\n if (i !== 0) ++lineNumber;\n if (i === lines.length - 1 && lines[i].length === 0) continue;\n result.nodes.push({\n type: \"text\",\n value: i === lines.length - 1 ? lines[i] : `${lines[i]}\n`,\n lineNumber\n });\n }\n result.lineNumber = lineNumber;\n return result;\n }\n if (node.children) {\n node.lineNumber = lineNumber;\n const processed = lineNumberify2(node.children, lineNumber);\n node.children = processed.nodes;\n result.lineNumber = processed.lineNumber;\n result.nodes.push(node);\n return result;\n }\n result.nodes.push(node);\n return result;\n },\n { nodes: [], lineNumber }\n );\n};\nconst wrapLines = function wrapLines2(ast, linesToHighlight) {\n const highlightAll = linesToHighlight.length === 1 && linesToHighlight[0] === 0;\n const allLines = Array.from(new Set(ast.map((x) => x.lineNumber)));\n let i = 0;\n const wrapped = allLines.reduce((nodes, marker) => {\n const line = marker;\n const children = [];\n for (; i < ast.length; i++) {\n if (ast[i].lineNumber < line) {\n nodes.push(ast[i]);\n continue;\n }\n if (ast[i].lineNumber === line) {\n children.push(ast[i]);\n continue;\n }\n if (ast[i].lineNumber > line) {\n break;\n }\n }\n nodes.push({\n type: \"element\",\n tagName: \"div\",\n properties: {\n dataLine: line,\n className: \"highlight-line\",\n dataHighlighted: linesToHighlight.includes(line) || highlightAll ? \"true\" : \"false\"\n },\n children,\n lineNumber: line\n });\n return nodes;\n }, []);\n return wrapped;\n};\nconst MULTILINE_TOKEN_SPAN = /<span class=\"token ([^\"]+)\">[^<]*\\n[^<]*<\\/span>/g;\nconst applyMultilineFix = (ast) => {\n let html = toHtml(ast);\n html = html.replace(\n MULTILINE_TOKEN_SPAN,\n (match, token) => match.replace(/\\n/g, `</span>\n<span class=\"token ${token}\">`)\n );\n const hast = unified().use(parse, { emitParseErrors: true, fragment: true }).parse(html);\n return hast[\"children\"];\n};\nfunction highlightLine(ast, lines) {\n const formattedAst = applyMultilineFix(ast);\n const numbered = lineNumberify(formattedAst).nodes;\n return wrapLines(numbered, lines);\n}\nexport {\n highlightLine\n};\n//# sourceMappingURL=highlightLine.js.map\n"],"mappings":";;;;;AAGA,MAAM,gBAAgB,SAAS,eAAe,KAAK,UAAU,GAAG;CAC9D,IAAI,aAAa;CACjB,OAAO,IAAI,QACR,QAAQ,SAAS;EAChB,IAAI,KAAK,SAAS,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AI,IAAI,GAAG,aAAa,MAAM;IAC5B;GACF;EACF;EACA,MAAM,KAAK;GACT,MAAM;GACN,SAAS;GACT,YAAY;IACV,UAAU;IACV,WAAW;IACX,iBAAiB,iBAAiB,SAAS,IAAI,KAAK,eAAe,SAAS;GAC9E;GACA;GACA,YAAY;EACd,CAAC;EACD,OAAO;CACT,GAAG,CAAC,CAAC;CACL,OAAO;AACT;AACA,MAAM,uBAAuB;AAC7B,MAAM,qBAAqB,QAAQ;CACjC,IAAI,OAAO,OAAO,GAAG;CACrB,OAAO,KAAK,QACV,uBACC,OAAO,UAAU,MAAM,QAAQ,OAAO;qBACtB,MAAM,GAAG,CAC5B;CACA,MAAM,OAAO,QAAQ,EAAE,IAAI,OAAO;EAAE,iBAAiB;EAAM,UAAU;CAAK,CAAC,EAAE,MAAM,IAAI;CACvF,OAAO,KAAK;AACd;AACA,SAAS,cAAc,KAAK,OAAO;CACjC,MAAM,eAAe,kBAAkB,GAAG;CAC1C,MAAM,WAAW,cAAc,YAAY,EAAE;CAC7C,OAAO,UAAU,UAAU,KAAK;AAClC"}
|
|
@@ -1,99 +1,101 @@
|
|
|
1
1
|
import { toHtml } from "hast-util-to-html";
|
|
2
2
|
import parse from "rehype-parse";
|
|
3
3
|
import { unified } from "unified";
|
|
4
|
+
|
|
4
5
|
var lineNumberify = function lineNumberify2(ast) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
6
|
+
var lineNum = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 1;
|
|
7
|
+
var lineNumber = lineNum;
|
|
8
|
+
return ast.reduce(function(result, node) {
|
|
9
|
+
if (node.type === "text") {
|
|
10
|
+
if (node.value.indexOf("\n") === -1) {
|
|
11
|
+
node.lineNumber = lineNumber;
|
|
12
|
+
result.nodes.push(node);
|
|
13
|
+
return result;
|
|
14
|
+
}
|
|
15
|
+
var lines = node.value.split("\n");
|
|
16
|
+
for (var i = 0; i < lines.length; i++) {
|
|
17
|
+
if (i !== 0) ++lineNumber;
|
|
18
|
+
if (i === lines.length - 1 && lines[i].length === 0) continue;
|
|
19
|
+
result.nodes.push({
|
|
20
|
+
type: "text",
|
|
21
|
+
value: i === lines.length - 1 ? lines[i] : `${lines[i]}
|
|
21
22
|
`,
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
23
|
+
lineNumber
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
result.lineNumber = lineNumber;
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
29
|
+
if (node.children) {
|
|
30
|
+
node.lineNumber = lineNumber;
|
|
31
|
+
var processed = lineNumberify2(node.children, lineNumber);
|
|
32
|
+
node.children = processed.nodes;
|
|
33
|
+
result.lineNumber = processed.lineNumber;
|
|
34
|
+
result.nodes.push(node);
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
37
|
+
result.nodes.push(node);
|
|
38
|
+
return result;
|
|
39
|
+
}, {
|
|
40
|
+
nodes: [],
|
|
41
|
+
lineNumber
|
|
42
|
+
});
|
|
42
43
|
};
|
|
43
44
|
var wrapLines = function wrapLines2(ast, linesToHighlight) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
45
|
+
var highlightAll = linesToHighlight.length === 1 && linesToHighlight[0] === 0;
|
|
46
|
+
var allLines = Array.from(new Set(ast.map(function(x) {
|
|
47
|
+
return x.lineNumber;
|
|
48
|
+
})));
|
|
49
|
+
var i = 0;
|
|
50
|
+
var wrapped = allLines.reduce(function(nodes, marker) {
|
|
51
|
+
var line = marker;
|
|
52
|
+
var children = [];
|
|
53
|
+
for (; i < ast.length; i++) {
|
|
54
|
+
if (ast[i].lineNumber < line) {
|
|
55
|
+
nodes.push(ast[i]);
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
if (ast[i].lineNumber === line) {
|
|
59
|
+
children.push(ast[i]);
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if (ast[i].lineNumber > line) {
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
nodes.push({
|
|
67
|
+
type: "element",
|
|
68
|
+
tagName: "div",
|
|
69
|
+
properties: {
|
|
70
|
+
dataLine: line,
|
|
71
|
+
className: "highlight-line",
|
|
72
|
+
dataHighlighted: linesToHighlight.includes(line) || highlightAll ? "true" : "false"
|
|
73
|
+
},
|
|
74
|
+
children,
|
|
75
|
+
lineNumber: line
|
|
76
|
+
});
|
|
77
|
+
return nodes;
|
|
78
|
+
}, []);
|
|
79
|
+
return wrapped;
|
|
79
80
|
};
|
|
80
81
|
var MULTILINE_TOKEN_SPAN = /<span class="token ([^"]+)">[^<]*\n[^<]*<\/span>/g;
|
|
81
|
-
var applyMultilineFix = function
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
82
|
+
var applyMultilineFix = function(ast) {
|
|
83
|
+
var html = toHtml(ast);
|
|
84
|
+
html = html.replace(MULTILINE_TOKEN_SPAN, function(match, token) {
|
|
85
|
+
return match.replace(/\n/g, `</span>
|
|
85
86
|
<span class="token ${token}">`);
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
87
|
+
});
|
|
88
|
+
var hast = unified().use(parse, {
|
|
89
|
+
emitParseErrors: true,
|
|
90
|
+
fragment: true
|
|
91
|
+
}).parse(html);
|
|
92
|
+
return hast["children"];
|
|
92
93
|
};
|
|
93
94
|
function highlightLine(ast, lines) {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
95
|
+
var formattedAst = applyMultilineFix(ast);
|
|
96
|
+
var numbered = lineNumberify(formattedAst).nodes;
|
|
97
|
+
return wrapLines(numbered, lines);
|
|
97
98
|
}
|
|
99
|
+
|
|
98
100
|
export { highlightLine };
|
|
99
101
|
//# sourceMappingURL=highlightLine.native.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"highlightLine.native.js","names":[],"sources":["esm/highlightLine.native.js"],"sourcesContent":["import { toHtml } from \"hast-util-to-html\";\nimport parse from \"rehype-parse\";\nimport { unified } from \"unified\";\nvar lineNumberify = function lineNumberify2(ast) {\n var lineNum = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 1;\n var lineNumber = lineNum;\n return ast.reduce(function(result, node) {\n if (node.type === \"text\") {\n if (node.value.indexOf(\"\\n\") === -1) {\n node.lineNumber = lineNumber;\n result.nodes.push(node);\n return result;\n }\n var lines = node.value.split(\"\\n\");\n for (var i = 0; i < lines.length; i++) {\n if (i !== 0) ++lineNumber;\n if (i === lines.length - 1 && lines[i].length === 0) continue;\n result.nodes.push({\n type: \"text\",\n value: i === lines.length - 1 ? lines[i] : `${lines[i]}\n`,\n lineNumber\n });\n }\n result.lineNumber = lineNumber;\n return result;\n }\n if (node.children) {\n node.lineNumber = lineNumber;\n var processed = lineNumberify2(node.children, lineNumber);\n node.children = processed.nodes;\n result.lineNumber = processed.lineNumber;\n result.nodes.push(node);\n return result;\n }\n result.nodes.push(node);\n return result;\n }, {\n nodes: [],\n lineNumber\n });\n};\nvar wrapLines = function wrapLines2(ast, linesToHighlight) {\n var highlightAll = linesToHighlight.length === 1 && linesToHighlight[0] === 0;\n var allLines = Array.from(new Set(ast.map(function(x) {\n return x.lineNumber;\n })));\n var i = 0;\n var wrapped = allLines.reduce(function(nodes, marker) {\n var line = marker;\n var children = [];\n for (; i < ast.length; i++) {\n if (ast[i].lineNumber < line) {\n nodes.push(ast[i]);\n continue;\n }\n if (ast[i].lineNumber === line) {\n children.push(ast[i]);\n continue;\n }\n if (ast[i].lineNumber > line) {\n break;\n }\n }\n nodes.push({\n type: \"element\",\n tagName: \"div\",\n properties: {\n dataLine: line,\n className: \"highlight-line\",\n dataHighlighted: linesToHighlight.includes(line) || highlightAll ? \"true\" : \"false\"\n },\n children,\n lineNumber: line\n });\n return nodes;\n }, []);\n return wrapped;\n};\nvar MULTILINE_TOKEN_SPAN = /<span class=\"token ([^\"]+)\">[^<]*\\n[^<]*<\\/span>/g;\nvar applyMultilineFix = function(ast) {\n var html = toHtml(ast);\n html = html.replace(MULTILINE_TOKEN_SPAN, function(match, token) {\n return match.replace(/\\n/g, `</span>\n<span class=\"token ${token}\">`);\n });\n var hast = unified().use(parse, {\n emitParseErrors: true,\n fragment: true\n }).parse(html);\n return hast[\"children\"];\n};\nfunction highlightLine(ast, lines) {\n var formattedAst = applyMultilineFix(ast);\n var numbered = lineNumberify(formattedAst).nodes;\n return wrapLines(numbered, lines);\n}\nexport {\n highlightLine\n};\n//# sourceMappingURL=highlightLine.js.map\n"],"mappings":";;;;;AAGA,IAAI,gBAAgB,SAAS,eAAe,KAAK;CAC/C,IAAI,UAAU,UAAU,SAAS,KAAK,UAAU,OAAO,KAAK,IAAI,UAAU,KAAK;CAC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AI,EAAE;IACjB;GACF;GACA,IAAI,IAAI,GAAG,eAAe,MAAM;IAC9B,SAAS,KAAK,IAAI,EAAE;IACpB;GACF;GACA,IAAI,IAAI,GAAG,aAAa,MAAM;IAC5B;GACF;EACF;EACA,MAAM,KAAK;GACT,MAAM;GACN,SAAS;GACT,YAAY;IACV,UAAU;IACV,WAAW;IACX,iBAAiB,iBAAiB,SAAS,IAAI,KAAK,eAAe,SAAS;GAC9E;GACA;GACA,YAAY;EACd,CAAC;EACD,OAAO;CACT,GAAG,CAAC,CAAC;CACL,OAAO;AACT;AACA,IAAI,uBAAuB;AAC3B,IAAI,oBAAoB,SAAS,KAAK;CACpC,IAAI,OAAO,OAAO,GAAG;CACrB,OAAO,KAAK,QAAQ,sBAAsB,SAAS,OAAO,OAAO;EAC/D,OAAO,MAAM,QAAQ,OAAO;qBACX,MAAM,GAAG;CAC5B,CAAC;CACD,IAAI,OAAO,QAAQ,EAAE,IAAI,OAAO;EAC9B,iBAAiB;EACjB,UAAU;CACZ,CAAC,EAAE,MAAM,IAAI;CACb,OAAO,KAAK;AACd;AACA,SAAS,cAAc,KAAK,OAAO;CACjC,IAAI,eAAe,kBAAkB,GAAG;CACxC,IAAI,WAAW,cAAc,YAAY,EAAE;CAC3C,OAAO,UAAU,UAAU,KAAK;AAClC"}
|
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import { toHtml } from "hast-util-to-html";
|
|
2
2
|
import parse from "rehype-parse";
|
|
3
3
|
import { unified } from "unified";
|
|
4
|
+
|
|
4
5
|
const CALLOUT = /__(.*?)__/g;
|
|
5
6
|
function highlightWord(code) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
const html = toHtml(code);
|
|
8
|
+
const result = html.replace(CALLOUT, (_, text) => `<span class="highlight-word">${text}</span>`);
|
|
9
|
+
const hast = unified().use(parse, {
|
|
10
|
+
emitParseErrors: true,
|
|
11
|
+
fragment: true
|
|
12
|
+
}).parse(result);
|
|
13
|
+
return hast["children"];
|
|
13
14
|
}
|
|
15
|
+
|
|
14
16
|
export { highlightWord };
|
|
15
17
|
//# sourceMappingURL=highlightWord.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"highlightWord.js","names":[],"sources":["esm/highlightWord.js"],"sourcesContent":["import { toHtml } from \"hast-util-to-html\";\nimport parse from \"rehype-parse\";\nimport { unified } from \"unified\";\nconst CALLOUT = /__(.*?)__/g;\nfunction highlightWord(code) {\n const html = toHtml(code);\n const result = html.replace(\n CALLOUT,\n (_, text) => `<span class=\"highlight-word\">${text}</span>`\n );\n const hast = unified().use(parse, { emitParseErrors: true, fragment: true }).parse(result);\n return hast[\"children\"];\n}\nexport {\n highlightWord\n};\n//# sourceMappingURL=highlightWord.js.map\n"],"mappings":";;;;;AAGA,MAAM,UAAU;AAChB,SAAS,cAAc,MAAM;CAC3B,MAAM,OAAO,OAAO,IAAI;CACxB,MAAM,SAAS,KAAK,QAClB,UACC,GAAG,SAAS,gCAAgC,KAAK,QACpD;CACA,MAAM,OAAO,QAAQ,EAAE,IAAI,OAAO;EAAE,iBAAiB;EAAM,UAAU;CAAK,CAAC,EAAE,MAAM,MAAM;CACzF,OAAO,KAAK;AACd"}
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import { toHtml } from "hast-util-to-html";
|
|
2
2
|
import parse from "rehype-parse";
|
|
3
3
|
import { unified } from "unified";
|
|
4
|
+
|
|
4
5
|
var CALLOUT = /__(.*?)__/g;
|
|
5
6
|
function highlightWord(code) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
7
|
+
var html = toHtml(code);
|
|
8
|
+
var result = html.replace(CALLOUT, function(_, text) {
|
|
9
|
+
return `<span class="highlight-word">${text}</span>`;
|
|
10
|
+
});
|
|
11
|
+
var hast = unified().use(parse, {
|
|
12
|
+
emitParseErrors: true,
|
|
13
|
+
fragment: true
|
|
14
|
+
}).parse(result);
|
|
15
|
+
return hast["children"];
|
|
15
16
|
}
|
|
17
|
+
|
|
16
18
|
export { highlightWord };
|
|
17
19
|
//# sourceMappingURL=highlightWord.native.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"highlightWord.native.js","names":[],"sources":["esm/highlightWord.native.js"],"sourcesContent":["import { toHtml } from \"hast-util-to-html\";\nimport parse from \"rehype-parse\";\nimport { unified } from \"unified\";\nvar CALLOUT = /__(.*?)__/g;\nfunction highlightWord(code) {\n var html = toHtml(code);\n var result = html.replace(CALLOUT, function(_, text) {\n return `<span class=\"highlight-word\">${text}</span>`;\n });\n var hast = unified().use(parse, {\n emitParseErrors: true,\n fragment: true\n }).parse(result);\n return hast[\"children\"];\n}\nexport {\n highlightWord\n};\n//# sourceMappingURL=highlightWord.js.map\n"],"mappings":";;;;;AAGA,IAAI,UAAU;AACd,SAAS,cAAc,MAAM;CAC3B,IAAI,OAAO,OAAO,IAAI;CACtB,IAAI,SAAS,KAAK,QAAQ,SAAS,SAAS,GAAG,MAAM;EACnD,OAAO,gCAAgC,KAAK;CAC9C,CAAC;CACD,IAAI,OAAO,QAAQ,EAAE,IAAI,OAAO;EAC9B,iBAAiB;EACjB,UAAU;CACZ,CAAC,EAAE,MAAM,MAAM;CACf,OAAO,KAAK;AACd"}
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
import { toHtml } from "hast-util-to-html";
|
|
2
2
|
import rangeParser from "parse-numeric-range";
|
|
3
3
|
import { refractor } from "refractor";
|
|
4
|
-
import css from "refractor/lang/css";
|
|
5
|
-
import tsx from "refractor/lang/tsx";
|
|
4
|
+
import css from "refractor/lang/css.js";
|
|
5
|
+
import tsx from "refractor/lang/tsx.js";
|
|
6
6
|
import { highlightLine } from "./highlightLine.mjs";
|
|
7
7
|
import { highlightWord } from "./highlightWord.mjs";
|
|
8
|
+
|
|
8
9
|
refractor.register(tsx);
|
|
9
10
|
refractor.register(css);
|
|
10
11
|
function codeToHTML(source, language, line = "0") {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
let result = refractor.highlight(source, language);
|
|
13
|
+
result = highlightLine(result, rangeParser(line));
|
|
14
|
+
result = highlightWord(result);
|
|
15
|
+
result = toHtml(result);
|
|
16
|
+
return result;
|
|
16
17
|
}
|
|
18
|
+
|
|
17
19
|
export { codeToHTML };
|
|
18
20
|
//# sourceMappingURL=index.mjs.map
|
package/dist/esm/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["esm/index.js"],"sourcesContent":["import { toHtml } from \"hast-util-to-html\";\nimport rangeParser from \"parse-numeric-range\";\nimport { refractor } from \"refractor\";\nimport css from \"refractor/lang/css.js\";\nimport tsx from \"refractor/lang/tsx.js\";\nimport { highlightLine } from \"./highlightLine\";\nimport { highlightWord } from \"./highlightWord\";\nrefractor.register(tsx);\nrefractor.register(css);\nfunction codeToHTML(source, language, line = \"0\") {\n let result = refractor.highlight(source, language);\n result = highlightLine(result, rangeParser(line));\n result = highlightWord(result);\n result = toHtml(result);\n return result;\n}\nexport {\n codeToHTML\n};\n//# sourceMappingURL=index.js.map\n"],"mappings":";;;;;;;;;AAOA,UAAU,SAAS,GAAG;AACtB,UAAU,SAAS,GAAG;AACtB,SAAS,WAAW,QAAQ,UAAU,OAAO,KAAK;CAChD,IAAI,SAAS,UAAU,UAAU,QAAQ,QAAQ;CACjD,SAAS,cAAc,QAAQ,YAAY,IAAI,CAAC;CAChD,SAAS,cAAc,MAAM;CAC7B,SAAS,OAAO,MAAM;CACtB,OAAO;AACT"}
|
package/dist/esm/index.native.js
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
import { toHtml } from "hast-util-to-html";
|
|
2
2
|
import rangeParser from "parse-numeric-range";
|
|
3
3
|
import { refractor } from "refractor";
|
|
4
|
-
import css from "refractor/lang/css";
|
|
5
|
-
import tsx from "refractor/lang/tsx";
|
|
4
|
+
import css from "refractor/lang/css.js";
|
|
5
|
+
import tsx from "refractor/lang/tsx.js";
|
|
6
6
|
import { highlightLine } from "./highlightLine.native.js";
|
|
7
7
|
import { highlightWord } from "./highlightWord.native.js";
|
|
8
|
+
|
|
8
9
|
refractor.register(tsx);
|
|
9
10
|
refractor.register(css);
|
|
10
11
|
function codeToHTML(source, language) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
var line = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : "0";
|
|
13
|
+
var result = refractor.highlight(source, language);
|
|
14
|
+
result = highlightLine(result, rangeParser(line));
|
|
15
|
+
result = highlightWord(result);
|
|
16
|
+
result = toHtml(result);
|
|
17
|
+
return result;
|
|
17
18
|
}
|
|
19
|
+
|
|
18
20
|
export { codeToHTML };
|
|
19
21
|
//# sourceMappingURL=index.native.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"file":"index.native.js","names":[],"sources":["esm/index.native.js"],"sourcesContent":["import { toHtml } from \"hast-util-to-html\";\nimport rangeParser from \"parse-numeric-range\";\nimport { refractor } from \"refractor\";\nimport css from \"refractor/lang/css.js\";\nimport tsx from \"refractor/lang/tsx.js\";\nimport { highlightLine } from \"./highlightLine\";\nimport { highlightWord } from \"./highlightWord\";\nrefractor.register(tsx);\nrefractor.register(css);\nfunction codeToHTML(source, language) {\n var line = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : \"0\";\n var result = refractor.highlight(source, language);\n result = highlightLine(result, rangeParser(line));\n result = highlightWord(result);\n result = toHtml(result);\n return result;\n}\nexport {\n codeToHTML\n};\n//# sourceMappingURL=index.js.map\n"],"mappings":";;;;;;;;;AAOA,UAAU,SAAS,GAAG;AACtB,UAAU,SAAS,GAAG;AACtB,SAAS,WAAW,QAAQ,UAAU;CACpC,IAAI,OAAO,UAAU,SAAS,KAAK,UAAU,OAAO,KAAK,IAAI,UAAU,KAAK;CAC5E,IAAI,SAAS,UAAU,UAAU,QAAQ,QAAQ;CACjD,SAAS,cAAc,QAAQ,YAAY,IAAI,CAAC;CAChD,SAAS,cAAc,MAAM;CAC7B,SAAS,OAAO,MAAM;CACtB,OAAO;AACT"}
|