@tamagui/code-to-html 1.61.3 → 1.62.0
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 +30 -62
- package/dist/cjs/highlightLine.js.map +2 -2
- package/dist/cjs/highlightLine.native.js +103 -0
- package/dist/cjs/highlightLine.native.js.map +6 -0
- package/dist/cjs/highlightWord.js +10 -21
- package/dist/cjs/highlightWord.js.map +1 -1
- package/dist/cjs/highlightWord.native.js +43 -0
- package/dist/cjs/highlightWord.native.js.map +6 -0
- package/dist/cjs/index.js +35 -79
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/index.native.js +124 -0
- package/dist/cjs/index.native.js.map +6 -0
- package/dist/esm/highlightLine.js +1406 -4729
- package/dist/esm/highlightLine.js.map +2 -2
- package/dist/esm/highlightWord.js +1390 -4692
- package/dist/esm/highlightWord.js.map +2 -2
- package/dist/esm/index.js +2202 -6112
- package/dist/esm/index.js.map +2 -2
- package/package.json +2 -2
|
@@ -1,20 +1,15 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable:
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
9
|
+
}, __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from == "object" || typeof from == "function")
|
|
14
11
|
for (let key of __getOwnPropNames(from))
|
|
15
|
-
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
12
|
+
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
13
|
return to;
|
|
19
14
|
};
|
|
20
15
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
@@ -22,10 +17,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
22
17
|
// file that has been converted to a CommonJS file using a Babel-
|
|
23
18
|
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
19
|
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable:
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
|
|
26
21
|
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
|
+
)), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
29
23
|
|
|
30
24
|
// src/highlightLine.ts
|
|
31
25
|
var highlightLine_exports = {};
|
|
@@ -33,56 +27,38 @@ __export(highlightLine_exports, {
|
|
|
33
27
|
highlightLine: () => highlightLine
|
|
34
28
|
});
|
|
35
29
|
module.exports = __toCommonJS(highlightLine_exports);
|
|
36
|
-
var import_hast_util_to_html = require("hast-util-to-html")
|
|
37
|
-
var import_rehype_parse = __toESM(require("rehype-parse"));
|
|
38
|
-
var import_unified = require("unified");
|
|
39
|
-
var lineNumberify = function lineNumberify2(ast, lineNum = 1) {
|
|
30
|
+
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) {
|
|
40
31
|
let lineNumber = lineNum;
|
|
41
32
|
return ast.reduce(
|
|
42
33
|
(result, node) => {
|
|
43
34
|
if (node.type === "text") {
|
|
44
|
-
if (node.value.indexOf(
|
|
45
|
-
|
|
46
|
-
result.nodes.push(node);
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if (i !== 0)
|
|
52
|
-
++lineNumber;
|
|
53
|
-
if (i === lines.length - 1 && lines[i].length === 0)
|
|
54
|
-
continue;
|
|
55
|
-
result.nodes.push({
|
|
35
|
+
if (node.value.indexOf(`
|
|
36
|
+
`) === -1)
|
|
37
|
+
return node.lineNumber = lineNumber, result.nodes.push(node), result;
|
|
38
|
+
let lines = node.value.split(`
|
|
39
|
+
`);
|
|
40
|
+
for (let i = 0; i < lines.length; i++)
|
|
41
|
+
i !== 0 && ++lineNumber, !(i === lines.length - 1 && lines[i].length === 0) && result.nodes.push({
|
|
56
42
|
type: "text",
|
|
57
43
|
value: i === lines.length - 1 ? lines[i] : `${lines[i]}
|
|
58
44
|
`,
|
|
59
45
|
lineNumber
|
|
60
46
|
});
|
|
61
|
-
|
|
62
|
-
result.lineNumber = lineNumber;
|
|
63
|
-
return result;
|
|
47
|
+
return result.lineNumber = lineNumber, result;
|
|
64
48
|
}
|
|
65
49
|
if (node.children) {
|
|
66
50
|
node.lineNumber = lineNumber;
|
|
67
|
-
|
|
68
|
-
node.children = processed.nodes;
|
|
69
|
-
result.lineNumber = processed.lineNumber;
|
|
70
|
-
result.nodes.push(node);
|
|
71
|
-
return result;
|
|
51
|
+
let processed = lineNumberify2(node.children, lineNumber);
|
|
52
|
+
return node.children = processed.nodes, result.lineNumber = processed.lineNumber, result.nodes.push(node), result;
|
|
72
53
|
}
|
|
73
|
-
result.nodes.push(node);
|
|
74
|
-
return result;
|
|
54
|
+
return result.nodes.push(node), result;
|
|
75
55
|
},
|
|
76
56
|
{ nodes: [], lineNumber }
|
|
77
57
|
);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
let i = 0;
|
|
83
|
-
const wrapped = allLines.reduce((nodes, marker) => {
|
|
84
|
-
const line = marker;
|
|
85
|
-
const children = [];
|
|
58
|
+
}, wrapLines = function(ast, linesToHighlight) {
|
|
59
|
+
let highlightAll = linesToHighlight.length === 1 && linesToHighlight[0] === 0, allLines = Array.from(new Set(ast.map((x) => x.lineNumber))), i = 0;
|
|
60
|
+
return allLines.reduce((nodes, marker) => {
|
|
61
|
+
let line = marker, children = [];
|
|
86
62
|
for (; i < ast.length; i++) {
|
|
87
63
|
if (ast[i].lineNumber < line) {
|
|
88
64
|
nodes.push(ast[i]);
|
|
@@ -92,11 +68,10 @@ var wrapLines = function wrapLines2(ast, linesToHighlight) {
|
|
|
92
68
|
children.push(ast[i]);
|
|
93
69
|
continue;
|
|
94
70
|
}
|
|
95
|
-
if (ast[i].lineNumber > line)
|
|
71
|
+
if (ast[i].lineNumber > line)
|
|
96
72
|
break;
|
|
97
|
-
}
|
|
98
73
|
}
|
|
99
|
-
nodes.push({
|
|
74
|
+
return nodes.push({
|
|
100
75
|
type: "element",
|
|
101
76
|
tagName: "div",
|
|
102
77
|
properties: {
|
|
@@ -106,25 +81,18 @@ var wrapLines = function wrapLines2(ast, linesToHighlight) {
|
|
|
106
81
|
},
|
|
107
82
|
children,
|
|
108
83
|
lineNumber: line
|
|
109
|
-
});
|
|
110
|
-
return nodes;
|
|
84
|
+
}), nodes;
|
|
111
85
|
}, []);
|
|
112
|
-
|
|
113
|
-
};
|
|
114
|
-
var MULTILINE_TOKEN_SPAN = /<span class="token ([^"]+)">[^<]*\n[^<]*<\/span>/g;
|
|
115
|
-
var applyMultilineFix = function(ast) {
|
|
86
|
+
}, MULTILINE_TOKEN_SPAN = /<span class="token ([^"]+)">[^<]*\n[^<]*<\/span>/g, applyMultilineFix = function(ast) {
|
|
116
87
|
let html = (0, import_hast_util_to_html.toHtml)(ast);
|
|
117
|
-
html = html.replace(
|
|
88
|
+
return html = html.replace(
|
|
118
89
|
MULTILINE_TOKEN_SPAN,
|
|
119
90
|
(match, token) => match.replace(/\n/g, `</span>
|
|
120
91
|
<span class="token ${token}">`)
|
|
121
|
-
);
|
|
122
|
-
const hast = (0, import_unified.unified)().use(import_rehype_parse.default, { emitParseErrors: true, fragment: true }).parse(html);
|
|
123
|
-
return hast.children;
|
|
92
|
+
), (0, import_unified.unified)().use(import_rehype_parse.default, { emitParseErrors: !0, fragment: !0 }).parse(html).children;
|
|
124
93
|
};
|
|
125
94
|
function highlightLine(ast, lines) {
|
|
126
|
-
|
|
127
|
-
const numbered = lineNumberify(formattedAst).nodes;
|
|
95
|
+
let formattedAst = applyMultilineFix(ast), numbered = lineNumberify(formattedAst).nodes;
|
|
128
96
|
return wrapLines(numbered, lines);
|
|
129
97
|
}
|
|
130
98
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/highlightLine.ts"],
|
|
4
|
-
"mappings": "
|
|
5
|
-
"names": ["lineNumberify", "
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,+BAAuB,8BACvB,sBAAkB,kCAClB,iBAAwB,oBAElB,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,YAAM,QAAQ,KAAK,MAAM,MAAM;AAAA,CAAI;AACnC,iBAAS,IAAI,GA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AU;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,SAAU,KAAK;AAEvC,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,MAAM,eAAe,kBAAkB,GAAG,GACpC,WAAW,cAAc,YAAY,EAAE;AAC7C,SAAO,UAAU,UAAU,KAAK;AAClC;",
|
|
5
|
+
"names": ["lineNumberify", "parse"]
|
|
6
6
|
}
|
|
@@ -0,0 +1,103 @@
|
|
|
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
|
+
|
|
25
|
+
// src/highlightLine.ts
|
|
26
|
+
var highlightLine_exports = {};
|
|
27
|
+
__export(highlightLine_exports, {
|
|
28
|
+
highlightLine: () => highlightLine
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(highlightLine_exports);
|
|
31
|
+
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) {
|
|
32
|
+
let lineNumber = lineNum;
|
|
33
|
+
return ast.reduce(
|
|
34
|
+
(result, node) => {
|
|
35
|
+
if (node.type === "text") {
|
|
36
|
+
if (node.value.indexOf(`
|
|
37
|
+
`) === -1)
|
|
38
|
+
return node.lineNumber = lineNumber, result.nodes.push(node), result;
|
|
39
|
+
let lines = node.value.split(`
|
|
40
|
+
`);
|
|
41
|
+
for (let i = 0; i < lines.length; i++)
|
|
42
|
+
i !== 0 && ++lineNumber, !(i === lines.length - 1 && lines[i].length === 0) && result.nodes.push({
|
|
43
|
+
type: "text",
|
|
44
|
+
value: i === lines.length - 1 ? lines[i] : `${lines[i]}
|
|
45
|
+
`,
|
|
46
|
+
lineNumber
|
|
47
|
+
});
|
|
48
|
+
return result.lineNumber = lineNumber, result;
|
|
49
|
+
}
|
|
50
|
+
if (node.children) {
|
|
51
|
+
node.lineNumber = lineNumber;
|
|
52
|
+
let processed = lineNumberify2(node.children, lineNumber);
|
|
53
|
+
return node.children = processed.nodes, result.lineNumber = processed.lineNumber, result.nodes.push(node), result;
|
|
54
|
+
}
|
|
55
|
+
return result.nodes.push(node), result;
|
|
56
|
+
},
|
|
57
|
+
{ nodes: [], lineNumber }
|
|
58
|
+
);
|
|
59
|
+
}, wrapLines = function(ast, linesToHighlight) {
|
|
60
|
+
let highlightAll = linesToHighlight.length === 1 && linesToHighlight[0] === 0, allLines = Array.from(new Set(ast.map((x) => x.lineNumber))), i = 0;
|
|
61
|
+
return allLines.reduce((nodes, marker) => {
|
|
62
|
+
let line = marker, children = [];
|
|
63
|
+
for (; i < ast.length; i++) {
|
|
64
|
+
if (ast[i].lineNumber < line) {
|
|
65
|
+
nodes.push(ast[i]);
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
if (ast[i].lineNumber === line) {
|
|
69
|
+
children.push(ast[i]);
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
if (ast[i].lineNumber > line)
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
return nodes.push({
|
|
76
|
+
type: "element",
|
|
77
|
+
tagName: "div",
|
|
78
|
+
properties: {
|
|
79
|
+
dataLine: line,
|
|
80
|
+
className: "highlight-line",
|
|
81
|
+
dataHighlighted: linesToHighlight.includes(line) || highlightAll ? "true" : "false"
|
|
82
|
+
},
|
|
83
|
+
children,
|
|
84
|
+
lineNumber: line
|
|
85
|
+
}), nodes;
|
|
86
|
+
}, []);
|
|
87
|
+
}, MULTILINE_TOKEN_SPAN = /<span class="token ([^"]+)">[^<]*\n[^<]*<\/span>/g, applyMultilineFix = function(ast) {
|
|
88
|
+
let html = (0, import_hast_util_to_html.toHtml)(ast);
|
|
89
|
+
return html = html.replace(
|
|
90
|
+
MULTILINE_TOKEN_SPAN,
|
|
91
|
+
(match, token) => match.replace(/\n/g, `</span>
|
|
92
|
+
<span class="token ${token}">`)
|
|
93
|
+
), (0, import_unified.unified)().use(import_rehype_parse.default, { emitParseErrors: !0, fragment: !0 }).parse(html).children;
|
|
94
|
+
};
|
|
95
|
+
function highlightLine(ast, lines) {
|
|
96
|
+
let formattedAst = applyMultilineFix(ast), numbered = lineNumberify(formattedAst).nodes;
|
|
97
|
+
return wrapLines(numbered, lines);
|
|
98
|
+
}
|
|
99
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
100
|
+
0 && (module.exports = {
|
|
101
|
+
highlightLine
|
|
102
|
+
});
|
|
103
|
+
//# 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,oBAElB,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,YAAM,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;A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,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,MAAM,eAAe,kBAAkB,GAAG,GACpC,WAAW,cAAc,YAAY,EAAE;AAC7C,SAAO,UAAU,UAAU,KAAK;AAClC;",
|
|
5
|
+
"names": ["lineNumberify", "parse"]
|
|
6
|
+
}
|
|
@@ -1,20 +1,15 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable:
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
9
|
+
}, __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from == "object" || typeof from == "function")
|
|
14
11
|
for (let key of __getOwnPropNames(from))
|
|
15
|
-
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
12
|
+
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
13
|
return to;
|
|
19
14
|
};
|
|
20
15
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
@@ -22,10 +17,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
22
17
|
// file that has been converted to a CommonJS file using a Babel-
|
|
23
18
|
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
19
|
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable:
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
|
|
26
21
|
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
|
+
)), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
29
23
|
|
|
30
24
|
// src/highlightWord.ts
|
|
31
25
|
var highlightWord_exports = {};
|
|
@@ -33,18 +27,13 @@ __export(highlightWord_exports, {
|
|
|
33
27
|
highlightWord: () => highlightWord
|
|
34
28
|
});
|
|
35
29
|
module.exports = __toCommonJS(highlightWord_exports);
|
|
36
|
-
var import_hast_util_to_html = require("hast-util-to-html");
|
|
37
|
-
var import_rehype_parse = __toESM(require("rehype-parse"));
|
|
38
|
-
var import_unified = require("unified");
|
|
39
|
-
var CALLOUT = /__(.*?)__/g;
|
|
30
|
+
var import_hast_util_to_html = require("hast-util-to-html"), import_rehype_parse = __toESM(require("rehype-parse")), import_unified = require("unified"), CALLOUT = /__(.*?)__/g;
|
|
40
31
|
function highlightWord(code) {
|
|
41
|
-
|
|
42
|
-
const result = html.replace(
|
|
32
|
+
let result = (0, import_hast_util_to_html.toHtml)(code).replace(
|
|
43
33
|
CALLOUT,
|
|
44
34
|
(_, text) => `<span class="highlight-word">${text}</span>`
|
|
45
35
|
);
|
|
46
|
-
|
|
47
|
-
return hast.children;
|
|
36
|
+
return (0, import_unified.unified)().use(import_rehype_parse.default, { emitParseErrors: !0, fragment: !0 }).parse(result).children;
|
|
48
37
|
}
|
|
49
38
|
// Annotate the CommonJS export names for ESM import in node:
|
|
50
39
|
0 && (module.exports = {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/highlightWord.ts"],
|
|
4
|
-
"mappings": "
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,+BAAuB,8BACvB,sBAAkB,kCAClB,iBAAwB,oBAElB,UAAU;AAET,SAAS,cAAc,MAAM;AAElC,MAAM,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
5
|
"names": ["parse"]
|
|
6
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
|
+
|
|
25
|
+
// src/highlightWord.ts
|
|
26
|
+
var highlightWord_exports = {};
|
|
27
|
+
__export(highlightWord_exports, {
|
|
28
|
+
highlightWord: () => highlightWord
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(highlightWord_exports);
|
|
31
|
+
var import_hast_util_to_html = require("hast-util-to-html"), import_rehype_parse = __toESM(require("rehype-parse")), import_unified = require("unified"), CALLOUT = /__(.*?)__/g;
|
|
32
|
+
function highlightWord(code) {
|
|
33
|
+
let result = (0, import_hast_util_to_html.toHtml)(code).replace(
|
|
34
|
+
CALLOUT,
|
|
35
|
+
(_, text) => `<span class="highlight-word">${text}</span>`
|
|
36
|
+
);
|
|
37
|
+
return (0, import_unified.unified)().use(import_rehype_parse.default, { emitParseErrors: !0, fragment: !0 }).parse(result).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/highlightWord.ts"],
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,+BAAuB,8BACvB,sBAAkB,kCAClB,iBAAwB,oBAElB,UAAU;AAET,SAAS,cAAc,MAAM;AAElC,MAAM,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
|
+
}
|
package/dist/cjs/index.js
CHANGED
|
@@ -1,20 +1,15 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf, __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable:
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: !0 });
|
|
9
|
+
}, __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from == "object" || typeof from == "function")
|
|
14
11
|
for (let key of __getOwnPropNames(from))
|
|
15
|
-
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
12
|
+
!__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
13
|
return to;
|
|
19
14
|
};
|
|
20
15
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
@@ -22,10 +17,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
22
17
|
// file that has been converted to a CommonJS file using a Babel-
|
|
23
18
|
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
19
|
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable:
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: !0 }) : target,
|
|
26
21
|
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
|
+
)), __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: !0 }), mod);
|
|
29
23
|
|
|
30
24
|
// src/index.ts
|
|
31
25
|
var src_exports = {};
|
|
@@ -33,63 +27,41 @@ __export(src_exports, {
|
|
|
33
27
|
codeToHTML: () => codeToHTML
|
|
34
28
|
});
|
|
35
29
|
module.exports = __toCommonJS(src_exports);
|
|
36
|
-
var import_hast_util_to_html3 = require("hast-util-to-html");
|
|
37
|
-
var import_parse_numeric_range = __toESM(require("parse-numeric-range"));
|
|
38
|
-
var import_refractor = require("refractor");
|
|
39
|
-
var import_css = __toESM(require("refractor/lang/css"));
|
|
40
|
-
var import_tsx = __toESM(require("refractor/lang/tsx"));
|
|
30
|
+
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"));
|
|
41
31
|
|
|
42
32
|
// src/highlightLine.ts
|
|
43
|
-
var import_hast_util_to_html = require("hast-util-to-html")
|
|
44
|
-
var import_rehype_parse = __toESM(require("rehype-parse"));
|
|
45
|
-
var import_unified = require("unified");
|
|
46
|
-
var lineNumberify = function lineNumberify2(ast, lineNum = 1) {
|
|
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) {
|
|
47
34
|
let lineNumber = lineNum;
|
|
48
35
|
return ast.reduce(
|
|
49
36
|
(result, node) => {
|
|
50
37
|
if (node.type === "text") {
|
|
51
|
-
if (node.value.indexOf(
|
|
52
|
-
|
|
53
|
-
result.nodes.push(node);
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
if (i !== 0)
|
|
59
|
-
++lineNumber;
|
|
60
|
-
if (i === lines.length - 1 && lines[i].length === 0)
|
|
61
|
-
continue;
|
|
62
|
-
result.nodes.push({
|
|
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({
|
|
63
45
|
type: "text",
|
|
64
46
|
value: i === lines.length - 1 ? lines[i] : `${lines[i]}
|
|
65
47
|
`,
|
|
66
48
|
lineNumber
|
|
67
49
|
});
|
|
68
|
-
|
|
69
|
-
result.lineNumber = lineNumber;
|
|
70
|
-
return result;
|
|
50
|
+
return result.lineNumber = lineNumber, result;
|
|
71
51
|
}
|
|
72
52
|
if (node.children) {
|
|
73
53
|
node.lineNumber = lineNumber;
|
|
74
|
-
|
|
75
|
-
node.children = processed.nodes;
|
|
76
|
-
result.lineNumber = processed.lineNumber;
|
|
77
|
-
result.nodes.push(node);
|
|
78
|
-
return result;
|
|
54
|
+
let processed = lineNumberify2(node.children, lineNumber);
|
|
55
|
+
return node.children = processed.nodes, result.lineNumber = processed.lineNumber, result.nodes.push(node), result;
|
|
79
56
|
}
|
|
80
|
-
result.nodes.push(node);
|
|
81
|
-
return result;
|
|
57
|
+
return result.nodes.push(node), result;
|
|
82
58
|
},
|
|
83
59
|
{ nodes: [], lineNumber }
|
|
84
60
|
);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
let i = 0;
|
|
90
|
-
const wrapped = allLines.reduce((nodes, marker) => {
|
|
91
|
-
const line = marker;
|
|
92
|
-
const children = [];
|
|
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 = [];
|
|
93
65
|
for (; i < ast.length; i++) {
|
|
94
66
|
if (ast[i].lineNumber < line) {
|
|
95
67
|
nodes.push(ast[i]);
|
|
@@ -99,11 +71,10 @@ var wrapLines = function wrapLines2(ast, linesToHighlight) {
|
|
|
99
71
|
children.push(ast[i]);
|
|
100
72
|
continue;
|
|
101
73
|
}
|
|
102
|
-
if (ast[i].lineNumber > line)
|
|
74
|
+
if (ast[i].lineNumber > line)
|
|
103
75
|
break;
|
|
104
|
-
}
|
|
105
76
|
}
|
|
106
|
-
nodes.push({
|
|
77
|
+
return nodes.push({
|
|
107
78
|
type: "element",
|
|
108
79
|
tagName: "div",
|
|
109
80
|
properties: {
|
|
@@ -113,41 +84,29 @@ var wrapLines = function wrapLines2(ast, linesToHighlight) {
|
|
|
113
84
|
},
|
|
114
85
|
children,
|
|
115
86
|
lineNumber: line
|
|
116
|
-
});
|
|
117
|
-
return nodes;
|
|
87
|
+
}), nodes;
|
|
118
88
|
}, []);
|
|
119
|
-
|
|
120
|
-
};
|
|
121
|
-
var MULTILINE_TOKEN_SPAN = /<span class="token ([^"]+)">[^<]*\n[^<]*<\/span>/g;
|
|
122
|
-
var applyMultilineFix = function(ast) {
|
|
89
|
+
}, MULTILINE_TOKEN_SPAN = /<span class="token ([^"]+)">[^<]*\n[^<]*<\/span>/g, applyMultilineFix = function(ast) {
|
|
123
90
|
let html = (0, import_hast_util_to_html.toHtml)(ast);
|
|
124
|
-
html = html.replace(
|
|
91
|
+
return html = html.replace(
|
|
125
92
|
MULTILINE_TOKEN_SPAN,
|
|
126
93
|
(match, token) => match.replace(/\n/g, `</span>
|
|
127
94
|
<span class="token ${token}">`)
|
|
128
|
-
);
|
|
129
|
-
const hast = (0, import_unified.unified)().use(import_rehype_parse.default, { emitParseErrors: true, fragment: true }).parse(html);
|
|
130
|
-
return hast.children;
|
|
95
|
+
), (0, import_unified.unified)().use(import_rehype_parse.default, { emitParseErrors: !0, fragment: !0 }).parse(html).children;
|
|
131
96
|
};
|
|
132
97
|
function highlightLine(ast, lines) {
|
|
133
|
-
|
|
134
|
-
const numbered = lineNumberify(formattedAst).nodes;
|
|
98
|
+
let formattedAst = applyMultilineFix(ast), numbered = lineNumberify(formattedAst).nodes;
|
|
135
99
|
return wrapLines(numbered, lines);
|
|
136
100
|
}
|
|
137
101
|
|
|
138
102
|
// src/highlightWord.ts
|
|
139
|
-
var import_hast_util_to_html2 = require("hast-util-to-html");
|
|
140
|
-
var import_rehype_parse2 = __toESM(require("rehype-parse"));
|
|
141
|
-
var import_unified2 = require("unified");
|
|
142
|
-
var CALLOUT = /__(.*?)__/g;
|
|
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;
|
|
143
104
|
function highlightWord(code) {
|
|
144
|
-
|
|
145
|
-
const result = html.replace(
|
|
105
|
+
let result = (0, import_hast_util_to_html2.toHtml)(code).replace(
|
|
146
106
|
CALLOUT,
|
|
147
107
|
(_, text) => `<span class="highlight-word">${text}</span>`
|
|
148
108
|
);
|
|
149
|
-
|
|
150
|
-
return hast.children;
|
|
109
|
+
return (0, import_unified2.unified)().use(import_rehype_parse2.default, { emitParseErrors: !0, fragment: !0 }).parse(result).children;
|
|
151
110
|
}
|
|
152
111
|
|
|
153
112
|
// src/index.ts
|
|
@@ -155,10 +114,7 @@ import_refractor.refractor.register(import_tsx.default);
|
|
|
155
114
|
import_refractor.refractor.register(import_css.default);
|
|
156
115
|
function codeToHTML(source, language, line = "0") {
|
|
157
116
|
let result = import_refractor.refractor.highlight(source, language);
|
|
158
|
-
result = highlightLine(result, (0, import_parse_numeric_range.default)(line));
|
|
159
|
-
result = highlightWord(result);
|
|
160
|
-
result = (0, import_hast_util_to_html3.toHtml)(result);
|
|
161
|
-
return result;
|
|
117
|
+
return result = highlightLine(result, (0, import_parse_numeric_range.default)(line)), result = highlightWord(result), result = (0, import_hast_util_to_html3.toHtml)(result), result;
|
|
162
118
|
}
|
|
163
119
|
// Annotate the CommonJS export names for ESM import in node:
|
|
164
120
|
0 && (module.exports = {
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/index.ts", "../../src/highlightLine.ts", "../../src/highlightWord.ts"],
|
|
4
|
-
"mappings": "
|
|
5
|
-
"names": ["import_hast_util_to_html", "lineNumberify", "
|
|
4
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,4BAAuB,8BACvB,6BAAwB,yCACxB,mBAA0B,sBAC1B,aAAgB,wCAChB,aAAgB;;;ACFhB,+BAAuB,8BACvB,sBAAkB,kCAClB,iBAAwB,oBAElB,gBAAgB,SAASC,eAAc,KAAK,UAAU,GAAG;AAC7D,MAAI,aAAa;AACjB,SAAO,IAAI;AAAA,IACT,CAAC,QAAQ,SAAS;AAChB,UAAI,KAAK,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MAAI,SAAc,2BAAU,UAAU,QAAQ,QAAQ;AACtD,kBAAS,cAAc,YAAQ,2BAAAC,SAAY,IAAI,CAAC,GAChD,SAAS,cAAc,MAAM,GAC7B,aAAS,kCAAO,MAAM,GACf;AACT;",
|
|
5
|
+
"names": ["import_hast_util_to_html", "lineNumberify", "parse", "import_hast_util_to_html", "import_rehype_parse", "import_unified", "parse", "tsx", "css", "rangeParser"]
|
|
6
6
|
}
|