@tamagui/code-to-html 1.89.26 → 1.89.27-1708112217600
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/index.native.js +52 -46
- package/dist/cjs/index.native.js.map +3 -3
- package/dist/esm/index.native.js +24609 -3527
- package/dist/esm/index.native.js.map +3 -3
- package/package.json +2 -2
package/dist/cjs/index.native.js
CHANGED
|
@@ -31,39 +31,38 @@ module.exports = __toCommonJS(src_exports);
|
|
|
31
31
|
var import_hast_util_to_html3 = require("hast-util-to-html"), import_parse_numeric_range = __toESM(require("parse-numeric-range")), import_refractor = require("refractor"), import_css = __toESM(require("refractor/lang/css")), import_tsx = __toESM(require("refractor/lang/tsx"));
|
|
32
32
|
|
|
33
33
|
// src/highlightLine.ts
|
|
34
|
-
var import_hast_util_to_html = require("hast-util-to-html"), import_rehype_parse = __toESM(require("rehype-parse")), import_unified = require("unified"), lineNumberify = function lineNumberify2(ast
|
|
35
|
-
|
|
36
|
-
return ast.reduce(
|
|
37
|
-
(
|
|
38
|
-
if (node.
|
|
39
|
-
if (node.value.indexOf(`
|
|
34
|
+
var import_hast_util_to_html = require("hast-util-to-html"), import_rehype_parse = __toESM(require("rehype-parse")), import_unified = require("unified"), lineNumberify = function lineNumberify2(ast) {
|
|
35
|
+
var lineNum = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 1, lineNumber = lineNum;
|
|
36
|
+
return ast.reduce(function(result, node) {
|
|
37
|
+
if (node.type === "text") {
|
|
38
|
+
if (node.value.indexOf(`
|
|
40
39
|
`) === -1)
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
`);
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
);
|
|
40
|
+
return node.lineNumber = lineNumber, result.nodes.push(node), result;
|
|
41
|
+
for (var lines = node.value.split(`
|
|
42
|
+
`), i = 0; i < lines.length; i++)
|
|
43
|
+
i !== 0 && ++lineNumber, !(i === lines.length - 1 && lines[i].length === 0) && result.nodes.push({
|
|
44
|
+
type: "text",
|
|
45
|
+
value: i === lines.length - 1 ? lines[i] : "".concat(lines[i], `
|
|
46
|
+
`),
|
|
47
|
+
lineNumber
|
|
48
|
+
});
|
|
49
|
+
return result.lineNumber = lineNumber, result;
|
|
50
|
+
}
|
|
51
|
+
if (node.children) {
|
|
52
|
+
node.lineNumber = lineNumber;
|
|
53
|
+
var processed = lineNumberify2(node.children, lineNumber);
|
|
54
|
+
return node.children = processed.nodes, result.lineNumber = processed.lineNumber, result.nodes.push(node), result;
|
|
55
|
+
}
|
|
56
|
+
return result.nodes.push(node), result;
|
|
57
|
+
}, {
|
|
58
|
+
nodes: [],
|
|
59
|
+
lineNumber
|
|
60
|
+
});
|
|
62
61
|
}, wrapLines = function(ast, linesToHighlight) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
for (; i < ast.length; i++) {
|
|
62
|
+
var highlightAll = linesToHighlight.length === 1 && linesToHighlight[0] === 0, allLines = Array.from(new Set(ast.map(function(x) {
|
|
63
|
+
return x.lineNumber;
|
|
64
|
+
}))), i = 0, wrapped = allLines.reduce(function(nodes, marker) {
|
|
65
|
+
for (var line = marker, children = []; i < ast.length; i++) {
|
|
67
66
|
if (ast[i].lineNumber < line) {
|
|
68
67
|
nodes.push(ast[i]);
|
|
69
68
|
continue;
|
|
@@ -87,34 +86,41 @@ var import_hast_util_to_html = require("hast-util-to-html"), import_rehype_parse
|
|
|
87
86
|
lineNumber: line
|
|
88
87
|
}), nodes;
|
|
89
88
|
}, []);
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
<span class="token
|
|
96
|
-
|
|
89
|
+
return wrapped;
|
|
90
|
+
}, MULTILINE_TOKEN_SPAN = /<span class="token ([^"]+)">[^<]*\n[^<]*<\/span>/g, applyMultilineFix = function(ast) {
|
|
91
|
+
var html = (0, import_hast_util_to_html.toHtml)(ast);
|
|
92
|
+
html = html.replace(MULTILINE_TOKEN_SPAN, function(match, token) {
|
|
93
|
+
return match.replace(/\n/g, `</span>
|
|
94
|
+
<span class="token `.concat(token, '">'));
|
|
95
|
+
});
|
|
96
|
+
var hast = (0, import_unified.unified)().use(import_rehype_parse.default, {
|
|
97
|
+
emitParseErrors: !0,
|
|
98
|
+
fragment: !0
|
|
99
|
+
}).parse(html);
|
|
100
|
+
return hast.children;
|
|
97
101
|
};
|
|
98
102
|
function highlightLine(ast, lines) {
|
|
99
|
-
|
|
103
|
+
var formattedAst = applyMultilineFix(ast), numbered = lineNumberify(formattedAst).nodes;
|
|
100
104
|
return wrapLines(numbered, lines);
|
|
101
105
|
}
|
|
102
106
|
|
|
103
107
|
// src/highlightWord.ts
|
|
104
108
|
var import_hast_util_to_html2 = require("hast-util-to-html"), import_rehype_parse2 = __toESM(require("rehype-parse")), import_unified2 = require("unified"), CALLOUT = /__(.*?)__/g;
|
|
105
109
|
function highlightWord(code) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
110
|
+
var html = (0, import_hast_util_to_html2.toHtml)(code), result = html.replace(CALLOUT, function(_, text) {
|
|
111
|
+
return '<span class="highlight-word">'.concat(text, "</span>");
|
|
112
|
+
}), hast = (0, import_unified2.unified)().use(import_rehype_parse2.default, {
|
|
113
|
+
emitParseErrors: !0,
|
|
114
|
+
fragment: !0
|
|
115
|
+
}).parse(result);
|
|
116
|
+
return hast.children;
|
|
111
117
|
}
|
|
112
118
|
|
|
113
119
|
// src/index.ts
|
|
114
120
|
import_refractor.refractor.register(import_tsx.default);
|
|
115
121
|
import_refractor.refractor.register(import_css.default);
|
|
116
|
-
function codeToHTML(source, language
|
|
117
|
-
|
|
122
|
+
function codeToHTML(source, language) {
|
|
123
|
+
var line = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : "0", result = import_refractor.refractor.highlight(source, language);
|
|
118
124
|
return result = highlightLine(result, (0, import_parse_numeric_range.default)(line)), result = highlightWord(result), result = (0, import_hast_util_to_html3.toHtml)(result), result;
|
|
119
125
|
}
|
|
120
126
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../src/index.ts", "../../src/highlightLine.ts", "../../src/highlightWord.ts"],
|
|
4
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;AAAA
|
|
5
|
-
"names": ["import_hast_util_to_html", "lineNumberify", "parse", "import_hast_util_to_html", "import_rehype_parse", "import_unified", "parse", "tsx", "css", "rangeParser"]
|
|
3
|
+
"sources": ["../../src/Users/n8/tamagui/packages/code-to-html/src/index.ts", "../../src/Users/n8/tamagui/packages/code-to-html/src/highlightLine.ts", "../../src/Users/n8/tamagui/packages/code-to-html/src/highlightWord.ts"],
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;IAAAA,4BAAuB,8BACvB,6BAAwB,yCACxB,mBAA0B,sBAC1B,aAAgB,wCAChB,aAAgB;;;ACFhB,+BAAuB,8BACvB,sBAAkB,kCAClB,iBAAwB,oBAElBC,gBAAgB,SAASA,eAAcC,KAAG;MAAEC,UAAAA,UAAAA,SAAAA,KAAAA,UAAAA,CAAAA,MAAAA,SAAAA,UAAAA,CAAAA,IAAU,GACtDC,aAAaD;AACjB,SAAOD,IAAIG,OACT,SAACC,QAAQC,MAAAA;AACP,QAAIA,KAAKC,SAAS,QAAQ;AACxB,UAAID,KAAKE,MAAMC,QAAQ;CAAA,MAAU;AAC/BH,oBAAKH,aAAaA,YAClBE,OAAOK,MAAMC,KAAKL,IAAAA,GACXD;AAIT,eADMO,QAAQN,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C,UAAgC;MAAEC,OAAAA,UAAAA,SAAAA,KAAAA,UAAAA,CAAAA,MAAAA,SAAAA,UAAAA,CAAAA,IAAO,KAC9EC,SAAcR,2BAAUS,UAAUJ,QAAQC,QAAAA;AAC9CE,kBAASE,cAAcF,YAAQG,2BAAAA,SAAYJ,IAAAA,CAAAA,GAC3CC,SAASI,cAAcJ,MAAAA,GACvBA,aAASK,kCAAOL,MAAAA,GACTA;AACT;",
|
|
5
|
+
"names": ["import_hast_util_to_html", "lineNumberify", "ast", "lineNum", "lineNumber", "reduce", "result", "node", "type", "value", "indexOf", "nodes", "push", "lines", "split", "i", "length", "children", "processed", "wrapLines", "linesToHighlight", "highlightAll", "allLines", "Array", "from", "Set", "map", "x", "wrapped", "marker", "line", "tagName", "properties", "dataLine", "className", "dataHighlighted", "includes", "MULTILINE_TOKEN_SPAN", "applyMultilineFix", "html", "toHtml", "replace", "match", "token", "hast", "unified", "use", "parse", "emitParseErrors", "fragment", "highlightLine", "formattedAst", "numbered", "import_hast_util_to_html", "import_rehype_parse", "import_unified", "CALLOUT", "highlightWord", "code", "html", "toHtml", "result", "replace", "_", "text", "hast", "unified", "use", "parse", "emitParseErrors", "fragment", "refractor", "register", "tsx", "css", "codeToHTML", "source", "language", "line", "result", "highlight", "highlightLine", "rangeParser", "highlightWord", "toHtml"]
|
|
6
6
|
}
|