@tamagui/code-to-html 1.112.0 → 1.112.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.js +98 -0
- package/dist/cjs/highlightLine.js.map +6 -0
- package/dist/cjs/highlightLine.native.js +105 -0
- package/dist/cjs/highlightLine.native.js.map +6 -0
- package/dist/cjs/highlightWord.js +37 -0
- package/dist/cjs/highlightWord.js.map +6 -0
- package/dist/cjs/highlightWord.native.js +43 -0
- package/dist/cjs/highlightWord.native.js.map +6 -0
- package/dist/cjs/index.js +2 -90
- package/dist/cjs/index.js.map +3 -3
- package/dist/cjs/index.native.js +2 -92
- package/dist/cjs/index.native.js.map +3 -3
- package/dist/esm/highlightLine.js +76 -0
- package/dist/esm/highlightLine.js.map +6 -0
- package/dist/esm/highlightLine.mjs +77 -0
- package/dist/esm/highlightLine.mjs.map +1 -0
- package/dist/esm/highlightLine.native.js +82 -0
- package/dist/esm/highlightLine.native.js.map +1 -0
- package/dist/esm/highlightWord.js +15 -0
- package/dist/esm/highlightWord.js.map +6 -0
- package/dist/esm/highlightWord.mjs +13 -0
- package/dist/esm/highlightWord.mjs.map +1 -0
- package/dist/esm/highlightWord.native.js +17 -0
- package/dist/esm/highlightWord.native.js.map +1 -0
- package/dist/esm/index.js +8 -13599
- package/dist/esm/index.js.map +3 -3
- package/dist/esm/index.mjs +10 -13603
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/index.native.js +12 -34794
- package/dist/esm/index.native.js.map +1 -6
- package/package.json +4 -4
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
9
|
+
}, __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from == "object" || typeof from == "function")
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
return to;
|
|
14
|
+
};
|
|
15
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
16
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
17
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
18
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
19
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
|
|
21
|
+
mod
|
|
22
|
+
)), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
23
|
+
var highlightLine_exports = {};
|
|
24
|
+
__export(highlightLine_exports, {
|
|
25
|
+
highlightLine: () => highlightLine
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(highlightLine_exports);
|
|
28
|
+
var import_hast_util_to_html = require("hast-util-to-html"), import_rehype_parse = __toESM(require("rehype-parse")), import_unified = require("unified");
|
|
29
|
+
const lineNumberify = function lineNumberify2(ast, lineNum = 1) {
|
|
30
|
+
let lineNumber = lineNum;
|
|
31
|
+
return ast.reduce(
|
|
32
|
+
(result, node) => {
|
|
33
|
+
if (node.type === "text") {
|
|
34
|
+
if (node.value.indexOf(`
|
|
35
|
+
`) === -1)
|
|
36
|
+
return node.lineNumber = lineNumber, result.nodes.push(node), result;
|
|
37
|
+
const lines = node.value.split(`
|
|
38
|
+
`);
|
|
39
|
+
for (let i = 0; i < lines.length; i++)
|
|
40
|
+
i !== 0 && ++lineNumber, !(i === lines.length - 1 && lines[i].length === 0) && result.nodes.push({
|
|
41
|
+
type: "text",
|
|
42
|
+
value: i === lines.length - 1 ? lines[i] : `${lines[i]}
|
|
43
|
+
`,
|
|
44
|
+
lineNumber
|
|
45
|
+
});
|
|
46
|
+
return result.lineNumber = lineNumber, result;
|
|
47
|
+
}
|
|
48
|
+
if (node.children) {
|
|
49
|
+
node.lineNumber = lineNumber;
|
|
50
|
+
const processed = lineNumberify2(node.children, lineNumber);
|
|
51
|
+
return node.children = processed.nodes, result.lineNumber = processed.lineNumber, result.nodes.push(node), result;
|
|
52
|
+
}
|
|
53
|
+
return result.nodes.push(node), result;
|
|
54
|
+
},
|
|
55
|
+
{ nodes: [], lineNumber }
|
|
56
|
+
);
|
|
57
|
+
}, wrapLines = function(ast, linesToHighlight) {
|
|
58
|
+
const highlightAll = linesToHighlight.length === 1 && linesToHighlight[0] === 0, allLines = Array.from(new Set(ast.map((x) => x.lineNumber)));
|
|
59
|
+
let i = 0;
|
|
60
|
+
return allLines.reduce((nodes, marker) => {
|
|
61
|
+
const line = marker, children = [];
|
|
62
|
+
for (; i < ast.length; i++) {
|
|
63
|
+
if (ast[i].lineNumber < line) {
|
|
64
|
+
nodes.push(ast[i]);
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
if (ast[i].lineNumber === line) {
|
|
68
|
+
children.push(ast[i]);
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
if (ast[i].lineNumber > line)
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
return nodes.push({
|
|
75
|
+
type: "element",
|
|
76
|
+
tagName: "div",
|
|
77
|
+
properties: {
|
|
78
|
+
dataLine: line,
|
|
79
|
+
className: "highlight-line",
|
|
80
|
+
dataHighlighted: linesToHighlight.includes(line) || highlightAll ? "true" : "false"
|
|
81
|
+
},
|
|
82
|
+
children,
|
|
83
|
+
lineNumber: line
|
|
84
|
+
}), nodes;
|
|
85
|
+
}, []);
|
|
86
|
+
}, MULTILINE_TOKEN_SPAN = /<span class="token ([^"]+)">[^<]*\n[^<]*<\/span>/g, applyMultilineFix = (ast) => {
|
|
87
|
+
let html = (0, import_hast_util_to_html.toHtml)(ast);
|
|
88
|
+
return html = html.replace(
|
|
89
|
+
MULTILINE_TOKEN_SPAN,
|
|
90
|
+
(match, token) => match.replace(/\n/g, `</span>
|
|
91
|
+
<span class="token ${token}">`)
|
|
92
|
+
), (0, import_unified.unified)().use(import_rehype_parse.default, { emitParseErrors: !0, fragment: !0 }).parse(html).children;
|
|
93
|
+
};
|
|
94
|
+
function highlightLine(ast, lines) {
|
|
95
|
+
const formattedAst = applyMultilineFix(ast), numbered = lineNumberify(formattedAst).nodes;
|
|
96
|
+
return wrapLines(numbered, lines);
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=highlightLine.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/highlightLine.ts"],
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,+BAAuB,8BACvB,sBAAkB,kCAClB,iBAAwB;AAExB,MAAM,gBAAgB,SAASA,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;AAAA,CAAI,MAAM;AAC/B,sBAAK,aAAa,YAClB,OAAO,MAAM,KAAK,IAAI,GACf;AAGT,cAAM,QAAQ,KAAK,MAAM,MAAM;AAAA,CAAI;AACnC,iBAAS,IAAI,GAAG,IAAI,MAAM,QAAQ;AAEhC,UADI,MAAM,KAAG,EAAE,YACX,QAAM,MAAM,SAAS,KAAK,MAAM,CAAC,EAAE,WAAW,MAClD,OAAO,MAAM,KAAK;AAAA,YAChB,MAAM;AAAA,YACN,OAAO,MAAM,MAAM,SAAS,IAAI,MAAM,CAAC,IAAI,GAAG,MAAM,CAAC,CAAC;AAAA;AAAA,YACtD;AAAA,UACF,CAAC;AAGH,sBAAO,aAAa,YACb;AAAA,MACT;AAEA,UAAI,KAAK,UAAU;AACjB,aAAK,aAAa;AAClB,cAAM,YAAYA,eAAc,KAAK,UAAU,UAAU;AACzD,oBAAK,WAAW,UAAU,OAC1B,OAAO,aAAa,UAAU,YAC9B,OAAO,MAAM,KAAK,IAAI,GACf;AAAA,MACT;AAEA,oBAAO,MAAM,KAAK,IAAI,GACf;AAAA,IACT;AAAA,IACA,EAAE,OAAO,CAAC,GAAG,WAAuB;AAAA,EACtC;AACF,GAEM,YAAY,SAAmB,KAAY,kBAAkB;AACjE,QAAM,eAAe,iBAAiB,WAAW,KAAK,iBAAiB,CAAC,MAAM,GACxE,WAAkB,MAAM,KAAK,IAAI,IAAI,IAAI,IAAI,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;AACxE,MAAI,IAAI;AAoCR,SAnCgB,SAAS,OAAO,CAAC,OAAO,WAAW;AACjD,UAAM,OAAO,QACP,WAAkB,CAAC;AACzB,WAAO,IAAI,IAAI,QAAQ,KAAK;AAC1B,UAAI,IAAI,CAAC,EAAE,aAAa,MAAM;AAC5B,cAAM,KAAK,IAAI,CAAC,CAAC;AACjB;AAAA,MACF;AAEA,UAAI,IAAI,CAAC,EAAE,eAAe,MAAM;AAC9B,iBAAS,KAAK,IAAI,CAAC,CAAC;AACpB;AAAA,MACF;AAEA,UAAI,IAAI,CAAC,EAAE,aAAa;AACtB;AAAA,IAEJ;AAEA,iBAAM,KAAK;AAAA,MACT,MAAM;AAAA,MACN,SAAS;AAAA,MACT,YAAY;AAAA,QACV,UAAU;AAAA,QACV,WAAW;AAAA,QACX,iBACE,iBAAiB,SAAS,IAAI,KAAK,eAAe,SAAS;AAAA,MAC/D;AAAA,MACA;AAAA,MACA,YAAY;AAAA,IACd,CAAC,GAEM;AAAA,EACT,GAAG,CAAC,CAAC;AAGP,GAGM,uBAAuB,qDAEvB,oBAAoB,CAAC,QAAQ;AAEjC,MAAI,WAAO,iCAAO,GAAG;AAGrB,gBAAO,KAAK;AAAA,IAAQ;AAAA,IAAsB,CAAC,OAAO,UAChD,MAAM,QAAQ,OAAO;AAAA,qBAA+B,KAAK,IAAI;AAAA,EAC/D,OAGa,wBAAQ,EAAE,IAAI,oBAAAC,SAAO,EAAE,iBAAiB,IAAM,UAAU,GAAK,CAAC,EAAE,MAAM,IAAI,EAE3E;AACd;AAEO,SAAS,cAAc,KAAK,OAAO;AACxC,QAAM,eAAe,kBAAkB,GAAG,GACpC,WAAW,cAAc,YAAY,EAAE;AAC7C,SAAO,UAAU,UAAU,KAAK;AAClC;",
|
|
5
|
+
"names": ["lineNumberify", "parse"]
|
|
6
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
10
|
+
}, __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from == "object" || typeof from == "function")
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
|
|
22
|
+
mod
|
|
23
|
+
)), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
24
|
+
var highlightLine_exports = {};
|
|
25
|
+
__export(highlightLine_exports, {
|
|
26
|
+
highlightLine: () => highlightLine
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(highlightLine_exports);
|
|
29
|
+
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) {
|
|
30
|
+
var lineNum = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 1, lineNumber = lineNum;
|
|
31
|
+
return ast.reduce(function(result, node) {
|
|
32
|
+
if (node.type === "text") {
|
|
33
|
+
if (node.value.indexOf(`
|
|
34
|
+
`) === -1)
|
|
35
|
+
return node.lineNumber = lineNumber, result.nodes.push(node), result;
|
|
36
|
+
for (var lines = node.value.split(`
|
|
37
|
+
`), i = 0; i < lines.length; i++)
|
|
38
|
+
i !== 0 && ++lineNumber, !(i === lines.length - 1 && lines[i].length === 0) && result.nodes.push({
|
|
39
|
+
type: "text",
|
|
40
|
+
value: i === lines.length - 1 ? lines[i] : `${lines[i]}
|
|
41
|
+
`,
|
|
42
|
+
lineNumber
|
|
43
|
+
});
|
|
44
|
+
return result.lineNumber = lineNumber, result;
|
|
45
|
+
}
|
|
46
|
+
if (node.children) {
|
|
47
|
+
node.lineNumber = lineNumber;
|
|
48
|
+
var processed = lineNumberify2(node.children, lineNumber);
|
|
49
|
+
return node.children = processed.nodes, result.lineNumber = processed.lineNumber, result.nodes.push(node), result;
|
|
50
|
+
}
|
|
51
|
+
return result.nodes.push(node), result;
|
|
52
|
+
}, {
|
|
53
|
+
nodes: [],
|
|
54
|
+
lineNumber
|
|
55
|
+
});
|
|
56
|
+
}, wrapLines = function(ast, linesToHighlight) {
|
|
57
|
+
var highlightAll = linesToHighlight.length === 1 && linesToHighlight[0] === 0, allLines = Array.from(new Set(ast.map(function(x) {
|
|
58
|
+
return x.lineNumber;
|
|
59
|
+
}))), i = 0, wrapped = allLines.reduce(function(nodes, marker) {
|
|
60
|
+
for (var line = marker, children = []; i < ast.length; i++) {
|
|
61
|
+
if (ast[i].lineNumber < line) {
|
|
62
|
+
nodes.push(ast[i]);
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
if (ast[i].lineNumber === line) {
|
|
66
|
+
children.push(ast[i]);
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
if (ast[i].lineNumber > line)
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
return nodes.push({
|
|
73
|
+
type: "element",
|
|
74
|
+
tagName: "div",
|
|
75
|
+
properties: {
|
|
76
|
+
dataLine: line,
|
|
77
|
+
className: "highlight-line",
|
|
78
|
+
dataHighlighted: linesToHighlight.includes(line) || highlightAll ? "true" : "false"
|
|
79
|
+
},
|
|
80
|
+
children,
|
|
81
|
+
lineNumber: line
|
|
82
|
+
}), nodes;
|
|
83
|
+
}, []);
|
|
84
|
+
return wrapped;
|
|
85
|
+
}, MULTILINE_TOKEN_SPAN = /<span class="token ([^"]+)">[^<]*\n[^<]*<\/span>/g, applyMultilineFix = function(ast) {
|
|
86
|
+
var html = (0, import_hast_util_to_html.toHtml)(ast);
|
|
87
|
+
html = html.replace(MULTILINE_TOKEN_SPAN, function(match, token) {
|
|
88
|
+
return match.replace(/\n/g, `</span>
|
|
89
|
+
<span class="token ${token}">`);
|
|
90
|
+
});
|
|
91
|
+
var hast = (0, import_unified.unified)().use(import_rehype_parse.default, {
|
|
92
|
+
emitParseErrors: !0,
|
|
93
|
+
fragment: !0
|
|
94
|
+
}).parse(html);
|
|
95
|
+
return hast.children;
|
|
96
|
+
};
|
|
97
|
+
function highlightLine(ast, lines) {
|
|
98
|
+
var formattedAst = applyMultilineFix(ast), numbered = lineNumberify(formattedAst).nodes;
|
|
99
|
+
return wrapLines(numbered, lines);
|
|
100
|
+
}
|
|
101
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
102
|
+
0 && (module.exports = {
|
|
103
|
+
highlightLine
|
|
104
|
+
});
|
|
105
|
+
//# sourceMappingURL=highlightLine.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/Users/n8/tamagui/code/packages/code-to-html/src/highlightLine.ts"],
|
|
4
|
+
"mappings": "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",
|
|
5
|
+
"names": ["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"]
|
|
6
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
9
|
+
}, __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from == "object" || typeof from == "function")
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
return to;
|
|
14
|
+
};
|
|
15
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
16
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
17
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
18
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
19
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
|
|
21
|
+
mod
|
|
22
|
+
)), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
23
|
+
var highlightWord_exports = {};
|
|
24
|
+
__export(highlightWord_exports, {
|
|
25
|
+
highlightWord: () => highlightWord
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(highlightWord_exports);
|
|
28
|
+
var import_hast_util_to_html = require("hast-util-to-html"), import_rehype_parse = __toESM(require("rehype-parse")), import_unified = require("unified");
|
|
29
|
+
const CALLOUT = /__(.*?)__/g;
|
|
30
|
+
function highlightWord(code) {
|
|
31
|
+
const result = (0, import_hast_util_to_html.toHtml)(code).replace(
|
|
32
|
+
CALLOUT,
|
|
33
|
+
(_, text) => `<span class="highlight-word">${text}</span>`
|
|
34
|
+
);
|
|
35
|
+
return (0, import_unified.unified)().use(import_rehype_parse.default, { emitParseErrors: !0, fragment: !0 }).parse(result).children;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=highlightWord.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/highlightWord.ts"],
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,+BAAuB,8BACvB,sBAAkB,kCAClB,iBAAwB;AAExB,MAAM,UAAU;AAET,SAAS,cAAc,MAAM;AAElC,QAAM,aADO,iCAAO,IAAI,EACJ;AAAA,IAClB;AAAA,IACA,CAAC,GAAG,SAAS,gCAAgC,IAAI;AAAA,EACnD;AAIA,aAHa,wBAAQ,EAClB,IAAI,oBAAAA,SAAO,EAAE,iBAAiB,IAAM,UAAU,GAAK,CAAC,EACpD,MAAM,MAAM,EACH;AACd;",
|
|
5
|
+
"names": ["parse"]
|
|
6
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
10
|
+
}, __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from == "object" || typeof from == "function")
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
|
|
22
|
+
mod
|
|
23
|
+
)), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
24
|
+
var highlightWord_exports = {};
|
|
25
|
+
__export(highlightWord_exports, {
|
|
26
|
+
highlightWord: () => highlightWord
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(highlightWord_exports);
|
|
29
|
+
var import_hast_util_to_html = require("hast-util-to-html"), import_rehype_parse = __toESM(require("rehype-parse")), import_unified = require("unified"), CALLOUT = /__(.*?)__/g;
|
|
30
|
+
function highlightWord(code) {
|
|
31
|
+
var html = (0, import_hast_util_to_html.toHtml)(code), result = html.replace(CALLOUT, function(_, text) {
|
|
32
|
+
return `<span class="highlight-word">${text}</span>`;
|
|
33
|
+
}), hast = (0, import_unified.unified)().use(import_rehype_parse.default, {
|
|
34
|
+
emitParseErrors: !0,
|
|
35
|
+
fragment: !0
|
|
36
|
+
}).parse(result);
|
|
37
|
+
return hast.children;
|
|
38
|
+
}
|
|
39
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
40
|
+
0 && (module.exports = {
|
|
41
|
+
highlightWord
|
|
42
|
+
});
|
|
43
|
+
//# sourceMappingURL=highlightWord.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/Users/n8/tamagui/code/packages/code-to-html/src/highlightWord.ts"],
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;AACA,+BAAuB,8BACvB,sBAAkB,kCAClB,iBAAwB,oBAElBA,UAAU;AAET,SAASC,cAAcC,MAAI;AAChC,MAAMC,WAAOC,iCAAOF,IAAAA,GACdG,SAASF,KAAKG,QAClBN,SACA,SAACO,GAAGC,MAAAA;WAAS,gCAAgCA,IAAAA;MAEzCC,WAAOC,wBAAAA,EACVC,IAAIC,oBAAAA,SAAO;IAAEC,iBAAiB;IAAMC,UAAU;EAAK,CAAA,EACnDF,MAAMP,MAAAA;AACT,SAAOI,KAAK;AACd;",
|
|
5
|
+
"names": ["CALLOUT", "highlightWord", "code", "html", "toHtml", "result", "replace", "_", "text", "hast", "unified", "use", "parse", "emitParseErrors", "fragment"]
|
|
6
|
+
}
|
package/dist/cjs/index.js
CHANGED
|
@@ -20,104 +20,16 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
20
20
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
|
|
21
21
|
mod
|
|
22
22
|
)), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
23
|
-
|
|
24
|
-
// src/index.ts
|
|
25
23
|
var src_exports = {};
|
|
26
24
|
__export(src_exports, {
|
|
27
25
|
codeToHTML: () => codeToHTML
|
|
28
26
|
});
|
|
29
27
|
module.exports = __toCommonJS(src_exports);
|
|
30
|
-
var
|
|
31
|
-
|
|
32
|
-
// src/highlightLine.ts
|
|
33
|
-
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, lineNum = 1) {
|
|
34
|
-
let lineNumber = lineNum;
|
|
35
|
-
return ast.reduce(
|
|
36
|
-
(result, node) => {
|
|
37
|
-
if (node.type === "text") {
|
|
38
|
-
if (node.value.indexOf(`
|
|
39
|
-
`) === -1)
|
|
40
|
-
return node.lineNumber = lineNumber, result.nodes.push(node), result;
|
|
41
|
-
let lines = node.value.split(`
|
|
42
|
-
`);
|
|
43
|
-
for (let i = 0; i < lines.length; i++)
|
|
44
|
-
i !== 0 && ++lineNumber, !(i === lines.length - 1 && lines[i].length === 0) && result.nodes.push({
|
|
45
|
-
type: "text",
|
|
46
|
-
value: i === lines.length - 1 ? lines[i] : `${lines[i]}
|
|
47
|
-
`,
|
|
48
|
-
lineNumber
|
|
49
|
-
});
|
|
50
|
-
return result.lineNumber = lineNumber, result;
|
|
51
|
-
}
|
|
52
|
-
if (node.children) {
|
|
53
|
-
node.lineNumber = lineNumber;
|
|
54
|
-
let processed = lineNumberify2(node.children, lineNumber);
|
|
55
|
-
return node.children = processed.nodes, result.lineNumber = processed.lineNumber, result.nodes.push(node), result;
|
|
56
|
-
}
|
|
57
|
-
return result.nodes.push(node), result;
|
|
58
|
-
},
|
|
59
|
-
{ nodes: [], lineNumber }
|
|
60
|
-
);
|
|
61
|
-
}, wrapLines = function(ast, linesToHighlight) {
|
|
62
|
-
let highlightAll = linesToHighlight.length === 1 && linesToHighlight[0] === 0, allLines = Array.from(new Set(ast.map((x) => x.lineNumber))), i = 0;
|
|
63
|
-
return allLines.reduce((nodes, marker) => {
|
|
64
|
-
let line = marker, children = [];
|
|
65
|
-
for (; i < ast.length; i++) {
|
|
66
|
-
if (ast[i].lineNumber < line) {
|
|
67
|
-
nodes.push(ast[i]);
|
|
68
|
-
continue;
|
|
69
|
-
}
|
|
70
|
-
if (ast[i].lineNumber === line) {
|
|
71
|
-
children.push(ast[i]);
|
|
72
|
-
continue;
|
|
73
|
-
}
|
|
74
|
-
if (ast[i].lineNumber > line)
|
|
75
|
-
break;
|
|
76
|
-
}
|
|
77
|
-
return nodes.push({
|
|
78
|
-
type: "element",
|
|
79
|
-
tagName: "div",
|
|
80
|
-
properties: {
|
|
81
|
-
dataLine: line,
|
|
82
|
-
className: "highlight-line",
|
|
83
|
-
dataHighlighted: linesToHighlight.includes(line) || highlightAll ? "true" : "false"
|
|
84
|
-
},
|
|
85
|
-
children,
|
|
86
|
-
lineNumber: line
|
|
87
|
-
}), nodes;
|
|
88
|
-
}, []);
|
|
89
|
-
}, MULTILINE_TOKEN_SPAN = /<span class="token ([^"]+)">[^<]*\n[^<]*<\/span>/g, applyMultilineFix = (ast) => {
|
|
90
|
-
let html = (0, import_hast_util_to_html.toHtml)(ast);
|
|
91
|
-
return html = html.replace(
|
|
92
|
-
MULTILINE_TOKEN_SPAN,
|
|
93
|
-
(match, token) => match.replace(/\n/g, `</span>
|
|
94
|
-
<span class="token ${token}">`)
|
|
95
|
-
), (0, import_unified.unified)().use(import_rehype_parse.default, { emitParseErrors: !0, fragment: !0 }).parse(html).children;
|
|
96
|
-
};
|
|
97
|
-
function highlightLine(ast, lines) {
|
|
98
|
-
let formattedAst = applyMultilineFix(ast), numbered = lineNumberify(formattedAst).nodes;
|
|
99
|
-
return wrapLines(numbered, lines);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// src/highlightWord.ts
|
|
103
|
-
var import_hast_util_to_html2 = require("hast-util-to-html"), import_rehype_parse2 = __toESM(require("rehype-parse")), import_unified2 = require("unified"), CALLOUT = /__(.*?)__/g;
|
|
104
|
-
function highlightWord(code) {
|
|
105
|
-
let result = (0, import_hast_util_to_html2.toHtml)(code).replace(
|
|
106
|
-
CALLOUT,
|
|
107
|
-
(_, text) => `<span class="highlight-word">${text}</span>`
|
|
108
|
-
);
|
|
109
|
-
return (0, import_unified2.unified)().use(import_rehype_parse2.default, { emitParseErrors: !0, fragment: !0 }).parse(result).children;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// src/index.ts
|
|
28
|
+
var import_hast_util_to_html = 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")), import_highlightLine = require("./highlightLine"), import_highlightWord = require("./highlightWord");
|
|
113
29
|
import_refractor.refractor.register(import_tsx.default);
|
|
114
30
|
import_refractor.refractor.register(import_css.default);
|
|
115
31
|
function codeToHTML(source, language, line = "0") {
|
|
116
32
|
let result = import_refractor.refractor.highlight(source, language);
|
|
117
|
-
return result = highlightLine(result, (0, import_parse_numeric_range.default)(line)), result = highlightWord(result), result = (0,
|
|
33
|
+
return result = (0, import_highlightLine.highlightLine)(result, (0, import_parse_numeric_range.default)(line)), result = (0, import_highlightWord.highlightWord)(result), result = (0, import_hast_util_to_html.toHtml)(result), result;
|
|
118
34
|
}
|
|
119
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
120
|
-
0 && (module.exports = {
|
|
121
|
-
codeToHTML
|
|
122
|
-
});
|
|
123
35
|
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../src/index.ts"
|
|
4
|
-
"mappings": "
|
|
5
|
-
"names": ["
|
|
3
|
+
"sources": ["../../src/index.ts"],
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,+BAAuB,8BACvB,6BAAwB,yCACxB,mBAA0B,sBAC1B,aAAgB,wCAChB,aAAgB,wCAEhB,uBAA8B,4BAC9B,uBAA8B;AAE9B,2BAAU,SAAS,WAAAA,OAAG;AACtB,2BAAU,SAAS,WAAAC,OAAG;AAEf,SAAS,WAAW,QAAgB,UAAkC,OAAO,KAAK;AACvF,MAAI,SAAc,2BAAU,UAAU,QAAQ,QAAQ;AACtD,sBAAS,oCAAc,YAAQ,2BAAAC,SAAY,IAAI,CAAC,GAChD,aAAS,oCAAc,MAAM,GAC7B,aAAS,iCAAO,MAAM,GACf;AACT;",
|
|
5
|
+
"names": ["tsx", "css", "rangeParser"]
|
|
6
6
|
}
|
package/dist/cjs/index.native.js
CHANGED
|
@@ -21,107 +21,17 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
21
21
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
|
|
22
22
|
mod
|
|
23
23
|
)), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
24
|
-
|
|
25
|
-
// src/index.ts
|
|
26
24
|
var src_exports = {};
|
|
27
25
|
__export(src_exports, {
|
|
28
26
|
codeToHTML: () => codeToHTML
|
|
29
27
|
});
|
|
30
28
|
module.exports = __toCommonJS(src_exports);
|
|
31
|
-
var
|
|
32
|
-
|
|
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
|
-
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(`
|
|
39
|
-
`) === -1)
|
|
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] : `${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
|
-
});
|
|
61
|
-
}, wrapLines = function(ast, linesToHighlight) {
|
|
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++) {
|
|
66
|
-
if (ast[i].lineNumber < line) {
|
|
67
|
-
nodes.push(ast[i]);
|
|
68
|
-
continue;
|
|
69
|
-
}
|
|
70
|
-
if (ast[i].lineNumber === line) {
|
|
71
|
-
children.push(ast[i]);
|
|
72
|
-
continue;
|
|
73
|
-
}
|
|
74
|
-
if (ast[i].lineNumber > line)
|
|
75
|
-
break;
|
|
76
|
-
}
|
|
77
|
-
return nodes.push({
|
|
78
|
-
type: "element",
|
|
79
|
-
tagName: "div",
|
|
80
|
-
properties: {
|
|
81
|
-
dataLine: line,
|
|
82
|
-
className: "highlight-line",
|
|
83
|
-
dataHighlighted: linesToHighlight.includes(line) || highlightAll ? "true" : "false"
|
|
84
|
-
},
|
|
85
|
-
children,
|
|
86
|
-
lineNumber: line
|
|
87
|
-
}), nodes;
|
|
88
|
-
}, []);
|
|
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 ${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;
|
|
101
|
-
};
|
|
102
|
-
function highlightLine(ast, lines) {
|
|
103
|
-
var formattedAst = applyMultilineFix(ast), numbered = lineNumberify(formattedAst).nodes;
|
|
104
|
-
return wrapLines(numbered, lines);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// src/highlightWord.ts
|
|
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;
|
|
109
|
-
function highlightWord(code) {
|
|
110
|
-
var html = (0, import_hast_util_to_html2.toHtml)(code), result = html.replace(CALLOUT, function(_, text) {
|
|
111
|
-
return `<span class="highlight-word">${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;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// src/index.ts
|
|
29
|
+
var import_hast_util_to_html = 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")), import_highlightLine = require("./highlightLine"), import_highlightWord = require("./highlightWord");
|
|
120
30
|
import_refractor.refractor.register(import_tsx.default);
|
|
121
31
|
import_refractor.refractor.register(import_css.default);
|
|
122
32
|
function codeToHTML(source, language) {
|
|
123
33
|
var line = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : "0", result = import_refractor.refractor.highlight(source, language);
|
|
124
|
-
return result = highlightLine(result, (0, import_parse_numeric_range.default)(line)), result = highlightWord(result), result = (0,
|
|
34
|
+
return result = (0, import_highlightLine.highlightLine)(result, (0, import_parse_numeric_range.default)(line)), result = (0, import_highlightWord.highlightWord)(result), result = (0, import_hast_util_to_html.toHtml)(result), result;
|
|
125
35
|
}
|
|
126
36
|
// Annotate the CommonJS export names for ESM import in node:
|
|
127
37
|
0 && (module.exports = {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../src/Users/n8/tamagui/code/packages/code-to-html/src/index.ts"
|
|
4
|
-
"mappings": "
|
|
5
|
-
"names": ["
|
|
3
|
+
"sources": ["../../src/Users/n8/tamagui/code/packages/code-to-html/src/index.ts"],
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;+BAAuB,8BACvB,6BAAwB,yCACxB,mBAA0B,sBAC1B,aAAgB,wCAChB,aAAgB,wCAEhB,uBAA8B,4BAC9B,uBAA8B;AAE9BA,2BAAUC,SAASC,WAAAA,OAAAA;AACnBF,2BAAUC,SAASE,WAAAA,OAAAA;AAEZ,SAASC,WAAWC,QAAgBC,UAAgC;MAAEC,OAAAA,UAAAA,SAAAA,KAAAA,UAAAA,CAAAA,MAAAA,SAAAA,UAAAA,CAAAA,IAAO,KAC9EC,SAAcR,2BAAUS,UAAUJ,QAAQC,QAAAA;AAC9CE,sBAASE,oCAAcF,YAAQG,2BAAAA,SAAYJ,IAAAA,CAAAA,GAC3CC,aAASI,oCAAcJ,MAAAA,GACvBA,aAASK,iCAAOL,MAAAA,GACTA;AACT;",
|
|
5
|
+
"names": ["refractor", "register", "tsx", "css", "codeToHTML", "source", "language", "line", "result", "highlight", "highlightLine", "rangeParser", "highlightWord", "toHtml"]
|
|
6
6
|
}
|