@tamagui/code-to-html 2.7.7 → 3.0.0-beta.637.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.
@@ -1,3 +1,4 @@
1
+
1
2
  var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -5,126 +6,117 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
5
6
  var __getProtoOf = Object.getPrototypeOf;
6
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
8
  var __export = (target, all) => {
8
- for (var name in all) __defProp(target, name, {
9
- get: all[name],
10
- enumerable: true
11
- });
9
+ for (var name in all) __defProp(target, name, {
10
+ get: all[name],
11
+ enumerable: true
12
+ });
12
13
  };
13
14
  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;
15
+ if (from && typeof from === "object" || typeof from === "function") {
16
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
17
+ get: () => from[key],
18
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
19
+ });
20
+ }
21
+ return to;
21
22
  };
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
23
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
24
+ value: mod,
25
+ enumerable: true
30
26
  }) : target, mod));
31
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
32
- value: true
33
- }), mod);
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
34
28
  var highlightLine_exports = {};
35
- __export(highlightLine_exports, {
36
- highlightLine: () => highlightLine
37
- });
29
+ __export(highlightLine_exports, { highlightLine: () => highlightLine });
38
30
  module.exports = __toCommonJS(highlightLine_exports);
39
31
  var import_hast_util_to_html = require("hast-util-to-html");
40
32
  var import_rehype_parse = __toESM(require("rehype-parse"));
41
33
  var import_unified = require("unified");
42
34
  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]}
35
+ let lineNumber = lineNum;
36
+ return ast.reduce((result, node) => {
37
+ if (node.type === "text") {
38
+ if (node.value.indexOf("\n") === -1) {
39
+ node.lineNumber = lineNumber;
40
+ result.nodes.push(node);
41
+ return result;
42
+ }
43
+ const lines = node.value.split("\n");
44
+ for (let i = 0; i < lines.length; i++) {
45
+ if (i !== 0) ++lineNumber;
46
+ if (i === lines.length - 1 && lines[i].length === 0) continue;
47
+ result.nodes.push({
48
+ type: "text",
49
+ value: i === lines.length - 1 ? lines[i] : `${lines[i]}
58
50
  `,
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
- });
51
+ lineNumber
52
+ });
53
+ }
54
+ result.lineNumber = lineNumber;
55
+ return result;
56
+ }
57
+ if (node.children) {
58
+ node.lineNumber = lineNumber;
59
+ const processed = lineNumberify2(node.children, lineNumber);
60
+ node.children = processed.nodes;
61
+ result.lineNumber = processed.lineNumber;
62
+ result.nodes.push(node);
63
+ return result;
64
+ }
65
+ result.nodes.push(node);
66
+ return result;
67
+ }, {
68
+ nodes: [],
69
+ lineNumber
70
+ });
79
71
  };
80
72
  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;
73
+ const highlightAll = linesToHighlight.length === 1 && linesToHighlight[0] === 0;
74
+ const allLines = Array.from(new Set(ast.map((x) => x.lineNumber)));
75
+ let i = 0;
76
+ const wrapped = allLines.reduce((nodes, marker) => {
77
+ const line = marker;
78
+ const children = [];
79
+ for (; i < ast.length; i++) {
80
+ if (ast[i].lineNumber < line) {
81
+ nodes.push(ast[i]);
82
+ continue;
83
+ }
84
+ if (ast[i].lineNumber === line) {
85
+ children.push(ast[i]);
86
+ continue;
87
+ }
88
+ if (ast[i].lineNumber > line) {
89
+ break;
90
+ }
91
+ }
92
+ nodes.push({
93
+ type: "element",
94
+ tagName: "div",
95
+ properties: {
96
+ dataLine: line,
97
+ className: "highlight-line",
98
+ dataHighlighted: linesToHighlight.includes(line) || highlightAll ? "true" : "false"
99
+ },
100
+ children,
101
+ lineNumber: line
102
+ });
103
+ return nodes;
104
+ }, []);
105
+ return wrapped;
114
106
  };
115
107
  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>
