@hanzogui/code-to-html 8.3.1 → 8.3.3
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 +96 -0
- package/dist/cjs/highlightLine.js.map +1 -0
- package/dist/cjs/highlightWord.js +18 -0
- package/dist/cjs/highlightWord.js.map +1 -0
- package/dist/cjs/index.js +21 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/esm/highlightLine.js +92 -0
- package/dist/esm/highlightLine.js.map +1 -0
- package/dist/esm/highlightWord.js +14 -0
- package/dist/esm/highlightWord.js.map +1 -0
- package/dist/esm/index.js +14 -15
- package/dist/esm/index.js.map +1 -1
- package/package.json +31 -13
- package/src/index.ts +4 -4
- package/dist/cjs/highlightLine.cjs +0 -130
- package/dist/cjs/highlightLine.native.js +0 -138
- package/dist/cjs/highlightLine.native.js.map +0 -1
- package/dist/cjs/highlightWord.cjs +0 -51
- package/dist/cjs/highlightWord.native.js +0 -56
- package/dist/cjs/highlightWord.native.js.map +0 -1
- package/dist/cjs/index.cjs +0 -54
- package/dist/cjs/index.native.js +0 -58
- package/dist/cjs/index.native.js.map +0 -1
- package/dist/esm/highlightLine.mjs +0 -94
- package/dist/esm/highlightLine.mjs.map +0 -1
- package/dist/esm/highlightLine.native.js +0 -99
- package/dist/esm/highlightLine.native.js.map +0 -1
- package/dist/esm/highlightWord.mjs +0 -15
- package/dist/esm/highlightWord.mjs.map +0 -1
- package/dist/esm/highlightWord.native.js +0 -17
- package/dist/esm/highlightWord.native.js.map +0 -1
- package/dist/esm/index.mjs +0 -18
- package/dist/esm/index.mjs.map +0 -1
- package/dist/esm/index.native.js +0 -19
- package/dist/esm/index.native.js.map +0 -1
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Inspired by https://github.com/j0lv3r4/mdx-prism
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.highlightLine = highlightLine;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const hast_util_to_html_1 = require("hast-util-to-html");
|
|
7
|
+
const rehype_parse_1 = tslib_1.__importDefault(require("rehype-parse"));
|
|
8
|
+
const unified_1 = require("unified");
|
|
9
|
+
const lineNumberify = function lineNumberify(ast, lineNum = 1) {
|
|
10
|
+
let lineNumber = lineNum;
|
|
11
|
+
return ast.reduce((result, node) => {
|
|
12
|
+
if (node.type === 'text') {
|
|
13
|
+
if (node.value.indexOf('\n') === -1) {
|
|
14
|
+
node.lineNumber = lineNumber;
|
|
15
|
+
result.nodes.push(node);
|
|
16
|
+
return result;
|
|
17
|
+
}
|
|
18
|
+
const lines = node.value.split('\n');
|
|
19
|
+
for (let i = 0; i < lines.length; i++) {
|
|
20
|
+
if (i !== 0)
|
|
21
|
+
++lineNumber;
|
|
22
|
+
if (i === lines.length - 1 && lines[i].length === 0)
|
|
23
|
+
continue;
|
|
24
|
+
result.nodes.push({
|
|
25
|
+
type: 'text',
|
|
26
|
+
value: i === lines.length - 1 ? lines[i] : `${lines[i]}\n`,
|
|
27
|
+
lineNumber: lineNumber,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
result.lineNumber = lineNumber;
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
if (node.children) {
|
|
34
|
+
node.lineNumber = lineNumber;
|
|
35
|
+
const processed = lineNumberify(node.children, lineNumber);
|
|
36
|
+
node.children = processed.nodes;
|
|
37
|
+
result.lineNumber = processed.lineNumber;
|
|
38
|
+
result.nodes.push(node);
|
|
39
|
+
return result;
|
|
40
|
+
}
|
|
41
|
+
result.nodes.push(node);
|
|
42
|
+
return result;
|
|
43
|
+
}, { nodes: [], lineNumber: lineNumber });
|
|
44
|
+
};
|
|
45
|
+
const wrapLines = function wrapLines(ast, linesToHighlight) {
|
|
46
|
+
const highlightAll = linesToHighlight.length === 1 && linesToHighlight[0] === 0;
|
|
47
|
+
const allLines = Array.from(new Set(ast.map((x) => x.lineNumber)));
|
|
48
|
+
let i = 0;
|
|
49
|
+
const wrapped = allLines.reduce((nodes, marker) => {
|
|
50
|
+
const line = marker;
|
|
51
|
+
const children = [];
|
|
52
|
+
for (; i < ast.length; i++) {
|
|
53
|
+
if (ast[i].lineNumber < line) {
|
|
54
|
+
nodes.push(ast[i]);
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
if (ast[i].lineNumber === line) {
|
|
58
|
+
children.push(ast[i]);
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
if (ast[i].lineNumber > line) {
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
nodes.push({
|
|
66
|
+
type: 'element',
|
|
67
|
+
tagName: 'div',
|
|
68
|
+
properties: {
|
|
69
|
+
dataLine: line,
|
|
70
|
+
className: 'highlight-line',
|
|
71
|
+
dataHighlighted: linesToHighlight.includes(line) || highlightAll ? 'true' : 'false',
|
|
72
|
+
},
|
|
73
|
+
children,
|
|
74
|
+
lineNumber: line,
|
|
75
|
+
});
|
|
76
|
+
return nodes;
|
|
77
|
+
}, []);
|
|
78
|
+
return wrapped;
|
|
79
|
+
};
|
|
80
|
+
// https://github.com/gatsbyjs/gatsby/pull/26161/files
|
|
81
|
+
const MULTILINE_TOKEN_SPAN = /<span class="token ([^"]+)">[^<]*\n[^<]*<\/span>/g;
|
|
82
|
+
const applyMultilineFix = (ast) => {
|
|
83
|
+
// AST to HTML
|
|
84
|
+
let html = (0, hast_util_to_html_1.toHtml)(ast);
|
|
85
|
+
// Fix JSX issue
|
|
86
|
+
html = html.replace(MULTILINE_TOKEN_SPAN, (match, token) => match.replace(/\n/g, `</span>\n<span class="token ${token}">`));
|
|
87
|
+
// HTML to AST
|
|
88
|
+
const hast = (0, unified_1.unified)().use(rehype_parse_1.default, { emitParseErrors: true, fragment: true }).parse(html);
|
|
89
|
+
return hast['children'];
|
|
90
|
+
};
|
|
91
|
+
function highlightLine(ast, lines) {
|
|
92
|
+
const formattedAst = applyMultilineFix(ast);
|
|
93
|
+
const numbered = lineNumberify(formattedAst).nodes;
|
|
94
|
+
return wrapLines(numbered, lines);
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=highlightLine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"highlightLine.js","sourceRoot":"","sources":["../../src/highlightLine.ts"],"names":[],"mappings":";AAAA,mDAAmD;;;;AAEnD,yDAA0C;AAC1C,wEAAgC;AAChC,qCAAiC;AAEjC,MAAM,aAAa,GAAG,SAAS,aAAa,CAAC,GAAG,EAAE,OAAO,GAAG,CAAC;IAC3D,IAAI,UAAU,GAAG,OAAO,CAAA;IACxB,OAAO,GAAG,CAAC,MAAM,CACf,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE;QACf,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;YACzB,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;gBACpC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;gBAC5B,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;gBACvB,OAAO,MAAM,CAAA;YACf,CAAC;YAED,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;YACpC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;gBACtC,IAAI,CAAC,KAAK,CAAC;oBAAE,EAAE,UAAU,CAAA;gBACzB,IAAI,CAAC,KAAK,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC;oBAAE,SAAQ;gBAC7D,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC;oBAChB,IAAI,EAAE,MAAM;o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AAC,GAAG,CAAC,CAAA;IAEtB,gBAAgB;IAChB,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,oBAAoB,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CACzD,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,+BAA+B,KAAK,IAAI,CAAC,CAC/D,CAAA;IAED,cAAc;IACd,MAAM,IAAI,GAAG,IAAA,iBAAO,GAAE,CAAC,GAAG,CAAC,sBAAK,EAAE,EAAE,eAAe,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAExF,OAAO,IAAI,CAAC,UAAU,CAAC,CAAA;AACzB,CAAC,CAAA;AAED,uBAA8B,GAAG,EAAE,KAAK;IACtC,MAAM,YAAY,GAAG,iBAAiB,CAAC,GAAG,CAAC,CAAA;IAC3C,MAAM,QAAQ,GAAG,aAAa,CAAC,YAAY,CAAC,CAAC,KAAK,CAAA;IAClD,OAAO,SAAS,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAA;AACnC,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.highlightWord = highlightWord;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
// const visit = require('unist-util-visit')
|
|
6
|
+
const hast_util_to_html_1 = require("hast-util-to-html");
|
|
7
|
+
const rehype_parse_1 = tslib_1.__importDefault(require("rehype-parse"));
|
|
8
|
+
const unified_1 = require("unified");
|
|
9
|
+
const CALLOUT = /__(.*?)__/g;
|
|
10
|
+
function highlightWord(code) {
|
|
11
|
+
const html = (0, hast_util_to_html_1.toHtml)(code);
|
|
12
|
+
const result = html.replace(CALLOUT, (_, text) => `<span class="highlight-word">${text}</span>`);
|
|
13
|
+
const hast = (0, unified_1.unified)()
|
|
14
|
+
.use(rehype_parse_1.default, { emitParseErrors: true, fragment: true })
|
|
15
|
+
.parse(result);
|
|
16
|
+
return hast['children'];
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=highlightWord.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"highlightWord.js","sourceRoot":"","sources":["../../src/highlightWord.ts"],"names":[],"mappings":";;;;AAAA,4CAA4C;AAC5C,yDAA0C;AAC1C,wEAAgC;AAChC,qCAAiC;AAEjC,MAAM,OAAO,GAAG,YAAY,CAAA;AAE5B,uBAA8B,IAAI;IAChC,MAAM,IAAI,GAAG,IAAA,0BAAM,EAAC,IAAI,CAAC,CAAA;IACzB,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CACzB,OAAO,EACP,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,CAAC,gCAAgC,IAAI,SAAS,CAC3D,CAAA;IACD,MAAM,IAAI,GAAG,IAAA,iBAAO,GAAE;SACnB,GAAG,CAAC,sBAAK,EAAE,EAAE,eAAe,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;SACrD,KAAK,CAAC,MAAM,CAAC,CAAA;IAChB,OAAO,IAAI,CAAC,UAAU,CAAC,CAAA;AACzB,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.codeToHTML = codeToHTML;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const hast_util_to_html_1 = require("hast-util-to-html");
|
|
6
|
+
const parse_numeric_range_1 = tslib_1.__importDefault(require("parse-numeric-range"));
|
|
7
|
+
const refractor_1 = require("refractor");
|
|
8
|
+
const css_1 = tslib_1.__importDefault(require("refractor/css"));
|
|
9
|
+
const tsx_1 = tslib_1.__importDefault(require("refractor/tsx"));
|
|
10
|
+
const highlightLine_ts_1 = require("./highlightLine.js");
|
|
11
|
+
const highlightWord_ts_1 = require("./highlightWord.js");
|
|
12
|
+
refractor_1.refractor.register(tsx_1.default);
|
|
13
|
+
refractor_1.refractor.register(css_1.default);
|
|
14
|
+
function codeToHTML(source, language, line = '0') {
|
|
15
|
+
let result = refractor_1.refractor.highlight(source, language);
|
|
16
|
+
result = (0, highlightLine_ts_1.highlightLine)(result, (0, parse_numeric_range_1.default)(line));
|
|
17
|
+
result = (0, highlightWord_ts_1.highlightWord)(result);
|
|
18
|
+
result = (0, hast_util_to_html_1.toHtml)(result);
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;AAAA,yDAA0C;AAC1C,sFAA6C;AAC7C,yCAAqC;AACrC,gEAA+B;AAC/B,gEAA+B;AAE/B,yDAAkD;AAClD,yDAAkD;AAElD,qBAAS,CAAC,QAAQ,CAAC,aAAG,CAAC,CAAA;AACvB,qBAAS,CAAC,QAAQ,CAAC,aAAG,CAAC,CAAA;AAEvB,oBAA2B,MAAc,EAAE,QAAgC,EAAE,IAAI,GAAG,GAAG;IACrF,IAAI,MAAM,GAAQ,qBAAS,CAAC,SAAS,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;IACvD,MAAM,GAAG,IAAA,gCAAa,EAAC,MAAM,EAAE,IAAA,6BAAW,EAAC,IAAI,CAAC,CAAC,CAAA;IACjD,MAAM,GAAG,IAAA,gCAAa,EAAC,MAAM,CAAC,CAAA;IAC9B,MAAM,GAAG,IAAA,0BAAM,EAAC,MAAM,CAAC,CAAA;IACvB,OAAO,MAAgB,CAAA;AACzB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{ "type": "commonjs" }
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// Inspired by https://github.com/j0lv3r4/mdx-prism
|
|
2
|
+
import { toHtml } from 'hast-util-to-html';
|
|
3
|
+
import parse from 'rehype-parse';
|
|
4
|
+
import { unified } from 'unified';
|
|
5
|
+
const lineNumberify = function lineNumberify(ast, lineNum = 1) {
|
|
6
|
+
let lineNumber = lineNum;
|
|
7
|
+
return ast.reduce((result, node) => {
|
|
8
|
+
if (node.type === 'text') {
|
|
9
|
+
if (node.value.indexOf('\n') === -1) {
|
|
10
|
+
node.lineNumber = lineNumber;
|
|
11
|
+
result.nodes.push(node);
|
|
12
|
+
return result;
|
|
13
|
+
}
|
|
14
|
+
const lines = node.value.split('\n');
|
|
15
|
+
for (let i = 0; i < lines.length; i++) {
|
|
16
|
+
if (i !== 0)
|
|
17
|
+
++lineNumber;
|
|
18
|
+
if (i === lines.length - 1 && lines[i].length === 0)
|
|
19
|
+
continue;
|
|
20
|
+
result.nodes.push({
|
|
21
|
+
type: 'text',
|
|
22
|
+
value: i === lines.length - 1 ? lines[i] : `${lines[i]}\n`,
|
|
23
|
+
lineNumber: lineNumber,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
result.lineNumber = lineNumber;
|
|
27
|
+
return result;
|
|
28
|
+
}
|
|
29
|
+
if (node.children) {
|
|
30
|
+
node.lineNumber = lineNumber;
|
|
31
|
+
const processed = lineNumberify(node.children, lineNumber);
|
|
32
|
+
node.children = processed.nodes;
|
|
33
|
+
result.lineNumber = processed.lineNumber;
|
|
34
|
+
result.nodes.push(node);
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
37
|
+
result.nodes.push(node);
|
|
38
|
+
return result;
|
|
39
|
+
}, { nodes: [], lineNumber: lineNumber });
|
|
40
|
+
};
|
|
41
|
+
const wrapLines = function wrapLines(ast, linesToHighlight) {
|
|
42
|
+
const highlightAll = linesToHighlight.length === 1 && linesToHighlight[0] === 0;
|
|
43
|
+
const allLines = Array.from(new Set(ast.map((x) => x.lineNumber)));
|
|
44
|
+
let i = 0;
|
|
45
|
+
const wrapped = allLines.reduce((nodes, marker) => {
|
|
46
|
+
const line = marker;
|
|
47
|
+
const children = [];
|
|
48
|
+
for (; i < ast.length; i++) {
|
|
49
|
+
if (ast[i].lineNumber < line) {
|
|
50
|
+
nodes.push(ast[i]);
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
if (ast[i].lineNumber === line) {
|
|
54
|
+
children.push(ast[i]);
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
if (ast[i].lineNumber > line) {
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
nodes.push({
|
|
62
|
+
type: 'element',
|
|
63
|
+
tagName: 'div',
|
|
64
|
+
properties: {
|
|
65
|
+
dataLine: line,
|
|
66
|
+
className: 'highlight-line',
|
|
67
|
+
dataHighlighted: linesToHighlight.includes(line) || highlightAll ? 'true' : 'false',
|
|
68
|
+
},
|
|
69
|
+
children,
|
|
70
|
+
lineNumber: line,
|
|
71
|
+
});
|
|
72
|
+
return nodes;
|
|
73
|
+
}, []);
|
|
74
|
+
return wrapped;
|
|
75
|
+
};
|
|
76
|
+
// https://github.com/gatsbyjs/gatsby/pull/26161/files
|
|
77
|
+
const MULTILINE_TOKEN_SPAN = /<span class="token ([^"]+)">[^<]*\n[^<]*<\/span>/g;
|
|
78
|
+
const applyMultilineFix = (ast) => {
|
|
79
|
+
// AST to HTML
|
|
80
|
+
let html = toHtml(ast);
|
|
81
|
+
// Fix JSX issue
|
|
82
|
+
html = html.replace(MULTILINE_TOKEN_SPAN, (match, token) => match.replace(/\n/g, `</span>\n<span class="token ${token}">`));
|
|
83
|
+
// HTML to AST
|
|
84
|
+
const hast = unified().use(parse, { emitParseErrors: true, fragment: true }).parse(html);
|
|
85
|
+
return hast['children'];
|
|
86
|
+
};
|
|
87
|
+
export function highlightLine(ast, lines) {
|
|
88
|
+
const formattedAst = applyMultilineFix(ast);
|
|
89
|
+
const numbered = lineNumberify(formattedAst).nodes;
|
|
90
|
+
return wrapLines(numbered, lines);
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=highlightLine.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3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E,CACzD,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,+BAA+B,KAAK,IAAI,CAAC,CAC/D,CAAA;IAED,cAAc;IACd,MAAM,IAAI,GAAG,OAAO,EAAE,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,eAAe,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;IAExF,OAAO,IAAI,CAAC,UAAU,CAAC,CAAA;AACzB,CAAC,CAAA;AAED,MAAM,UAAU,aAAa,CAAC,GAAG,EAAE,KAAK;IACtC,MAAM,YAAY,GAAG,iBAAiB,CAAC,GAAG,CAAC,CAAA;IAC3C,MAAM,QAAQ,GAAG,aAAa,CAAC,YAAY,CAAC,CAAC,KAAK,CAAA;IAClD,OAAO,SAAS,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAA;AACnC,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// const visit = require('unist-util-visit')
|
|
2
|
+
import { toHtml } from 'hast-util-to-html';
|
|
3
|
+
import parse from 'rehype-parse';
|
|
4
|
+
import { unified } from 'unified';
|
|
5
|
+
const CALLOUT = /__(.*?)__/g;
|
|
6
|
+
export function highlightWord(code) {
|
|
7
|
+
const html = toHtml(code);
|
|
8
|
+
const result = html.replace(CALLOUT, (_, text) => `<span class="highlight-word">${text}</span>`);
|
|
9
|
+
const hast = unified()
|
|
10
|
+
.use(parse, { emitParseErrors: true, fragment: true })
|
|
11
|
+
.parse(result);
|
|
12
|
+
return hast['children'];
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=highlightWord.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"highlightWord.js","sourceRoot":"","sources":["../../src/highlightWord.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAC1C,OAAO,KAAK,MAAM,cAAc,CAAA;AAChC,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAEjC,MAAM,OAAO,GAAG,YAAY,CAAA;AAE5B,MAAM,UAAU,aAAa,CAAC,IAAI;IAChC,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,CAAA;IACzB,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CACzB,OAAO,EACP,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,CAAC,gCAAgC,IAAI,SAAS,CAC3D,CAAA;IACD,MAAM,IAAI,GAAG,OAAO,EAAE;SACnB,GAAG,CAAC,KAAK,EAAE,EAAE,eAAe,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;SACrD,KAAK,CAAC,MAAM,CAAC,CAAA;IAChB,OAAO,IAAI,CAAC,UAAU,CAAC,CAAA;AACzB,CAAC"}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
import { toHtml } from
|
|
2
|
-
import rangeParser from
|
|
3
|
-
import { refractor } from
|
|
4
|
-
import css from
|
|
5
|
-
import tsx from
|
|
6
|
-
import { highlightLine } from
|
|
7
|
-
import { highlightWord } from
|
|
1
|
+
import { toHtml } from 'hast-util-to-html';
|
|
2
|
+
import rangeParser from 'parse-numeric-range';
|
|
3
|
+
import { refractor } from 'refractor';
|
|
4
|
+
import css from 'refractor/css';
|
|
5
|
+
import tsx from 'refractor/tsx';
|
|
6
|
+
import { highlightLine } from './highlightLine.js';
|
|
7
|
+
import { highlightWord } from './highlightWord.js';
|
|
8
8
|
refractor.register(tsx);
|
|
9
9
|
refractor.register(css);
|
|
10
|
-
function codeToHTML(source, language, line =
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
export function codeToHTML(source, language, line = '0') {
|
|
11
|
+
let result = refractor.highlight(source, language);
|
|
12
|
+
result = highlightLine(result, rangeParser(line));
|
|
13
|
+
result = highlightWord(result);
|
|
14
|
+
result = toHtml(result);
|
|
15
|
+
return result;
|
|
16
16
|
}
|
|
17
|
-
|
|
18
|
-
//# sourceMappingURL=index.js.map
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAC1C,OAAO,WAAW,MAAM,qBAAqB,CAAA;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AACrC,OAAO,GAAG,MAAM,eAAe,CAAA;AAC/B,OAAO,GAAG,MAAM,eAAe,CAAA;AAE/B,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAElD,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAA;AACvB,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAA;AAEvB,MAAM,UAAU,UAAU,CAAC,MAAc,EAAE,QAAgC,EAAE,IAAI,GAAG,GAAG;IACrF,IAAI,MAAM,GAAQ,SAAS,CAAC,SAAS,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;IACvD,MAAM,GAAG,aAAa,CAAC,MAAM,EAAE,WAAW,CAAC,IAAI,CAAC,CAAC,CAAA;IACjD,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC,CAAA;IAC9B,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,CAAA;IACvB,OAAO,MAAgB,CAAA;AACzB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,36 +1,54 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hanzogui/code-to-html",
|
|
3
|
-
"version": "8.3.
|
|
3
|
+
"version": "8.3.3",
|
|
4
4
|
"source": "src/index.ts",
|
|
5
5
|
"files": [
|
|
6
6
|
"src",
|
|
7
7
|
"types",
|
|
8
8
|
"dist"
|
|
9
9
|
],
|
|
10
|
-
"
|
|
11
|
-
"
|
|
10
|
+
"type": "module",
|
|
11
|
+
"main": "./dist/cjs/index.js",
|
|
12
|
+
"module": "./dist/esm/index.js",
|
|
12
13
|
"types": "./types/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
"./package.json": "./package.json",
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./types/index.d.ts",
|
|
18
|
+
"react-native": "./dist/esm/index.js",
|
|
19
|
+
"browser": "./dist/esm/index.js",
|
|
20
|
+
"module": "./dist/esm/index.js",
|
|
21
|
+
"import": "./dist/esm/index.js",
|
|
22
|
+
"require": "./dist/cjs/index.js",
|
|
23
|
+
"default": "./dist/esm/index.js"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
13
26
|
"publishConfig": {
|
|
14
27
|
"access": "public"
|
|
15
28
|
},
|
|
16
29
|
"scripts": {
|
|
17
|
-
"build": "hanzogui-build",
|
|
30
|
+
"build": "hanzogui-build --skip-native",
|
|
18
31
|
"watch": "hanzogui-build --watch",
|
|
19
32
|
"clean": "hanzogui-build clean",
|
|
20
33
|
"clean:build": "hanzogui-build clean:build"
|
|
21
34
|
},
|
|
22
35
|
"dependencies": {
|
|
23
|
-
"hast-util-to-html": "^
|
|
24
|
-
"hast-util-to-string": "^
|
|
36
|
+
"hast-util-to-html": "^9.0.5",
|
|
37
|
+
"hast-util-to-string": "^3.0.1",
|
|
25
38
|
"parse-numeric-range": "^1.3.0",
|
|
26
|
-
"refractor": "^
|
|
27
|
-
"rehype": "^
|
|
28
|
-
"rehype-parse": "^
|
|
29
|
-
"rehype-slug": "^
|
|
30
|
-
"unified": "^
|
|
31
|
-
"url": "^0.11.
|
|
39
|
+
"refractor": "^5.0.0",
|
|
40
|
+
"rehype": "^13.0.2",
|
|
41
|
+
"rehype-parse": "^9.0.1",
|
|
42
|
+
"rehype-slug": "^6.0.0",
|
|
43
|
+
"unified": "^11.0.5",
|
|
44
|
+
"url": "^0.11.4"
|
|
32
45
|
},
|
|
33
46
|
"devDependencies": {
|
|
34
|
-
"@hanzogui/build": "8.3.
|
|
47
|
+
"@hanzogui/build": "8.3.3"
|
|
48
|
+
},
|
|
49
|
+
"repository": {
|
|
50
|
+
"type": "git",
|
|
51
|
+
"url": "git+https://github.com/hanzoai/gui.git",
|
|
52
|
+
"directory": "pkgs/code-to-html"
|
|
35
53
|
}
|
|
36
54
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { toHtml } from 'hast-util-to-html'
|
|
2
2
|
import rangeParser from 'parse-numeric-range'
|
|
3
3
|
import { refractor } from 'refractor'
|
|
4
|
-
import css from 'refractor/
|
|
5
|
-
import tsx from 'refractor/
|
|
4
|
+
import css from 'refractor/css'
|
|
5
|
+
import tsx from 'refractor/tsx'
|
|
6
6
|
|
|
7
|
-
import { highlightLine } from './highlightLine'
|
|
8
|
-
import { highlightWord } from './highlightWord'
|
|
7
|
+
import { highlightLine } from './highlightLine.ts'
|
|
8
|
+
import { highlightWord } from './highlightWord.ts'
|
|
9
9
|
|
|
10
10
|
refractor.register(tsx)
|
|
11
11
|
refractor.register(css)
|
|
@@ -1,130 +0,0 @@
|
|
|
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;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all) __defProp(target, name, {
|
|
9
|
-
get: all[name],
|
|
10
|
-
enumerable: true
|
|
11
|
-
});
|
|
12
|
-
};
|
|
13
|
-
var __copyProps = (to, from, except, desc) => {
|
|
14
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
-
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
16
|
-
get: () => from[key],
|
|
17
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
return to;
|
|
21
|
-
};
|
|
22
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
24
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
25
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
28
|
-
value: mod,
|
|
29
|
-
enumerable: true
|
|
30
|
-
}) : target, mod));
|
|
31
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
32
|
-
value: true
|
|
33
|
-
}), mod);
|
|
34
|
-
var highlightLine_exports = {};
|
|
35
|
-
__export(highlightLine_exports, {
|
|
36
|
-
highlightLine: () => highlightLine
|
|
37
|
-
});
|
|
38
|
-
module.exports = __toCommonJS(highlightLine_exports);
|
|
39
|
-
var import_hast_util_to_html = require("hast-util-to-html");
|
|
40
|
-
var import_rehype_parse = __toESM(require("rehype-parse"));
|
|
41
|
-
var import_unified = require("unified");
|
|
42
|
-
const lineNumberify = function lineNumberify2(ast, lineNum = 1) {
|
|
43
|
-
let lineNumber = lineNum;
|
|
44
|
-
return ast.reduce((result, node) => {
|
|
45
|
-
if (node.type === "text") {
|
|
46
|
-
if (node.value.indexOf("\n") === -1) {
|
|
47
|
-
node.lineNumber = lineNumber;
|
|
48
|
-
result.nodes.push(node);
|
|
49
|
-
return result;
|
|
50
|
-
}
|
|
51
|
-
const lines = node.value.split("\n");
|
|
52
|
-
for (let i = 0; i < lines.length; i++) {
|
|
53
|
-
if (i !== 0) ++lineNumber;
|
|
54
|
-
if (i === lines.length - 1 && lines[i].length === 0) continue;
|
|
55
|
-
result.nodes.push({
|
|
56
|
-
type: "text",
|
|
57
|
-
value: i === lines.length - 1 ? lines[i] : `${lines[i]}
|
|
58
|
-
`,
|
|
59
|
-
lineNumber
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
result.lineNumber = lineNumber;
|
|
63
|
-
return result;
|
|
64
|
-
}
|
|
65
|
-
if (node.children) {
|
|
66
|
-
node.lineNumber = lineNumber;
|
|
67
|
-
const processed = lineNumberify2(node.children, lineNumber);
|
|
68
|
-
node.children = processed.nodes;
|
|
69
|
-
result.lineNumber = processed.lineNumber;
|
|
70
|
-
result.nodes.push(node);
|
|
71
|
-
return result;
|
|
72
|
-
}
|
|
73
|
-
result.nodes.push(node);
|
|
74
|
-
return result;
|
|
75
|
-
}, {
|
|
76
|
-
nodes: [],
|
|
77
|
-
lineNumber
|
|
78
|
-
});
|
|
79
|
-
};
|
|
80
|
-
const wrapLines = function wrapLines2(ast, linesToHighlight) {
|
|
81
|
-
const highlightAll = linesToHighlight.length === 1 && linesToHighlight[0] === 0;
|
|
82
|
-
const allLines = Array.from(new Set(ast.map(x => x.lineNumber)));
|
|
83
|
-
let i = 0;
|
|
84
|
-
const wrapped = allLines.reduce((nodes, marker) => {
|
|
85
|
-
const line = marker;
|
|
86
|
-
const children = [];
|
|
87
|
-
for (; i < ast.length; i++) {
|
|
88
|
-
if (ast[i].lineNumber < line) {
|
|
89
|
-
nodes.push(ast[i]);
|
|
90
|
-
continue;
|
|
91
|
-
}
|
|
92
|
-
if (ast[i].lineNumber === line) {
|
|
93
|
-
children.push(ast[i]);
|
|
94
|
-
continue;
|
|
95
|
-
}
|
|
96
|
-
if (ast[i].lineNumber > line) {
|
|
97
|
-
break;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
nodes.push({
|
|
101
|
-
type: "element",
|
|
102
|
-
tagName: "div",
|
|
103
|
-
properties: {
|
|
104
|
-
dataLine: line,
|
|
105
|
-
className: "highlight-line",
|
|
106
|
-
dataHighlighted: linesToHighlight.includes(line) || highlightAll ? "true" : "false"
|
|
107
|
-
},
|
|
108
|
-
children,
|
|
109
|
-
lineNumber: line
|
|
110
|
-
});
|
|
111
|
-
return nodes;
|
|
112
|
-
}, []);
|
|
113
|
-
return wrapped;
|
|
114
|
-
};
|
|
115
|
-
const MULTILINE_TOKEN_SPAN = /<span class="token ([^"]+)">[^<]*\n[^<]*<\/span>/g;
|
|
116
|
-
const applyMultilineFix = ast => {
|
|
117
|
-
let html = (0, import_hast_util_to_html.toHtml)(ast);
|
|
118
|
-
html = html.replace(MULTILINE_TOKEN_SPAN, (match, token) => match.replace(/\n/g, `</span>
|
|
119
|
-
<span class="token ${token}">`));
|
|
120
|
-
const hast = (0, import_unified.unified)().use(import_rehype_parse.default, {
|
|
121
|
-
emitParseErrors: true,
|
|
122
|
-
fragment: true
|
|
123
|
-
}).parse(html);
|
|
124
|
-
return hast["children"];
|
|
125
|
-
};
|
|
126
|
-
function highlightLine(ast, lines) {
|
|
127
|
-
const formattedAst = applyMultilineFix(ast);
|
|
128
|
-
const numbered = lineNumberify(formattedAst).nodes;
|
|
129
|
-
return wrapLines(numbered, lines);
|
|
130
|
-
}
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var __create = Object.create;
|
|
4
|
-
var __defProp = Object.defineProperty;
|
|
5
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
-
var __export = (target, all) => {
|
|
10
|
-
for (var name in all) __defProp(target, name, {
|
|
11
|
-
get: all[name],
|
|
12
|
-
enumerable: true
|
|
13
|
-
});
|
|
14
|
-
};
|
|
15
|
-
var __copyProps = (to, from, except, desc) => {
|
|
16
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
17
|
-
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
18
|
-
get: () => from[key],
|
|
19
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
return to;
|
|
23
|
-
};
|
|
24
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
25
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
26
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
27
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
28
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
29
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
30
|
-
value: mod,
|
|
31
|
-
enumerable: true
|
|
32
|
-
}) : target, mod));
|
|
33
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
34
|
-
value: true
|
|
35
|
-
}), mod);
|
|
36
|
-
var highlightLine_exports = {};
|
|
37
|
-
__export(highlightLine_exports, {
|
|
38
|
-
highlightLine: () => highlightLine
|
|
39
|
-
});
|
|
40
|
-
module.exports = __toCommonJS(highlightLine_exports);
|
|
41
|
-
var import_hast_util_to_html = require("hast-util-to-html");
|
|
42
|
-
var import_rehype_parse = __toESM(require("rehype-parse"));
|
|
43
|
-
var import_unified = require("unified");
|
|
44
|
-
var lineNumberify = function lineNumberify2(ast) {
|
|
45
|
-
var lineNum = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 1;
|
|
46
|
-
var lineNumber = lineNum;
|
|
47
|
-
return ast.reduce(function (result, node) {
|
|
48
|
-
if (node.type === "text") {
|
|
49
|
-
if (node.value.indexOf("\n") === -1) {
|
|
50
|
-
node.lineNumber = lineNumber;
|
|
51
|
-
result.nodes.push(node);
|
|
52
|
-
return result;
|
|
53
|
-
}
|
|
54
|
-
var lines = node.value.split("\n");
|
|
55
|
-
for (var i = 0; i < lines.length; i++) {
|
|
56
|
-
if (i !== 0) ++lineNumber;
|
|
57
|
-
if (i === lines.length - 1 && lines[i].length === 0) 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) {
|
|
69
|
-
node.lineNumber = lineNumber;
|
|
70
|
-
var processed = lineNumberify2(node.children, lineNumber);
|
|
71
|
-
node.children = processed.nodes;
|
|
72
|
-
result.lineNumber = processed.lineNumber;
|
|
73
|
-
result.nodes.push(node);
|
|
74
|
-
return result;
|
|
75
|
-
}
|
|
76
|
-
result.nodes.push(node);
|
|
77
|
-
return result;
|
|
78
|
-
}, {
|
|
79
|
-
nodes: [],
|
|
80
|
-
lineNumber
|
|
81
|
-
});
|
|
82
|
-
};
|
|
83
|
-
var wrapLines = function wrapLines2(ast, linesToHighlight) {
|
|
84
|
-
var highlightAll = linesToHighlight.length === 1 && linesToHighlight[0] === 0;
|
|
85
|
-
var allLines = Array.from(new Set(ast.map(function (x) {
|
|
86
|
-
return x.lineNumber;
|
|
87
|
-
})));
|
|
88
|
-
var i = 0;
|
|
89
|
-
var wrapped = allLines.reduce(function (nodes, marker) {
|
|
90
|
-
var line = marker;
|
|
91
|
-
var children = [];
|
|
92
|
-
for (; i < ast.length; i++) {
|
|
93
|
-
if (ast[i].lineNumber < line) {
|
|
94
|
-
nodes.push(ast[i]);
|
|
95
|
-
continue;
|
|
96
|
-
}
|
|
97
|
-
if (ast[i].lineNumber === line) {
|
|
98
|
-
children.push(ast[i]);
|
|
99
|
-
continue;
|
|
100
|
-
}
|
|
101
|
-
if (ast[i].lineNumber > line) {
|
|
102
|
-
break;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
nodes.push({
|
|
106
|
-
type: "element",
|
|
107
|
-
tagName: "div",
|
|
108
|
-
properties: {
|
|
109
|
-
dataLine: line,
|
|
110
|
-
className: "highlight-line",
|
|
111
|
-
dataHighlighted: linesToHighlight.includes(line) || highlightAll ? "true" : "false"
|
|
112
|
-
},
|
|
113
|
-
children,
|
|
114
|
-
lineNumber: line
|
|
115
|
-
});
|
|
116
|
-
return nodes;
|
|
117
|
-
}, []);
|
|
118
|
-
return wrapped;
|
|
119
|
-
};
|
|
120
|
-
var MULTILINE_TOKEN_SPAN = /<span class="token ([^"]+)">[^<]*\n[^<]*<\/span>/g;
|
|
121
|
-
var applyMultilineFix = function (ast) {
|
|
122
|
-
var html = (0, import_hast_util_to_html.toHtml)(ast);
|
|
123
|
-
html = html.replace(MULTILINE_TOKEN_SPAN, function (match, token) {
|
|
124
|
-
return match.replace(/\n/g, `</span>
|
|
125
|
-
<span class="token ${token}">`);
|
|
126
|
-
});
|
|
127
|
-
var hast = (0, import_unified.unified)().use(import_rehype_parse.default, {
|
|
128
|
-
emitParseErrors: true,
|
|
129
|
-
fragment: true
|
|
130
|
-
}).parse(html);
|
|
131
|
-
return hast["children"];
|
|
132
|
-
};
|
|
133
|
-
function highlightLine(ast, lines) {
|
|
134
|
-
var formattedAst = applyMultilineFix(ast);
|
|
135
|
-
var numbered = lineNumberify(formattedAst).nodes;
|
|
136
|
-
return wrapLines(numbered, lines);
|
|
137
|
-
}
|
|
138
|
-
//# sourceMappingURL=highlightLine.native.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","highlightLine_exports","__export","highlightLine","module","exports","import_hast_util_to_html","require","import_rehype_parse","__toESM","import_unified","lineNumberify","lineNumberify2","ast","lineNum","arguments","length","lineNumber","reduce","result","node","type","indexOf","nodes","push","lines","split","i","children","processed","wrapLines","wrapLines2","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","default","emitParseErrors","fragment","parse"],"sources":["../../src/highlightLine.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,qBAAA;AAAAC,QAAA,CAAAD,qBAAA;EAAAE,aAAA,EAAAA,CAAA,KAAAA;AAAA;AAEAC,MAAA,CAAAC,OAAA,GAAAT,YAAA,CAAAK,qBAAuB;AACvB,IAAAK,wBAAkB,GAAAC,OAAA;AAClB,IAAAC,mBAAwB,GAAAC,OAAA,CAAAF,OAAA;AAExB,IAAAG,cAAM,GAAAH,OAAgB,UAAS;AAC7B,IAAAI,aAAI,GAAa,SAAAC,eAAAC,GAAA;EACjB,IAAAC,OAAW,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,iBAAAA,SAAA;EAAA,IACRE,UAAQ,GAAAH,OAAS;EAChB,OAAAD,GAAI,CAAAK,MAAK,WAASC,MAAQ,EAAAC,IAAA;IACxB,IAAAA,IAAI,CAAAC,IAAK,WAAM;MACb,IAAAD,IAAA,CAAKpB,KAAA,CAAAsB,OAAa;QAClBF,IAAA,CAAAH,UAAa,GAAAA,UAAS;QACtBE,MAAA,CAAAI,KAAO,CAAAC,IAAA,CAAAJ,IAAA;QACT,OAAAD,MAAA;MAEA;MACA,IAAAM,KAAA,GAASL,IAAI,CAAApB,KAAO,CAAA0B,KAAM;MACxB,SAAIC,CAAA,IAAM,EAAGA,CAAA,GAAEF,KAAA,CAAAT,MAAA,EAAAW,CAAA;QACf,IAAAA,CAAA,KAAI,GAAM,EAAAV,UAAM;QAChB,IAAAU,CAAA,KAAOF,KAAM,CAAAT,MA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GAAA,CAAIc,CAAC,EAAEV,UAAA,GAAAyB,IAAe;QACxBnB,KAAA,CAAAC,IAAS,CAAAX,GAAK,CAAAc,CAAA,EAAI;QAClB;MACF;MAEA,IAAId,GAAA,CAAIc,CAAC,EAAEV,UAAA,KAAayB,IAAM;QAC5Bd,QAAA,CAAAJ,IAAA,CAAAX,GAAA,CAAAc,CAAA;QACF;MACF;MAEA,IAAMd,GAAA,CAAAc,CAAK,EAAAV,UAAA,GAAAyB,IAAA;QACT;MACA;IAAS;IACGnB,KACV,CAAAC,IAAA;MAAUH,IACV,WAAW;MAAAsB,OACX;MAEFC,UAAA;QACAC,QAAA,EAAAH,IAAA;QACAI,SAAA,EAAY;QACbC,eAAA,EAAAf,gBAAA,CAAAgB,QAAA,CAAAN,IAAA,KAAAT,YAAA;MAED;MACEL,QAAC;MAELX,UAAO,EAAAyB;IACT;IAGA,OAAMnB,KAAA;EAEN,KAAM;EAEJ,OAAIiB,OAAA;AAGJ;AAAY,IAAQS,oBAAA;AAAA,IAAsBC,iBAAQ,GAChD,SAAAA,CAAMrC,GAAQ;EAAO,IAAAsC,IAAA,OAAA7C,wBAAwC,CAAA8C,MAAA,EAAAvC,GAAA;EAC/DsC,IAAA,GAAAA,IAAA,CAAAE,OAAA,CAAAJ,oBAAA,YAAAK,KAAA,EAAAC,KAAA;IAGA,OAAMD,KAAA,CAAAD,OAAO;AAEb,qBAAYE,KAAU;EACxB;EAEO,IAAAC,IAAS,OAAA9C,cAAmB,CAAA+C,OAAO,IAAAC,GAAA,CAAAlD,mBAAA,CAAAmD,OAAA;IACxCC,eAAM,MAAe;IACrBC,QAAM;EACN,GAAAC,KAAO,CAAAX,IAAA;EACT,OAAAK,IAAA","ignoreList":[]}
|
|
@@ -1,51 +0,0 @@
|
|
|
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;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all) __defProp(target, name, {
|
|
9
|
-
get: all[name],
|
|
10
|
-
enumerable: true
|
|
11
|
-
});
|
|
12
|
-
};
|
|
13
|
-
var __copyProps = (to, from, except, desc) => {
|
|
14
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
-
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
16
|
-
get: () => from[key],
|
|
17
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
return to;
|
|
21
|
-
};
|
|
22
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
24
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
25
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
28
|
-
value: mod,
|
|
29
|
-
enumerable: true
|
|
30
|
-
}) : target, mod));
|
|
31
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
32
|
-
value: true
|
|
33
|
-
}), mod);
|
|
34
|
-
var highlightWord_exports = {};
|
|
35
|
-
__export(highlightWord_exports, {
|
|
36
|
-
highlightWord: () => highlightWord
|
|
37
|
-
});
|
|
38
|
-
module.exports = __toCommonJS(highlightWord_exports);
|
|
39
|
-
var import_hast_util_to_html = require("hast-util-to-html");
|
|
40
|
-
var import_rehype_parse = __toESM(require("rehype-parse"));
|
|
41
|
-
var import_unified = require("unified");
|
|
42
|
-
const CALLOUT = /__(.*?)__/g;
|
|
43
|
-
function highlightWord(code) {
|
|
44
|
-
const html = (0, import_hast_util_to_html.toHtml)(code);
|
|
45
|
-
const result = html.replace(CALLOUT, (_, text) => `<span class="highlight-word">${text}</span>`);
|
|
46
|
-
const hast = (0, import_unified.unified)().use(import_rehype_parse.default, {
|
|
47
|
-
emitParseErrors: true,
|
|
48
|
-
fragment: true
|
|
49
|
-
}).parse(result);
|
|
50
|
-
return hast["children"];
|
|
51
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var __create = Object.create;
|
|
4
|
-
var __defProp = Object.defineProperty;
|
|
5
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
-
var __export = (target, all) => {
|
|
10
|
-
for (var name in all) __defProp(target, name, {
|
|
11
|
-
get: all[name],
|
|
12
|
-
enumerable: true
|
|
13
|
-
});
|
|
14
|
-
};
|
|
15
|
-
var __copyProps = (to, from, except, desc) => {
|
|
16
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
17
|
-
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
18
|
-
get: () => from[key],
|
|
19
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
return to;
|
|
23
|
-
};
|
|
24
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
25
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
26
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
27
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
28
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
29
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
30
|
-
value: mod,
|
|
31
|
-
enumerable: true
|
|
32
|
-
}) : target, mod));
|
|
33
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
34
|
-
value: true
|
|
35
|
-
}), mod);
|
|
36
|
-
var highlightWord_exports = {};
|
|
37
|
-
__export(highlightWord_exports, {
|
|
38
|
-
highlightWord: () => highlightWord
|
|
39
|
-
});
|
|
40
|
-
module.exports = __toCommonJS(highlightWord_exports);
|
|
41
|
-
var import_hast_util_to_html = require("hast-util-to-html");
|
|
42
|
-
var import_rehype_parse = __toESM(require("rehype-parse"));
|
|
43
|
-
var import_unified = require("unified");
|
|
44
|
-
var CALLOUT = /__(.*?)__/g;
|
|
45
|
-
function highlightWord(code) {
|
|
46
|
-
var html = (0, import_hast_util_to_html.toHtml)(code);
|
|
47
|
-
var result = html.replace(CALLOUT, function (_, text) {
|
|
48
|
-
return `<span class="highlight-word">${text}</span>`;
|
|
49
|
-
});
|
|
50
|
-
var hast = (0, import_unified.unified)().use(import_rehype_parse.default, {
|
|
51
|
-
emitParseErrors: true,
|
|
52
|
-
fragment: true
|
|
53
|
-
}).parse(result);
|
|
54
|
-
return hast["children"];
|
|
55
|
-
}
|
|
56
|
-
//# sourceMappingURL=highlightWord.native.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","highlightWord_exports","__export","highlightWord","module","exports","import_hast_util_to_html","require","import_rehype_parse","__toESM","import_unified","CALLOUT","code","html","toHtml","result","replace","_","text","hast","unified","use","default","emitParseErrors","fragment"],"sources":["../../src/highlightWord.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,qBAAA;AAAAC,QAAA,CAAAD,qBAAA;EAAAE,aAAA,EAAAA,CAAA,KAAAA;AAAA;AACAC,MAAA,CAAAC,OAAA,GAAAT,YAAA,CAAAK,qBAAuB;AACvB,IAAAK,wBAAkB,GAAAC,OAAA;AAClB,IAAAC,mBAAwB,GAAAC,OAAA,CAAAF,OAAA;AAExB,IAAAG,cAAgB,GAAAH,OAAA;AAET,IAAAI,OAAS,eAAc;AAC5B,SAAMR,aAAOA,CAAAS,IAAA;EACb,IAAAC,IAAM,OAASP,wBAAK,CAAAQ,MAAA,EAAAF,IAAA;EAAA,IAClBG,MAAA,GAAAF,IAAA,CAAAG,OAAA,CAAAL,OAAA,YAAAM,CAAA,EAAAC,IAAA;IACA,OAAI,gCAASA,IAAA,SAAoC;EACnD;EACA,IAAAC,IAAM,OAAAT,cAAO,CAAAU,OAAA,IAAQC,GAClB,CAAAb,mBAAI,CAAAc,OAAA;IAEPC,eAAY,MAAU;IACxBC,QAAA","ignoreList":[]}
|
package/dist/cjs/index.cjs
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
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;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all) __defProp(target, name, {
|
|
9
|
-
get: all[name],
|
|
10
|
-
enumerable: true
|
|
11
|
-
});
|
|
12
|
-
};
|
|
13
|
-
var __copyProps = (to, from, except, desc) => {
|
|
14
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
-
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
16
|
-
get: () => from[key],
|
|
17
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
return to;
|
|
21
|
-
};
|
|
22
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
24
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
25
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
28
|
-
value: mod,
|
|
29
|
-
enumerable: true
|
|
30
|
-
}) : target, mod));
|
|
31
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
32
|
-
value: true
|
|
33
|
-
}), mod);
|
|
34
|
-
var index_exports = {};
|
|
35
|
-
__export(index_exports, {
|
|
36
|
-
codeToHTML: () => codeToHTML
|
|
37
|
-
});
|
|
38
|
-
module.exports = __toCommonJS(index_exports);
|
|
39
|
-
var import_hast_util_to_html = require("hast-util-to-html");
|
|
40
|
-
var import_parse_numeric_range = __toESM(require("parse-numeric-range"));
|
|
41
|
-
var import_refractor = require("refractor");
|
|
42
|
-
var import_css = __toESM(require("refractor/lang/css"));
|
|
43
|
-
var import_tsx = __toESM(require("refractor/lang/tsx"));
|
|
44
|
-
var import_highlightLine = require("./highlightLine.cjs");
|
|
45
|
-
var import_highlightWord = require("./highlightWord.cjs");
|
|
46
|
-
import_refractor.refractor.register(import_tsx.default);
|
|
47
|
-
import_refractor.refractor.register(import_css.default);
|
|
48
|
-
function codeToHTML(source, language, line = "0") {
|
|
49
|
-
let result = import_refractor.refractor.highlight(source, language);
|
|
50
|
-
result = (0, import_highlightLine.highlightLine)(result, (0, import_parse_numeric_range.default)(line));
|
|
51
|
-
result = (0, import_highlightWord.highlightWord)(result);
|
|
52
|
-
result = (0, import_hast_util_to_html.toHtml)(result);
|
|
53
|
-
return result;
|
|
54
|
-
}
|
package/dist/cjs/index.native.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var __create = Object.create;
|
|
4
|
-
var __defProp = Object.defineProperty;
|
|
5
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
-
var __export = (target, all) => {
|
|
10
|
-
for (var name in all) __defProp(target, name, {
|
|
11
|
-
get: all[name],
|
|
12
|
-
enumerable: true
|
|
13
|
-
});
|
|
14
|
-
};
|
|
15
|
-
var __copyProps = (to, from, except, desc) => {
|
|
16
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
17
|
-
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
18
|
-
get: () => from[key],
|
|
19
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
return to;
|
|
23
|
-
};
|
|
24
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
25
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
26
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
27
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
28
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
29
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
30
|
-
value: mod,
|
|
31
|
-
enumerable: true
|
|
32
|
-
}) : target, mod));
|
|
33
|
-
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
34
|
-
value: true
|
|
35
|
-
}), mod);
|
|
36
|
-
var index_exports = {};
|
|
37
|
-
__export(index_exports, {
|
|
38
|
-
codeToHTML: () => codeToHTML
|
|
39
|
-
});
|
|
40
|
-
module.exports = __toCommonJS(index_exports);
|
|
41
|
-
var import_hast_util_to_html = require("hast-util-to-html");
|
|
42
|
-
var import_parse_numeric_range = __toESM(require("parse-numeric-range"));
|
|
43
|
-
var import_refractor = require("refractor");
|
|
44
|
-
var import_css = __toESM(require("refractor/lang/css"));
|
|
45
|
-
var import_tsx = __toESM(require("refractor/lang/tsx"));
|
|
46
|
-
var import_highlightLine = require("./highlightLine.native.js");
|
|
47
|
-
var import_highlightWord = require("./highlightWord.native.js");
|
|
48
|
-
import_refractor.refractor.register(import_tsx.default);
|
|
49
|
-
import_refractor.refractor.register(import_css.default);
|
|
50
|
-
function codeToHTML(source, language) {
|
|
51
|
-
var line = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : "0";
|
|
52
|
-
var result = import_refractor.refractor.highlight(source, language);
|
|
53
|
-
result = (0, import_highlightLine.highlightLine)(result, (0, import_parse_numeric_range.default)(line));
|
|
54
|
-
result = (0, import_highlightWord.highlightWord)(result);
|
|
55
|
-
result = (0, import_hast_util_to_html.toHtml)(result);
|
|
56
|
-
return result;
|
|
57
|
-
}
|
|
58
|
-
//# sourceMappingURL=index.native.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","index_exports","__export","codeToHTML","module","exports","import_hast_util_to_html","require","import_parse_numeric_range","__toESM","import_refractor","import_css","import_tsx","import_highlightLine","import_highlightWord","refractor","register","default","source","language","line","arguments","length","result","highlight","highlightLine","highlightWord","toHtml"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,aAAA;AAAAC,QAAA,CAAAD,aAAA;EAAAE,UAAA,EAAAA,CAAA,KAAAA;AAAA;AAAAC,MAAA,CAAAC,OAAA,GAAAT,YAAA,CAAAK,aAAuB;AACvB,IAAAK,wBAAA,GAAAC,OAAwB;AACxB,IAAAC,0BAA0B,GAAAC,OAAA,CAAAF,OAAA;AAC1B,IAAAG,gBAAgB,GAAAH,OAAA;AAChB,IAAAI,UAAA,GAAgBF,OAAA,CAAAF,OAAA;AAEhB,IAAAK,UAAA,GAAAH,OAAA,CAAAF,OAA8B;AAC9B,IAAAM,oBAAA,GAA8BN,OAAA;AAE9B,IAAAO,oBAAA,GAAUP,OAAA,4BAAS;AACnBG,gBAAA,CAAAK,SAAA,CAAUC,QAAA,CAASJ,UAAA,CAAAK,OAAG;AAEfP,gBAAS,CAAAK,SAAW,CAAAC,QAAgB,CAAAL,UAAyC,CAAAM,OAAK;AACvF,SAAId,UAAcA,CAAAe,MAAA,EAAAC,QAAA;EAClB,IAAAC,IAAA,GAAAC,SAAS,CAAAC,MAAA,QAAAD,SAAA,QAAc,SAAQA,SAAA;EAC/B,IAAAE,MAAA,GAASb,gBAAA,CAAAK,SAAA,CAAAS,SAAc,CAAAN,MAAM,EAAAC,QAAA;EAC7BI,MAAA,OAASV,oBAAA,CAAAY,aAAO,EAAAF,MAAM,MAAAf,0BAAA,CAAAS,OAAA,EAAAG,IAAA;EACtBG,MAAA,GAAO,IAAAT,oBAAA,CAAAY,aAAA,EAAAH,MAAA;EACTA,MAAA,OAAAjB,wBAAA,CAAAqB,MAAA,EAAAJ,MAAA","ignoreList":[]}
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { toHtml } from "hast-util-to-html";
|
|
2
|
-
import parse from "rehype-parse";
|
|
3
|
-
import { unified } from "unified";
|
|
4
|
-
const lineNumberify = function lineNumberify2(ast, lineNum = 1) {
|
|
5
|
-
let lineNumber = lineNum;
|
|
6
|
-
return ast.reduce((result, node) => {
|
|
7
|
-
if (node.type === "text") {
|
|
8
|
-
if (node.value.indexOf("\n") === -1) {
|
|
9
|
-
node.lineNumber = lineNumber;
|
|
10
|
-
result.nodes.push(node);
|
|
11
|
-
return result;
|
|
12
|
-
}
|
|
13
|
-
const lines = node.value.split("\n");
|
|
14
|
-
for (let i = 0; i < lines.length; i++) {
|
|
15
|
-
if (i !== 0) ++lineNumber;
|
|
16
|
-
if (i === lines.length - 1 && lines[i].length === 0) continue;
|
|
17
|
-
result.nodes.push({
|
|
18
|
-
type: "text",
|
|
19
|
-
value: i === lines.length - 1 ? lines[i] : `${lines[i]}
|
|
20
|
-
`,
|
|
21
|
-
lineNumber
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
result.lineNumber = lineNumber;
|
|
25
|
-
return result;
|
|
26
|
-
}
|
|
27
|
-
if (node.children) {
|
|
28
|
-
node.lineNumber = lineNumber;
|
|
29
|
-
const processed = lineNumberify2(node.children, lineNumber);
|
|
30
|
-
node.children = processed.nodes;
|
|
31
|
-
result.lineNumber = processed.lineNumber;
|
|
32
|
-
result.nodes.push(node);
|
|
33
|
-
return result;
|
|
34
|
-
}
|
|
35
|
-
result.nodes.push(node);
|
|
36
|
-
return result;
|
|
37
|
-
}, {
|
|
38
|
-
nodes: [],
|
|
39
|
-
lineNumber
|
|
40
|
-
});
|
|
41
|
-
};
|
|
42
|
-
const wrapLines = function wrapLines2(ast, linesToHighlight) {
|
|
43
|
-
const highlightAll = linesToHighlight.length === 1 && linesToHighlight[0] === 0;
|
|
44
|
-
const allLines = Array.from(new Set(ast.map(x => x.lineNumber)));
|
|
45
|
-
let i = 0;
|
|
46
|
-
const wrapped = allLines.reduce((nodes, marker) => {
|
|
47
|
-
const line = marker;
|
|
48
|
-
const children = [];
|
|
49
|
-
for (; i < ast.length; i++) {
|
|
50
|
-
if (ast[i].lineNumber < line) {
|
|
51
|
-
nodes.push(ast[i]);
|
|
52
|
-
continue;
|
|
53
|
-
}
|
|
54
|
-
if (ast[i].lineNumber === line) {
|
|
55
|
-
children.push(ast[i]);
|
|
56
|
-
continue;
|
|
57
|
-
}
|
|
58
|
-
if (ast[i].lineNumber > line) {
|
|
59
|
-
break;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
nodes.push({
|
|
63
|
-
type: "element",
|
|
64
|
-
tagName: "div",
|
|
65
|
-
properties: {
|
|
66
|
-
dataLine: line,
|
|
67
|
-
className: "highlight-line",
|
|
68
|
-
dataHighlighted: linesToHighlight.includes(line) || highlightAll ? "true" : "false"
|
|
69
|
-
},
|
|
70
|
-
children,
|
|
71
|
-
lineNumber: line
|
|
72
|
-
});
|
|
73
|
-
return nodes;
|
|
74
|
-
}, []);
|
|
75
|
-
return wrapped;
|
|
76
|
-
};
|
|
77
|
-
const MULTILINE_TOKEN_SPAN = /<span class="token ([^"]+)">[^<]*\n[^<]*<\/span>/g;
|
|
78
|
-
const applyMultilineFix = ast => {
|
|
79
|
-
let html = toHtml(ast);
|
|
80
|
-
html = html.replace(MULTILINE_TOKEN_SPAN, (match, token) => match.replace(/\n/g, `</span>
|
|
81
|
-
<span class="token ${token}">`));
|
|
82
|
-
const hast = unified().use(parse, {
|
|
83
|
-
emitParseErrors: true,
|
|
84
|
-
fragment: true
|
|
85
|
-
}).parse(html);
|
|
86
|
-
return hast["children"];
|
|
87
|
-
};
|
|
88
|
-
function highlightLine(ast, lines) {
|
|
89
|
-
const formattedAst = applyMultilineFix(ast);
|
|
90
|
-
const numbered = lineNumberify(formattedAst).nodes;
|
|
91
|
-
return wrapLines(numbered, lines);
|
|
92
|
-
}
|
|
93
|
-
export { highlightLine };
|
|
94
|
-
//# sourceMappingURL=highlightLine.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["toHtml","parse","unified","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","replace","match","token","hast","use","emitParseErrors","fragment","highlightLine","formattedAst","numbered"],"sources":["../../src/highlightLine.ts"],"sourcesContent":[null],"mappings":"AAEA,SAASA,MAAA,QAAc;AACvB,OAAOC,KAAA,MAAW;AAClB,SAASC,OAAA,QAAe;AAExB,MAAMC,aAAA,GAAgB,SAASA,eAAcC,GAAA,EAAKC,OAAA,GAAU,GAAG;EAC7D,IAAIC,UAAA,GAAaD,OAAA;EACjB,OAAOD,GAAA,CAAIG,MAAA,CACT,CAACC,MAAA,EAAQC,IAAA,KAAS;IAChB,IAAIA,IAAA,CAAKC,IAAA,KAAS,QAAQ;MACxB,IAAID,IAAA,CAAKE,KAAA,CAAMC,OAAA,CAAQ,IAAI,MAAM,IAAI;QACnCH,IAAA,CAAKH,UAAA,GAAaA,UAAA;QAClBE,MAAA,CAAOK,KAAA,CAAMC,IAAA,CAAKL,IAAI;QACtB,OAAOD,MAAA;MACT;MAEA,MAAMO,KAAA,GAAQN,IAAA,CAAKE,KAAA,CAAMK,KAAA,CAAM,IAAI;MACnC,SAASC,CAAA,GAAI,GAAGA,CAAA,GAAIF,KAAA,CAAMG,MAAA,EAAQD,CAAA,IAAK;QACrC,IAAIA,CAAA,KAAM,GAAG,EAAEX,UAAA;QACf,IAAIW,CAAA,KAAMF,KAAA,CAAMG,MAAA,GAAS,KAAKH,KAAA,CAAME,CAAC,EAAEC,MAAA,KAAW,GAAG;QACrDV,MAAA,CAAOK,KAAA,CAAMC,IAAA,CAAK;UAChBJ,IAAA,EAAM;UACNC,KAAA,EAAOM,CAAA,KAAMF,KAAA,CAAMG,MAAA,GAAS,IAAIH,KAAA,CAAME,CAAC,IAAI,GAAGF,KAAA,CAAME,CAAC,CAAC;AAAA;UACtDX;QACF,CAAC;MACH;MAEAE,MAAA,CAAOF,UAAA,GAAaA,UAAA;MACpB,OAAOE,MAAA;IACT;IAEA,IAAIC,IAAA,CAAKU,QAAA,EAAU;MACjBV,IAAA,CAAKH,UAAA,GAAaA,UAAA;MAClB,M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AC,EAAEX,UAAA,GAAa0B,IAAA,EAAM;QAC5B;MACF;IACF;IAEAnB,KAAA,CAAMC,IAAA,CAAK;MACTJ,IAAA,EAAM;MACNuB,OAAA,EAAS;MACTC,UAAA,EAAY;QACVC,QAAA,EAAUH,IAAA;QACVI,SAAA,EAAW;QACXC,eAAA,EACEf,gBAAA,CAAiBgB,QAAA,CAASN,IAAI,KAAKT,YAAA,GAAe,SAAS;MAC/D;MACAJ,QAAA;MACAb,UAAA,EAAY0B;IACd,CAAC;IAED,OAAOnB,KAAA;EACT,GAAG,EAAE;EAEL,OAAOiB,OAAA;AACT;AAGA,MAAMS,oBAAA,GAAuB;AAE7B,MAAMC,iBAAA,GAAqBpC,GAAA,IAAQ;EAEjC,IAAIqC,IAAA,GAAOzC,MAAA,CAAOI,GAAG;EAGrBqC,IAAA,GAAOA,IAAA,CAAKC,OAAA,CAAQH,oBAAA,EAAsB,CAACI,KAAA,EAAOC,KAAA,KAChDD,KAAA,CAAMD,OAAA,CAAQ,OAAO;AAAA,qBAA+BE,KAAK,IAAI,CAC/D;EAGA,MAAMC,IAAA,GAAO3C,OAAA,CAAQ,EAAE4C,GAAA,CAAI7C,KAAA,EAAO;IAAE8C,eAAA,EAAiB;IAAMC,QAAA,EAAU;EAAK,CAAC,EAAE/C,KAAA,CAAMwC,IAAI;EAEvF,OAAOI,IAAA,CAAK,UAAU;AACxB;AAEO,SAASI,cAAc7C,GAAA,EAAKW,KAAA,EAAO;EACxC,MAAMmC,YAAA,GAAeV,iBAAA,CAAkBpC,GAAG;EAC1C,MAAM+C,QAAA,GAAWhD,aAAA,CAAc+C,YAAY,EAAErC,KAAA;EAC7C,OAAOQ,SAAA,CAAU8B,QAAA,EAAUpC,KAAK;AAClC","ignoreList":[]}
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { toHtml } from "hast-util-to-html";
|
|
2
|
-
import parse from "rehype-parse";
|
|
3
|
-
import { unified } from "unified";
|
|
4
|
-
var lineNumberify = function lineNumberify2(ast) {
|
|
5
|
-
var lineNum = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 1;
|
|
6
|
-
var lineNumber = lineNum;
|
|
7
|
-
return ast.reduce(function (result, node) {
|
|
8
|
-
if (node.type === "text") {
|
|
9
|
-
if (node.value.indexOf("\n") === -1) {
|
|
10
|
-
node.lineNumber = lineNumber;
|
|
11
|
-
result.nodes.push(node);
|
|
12
|
-
return result;
|
|
13
|
-
}
|
|
14
|
-
var lines = node.value.split("\n");
|
|
15
|
-
for (var i = 0; i < lines.length; i++) {
|
|
16
|
-
if (i !== 0) ++lineNumber;
|
|
17
|
-
if (i === lines.length - 1 && lines[i].length === 0) continue;
|
|
18
|
-
result.nodes.push({
|
|
19
|
-
type: "text",
|
|
20
|
-
value: i === lines.length - 1 ? lines[i] : `${lines[i]}
|
|
21
|
-
`,
|
|
22
|
-
lineNumber
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
result.lineNumber = lineNumber;
|
|
26
|
-
return result;
|
|
27
|
-
}
|
|
28
|
-
if (node.children) {
|
|
29
|
-
node.lineNumber = lineNumber;
|
|
30
|
-
var processed = lineNumberify2(node.children, lineNumber);
|
|
31
|
-
node.children = processed.nodes;
|
|
32
|
-
result.lineNumber = processed.lineNumber;
|
|
33
|
-
result.nodes.push(node);
|
|
34
|
-
return result;
|
|
35
|
-
}
|
|
36
|
-
result.nodes.push(node);
|
|
37
|
-
return result;
|
|
38
|
-
}, {
|
|
39
|
-
nodes: [],
|
|
40
|
-
lineNumber
|
|
41
|
-
});
|
|
42
|
-
};
|
|
43
|
-
var wrapLines = function wrapLines2(ast, linesToHighlight) {
|
|
44
|
-
var highlightAll = linesToHighlight.length === 1 && linesToHighlight[0] === 0;
|
|
45
|
-
var allLines = Array.from(new Set(ast.map(function (x) {
|
|
46
|
-
return x.lineNumber;
|
|
47
|
-
})));
|
|
48
|
-
var i = 0;
|
|
49
|
-
var wrapped = allLines.reduce(function (nodes, marker) {
|
|
50
|
-
var line = marker;
|
|
51
|
-
var children = [];
|
|
52
|
-
for (; i < ast.length; i++) {
|
|
53
|
-
if (ast[i].lineNumber < line) {
|
|
54
|
-
nodes.push(ast[i]);
|
|
55
|
-
continue;
|
|
56
|
-
}
|
|
57
|
-
if (ast[i].lineNumber === line) {
|
|
58
|
-
children.push(ast[i]);
|
|
59
|
-
continue;
|
|
60
|
-
}
|
|
61
|
-
if (ast[i].lineNumber > line) {
|
|
62
|
-
break;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
nodes.push({
|
|
66
|
-
type: "element",
|
|
67
|
-
tagName: "div",
|
|
68
|
-
properties: {
|
|
69
|
-
dataLine: line,
|
|
70
|
-
className: "highlight-line",
|
|
71
|
-
dataHighlighted: linesToHighlight.includes(line) || highlightAll ? "true" : "false"
|
|
72
|
-
},
|
|
73
|
-
children,
|
|
74
|
-
lineNumber: line
|
|
75
|
-
});
|
|
76
|
-
return nodes;
|
|
77
|
-
}, []);
|
|
78
|
-
return wrapped;
|
|
79
|
-
};
|
|
80
|
-
var MULTILINE_TOKEN_SPAN = /<span class="token ([^"]+)">[^<]*\n[^<]*<\/span>/g;
|
|
81
|
-
var applyMultilineFix = function (ast) {
|
|
82
|
-
var html = toHtml(ast);
|
|
83
|
-
html = html.replace(MULTILINE_TOKEN_SPAN, function (match, token) {
|
|
84
|
-
return match.replace(/\n/g, `</span>
|
|
85
|
-
<span class="token ${token}">`);
|
|
86
|
-
});
|
|
87
|
-
var hast = unified().use(parse, {
|
|
88
|
-
emitParseErrors: true,
|
|
89
|
-
fragment: true
|
|
90
|
-
}).parse(html);
|
|
91
|
-
return hast["children"];
|
|
92
|
-
};
|
|
93
|
-
function highlightLine(ast, lines) {
|
|
94
|
-
var formattedAst = applyMultilineFix(ast);
|
|
95
|
-
var numbered = lineNumberify(formattedAst).nodes;
|
|
96
|
-
return wrapLines(numbered, lines);
|
|
97
|
-
}
|
|
98
|
-
export { highlightLine };
|
|
99
|
-
//# sourceMappingURL=highlightLine.native.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["toHtml","parse","unified","lineNumberify","lineNumberify2","ast","lineNum","arguments","length","lineNumber","reduce","result","node","type","value","indexOf","nodes","push","lines","split","i","children","processed","wrapLines","wrapLines2","linesToHighlight","highlightAll","allLines","Array","from","Set","map","x","wrapped","marker","line","tagName","properties","dataLine","className","dataHighlighted","includes","MULTILINE_TOKEN_SPAN","applyMultilineFix","html","replace","match","token","hast","use","emitParseErrors","fragment"],"sources":["../../src/highlightLine.ts"],"sourcesContent":[null],"mappings":"AAEA,SAASA,MAAA,QAAc;AACvB,OAAOC,KAAA,MAAW;AAClB,SAASC,OAAA,QAAe;AAExB,IAAAC,aAAM,YAAgBC,cAASD,CAAAE,GAAc;EAC3C,IAAIC,OAAA,GAAAC,SAAa,CAAAC,MAAA,QAAAD,SAAA,iBAAAA,SAAA;EACjB,IAAAE,UAAW,GAAAH,OAAA;EAAA,OACRD,GAAA,CAAQK,MAAA,WAASC,MAAA,EAAAC,IAAA;IAChB,IAAAA,IAAI,CAAAC,IAAK,WAAS;MAChB,IAAAD,IAAI,CAAAE,KAAK,CAAAC,OAAM,KAAQ,MAAI,EAAM;QAC/BH,IAAA,CAAAH,UAAK,GAAAA,UAAa;QAClBE,MAAA,CAAAK,KAAO,CAAAC,IAAM,CAAAL,IAAK;QAClB,OAAAD,MAAO;MAAA;MAGT,IAAAO,KAAM,GAAAN,IAAQ,CAAAE,KAAK,CAAAK,KAAM,KAAM;MAC/B,SAAAC,CAAA,GAAS,GAAIA,CAAA,GAAGF,KAAI,CAAAV,MAAM,EAAAY,CAAA,EAAQ;QAChC,IAAAA,CAAA,KAAI,GAAM,EAAGX,UAAE;QACf,IAAAW,CAAA,KAAIF,KAAM,CAAAV,MAAM,QAASU,KAAK,CAAAE,CAAA,CAAM,CAACZ,MAAE,QAAW;QAClDG,MAAA,CAAAK,KAAO,CAAAC,IAAM;UAAKJ,IAChB,QAAM;UAAAC,KACN,EAAAM,C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AAA,CAAAe,CAAA;QACT;MACA;MACF,IAAAf,GAAA,CAAAe,CAAA,EAAAX,UAAA,KAAA0B,IAAA;QAEAd,QAAS,CAAEJ,IAAA,CAAAZ,GAAA,CAAAe,CAAA;QACT;MACF;MACF,IAAAf,GAAA,CAAAe,CAAA,EAAAX,UAAA,GAAA0B,IAAA;QAEA;MACE;IAAM;IACGnB,KACT,CAAAC,IAAA;MAAYJ,IACV,WAAU;MAAAuB,OACV,OAAW;MAAAC,UACX;QAEFC,QAAA,EAAAH,IAAA;QACAI,SAAA;QACAC,eAAY,EAAAf,gBAAA,CAAAgB,QAAA,CAAAN,IAAA,KAAAT,YAAA;MACb;MAEDL,QAAO;MACLZ,UAAC,EAAA0B;IAEL;IACF,OAAAnB,KAAA;EAGA,KAAM;EAEN,OAAMiB,OAAA;AAEJ;AAGA,IAAAS,oBAAY;AAAA,IAAQC,iBAAA,YAAAA,CAAAtC,GAAA;EAAA,IAAuBuC,IAAA,GAAO5C,MAAA,CAAAK,GAChD;EAAqBuC,IAAA,GAAAA,IAAA,CAAAC,OAA+B,CAAAH,oBAAS,YAAAI,KAAA,EAAAC,KAAA;IAC/D,OAAAD,KAAA,CAAAD,OAAA;AAGA,qBAAaE,KAAU,IAAI;EAE3B;EACF,IAAAC,IAAA,GAAA9C,OAAA,GAAA+C,GAAA,CAAAhD,KAAA;IAEOiD,eAAS,MAAc;IAC5BC,QAAM;EACN,GAAAlD,KAAM,CAAA2C,IAAA;EACN,OAAOI,IAAA,WAAU;AACnB","ignoreList":[]}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { toHtml } from "hast-util-to-html";
|
|
2
|
-
import parse from "rehype-parse";
|
|
3
|
-
import { unified } from "unified";
|
|
4
|
-
const CALLOUT = /__(.*?)__/g;
|
|
5
|
-
function highlightWord(code) {
|
|
6
|
-
const html = toHtml(code);
|
|
7
|
-
const result = html.replace(CALLOUT, (_, text) => `<span class="highlight-word">${text}</span>`);
|
|
8
|
-
const hast = unified().use(parse, {
|
|
9
|
-
emitParseErrors: true,
|
|
10
|
-
fragment: true
|
|
11
|
-
}).parse(result);
|
|
12
|
-
return hast["children"];
|
|
13
|
-
}
|
|
14
|
-
export { highlightWord };
|
|
15
|
-
//# sourceMappingURL=highlightWord.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["toHtml","parse","unified","CALLOUT","highlightWord","code","html","result","replace","_","text","hast","use","emitParseErrors","fragment"],"sources":["../../src/highlightWord.ts"],"sourcesContent":[null],"mappings":"AACA,SAASA,MAAA,QAAc;AACvB,OAAOC,KAAA,MAAW;AAClB,SAASC,OAAA,QAAe;AAExB,MAAMC,OAAA,GAAU;AAET,SAASC,cAAcC,IAAA,EAAM;EAClC,MAAMC,IAAA,GAAON,MAAA,CAAOK,IAAI;EACxB,MAAME,MAAA,GAASD,IAAA,CAAKE,OAAA,CAClBL,OAAA,EACA,CAACM,CAAA,EAAGC,IAAA,KAAS,gCAAgCA,IAAI,SACnD;EACA,MAAMC,IAAA,GAAOT,OAAA,CAAQ,EAClBU,GAAA,CAAIX,KAAA,EAAO;IAAEY,eAAA,EAAiB;IAAMC,QAAA,EAAU;EAAK,CAAC,EACpDb,KAAA,CAAMM,MAAM;EACf,OAAOI,IAAA,CAAK,UAAU;AACxB","ignoreList":[]}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { toHtml } from "hast-util-to-html";
|
|
2
|
-
import parse from "rehype-parse";
|
|
3
|
-
import { unified } from "unified";
|
|
4
|
-
var CALLOUT = /__(.*?)__/g;
|
|
5
|
-
function highlightWord(code) {
|
|
6
|
-
var html = toHtml(code);
|
|
7
|
-
var result = html.replace(CALLOUT, function (_, text) {
|
|
8
|
-
return `<span class="highlight-word">${text}</span>`;
|
|
9
|
-
});
|
|
10
|
-
var hast = unified().use(parse, {
|
|
11
|
-
emitParseErrors: true,
|
|
12
|
-
fragment: true
|
|
13
|
-
}).parse(result);
|
|
14
|
-
return hast["children"];
|
|
15
|
-
}
|
|
16
|
-
export { highlightWord };
|
|
17
|
-
//# sourceMappingURL=highlightWord.native.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["toHtml","parse","unified","CALLOUT","highlightWord","code","html","result","replace","_","text","hast","use","emitParseErrors","fragment"],"sources":["../../src/highlightWord.ts"],"sourcesContent":[null],"mappings":"AACA,SAASA,MAAA,QAAc;AACvB,OAAOC,KAAA,MAAW;AAClB,SAASC,OAAA,QAAe;AAExB,IAAAC,OAAM,eAAU;AAET,SAASC,cAAcC,IAAA,EAAM;EAClC,IAAAC,IAAM,GAAAN,MAAO,CAAAK,IAAO;EACpB,IAAAE,MAAM,GAAAD,IAAS,CAAAE,OAAK,CAAAL,OAAA,YAAAM,CAAA,EAAAC,IAAA;IAClB,uCAAAA,IAAA;EAAA,EACA;EACF,IAAAC,IAAA,GAAAT,OAAA,GAAAU,GAAA,CAAAX,KAAA;IACAY,eAAa,MACV;IAEHC,QAAO,EAAK;EACd,GAAAb,KAAA,CAAAM,MAAA","ignoreList":[]}
|
package/dist/esm/index.mjs
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { toHtml } from "hast-util-to-html";
|
|
2
|
-
import rangeParser from "parse-numeric-range";
|
|
3
|
-
import { refractor } from "refractor";
|
|
4
|
-
import css from "refractor/lang/css";
|
|
5
|
-
import tsx from "refractor/lang/tsx";
|
|
6
|
-
import { highlightLine } from "./highlightLine.mjs";
|
|
7
|
-
import { highlightWord } from "./highlightWord.mjs";
|
|
8
|
-
refractor.register(tsx);
|
|
9
|
-
refractor.register(css);
|
|
10
|
-
function codeToHTML(source, language, line = "0") {
|
|
11
|
-
let result = refractor.highlight(source, language);
|
|
12
|
-
result = highlightLine(result, rangeParser(line));
|
|
13
|
-
result = highlightWord(result);
|
|
14
|
-
result = toHtml(result);
|
|
15
|
-
return result;
|
|
16
|
-
}
|
|
17
|
-
export { codeToHTML };
|
|
18
|
-
//# sourceMappingURL=index.mjs.map
|
package/dist/esm/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["toHtml","rangeParser","refractor","css","tsx","highlightLine","highlightWord","register","codeToHTML","source","language","line","result","highlight"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,MAAA,QAAc;AACvB,OAAOC,WAAA,MAAiB;AACxB,SAASC,SAAA,QAAiB;AAC1B,OAAOC,GAAA,MAAS;AAChB,OAAOC,GAAA,MAAS;AAEhB,SAASC,aAAA,QAAqB;AAC9B,SAASC,aAAA,QAAqB;AAE9BJ,SAAA,CAAUK,QAAA,CAASH,GAAG;AACtBF,SAAA,CAAUK,QAAA,CAASJ,GAAG;AAEf,SAASK,WAAWC,MAAA,EAAgBC,QAAA,EAAkCC,IAAA,GAAO,KAAK;EACvF,IAAIC,MAAA,GAAcV,SAAA,CAAUW,SAAA,CAAUJ,MAAA,EAAQC,QAAQ;EACtDE,MAAA,GAASP,aAAA,CAAcO,MAAA,EAAQX,WAAA,CAAYU,IAAI,CAAC;EAChDC,MAAA,GAASN,aAAA,CAAcM,MAAM;EAC7BA,MAAA,GAASZ,MAAA,CAAOY,MAAM;EACtB,OAAOA,MAAA;AACT","ignoreList":[]}
|
package/dist/esm/index.native.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { toHtml } from "hast-util-to-html";
|
|
2
|
-
import rangeParser from "parse-numeric-range";
|
|
3
|
-
import { refractor } from "refractor";
|
|
4
|
-
import css from "refractor/lang/css";
|
|
5
|
-
import tsx from "refractor/lang/tsx";
|
|
6
|
-
import { highlightLine } from "./highlightLine.native.js";
|
|
7
|
-
import { highlightWord } from "./highlightWord.native.js";
|
|
8
|
-
refractor.register(tsx);
|
|
9
|
-
refractor.register(css);
|
|
10
|
-
function codeToHTML(source, language) {
|
|
11
|
-
var line = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : "0";
|
|
12
|
-
var result = refractor.highlight(source, language);
|
|
13
|
-
result = highlightLine(result, rangeParser(line));
|
|
14
|
-
result = highlightWord(result);
|
|
15
|
-
result = toHtml(result);
|
|
16
|
-
return result;
|
|
17
|
-
}
|
|
18
|
-
export { codeToHTML };
|
|
19
|
-
//# sourceMappingURL=index.native.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["toHtml","rangeParser","refractor","css","tsx","highlightLine","highlightWord","register","codeToHTML","source","language","line","arguments","length","result","highlight"],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,MAAA,QAAc;AACvB,OAAOC,WAAA,MAAiB;AACxB,SAASC,SAAA,QAAiB;AAC1B,OAAOC,GAAA,MAAS;AAChB,OAAOC,GAAA,MAAS;AAEhB,SAASC,aAAA,QAAqB;AAC9B,SAASC,aAAA,QAAqB;AAE9BJ,SAAA,CAAUK,QAAA,CAASH,GAAG;AACtBF,SAAA,CAAUK,QAAA,CAASJ,GAAG;AAEf,SAASK,WAAWC,MAAA,EAAgBC,QAAA,EAAkC;EAC3E,IAAIC,IAAA,GAAAC,SAAc,CAAAC,MAAU,QAAUD,SAAQ,QAAQ,SAAAA,SAAA;EACtD,IAAAE,MAAS,GAAAZ,SAAA,CAAca,SAAQ,CAAAN,MAAA,EAAAC,QAAiB;EAChDI,MAAA,GAAST,aAAA,CAAcS,MAAM,EAAAb,WAAA,CAAAU,IAAA;EAC7BG,MAAA,GAASR,aAAa,CAAAQ,MAAA;EACtBA,MAAA,GAAOd,MAAA,CAAAc,MAAA;EACT,OAAAA,MAAA","ignoreList":[]}
|