@tamagui/code-to-html 2.7.7 → 3.0.0-beta.1091.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,126 +5,117 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
5
5
  var __getProtoOf = Object.getPrototypeOf;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
7
  var __export = (target, all) => {
8
- for (var name in all) __defProp(target, name, {
9
- get: all[name],
10
- enumerable: true
11
- });
8
+ for (var name in all) __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: true
11
+ });
12
12
  };
13
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;
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
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
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
+ value: mod,
24
+ enumerable: true
30
25
  }) : target, mod));
31
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
32
- value: true
33
- }), mod);
26
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
34
27
  var highlightLine_exports = {};
35
- __export(highlightLine_exports, {
36
- highlightLine: () => highlightLine
37
- });
28
+ __export(highlightLine_exports, { highlightLine: () => highlightLine });
38
29
  module.exports = __toCommonJS(highlightLine_exports);
39
30
  var import_hast_util_to_html = require("hast-util-to-html");
40
31
  var import_rehype_parse = __toESM(require("rehype-parse"));
41
32
  var import_unified = require("unified");
42
33
  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]}
34
+ let lineNumber = lineNum;
35
+ return ast.reduce((result, node) => {
36
+ if (node.type === "text") {
37
+ if (node.value.indexOf("\n") === -1) {
38
+ node.lineNumber = lineNumber;
39
+ result.nodes.push(node);
40
+ return result;
41
+ }
42
+ const lines = node.value.split("\n");
43
+ for (let i = 0; i < lines.length; i++) {
44
+ if (i !== 0) ++lineNumber;
45
+ if (i === lines.length - 1 && lines[i].length === 0) continue;
46
+ result.nodes.push({
47
+ type: "text",
48
+ value: i === lines.length - 1 ? lines[i] : `${lines[i]}
58
49
  `,
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
- });
50
+ lineNumber
51
+ });
52
+ }
53
+ result.lineNumber = lineNumber;
54
+ return result;
55
+ }
56
+ if (node.children) {
57
+ node.lineNumber = lineNumber;
58
+ const processed = lineNumberify2(node.children, lineNumber);
59
+ node.children = processed.nodes;
60
+ result.lineNumber = processed.lineNumber;
61
+ result.nodes.push(node);
62
+ return result;
63
+ }
64
+ result.nodes.push(node);
65
+ return result;
66
+ }, {
67
+ nodes: [],
68
+ lineNumber
69
+ });
79
70
  };
80
71
  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;
72
+ const highlightAll = linesToHighlight.length === 1 && linesToHighlight[0] === 0;
73
+ const allLines = Array.from(new Set(ast.map((x) => x.lineNumber)));
74
+ let i = 0;
75
+ const wrapped = allLines.reduce((nodes, marker) => {
76
+ const line = marker;
77
+ const children = [];
78
+ for (; i < ast.length; i++) {
79
+ if (ast[i].lineNumber < line) {
80
+ nodes.push(ast[i]);
81
+ continue;
82
+ }
83
+ if (ast[i].lineNumber === line) {
84
+ children.push(ast[i]);
85
+ continue;
86
+ }
87
+ if (ast[i].lineNumber > line) {
88
+ break;
89
+ }
90
+ }
91
+ nodes.push({
92
+ type: "element",
93
+ tagName: "div",
94
+ properties: {
95
+ dataLine: line,
96
+ className: "highlight-line",
97
+ dataHighlighted: linesToHighlight.includes(line) || highlightAll ? "true" : "false"
98
+ },
99
+ children,
100
+ lineNumber: line
101
+ });
102
+ return nodes;
103
+ }, []);
104
+ return wrapped;
114
105
  };
115
106
  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>
