@tamagui/code-to-html 1.0.1-beta.151 → 1.0.1-beta.152
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.js +40 -31
- package/dist/cjs/highlightLine.js.map +2 -2
- package/dist/cjs/highlightWord.js +4 -1
- package/dist/cjs/highlightWord.js.map +2 -2
- package/dist/cjs/index.js +40 -31
- package/dist/cjs/index.js.map +2 -2
- package/dist/esm/highlightLine.js +190 -111
- package/dist/esm/highlightLine.js.map +3 -3
- package/dist/esm/highlightWord.js +154 -81
- package/dist/esm/highlightWord.js.map +3 -3
- package/dist/esm/index.js +556 -246
- package/dist/esm/index.js.map +3 -3
- package/package.json +2 -2
|
@@ -17,7 +17,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
}
|
|
18
18
|
return to;
|
|
19
19
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
21
24
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
25
|
|
|
23
26
|
// src/highlightLine.ts
|
|
@@ -31,40 +34,43 @@ var import_rehype_parse = __toESM(require("rehype-parse"));
|
|
|
31
34
|
var import_unified = require("unified");
|
|
32
35
|
var lineNumberify = function lineNumberify2(ast, lineNum = 1) {
|
|
33
36
|
let lineNumber = lineNum;
|
|
34
|
-
return ast.reduce(
|
|
35
|
-
|
|
36
|
-
if (node.
|
|
37
|
+
return ast.reduce(
|
|
38
|
+
(result, node) => {
|
|
39
|
+
if (node.type === "text") {
|
|
40
|
+
if (node.value.indexOf("\n") === -1) {
|
|
41
|
+
node.lineNumber = lineNumber;
|
|
42
|
+
result.nodes.push(node);
|
|
43
|
+
return result;
|
|
44
|
+
}
|
|
45
|
+
const lines = node.value.split("\n");
|
|
46
|
+
for (let i = 0; i < lines.length; i++) {
|
|
47
|
+
if (i !== 0)
|
|
48
|
+
++lineNumber;
|
|
49
|
+
if (i === lines.length - 1 && lines[i].length === 0)
|
|
50
|
+
continue;
|
|
51
|
+
result.nodes.push({
|
|
52
|
+
type: "text",
|
|
53
|
+
value: i === lines.length - 1 ? lines[i] : `${lines[i]}
|
|
54
|
+
`,
|
|
55
|
+
lineNumber
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
result.lineNumber = lineNumber;
|
|
59
|
+
return result;
|
|
60
|
+
}
|
|
61
|
+
if (node.children) {
|
|
37
62
|
node.lineNumber = lineNumber;
|
|
63
|
+
const processed = lineNumberify2(node.children, lineNumber);
|
|
64
|
+
node.children = processed.nodes;
|
|
65
|
+
result.lineNumber = processed.lineNumber;
|
|
38
66
|
result.nodes.push(node);
|
|
39
67
|
return result;
|
|
40
68
|
}
|
|
41
|
-
const lines = node.value.split("\n");
|
|
42
|
-
for (let i = 0; i < lines.length; i++) {
|
|
43
|
-
if (i !== 0)
|
|
44
|
-
++lineNumber;
|
|
45
|
-
if (i === lines.length - 1 && lines[i].length === 0)
|
|
46
|
-
continue;
|
|
47
|
-
result.nodes.push({
|
|
48
|
-
type: "text",
|
|
49
|
-
value: i === lines.length - 1 ? lines[i] : `${lines[i]}
|
|
50
|
-
`,
|
|
51
|
-
lineNumber
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
result.lineNumber = lineNumber;
|
|
55
|
-
return result;
|
|
56
|
-
}
|
|
57
|
-
if (node.children) {
|
|
58
|
-
node.lineNumber = lineNumber;
|
|
59
|
-
const processed = lineNumberify2(node.children, lineNumber);
|
|
60
|
-
node.children = processed.nodes;
|
|
61
|
-
result.lineNumber = processed.lineNumber;
|
|
62
69
|
result.nodes.push(node);
|
|
63
70
|
return result;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}, { nodes: [], lineNumber });
|
|
71
|
+
},
|
|
72
|
+
{ nodes: [], lineNumber }
|
|
73
|
+
);
|
|
68
74
|
};
|
|
69
75
|
var wrapLines = function wrapLines2(ast, linesToHighlight) {
|
|
70
76
|
const highlightAll = linesToHighlight.length === 1 && linesToHighlight[0] === 0;
|
|
@@ -104,8 +110,11 @@ var wrapLines = function wrapLines2(ast, linesToHighlight) {
|
|
|
104
110
|
var MULTILINE_TOKEN_SPAN = /<span class="token ([^"]+)">[^<]*\n[^<]*<\/span>/g;
|
|
105
111
|
var applyMultilineFix = function(ast) {
|
|
106
112
|
let html = (0, import_hast_util_to_html.toHtml)(ast);
|
|
107
|
-
html = html.replace(
|
|
108
|
-
|
|
113
|
+
html = html.replace(
|
|
114
|
+
MULTILINE_TOKEN_SPAN,
|
|
115
|
+
(match, token) => match.replace(/\n/g, `</span>
|
|
116
|
+
<span class="token ${token}">`)
|
|
117
|
+
);
|
|
109
118
|
const hast = (0, import_unified.unified)().use(import_rehype_parse.default, { emitParseErrors: true, fragment: true }).parse(html);
|
|
110
119
|
return hast.children;
|
|
111
120
|
};
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/highlightLine.ts"],
|
|
4
4
|
"sourcesContent": ["// Inspired by https://github.com/j0lv3r4/mdx-prism\n\nimport { toHtml } from 'hast-util-to-html'\nimport parse from 'rehype-parse'\nimport { unified } from 'unified'\n\nconst lineNumberify = function lineNumberify(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\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: lineNumber,\n })\n }\n\n result.lineNumber = lineNumber\n return result\n }\n\n if (node.children) {\n node.lineNumber = lineNumber\n const processed = lineNumberify(node.children, lineNumber)\n node.children = processed.nodes\n result.lineNumber = processed.lineNumber\n result.nodes.push(node)\n return result\n }\n\n result.nodes.push(node)\n return result\n },\n { nodes: [], lineNumber: lineNumber }\n )\n}\n\nconst wrapLines = function wrapLines(ast: any[], linesToHighlight) {\n const highlightAll = linesToHighlight.length === 1 && linesToHighlight[0] === 0\n const allLines: any[] = 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: any[] = []\n for (; i < ast.length; i++) {\n if (ast[i].lineNumber < line) {\n nodes.push(ast[i])\n continue\n }\n\n if (ast[i].lineNumber === line) {\n children.push(ast[i])\n continue\n }\n\n if (ast[i].lineNumber > line) {\n break\n }\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\n return nodes\n }, [])\n\n return wrapped\n}\n\n// https://github.com/gatsbyjs/gatsby/pull/26161/files\nconst MULTILINE_TOKEN_SPAN = /<span class=\"token ([^\"]+)\">[^<]*\\n[^<]*<\\/span>/g\n\nconst applyMultilineFix = function (ast) {\n // AST to HTML\n let html = toHtml(ast)\n\n // Fix JSX issue\n html = html.replace(MULTILINE_TOKEN_SPAN, (match, token) =>\n match.replace(/\\n/g, `</span>\\n<span class=\"token ${token}\">`)\n )\n\n // HTML to AST\n const hast = unified().use(parse, { emitParseErrors: true, fragment: true }).parse(html)\n\n return hast.children\n}\n\nexport function highlightLine(ast, lines) {\n const formattedAst = applyMultilineFix(ast)\n const numbered = lineNumberify(formattedAst).nodes\n return wrapLines(numbered, lines)\n}\n"],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rapLines", "parse"]
|
|
7
7
|
}
|
|
@@ -17,7 +17,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
}
|
|
18
18
|
return to;
|
|
19
19
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
21
24
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
25
|
|
|
23
26
|
// src/highlightWord.ts
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/highlightWord.ts"],
|
|
4
4
|
"sourcesContent": ["// const visit = require('unist-util-visit')\nimport { toHtml } from 'hast-util-to-html'\nimport parse from 'rehype-parse'\nimport { unified } from 'unified'\n\nconst CALLOUT = /__(.*?)__/g\n\nexport function highlightWord(code) {\n const html = toHtml(code)\n const result = html.replace(CALLOUT, (_, text) => `<span class=\"highlight-word\">${text}</span>`)\n const hast = unified().use(parse, { emitParseErrors: true, fragment: true }).parse(result)\n return hast.children\n}\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": []
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,+BAAuB;AACvB,0BAAkB;AAClB,qBAAwB;AAExB,IAAM,UAAU;AAET,SAAS,cAAc,MAAM;AAClC,QAAM,WAAO,iCAAO,IAAI;AACxB,QAAM,SAAS,KAAK,QAAQ,SAAS,CAAC,GAAG,SAAS,gCAAgC,aAAa;AAC/F,QAAM,WAAO,wBAAQ,EAAE,IAAI,oBAAAA,SAAO,EAAE,iBAAiB,MAAM,UAAU,KAAK,CAAC,EAAE,MAAM,MAAM;AACzF,SAAO,KAAK;AACd;",
|
|
6
|
+
"names": ["parse"]
|
|
7
7
|
}
|
package/dist/cjs/index.js
CHANGED
|
@@ -17,7 +17,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
}
|
|
18
18
|
return to;
|
|
19
19
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
21
24
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
25
|
|
|
23
26
|
// src/index.ts
|
|
@@ -38,40 +41,43 @@ var import_rehype_parse = __toESM(require("rehype-parse"));
|
|
|
38
41
|
var import_unified = require("unified");
|
|
39
42
|
var lineNumberify = function lineNumberify2(ast, lineNum = 1) {
|
|
40
43
|
let lineNumber = lineNum;
|
|
41
|
-
return ast.reduce(
|
|
42
|
-
|
|
43
|
-
if (node.
|
|
44
|
+
return ast.reduce(
|
|
45
|
+
(result, node) => {
|
|
46
|
+
if (node.type === "text") {
|
|
47
|
+
if (node.value.indexOf("\n") === -1) {
|
|
48
|
+
node.lineNumber = lineNumber;
|
|
49
|
+
result.nodes.push(node);
|
|
50
|
+
return result;
|
|
51
|
+
}
|
|
52
|
+
const lines = node.value.split("\n");
|
|
53
|
+
for (let i = 0; i < lines.length; i++) {
|
|
54
|
+
if (i !== 0)
|
|
55
|
+
++lineNumber;
|
|
56
|
+
if (i === lines.length - 1 && lines[i].length === 0)
|
|
57
|
+
continue;
|
|
58
|
+
result.nodes.push({
|
|
59
|
+
type: "text",
|
|
60
|
+
value: i === lines.length - 1 ? lines[i] : `${lines[i]}
|
|
61
|
+
`,
|
|
62
|
+
lineNumber
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
result.lineNumber = lineNumber;
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
if (node.children) {
|
|
44
69
|
node.lineNumber = lineNumber;
|
|
70
|
+
const processed = lineNumberify2(node.children, lineNumber);
|
|
71
|
+
node.children = processed.nodes;
|
|
72
|
+
result.lineNumber = processed.lineNumber;
|
|
45
73
|
result.nodes.push(node);
|
|
46
74
|
return result;
|
|
47
75
|
}
|
|
48
|
-
const lines = node.value.split("\n");
|
|
49
|
-
for (let i = 0; i < lines.length; i++) {
|
|
50
|
-
if (i !== 0)
|
|
51
|
-
++lineNumber;
|
|
52
|
-
if (i === lines.length - 1 && lines[i].length === 0)
|
|
53
|
-
continue;
|
|
54
|
-
result.nodes.push({
|
|
55
|
-
type: "text",
|
|
56
|
-
value: i === lines.length - 1 ? lines[i] : `${lines[i]}
|
|
57
|
-
`,
|
|
58
|
-
lineNumber
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
result.lineNumber = lineNumber;
|
|
62
|
-
return result;
|
|
63
|
-
}
|
|
64
|
-
if (node.children) {
|
|
65
|
-
node.lineNumber = lineNumber;
|
|
66
|
-
const processed = lineNumberify2(node.children, lineNumber);
|
|
67
|
-
node.children = processed.nodes;
|
|
68
|
-
result.lineNumber = processed.lineNumber;
|
|
69
76
|
result.nodes.push(node);
|
|
70
77
|
return result;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}, { nodes: [], lineNumber });
|
|
78
|
+
},
|
|
79
|
+
{ nodes: [], lineNumber }
|
|
80
|
+
);
|
|
75
81
|
};
|
|
76
82
|
var wrapLines = function wrapLines2(ast, linesToHighlight) {
|
|
77
83
|
const highlightAll = linesToHighlight.length === 1 && linesToHighlight[0] === 0;
|
|
@@ -111,8 +117,11 @@ var wrapLines = function wrapLines2(ast, linesToHighlight) {
|
|
|
111
117
|
var MULTILINE_TOKEN_SPAN = /<span class="token ([^"]+)">[^<]*\n[^<]*<\/span>/g;
|
|
112
118
|
var applyMultilineFix = function(ast) {
|
|
113
119
|
let html = (0, import_hast_util_to_html.toHtml)(ast);
|
|
114
|
-
html = html.replace(
|
|
115
|
-
|
|
120
|
+
html = html.replace(
|
|
121
|
+
MULTILINE_TOKEN_SPAN,
|
|
122
|
+
(match, token) => match.replace(/\n/g, `</span>
|
|
123
|
+
<span class="token ${token}">`)
|
|
124
|
+
);
|
|
116
125
|
const hast = (0, import_unified.unified)().use(import_rehype_parse.default, { emitParseErrors: true, fragment: true }).parse(html);
|
|
117
126
|
return hast.children;
|
|
118
127
|
};
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/index.ts", "../../src/highlightLine.ts", "../../src/highlightWord.ts"],
|
|
4
4
|
"sourcesContent": ["import { toHtml } from 'hast-util-to-html'\nimport rangeParser from 'parse-numeric-range'\nimport { refractor } from 'refractor'\nimport css from 'refractor/lang/css'\nimport tsx from 'refractor/lang/tsx'\n\nimport { highlightLine } from './highlightLine'\nimport { highlightWord } from './highlightWord'\n\nrefractor.register(tsx)\nrefractor.register(css)\n\nexport function codeToHTML(source: string, language: 'tsx' | 'css' | string, line = '0') {\n let result: any = refractor.highlight(source, language)\n result = highlightLine(result, rangeParser(line))\n result = highlightWord(result)\n result = toHtml(result)\n return result as string\n}\n", "// Inspired by https://github.com/j0lv3r4/mdx-prism\n\nimport { toHtml } from 'hast-util-to-html'\nimport parse from 'rehype-parse'\nimport { unified } from 'unified'\n\nconst lineNumberify = function lineNumberify(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\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: lineNumber,\n })\n }\n\n result.lineNumber = lineNumber\n return result\n }\n\n if (node.children) {\n node.lineNumber = lineNumber\n const processed = lineNumberify(node.children, lineNumber)\n node.children = processed.nodes\n result.lineNumber = processed.lineNumber\n result.nodes.push(node)\n return result\n }\n\n result.nodes.push(node)\n return result\n },\n { nodes: [], lineNumber: lineNumber }\n )\n}\n\nconst wrapLines = function wrapLines(ast: any[], linesToHighlight) {\n const highlightAll = linesToHighlight.length === 1 && linesToHighlight[0] === 0\n const allLines: any[] = 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: any[] = []\n for (; i < ast.length; i++) {\n if (ast[i].lineNumber < line) {\n nodes.push(ast[i])\n continue\n }\n\n if (ast[i].lineNumber === line) {\n children.push(ast[i])\n continue\n }\n\n if (ast[i].lineNumber > line) {\n break\n }\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\n return nodes\n }, [])\n\n return wrapped\n}\n\n// https://github.com/gatsbyjs/gatsby/pull/26161/files\nconst MULTILINE_TOKEN_SPAN = /<span class=\"token ([^\"]+)\">[^<]*\\n[^<]*<\\/span>/g\n\nconst applyMultilineFix = function (ast) {\n // AST to HTML\n let html = toHtml(ast)\n\n // Fix JSX issue\n html = html.replace(MULTILINE_TOKEN_SPAN, (match, token) =>\n match.replace(/\\n/g, `</span>\\n<span class=\"token ${token}\">`)\n )\n\n // HTML to AST\n const hast = unified().use(parse, { emitParseErrors: true, fragment: true }).parse(html)\n\n return hast.children\n}\n\nexport function highlightLine(ast, lines) {\n const formattedAst = applyMultilineFix(ast)\n const numbered = lineNumberify(formattedAst).nodes\n return wrapLines(numbered, lines)\n}\n", "// const visit = require('unist-util-visit')\nimport { toHtml } from 'hast-util-to-html'\nimport parse from 'rehype-parse'\nimport { unified } from 'unified'\n\nconst CALLOUT = /__(.*?)__/g\n\nexport function highlightWord(code) {\n const html = toHtml(code)\n const result = html.replace(CALLOUT, (_, text) => `<span class=\"highlight-word\">${text}</span>`)\n const hast = unified().use(parse, { emitParseErrors: true, fragment: true }).parse(result)\n return hast.children\n}\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": []
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,4BAAuB;AACvB,iCAAwB;AACxB,uBAA0B;AAC1B,iBAAgB;AAChB,iBAAgB;;;ACFhB,+BAAuB;AACvB,0BAAkB;AAClB,qBAAwB;AAExB,IAAM,gBAAgB,SAASC,eAAc,KAAK,UAAU,GAAG;AAC7D,MAAI,aAAa;AACjB,SAAO,IAAI;AAAA,IACT,CAAC,QAAQ,SAAS;AAChB,UAAI,KAAK,SAAS,QAAQ;AACxB,YAAI,KAAK,MAAM,QAAQ,IAAI,MAAM,IAAI;AACnC,eAAK,aAAa;AAClB,iBAAO,MAAM,KAAK,IAAI;AACtB,iBAAO;AAAA,QACT;AAEA,cAAM,QAAQ,KAAK,MAAM,MAAM,IAAI;AACnC,iBAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;AACrC,cAAI,MAAM;AAAG,cAAE;AACf,cAAI,MAAM,MAAM,SAAS,KAAK,MAAM,GAAG,WAAW;AAAG;AACrD,iBAAO,MAAM,KAAK;AAAA,YAChB,MAAM;AAAA,YACN,OAAO,MAAM,MAAM,SAAS,IAAI,MAAM,KAAK,GAAG,MAAM;AAAA;AAAA,YACpD;AAAA,UACF,CAAC;AAAA,QACH;AAEA,eAAO,aAAa;AACpB,eAAO;AAAA,MACT;AAEA,UAAI,KAAK,UAAU;AACjB,aAAK,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A,IAAsB,CAAC,OAAO,UAChD,MAAM,QAAQ,OAAO;AAAA,qBAA+B,SAAS;AAAA,EAC/D;AAGA,QAAM,WAAO,wBAAQ,EAAE,IAAI,oBAAAC,SAAO,EAAE,iBAAiB,MAAM,UAAU,KAAK,CAAC,EAAE,MAAM,IAAI;AAEvF,SAAO,KAAK;AACd;AAEO,SAAS,cAAc,KAAK,OAAO;AACxC,QAAM,eAAe,kBAAkB,GAAG;AAC1C,QAAM,WAAW,cAAc,YAAY,EAAE;AAC7C,SAAO,UAAU,UAAU,KAAK;AAClC;;;AC9GA,IAAAC,4BAAuB;AACvB,IAAAC,uBAAkB;AAClB,IAAAC,kBAAwB;AAExB,IAAM,UAAU;AAET,SAAS,cAAc,MAAM;AAClC,QAAM,WAAO,kCAAO,IAAI;AACxB,QAAM,SAAS,KAAK,QAAQ,SAAS,CAAC,GAAG,SAAS,gCAAgC,aAAa;AAC/F,QAAM,WAAO,yBAAQ,EAAE,IAAI,qBAAAC,SAAO,EAAE,iBAAiB,MAAM,UAAU,KAAK,CAAC,EAAE,MAAM,MAAM;AACzF,SAAO,KAAK;AACd;;;AFHA,2BAAU,SAAS,WAAAC,OAAG;AACtB,2BAAU,SAAS,WAAAC,OAAG;AAEf,SAAS,WAAW,QAAgB,UAAkC,OAAO,KAAK;AACvF,MAAI,SAAc,2BAAU,UAAU,QAAQ,QAAQ;AACtD,WAAS,cAAc,YAAQ,2BAAAC,SAAY,IAAI,CAAC;AAChD,WAAS,cAAc,MAAM;AAC7B,eAAS,kCAAO,MAAM;AACtB,SAAO;AACT;",
|
|
6
|
+
"names": ["import_hast_util_to_html", "lineNumberify", "wrapLines", "parse", "import_hast_util_to_html", "import_rehype_parse", "import_unified", "parse", "tsx", "css", "rangeParser"]
|
|
7
7
|
}
|