108
+ const applyMultilineFix = (ast) => {
109
+ let html = (0, import_hast_util_to_html.toHtml)(ast);
110
+ html = html.replace(MULTILINE_TOKEN_SPAN, (match, token) => match.replace(/\n/g, `</span>
119
111
  <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"];
112
+ const hast = (0, import_unified.unified)().use(import_rehype_parse.default, {
113
+ emitParseErrors: true,
114
+ fragment: true
115
+ }).parse(html);
116
+ return hast["children"];
125
117
  };
126
118
  function highlightLine(ast, lines) {
127
- const formattedAst = applyMultilineFix(ast);
128
- const numbered = lineNumberify(formattedAst).nodes;
129
- return wrapLines(numbered, lines);
130
- }
119
+ const formattedAst = applyMultilineFix(ast);
120
+ const numbered = lineNumberify(formattedAst).nodes;
121
+ return wrapLines(numbered, lines);
122
+ }
@@ -0,0 +1,129 @@
1
+ "use strict";
2
+
3
+
4
+ var __create = Object.create;
5
+ var __defProp = Object.defineProperty;
6
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
+ var __getOwnPropNames = Object.getOwnPropertyNames;
8
+ var __getProtoOf = Object.getPrototypeOf;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __export = (target, all) => {
11
+ for (var name in all) __defProp(target, name, {
12
+ get: all[name],
13
+ enumerable: true
14
+ });
15
+ };
16
+ var __copyProps = (to, from, except, desc) => {
17
+ if (from && typeof from === "object" || typeof from === "function") {
18
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
19
+ get: () => from[key],
20
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
21
+ });
22
+ }
23
+ return to;
24
+ };
25
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
26
+ value: mod,
27
+ enumerable: true
28
+ }) : target, mod));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+ var highlightLine_exports = {};
31
+ __export(highlightLine_exports, { highlightLine: () => highlightLine });
32
+ module.exports = __toCommonJS(highlightLine_exports);
33
+ var import_hast_util_to_html = require("hast-util-to-html");
34
+ var import_rehype_parse = __toESM(require("rehype-parse"));
35
+ var import_unified = require("unified");
36
+ var lineNumberify = function lineNumberify2(ast) {
37
+ var lineNum = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 1;
38
+ var lineNumber = lineNum;
39
+ return ast.reduce(function(result, node) {
40
+ if (node.type === "text") {
41
+ if (node.value.indexOf("\n") === -1) {
42
+ node.lineNumber = lineNumber;
43
+ result.nodes.push(node);
44
+ return result;
45
+ }
46
+ var lines = node.value.split("\n");
47
+ for (var i = 0; i < lines.length; i++) {
48
+ if (i !== 0) ++lineNumber;
49
+ if (i === lines.length - 1 && lines[i].length === 0) continue;
50
+ result.nodes.push({
51
+ type: "text",
52
+ value: i === lines.length - 1 ? lines[i] : `${lines[i]}
53
+ `,
54
+ lineNumber
55
+ });
56
+ }
57
+ result.lineNumber = lineNumber;
58
+ return result;
59
+ }
60
+ if (node.children) {
61
+ node.lineNumber = lineNumber;
62
+ var processed = lineNumberify2(node.children, lineNumber);
63
+ node.children = processed.nodes;
64
+ result.lineNumber = processed.lineNumber;
65
+ result.nodes.push(node);
66
+ return result;
67
+ }
68
+ result.nodes.push(node);
69
+ return result;
70
+ }, {
71
+ nodes: [],
72
+ lineNumber
73
+ });
74
+ };
75
+ var wrapLines = function wrapLines2(ast, linesToHighlight) {
76
+ var highlightAll = linesToHighlight.length === 1 && linesToHighlight[0] === 0;
77
+ var allLines = Array.from(new Set(ast.map(function(x) {
78
+ return x.lineNumber;
79
+ })));
80
+ var i = 0;
81
+ var wrapped = allLines.reduce(function(nodes, marker) {
82
+ var line = marker;
83
+ var children = [];
84
+ for (; i < ast.length; i++) {
85
+ if (ast[i].lineNumber < line) {
86
+ nodes.push(ast[i]);
87
+ continue;
88
+ }
89
+ if (ast[i].lineNumber === line) {
90
+ children.push(ast[i]);
91
+ continue;
92
+ }
93
+ if (ast[i].lineNumber > line) {
94
+ break;
95
+ }
96
+ }
97
+ nodes.push({
98
+ type: "element",
99
+ tagName: "div",
100
+ properties: {
101
+ dataLine: line,
102
+ className: "highlight-line",
103
+ dataHighlighted: linesToHighlight.includes(line) || highlightAll ? "true" : "false"
104
+ },
105
+ children,
106
+ lineNumber: line
107
+ });
108
+ return nodes;
109
+ }, []);
110
+ return wrapped;
111
+ };
112
+ var MULTILINE_TOKEN_SPAN = /<span class="token ([^"]+)">[^<]*\n[^<]*<\/span>/g;
113
+ var applyMultilineFix = function(ast) {
114
+ var html = (0, import_hast_util_to_html.toHtml)(ast);
115
+ html = html.replace(MULTILINE_TOKEN_SPAN, function(match, token) {
116
+ return match.replace(/\n/g, `</span>
117
+ <span class="token ${token}">`);
118
+ });
119
+ var hast = (0, import_unified.unified)().use(import_rehype_parse.default, {
120
+ emitParseErrors: true,
121
+ fragment: true
122
+ }).parse(html);
123
+ return hast["children"];
124
+ };
125
+ function highlightLine(ast, lines) {
126
+ var formattedAst = applyMultilineFix(ast);
127
+ var numbered = lineNumberify(formattedAst).nodes;
128
+ return wrapLines(numbered, lines);
129
+ }
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
 
3
+
3
4
  var __create = Object.create;
4
5
  var __defProp = Object.defineProperty;
5
6
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -7,132 +8,124 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
7
8
  var __getProtoOf = Object.getPrototypeOf;
8
9
  var __hasOwnProp = Object.prototype.hasOwnProperty;
9
10
  var __export = (target, all) => {
10
- for (var name in all) __defProp(target, name, {
11
- get: all[name],
12
- enumerable: true
13
- });
11
+ for (var name in all) __defProp(target, name, {
12
+ get: all[name],
13
+ enumerable: true
14
+ });
14
15
  };
15
16
  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;
17
+ if (from && typeof from === "object" || typeof from === "function") {
18
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
19
+ get: () => from[key],
20
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
21
+ });
22
+ }
23
+ return to;
23
24
  };
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
25
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
26
+ value: mod,
27
+ enumerable: true
32
28
  }) : target, mod));
33
- var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
34
- value: true
35
- }), mod);
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
36
30
  var highlightLine_exports = {};
37
- __export(highlightLine_exports, {
38
- highlightLine: () => highlightLine
39
- });
31
+ __export(highlightLine_exports, { highlightLine: () => highlightLine });
40
32
  module.exports = __toCommonJS(highlightLine_exports);
41
33
  var import_hast_util_to_html = require("hast-util-to-html");
42
34
  var import_rehype_parse = __toESM(require("rehype-parse"));
43
35
  var import_unified = require("unified");
44
36
  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]}
37
+ var lineNum = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 1;
38
+ var lineNumber = lineNum;
39
+ return ast.reduce(function(result, node) {
40
+ if (node.type === "text") {
41
+ if (node.value.indexOf("\n") === -1) {
42
+ node.lineNumber = lineNumber;
43
+ result.nodes.push(node);
44
+ return result;
45
+ }
46
+ var lines = node.value.split("\n");
47
+ for (var i = 0; i < lines.length; i++) {
48
+ if (i !== 0) ++lineNumber;
49
+ if (i === lines.length - 1 && lines[i].length === 0) continue;
50
+ result.nodes.push({
51
+ type: "text",
52
+ value: i === lines.length - 1 ? lines[i] : `${lines[i]}
61
53
  `,
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
- });
54
+ lineNumber
55
+ });
56
+ }
57
+ result.lineNumber = lineNumber;
58
+ return result;
59
+ }
60
+ if (node.children) {
61
+ node.lineNumber = lineNumber;
62
+ var processed = lineNumberify2(node.children, lineNumber);
63
+ node.children = processed.nodes;
64
+ result.lineNumber = processed.lineNumber;
65
+ result.nodes.push(node);
66
+ return result;
67
+ }
68
+ result.nodes.push(node);
69
+ return result;
70
+ }, {
71
+ nodes: [],
72
+ lineNumber
73
+ });
82
74
  };
83
75
  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;
76
+ var highlightAll = linesToHighlight.length === 1 && linesToHighlight[0] === 0;
77
+ var allLines = Array.from(new Set(ast.map(function(x) {
78
+ return x.lineNumber;
79
+ })));
80
+ var i = 0;
81
+ var wrapped = allLines.reduce(function(nodes, marker) {
82
+ var line = marker;
83
+ var children = [];
84
+ for (; i < ast.length; i++) {
85
+ if (ast[i].lineNumber < line) {
86
+ nodes.push(ast[i]);
87
+ continue;
88
+ }
89
+ if (ast[i].lineNumber === line) {
90
+ children.push(ast[i]);
91
+ continue;
92
+ }
93
+ if (ast[i].lineNumber > line) {
94
+ break;
95
+ }
96
+ }
97
+ nodes.push({
98
+ type: "element",
99
+ tagName: "div",
100
+ properties: {
101
+ dataLine: line,
102
+ className: "highlight-line",
103
+ dataHighlighted: linesToHighlight.includes(line) || highlightAll ? "true" : "false"
104
+ },
105
+ children,
106
+ lineNumber: line
107
+ });
108
+ return nodes;
109
+ }, []);
110
+ return wrapped;
119
111
  };
120
112
  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>
113
+ var applyMultilineFix = function(ast) {
114
+ var html = (0, import_hast_util_to_html.toHtml)(ast);
115
+ html = html.replace(MULTILINE_TOKEN_SPAN, function(match, token) {
116
+ return match.replace(/\n/g, `</span>
125
117
  <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"];
118
+ });
119
+ var hast = (0, import_unified.unified)().use(import_rehype_parse.default, {
120
+ emitParseErrors: true,
121
+ fragment: true
122
+ }).parse(html);
123
+ return hast["children"];
132
124
  };