107
+ const applyMultilineFix = (ast) => {
108
+ let html = (0, import_hast_util_to_html.toHtml)(ast);
109
+ html = html.replace(MULTILINE_TOKEN_SPAN, (match, token) => match.replace(/\n/g, `</span>
119
110
  <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"];
111
+ const hast = (0, import_unified.unified)().use(import_rehype_parse.default, {
112
+ emitParseErrors: true,
113
+ fragment: true
114
+ }).parse(html);
115
+ return hast["children"];
125
116
  };
126
117
  function highlightLine(ast, lines) {
127
- const formattedAst = applyMultilineFix(ast);
128
- const numbered = lineNumberify(formattedAst).nodes;
129
- return wrapLines(numbered, lines);
130
- }
118
+ const formattedAst = applyMultilineFix(ast);
119
+ const numbered = lineNumberify(formattedAst).nodes;
120
+ return wrapLines(numbered, lines);
121
+ }
@@ -0,0 +1,128 @@
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(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
25
+ value: mod,
26
+ enumerable: true
27
+ }) : target, mod));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var highlightLine_exports = {};
30
+ __export(highlightLine_exports, { highlightLine: () => highlightLine });
31
+ module.exports = __toCommonJS(highlightLine_exports);
32
+ var import_hast_util_to_html = require("hast-util-to-html");
33
+ var import_rehype_parse = __toESM(require("rehype-parse"));
34
+ var import_unified = require("unified");
35
+ var lineNumberify = function lineNumberify2(ast) {
36
+ var lineNum = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 1;
37
+ var lineNumber = lineNum;
38
+ return ast.reduce(function(result, node) {
39
+ if (node.type === "text") {
40
+ if (node.value.indexOf("\n") === -1) {
41
+ node.lineNumber = lineNumber;
42
+ result.nodes.push(node);
43
+ return result;
44
+ }
45
+ var lines = node.value.split("\n");
46
+ for (var i = 0; i < lines.length; i++) {
47
+ if (i !== 0) ++lineNumber;
48
+ if (i === lines.length - 1 && lines[i].length === 0) continue;
49
+ result.nodes.push({
50
+ type: "text",
51
+ value: i === lines.length - 1 ? lines[i] : `${lines[i]}
52
+ `,
53
+ lineNumber
54
+ });
55
+ }
56
+ result.lineNumber = lineNumber;
57
+ return result;
58
+ }
59
+ if (node.children) {
60
+ node.lineNumber = lineNumber;
61
+ var processed = lineNumberify2(node.children, lineNumber);
62
+ node.children = processed.nodes;
63
+ result.lineNumber = processed.lineNumber;
64
+ result.nodes.push(node);
65
+ return result;
66
+ }
67
+ result.nodes.push(node);
68
+ return result;
69
+ }, {
70
+ nodes: [],
71
+ lineNumber
72
+ });
73
+ };
74
+ var wrapLines = function wrapLines2(ast, linesToHighlight) {
75
+ var highlightAll = linesToHighlight.length === 1 && linesToHighlight[0] === 0;
76
+ var allLines = Array.from(new Set(ast.map(function(x) {
77
+ return x.lineNumber;
78
+ })));
79
+ var i = 0;
80
+ var wrapped = allLines.reduce(function(nodes, marker) {
81
+ var line = marker;
82
+ var children = [];
83
+ for (; i < ast.length; i++) {
84
+ if (ast[i].lineNumber < line) {
85
+ nodes.push(ast[i]);
86
+ continue;
87
+ }
88
+ if (ast[i].lineNumber === line) {
89
+ children.push(ast[i]);
90
+ continue;
91
+ }
92
+ if (ast[i].lineNumber > line) {
93
+ break;
94
+ }
95
+ }
96
+ nodes.push({
97
+ type: "element",
98
+ tagName: "div",
99
+ properties: {
100
+ dataLine: line,
101
+ className: "highlight-line",
102
+ dataHighlighted: linesToHighlight.includes(line) || highlightAll ? "true" : "false"
103
+ },
104
+ children,
105
+ lineNumber: line
106
+ });
107
+ return nodes;
108
+ }, []);
109
+ return wrapped;
110
+ };
111
+ var MULTILINE_TOKEN_SPAN = /<span class="token ([^"]+)">[^<]*\n[^<]*<\/span>/g;
112
+ var applyMultilineFix = function(ast) {
113
+ var html = (0, import_hast_util_to_html.toHtml)(ast);
114
+ html = html.replace(MULTILINE_TOKEN_SPAN, function(match, token) {
115
+ return match.replace(/\n/g, `</span>
116
+ <span class="token ${token}">`);
117
+ });
118
+ var hast = (0, import_unified.unified)().use(import_rehype_parse.default, {
119
+ emitParseErrors: true,
120
+ fragment: true
121
+ }).parse(html);
122
+ return hast["children"];
123
+ };
124
+ function highlightLine(ast, lines) {
125
+ var formattedAst = applyMultilineFix(ast);
126
+ var numbered = lineNumberify(formattedAst).nodes;
127
+ return wrapLines(numbered, lines);
128
+ }
@@ -7,132 +7,124 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
7
7
  var __getProtoOf = Object.getPrototypeOf;
8
8
  var __hasOwnProp = Object.prototype.hasOwnProperty;
9
9
  var __export = (target, all) => {
10
- for (var name in all) __defProp(target, name, {
11
- get: all[name],
12
- enumerable: true
13
- });
10
+ for (var name in all) __defProp(target, name, {
11
+ get: all[name],
12
+ enumerable: true
13
+ });
14
14
  };
15
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;
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
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
24
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
25
+ value: mod,
26
+ enumerable: true
32
27
  }) : target, mod));
33
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
34
- value: true
35
- }), mod);
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
36
29
  var highlightLine_exports = {};
37
- __export(highlightLine_exports, {
38
- highlightLine: () => highlightLine
39
- });
30
+ __export(highlightLine_exports, { highlightLine: () => highlightLine });
40
31
  module.exports = __toCommonJS(highlightLine_exports);
41
32
  var import_hast_util_to_html = require("hast-util-to-html");
42
33
  var import_rehype_parse = __toESM(require("rehype-parse"));
43
34
  var import_unified = require("unified");
44
35
  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]}
36
+ var lineNum = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 1;
37
+ var lineNumber = lineNum;
38
+ return ast.reduce(function(result, node) {
39
+ if (node.type === "text") {
40
+ if (node.value.indexOf("\n") === -1) {
41
+ node.lineNumber = lineNumber;
42
+ result.nodes.push(node);
43
+ return result;
44
+ }
45
+ var lines = node.value.split("\n");
46
+ for (var i = 0; i < lines.length; i++) {
47
+ if (i !== 0) ++lineNumber;
48
+ if (i === lines.length - 1 && lines[i].length === 0) continue;
49
+ result.nodes.push({
50
+ type: "text",
51
+ value: i === lines.length - 1 ? lines[i] : `${lines[i]}
61
52
  `,
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
- });
53
+ lineNumber
54
+ });
55
+ }
56
+ result.lineNumber = lineNumber;
57
+ return result;
58
+ }
59
+ if (node.children) {
60
+ node.lineNumber = lineNumber;
61
+ var processed = lineNumberify2(node.children, lineNumber);
62
+ node.children = processed.nodes;
63
+ result.lineNumber = processed.lineNumber;
64
+ result.nodes.push(node);
65
+ return result;
66
+ }
67
+ result.nodes.push(node);
68
+ return result;
69
+ }, {
70
+ nodes: [],
71
+ lineNumber
72
+ });
82
73
  };
83
74
  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;
75
+ var highlightAll = linesToHighlight.length === 1 && linesToHighlight[0] === 0;
76
+ var allLines = Array.from(new Set(ast.map(function(x) {
77
+ return x.lineNumber;
78
+ })));
79
+ var i = 0;
80
+ var wrapped = allLines.reduce(function(nodes, marker) {
81
+ var line = marker;
82
+ var children = [];
83
+ for (; i < ast.length; i++) {
84
+ if (ast[i].lineNumber < line) {
85
+ nodes.push(ast[i]);
86
+ continue;
87
+ }
88
+ if (ast[i].lineNumber === line) {
89
+ children.push(ast[i]);
90
+ continue;
91
+ }
92
+ if (ast[i].lineNumber > line) {
93
+ break;
94
+ }
95
+ }
96
+ nodes.push({
97
+ type: "element",
98
+ tagName: "div",
99
+ properties: {
100
+ dataLine: line,
101
+ className: "highlight-line",
102
+ dataHighlighted: linesToHighlight.includes(line) || highlightAll ? "true" : "false"
103
+ },
104
+ children,
105
+ lineNumber: line
106
+ });
107
+ return nodes;
108
+ }, []);
109
+ return wrapped;
119
110
  };
120
111
  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>
112
+ var applyMultilineFix = function(ast) {
113
+ var html = (0, import_hast_util_to_html.toHtml)(ast);
114
+ html = html.replace(MULTILINE_TOKEN_SPAN, function(match, token) {
115
+ return match.replace(/\n/g, `</span>
125
116
  <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"];
117
+ });
118
+ var hast = (0, import_unified.unified)().use(import_rehype_parse.default, {
119
+ emitParseErrors: true,
120
+ fragment: true
121
+ }).parse(html);
122
+ return hast["children"];
132
123
  };