133
125
  function highlightLine(ast, lines) {
134
- var formattedAst = applyMultilineFix(ast);
135
- var numbered = lineNumberify(formattedAst).nodes;
136
- return wrapLines(numbered, lines);
126
+ var formattedAst = applyMultilineFix(ast);
127
+ var numbered = lineNumberify(formattedAst).nodes;
128
+ return wrapLines(numbered, lines);
137
129
  }
130
+
138
131
  //# 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,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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,WAAW,OAAO;AACtB,IAAI,YAAY,OAAO;AACvB,IAAI,mBAAmB,OAAO;AAC9B,IAAI,oBAAoB,OAAO;AAC/B,IAAI,eAAe,OAAO;AAC1B,IAAI,eAAe,OAAO,UAAU;AACpC,IAAI,YAAY,QAAQ,QAAQ;CAC9B,KAAK,IAAI,QAAQ,KACf,UAAU,QAAQ,MAAM;EAAE,KAAK,IAAI;EAAO,YAAY;CAAK,CAAC;AAChE;AACA,IAAI,eAAe,IAAI,MAAM,QAAQ,SAAS;CAC5C,IAAI,QAAQ,OAAO,SAAS,YAAY,OAAO,SAAS,YAAY;EAClE,KAAK,IAAI,OAAO,kBAAkB,IAAI,GACpC,IAAI,CAAC,aAAa,KAAK,IAAI,GAAG,KAAK,QAAQ,QACzC,UAAU,IAAI,KAAK;GAAE,WAAW,KAAK;GAAM,YAAY,EAAE,OAAO,iBAAiB,MAAM,GAAG,MAAM,KAAK;EAAW,CAAC;CACvH;CACA,OAAO;AACT;AACA,IAAI,WAAW,KAAK,YAAY,YAAY,SAAS,OAAO,OAAO,SAAS,aAAa,GAAG,CAAC,IAAI,CAAC,GAAG,YAKnG,cAAc,CAAC,OAAO,CAAC,IAAI,aAAa,UAAU,QAAQ,WAAW;CAAE,OAAO;CAAK,YAAY;AAAK,CAAC,IAAI,QACzG,GACF;AACA,IAAI,gBAAgB,QAAQ,YAAY,UAAU,CAAC,GAAG,cAAc,EAAE,OAAO,KAAK,CAAC,GAAG,GAAG;AACzF,IAAI,wBAAwB,CAAC;AAC7B,SAAS,uBAAuB,EAC9B,qBAAqB,cACvB,CAAC;AACD,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