133
124
  function highlightLine(ast, lines) {
134
- var formattedAst = applyMultilineFix(ast);
135
- var numbered = lineNumberify(formattedAst).nodes;
136
- return wrapLines(numbered, lines);
125
+ var formattedAst = applyMultilineFix(ast);
126
+ var numbered = lineNumberify(formattedAst).nodes;
127
+ return wrapLines(numbered, lines);
137
128
  }
129
+
138
130
  //# sourceMappingURL=highlightLine.native.js.map
@@ -1 +1 @@
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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ACFD,CAAA,GAAAd,GAAA,CAAAG,MAAA,EAAAW,CAAA;MAEA,IAAId,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
+ {"version":3,"file":"highlightLine.native.js","names":[],"sources":["cjs/highlightLine.native.js"],"sourcesContent":["\"use strict\";\nvar __create = Object.create;\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __getProtoOf = Object.getPrototypeOf;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(\n // If the importer is in node compatibility mode or this is not an ESM\n // file that has been converted to a CommonJS file using a Babel-\n // compatible transform (i.e. \"__esModule\" has not been set), then set\n // \"default\" to the CommonJS \"module.exports\" for node compatibility.\n isNodeMode || !mod || !mod.__esModule ? __defProp(target, \"default\", { value: mod, enumerable: true }) : target,\n mod\n));\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar highlightLine_exports = {};\n__export(highlightLine_exports, {\n highlightLine: () => highlightLine\n});\nmodule.exports = __toCommonJS(highlightLine_exports);\nvar import_hast_util_to_html = require(\"hast-util-to-html\");\nvar import_rehype_parse = __toESM(require(\"rehype-parse\"));\nvar import_unified = require(\"unified\");\nvar lineNumberify = function lineNumberify2(ast) {\n var lineNum = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 1;\n var lineNumber = lineNum;\n return ast.reduce(function(result, node) {\n if (node.type === \"text\") {\n if (node.value.indexOf(\"\\n\") === -1) {\n node.lineNumber = lineNumber;\n result.nodes.push(node);\n return result;\n }\n var lines = node.value.split(\"\\n\");\n for (var i = 0; i < lines.length; i++) {\n if (i !== 0) ++lineNumber;\n if (i === lines.length - 1 && lines[i].length === 0) continue;\n result.nodes.push({\n type: \"text\",\n value: i === lines.length - 1 ? lines[i] : `${lines[i]}\n`,\n lineNumber\n });\n }\n result.lineNumber = lineNumber;\n return result;\n }\n if (node.children) {\n node.lineNumber = lineNumber;\n var processed = lineNumberify2(node.children, lineNumber);\n node.children = processed.nodes;\n result.lineNumber = processed.lineNumber;\n result.nodes.push(node);\n return result;\n }\n result.nodes.push(node);\n return result;\n }, {\n nodes: [],\n lineNumber\n });\n};\nvar wrapLines = function wrapLines2(ast, linesToHighlight) {\n var highlightAll = linesToHighlight.length === 1 && linesToHighlight[0] === 0;\n var allLines = Array.from(new Set(ast.map(function(x) {\n return x.lineNumber;\n })));\n var i = 0;\n var wrapped = allLines.reduce(function(nodes, marker) {\n var line = marker;\n var children = [];\n for (; i < ast.length; i++) {\n if (ast[i].lineNumber < line) {\n nodes.push(ast[i]);\n continue;\n }\n if (ast[i].lineNumber === line) {\n children.push(ast[i]);\n continue;\n }\n if (ast[i].lineNumber > line) {\n break;\n }\n }\n nodes.push({\n type: \"element\",\n tagName: \"div\",\n properties: {\n dataLine: line,\n className: \"highlight-line\",\n dataHighlighted: linesToHighlight.includes(line) || highlightAll ? \"true\" : \"false\"\n },\n children,\n lineNumber: line\n });\n return nodes;\n }, []);\n return wrapped;\n};\nvar MULTILINE_TOKEN_SPAN = /<span class=\"token ([^\"]+)\">[^<]*\\n[^<]*<\\/span>/g;\nvar applyMultilineFix = function(ast) {\n var html = (0, import_hast_util_to_html.toHtml)(ast);\n html = html.replace(MULTILINE_TOKEN_SPAN, function(match, token) {\n return match.replace(/\\n/g, `</span>\n<span class=\"token ${token}\">`);\n });\n var hast = (0, import_unified.unified)().use(import_rehype_parse.default, {\n emitParseErrors: true,\n fragment: true\n }).parse(html);\n return hast[\"children\"];\n};\nfunction highlightLine(ast, lines) {\n var formattedAst = applyMultilineFix(ast);\n var numbered = lineNumberify(formattedAst).nodes;\n return wrapLines(numbered, lines);\n}\n//# sourceMappingURL=highlightLine.js.map\n"],"mappings":";;;AACA,IAAI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