@getpaseo/highlight 0.1.32
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/colors.d.ts +4 -0
- package/dist/colors.d.ts.map +1 -0
- package/dist/colors.js +45 -0
- package/dist/colors.js.map +1 -0
- package/dist/highlighter.d.ts +4 -0
- package/dist/highlighter.d.ts.map +1 -0
- package/dist/highlighter.js +97 -0
- package/dist/highlighter.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/parsers.d.ts +5 -0
- package/dist/parsers.d.ts.map +1 -0
- package/dist/parsers.js +75 -0
- package/dist/parsers.js.map +1 -0
- package/dist/types.d.ts +6 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +41 -0
package/dist/colors.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"colors.d.ts","sourceRoot":"","sources":["../src/colors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,eAAO,MAAM,mBAAmB,EAAE,MAAM,CAAC,cAAc,EAAE,MAAM,CAqB9D,CAAC;AAEF,eAAO,MAAM,oBAAoB,EAAE,MAAM,CAAC,cAAc,EAAE,MAAM,CAqB/D,CAAC"}
|
package/dist/colors.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export const darkHighlightColors = {
|
|
2
|
+
keyword: "#ff7b72",
|
|
3
|
+
comment: "#8b949e",
|
|
4
|
+
string: "#a5d6ff",
|
|
5
|
+
number: "#79c0ff",
|
|
6
|
+
literal: "#79c0ff",
|
|
7
|
+
function: "#d2a8ff",
|
|
8
|
+
definition: "#d2a8ff",
|
|
9
|
+
class: "#ffa657",
|
|
10
|
+
type: "#ff7b72",
|
|
11
|
+
tag: "#7ee787",
|
|
12
|
+
attribute: "#79c0ff",
|
|
13
|
+
property: "#79c0ff",
|
|
14
|
+
variable: "#c9d1d9",
|
|
15
|
+
operator: "#79c0ff",
|
|
16
|
+
punctuation: "#c9d1d9",
|
|
17
|
+
regexp: "#a5d6ff",
|
|
18
|
+
escape: "#79c0ff",
|
|
19
|
+
meta: "#8b949e",
|
|
20
|
+
heading: "#79c0ff",
|
|
21
|
+
link: "#a5d6ff",
|
|
22
|
+
};
|
|
23
|
+
export const lightHighlightColors = {
|
|
24
|
+
keyword: "#cf222e",
|
|
25
|
+
comment: "#6e7781",
|
|
26
|
+
string: "#0a3069",
|
|
27
|
+
number: "#0550ae",
|
|
28
|
+
literal: "#0550ae",
|
|
29
|
+
function: "#8250df",
|
|
30
|
+
definition: "#8250df",
|
|
31
|
+
class: "#953800",
|
|
32
|
+
type: "#cf222e",
|
|
33
|
+
tag: "#116329",
|
|
34
|
+
attribute: "#0550ae",
|
|
35
|
+
property: "#0550ae",
|
|
36
|
+
variable: "#24292f",
|
|
37
|
+
operator: "#0550ae",
|
|
38
|
+
punctuation: "#24292f",
|
|
39
|
+
regexp: "#0a3069",
|
|
40
|
+
escape: "#0550ae",
|
|
41
|
+
meta: "#6e7781",
|
|
42
|
+
heading: "#0550ae",
|
|
43
|
+
link: "#0a3069",
|
|
44
|
+
};
|
|
45
|
+
//# sourceMappingURL=colors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"colors.js","sourceRoot":"","sources":["../src/colors.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,mBAAmB,GAAmC;IACjE,OAAO,EAAE,SAAS;IAClB,OAAO,EAAE,SAAS;IAClB,MAAM,EAAE,SAAS;IACjB,MAAM,EAAE,SAAS;IACjB,OAAO,EAAE,SAAS;IAClB,QAAQ,EAAE,SAAS;IACnB,UAAU,EAAE,SAAS;IACrB,KAAK,EAAE,SAAS;IAChB,IAAI,EAAE,SAAS;IACf,GAAG,EAAE,SAAS;IACd,SAAS,EAAE,SAAS;IACpB,QAAQ,EAAE,SAAS;IACnB,QAAQ,EAAE,SAAS;IACnB,QAAQ,EAAE,SAAS;IACnB,WAAW,EAAE,SAAS;IACtB,MAAM,EAAE,SAAS;IACjB,MAAM,EAAE,SAAS;IACjB,IAAI,EAAE,SAAS;IACf,OAAO,EAAE,SAAS;IAClB,IAAI,EAAE,SAAS;CAChB,CAAC;AAEF,MAAM,CAAC,MAAM,oBAAoB,GAAmC;IAClE,OAAO,EAAE,SAAS;IAClB,OAAO,EAAE,SAAS;IAClB,MAAM,EAAE,SAAS;IACjB,MAAM,EAAE,SAAS;IACjB,OAAO,EAAE,SAAS;IAClB,QAAQ,EAAE,SAAS;IACnB,UAAU,EAAE,SAAS;IACrB,KAAK,EAAE,SAAS;IAChB,IAAI,EAAE,SAAS;IACf,GAAG,EAAE,SAAS;IACd,SAAS,EAAE,SAAS;IACpB,QAAQ,EAAE,SAAS;IACnB,QAAQ,EAAE,SAAS;IACnB,QAAQ,EAAE,SAAS;IACnB,WAAW,EAAE,SAAS;IACtB,MAAM,EAAE,SAAS;IACjB,MAAM,EAAE,SAAS;IACjB,IAAI,EAAE,SAAS;IACf,OAAO,EAAE,SAAS;IAClB,IAAI,EAAE,SAAS;CAChB,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { HighlightToken } from "./types.js";
|
|
2
|
+
export declare function highlightCode(code: string, filename: string): HighlightToken[][];
|
|
3
|
+
export declare function highlightLine(line: string, filename: string): HighlightToken[];
|
|
4
|
+
//# sourceMappingURL=highlighter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"highlighter.d.ts","sourceRoot":"","sources":["../src/highlighter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAkB,cAAc,EAAE,MAAM,YAAY,CAAC;AA+CjE,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,cAAc,EAAE,EAAE,CAyDhF;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,cAAc,EAAE,CAG9E"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { highlightTree, tagHighlighter, tags } from "@lezer/highlight";
|
|
2
|
+
import { getParserForFile } from "./parsers.js";
|
|
3
|
+
const highlighter = tagHighlighter([
|
|
4
|
+
{ tag: tags.keyword, class: "keyword" },
|
|
5
|
+
{ tag: tags.controlKeyword, class: "keyword" },
|
|
6
|
+
{ tag: tags.operatorKeyword, class: "keyword" },
|
|
7
|
+
{ tag: tags.definitionKeyword, class: "keyword" },
|
|
8
|
+
{ tag: tags.moduleKeyword, class: "keyword" },
|
|
9
|
+
{ tag: tags.comment, class: "comment" },
|
|
10
|
+
{ tag: tags.lineComment, class: "comment" },
|
|
11
|
+
{ tag: tags.blockComment, class: "comment" },
|
|
12
|
+
{ tag: tags.docComment, class: "comment" },
|
|
13
|
+
{ tag: tags.string, class: "string" },
|
|
14
|
+
{ tag: tags.special(tags.string), class: "string" },
|
|
15
|
+
{ tag: tags.number, class: "number" },
|
|
16
|
+
{ tag: tags.integer, class: "number" },
|
|
17
|
+
{ tag: tags.float, class: "number" },
|
|
18
|
+
{ tag: tags.bool, class: "literal" },
|
|
19
|
+
{ tag: tags.null, class: "literal" },
|
|
20
|
+
{ tag: tags.function(tags.variableName), class: "function" },
|
|
21
|
+
{ tag: tags.function(tags.propertyName), class: "function" },
|
|
22
|
+
{ tag: tags.definition(tags.variableName), class: "definition" },
|
|
23
|
+
{ tag: tags.definition(tags.propertyName), class: "definition" },
|
|
24
|
+
{ tag: tags.definition(tags.function(tags.variableName)), class: "definition" },
|
|
25
|
+
{ tag: tags.className, class: "class" },
|
|
26
|
+
{ tag: tags.definition(tags.className), class: "class" },
|
|
27
|
+
{ tag: tags.typeName, class: "type" },
|
|
28
|
+
{ tag: tags.tagName, class: "tag" },
|
|
29
|
+
{ tag: tags.attributeName, class: "attribute" },
|
|
30
|
+
{ tag: tags.attributeValue, class: "string" },
|
|
31
|
+
{ tag: tags.propertyName, class: "property" },
|
|
32
|
+
{ tag: tags.variableName, class: "variable" },
|
|
33
|
+
{ tag: tags.local(tags.variableName), class: "variable" },
|
|
34
|
+
{ tag: tags.special(tags.variableName), class: "variable" },
|
|
35
|
+
{ tag: tags.operator, class: "operator" },
|
|
36
|
+
{ tag: tags.punctuation, class: "punctuation" },
|
|
37
|
+
{ tag: tags.bracket, class: "punctuation" },
|
|
38
|
+
{ tag: tags.separator, class: "punctuation" },
|
|
39
|
+
{ tag: tags.regexp, class: "regexp" },
|
|
40
|
+
{ tag: tags.escape, class: "escape" },
|
|
41
|
+
{ tag: tags.meta, class: "meta" },
|
|
42
|
+
{ tag: tags.heading, class: "heading" },
|
|
43
|
+
{ tag: tags.link, class: "link" },
|
|
44
|
+
{ tag: tags.url, class: "link" },
|
|
45
|
+
]);
|
|
46
|
+
export function highlightCode(code, filename) {
|
|
47
|
+
const parser = getParserForFile(filename);
|
|
48
|
+
if (!parser) {
|
|
49
|
+
return code.split("\n").map((line) => [{ text: line, style: null }]);
|
|
50
|
+
}
|
|
51
|
+
const tree = parser.parse(code);
|
|
52
|
+
const lines = code.split("\n");
|
|
53
|
+
const result = [];
|
|
54
|
+
for (let i = 0; i < lines.length; i++) {
|
|
55
|
+
result.push([]);
|
|
56
|
+
}
|
|
57
|
+
// Build a map of character positions to styles
|
|
58
|
+
const styleMap = new Array(code.length).fill(null);
|
|
59
|
+
highlightTree(tree, highlighter, (from, to, classes) => {
|
|
60
|
+
for (let i = from; i < to && i < styleMap.length; i++) {
|
|
61
|
+
styleMap[i] = classes;
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
// Convert style map to tokens per line
|
|
65
|
+
let pos = 0;
|
|
66
|
+
for (let lineIndex = 0; lineIndex < lines.length; lineIndex++) {
|
|
67
|
+
const line = lines[lineIndex];
|
|
68
|
+
if (line.length === 0) {
|
|
69
|
+
result[lineIndex].push({ text: "", style: null });
|
|
70
|
+
pos++; // skip newline
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
let currentToken = { text: "", style: styleMap[pos] };
|
|
74
|
+
for (let i = 0; i < line.length; i++) {
|
|
75
|
+
const charStyle = styleMap[pos + i];
|
|
76
|
+
if (charStyle === currentToken.style) {
|
|
77
|
+
currentToken.text += line[i];
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
if (currentToken.text) {
|
|
81
|
+
result[lineIndex].push(currentToken);
|
|
82
|
+
}
|
|
83
|
+
currentToken = { text: line[i], style: charStyle };
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (currentToken.text) {
|
|
87
|
+
result[lineIndex].push(currentToken);
|
|
88
|
+
}
|
|
89
|
+
pos += line.length + 1; // +1 for newline
|
|
90
|
+
}
|
|
91
|
+
return result;
|
|
92
|
+
}
|
|
93
|
+
export function highlightLine(line, filename) {
|
|
94
|
+
const result = highlightCode(line, filename);
|
|
95
|
+
return result[0] ?? [{ text: line, style: null }];
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=highlighter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"highlighter.js","sourceRoot":"","sources":["../src/highlighter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAEvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEhD,MAAM,WAAW,GAAG,cAAc,CAAC;IACjC,EAAE,GAAG,EAAE,IAAI,CAAC,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE;IACvC,EAAE,GAAG,EAAE,IAAI,CAAC,cAAc,EAAE,KAAK,EAAE,SAAS,EAAE;IAC9C,EAAE,GAAG,EAAE,IAAI,CAAC,eAAe,EAAE,KAAK,EAAE,SAAS,EAAE;IAC/C,EAAE,GAAG,EAAE,IAAI,CAAC,iBAAiB,EAA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I,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC;YAC/B,CAAC;iBAAM,CAAC;gBACN,IAAI,YAAY,CAAC,IAAI,EAAE,CAAC;oBACtB,MAAM,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;gBACvC,CAAC;gBACD,YAAY,GAAG,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;YACrD,CAAC;QACH,CAAC;QAED,IAAI,YAAY,CAAC,IAAI,EAAE,CAAC;YACtB,MAAM,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QACvC,CAAC;QAED,GAAG,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,iBAAiB;IAC3C,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,IAAY,EAAE,QAAgB;IAC1D,MAAM,MAAM,GAAG,aAAa,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAC7C,OAAO,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AACpD,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type { HighlightStyle, HighlightToken } from "./types.js";
|
|
2
|
+
export { getParserForFile, isLanguageSupported, getSupportedExtensions } from "./parsers.js";
|
|
3
|
+
export { highlightCode, highlightLine } from "./highlighter.js";
|
|
4
|
+
export { darkHighlightColors, lightHighlightColors } from "./colors.js";
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACjE,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAC7F,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC;AAC7F,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Parser } from "@lezer/common";
|
|
2
|
+
export declare function getParserForFile(filename: string): Parser | null;
|
|
3
|
+
export declare function isLanguageSupported(filename: string): boolean;
|
|
4
|
+
export declare function getSupportedExtensions(): string[];
|
|
5
|
+
//# sourceMappingURL=parsers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parsers.d.ts","sourceRoot":"","sources":["../src/parsers.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAmD5C,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAIhE;AAED,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAE7D;AAED,wBAAgB,sBAAsB,IAAI,MAAM,EAAE,CAEjD"}
|
package/dist/parsers.js
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { parser as jsParser } from "@lezer/javascript";
|
|
2
|
+
import { parser as jsonParser } from "@lezer/json";
|
|
3
|
+
import { parser as cssParser } from "@lezer/css";
|
|
4
|
+
import { parser as cppParser } from "@lezer/cpp";
|
|
5
|
+
import { parser as goParser } from "@lezer/go";
|
|
6
|
+
import { parser as htmlParser } from "@lezer/html";
|
|
7
|
+
import { parser as javaParser } from "@lezer/java";
|
|
8
|
+
import { parser as pythonParser } from "@lezer/python";
|
|
9
|
+
import { parser as markdownParser } from "@lezer/markdown";
|
|
10
|
+
import { parser as phpParser } from "@lezer/php";
|
|
11
|
+
import { parser as rustParser } from "@lezer/rust";
|
|
12
|
+
import { parser as xmlParser } from "@lezer/xml";
|
|
13
|
+
import { parser as yamlParser } from "@lezer/yaml";
|
|
14
|
+
import { parser as elixirParser } from "lezer-elixir";
|
|
15
|
+
const parsersByExtension = {
|
|
16
|
+
// JavaScript/TypeScript
|
|
17
|
+
js: jsParser,
|
|
18
|
+
jsx: jsParser.configure({ dialect: "jsx" }),
|
|
19
|
+
ts: jsParser.configure({ dialect: "ts" }),
|
|
20
|
+
tsx: jsParser.configure({ dialect: "ts jsx" }),
|
|
21
|
+
mjs: jsParser,
|
|
22
|
+
cjs: jsParser,
|
|
23
|
+
// C / C++ / Objective-C
|
|
24
|
+
c: cppParser,
|
|
25
|
+
h: cppParser,
|
|
26
|
+
cc: cppParser,
|
|
27
|
+
cpp: cppParser,
|
|
28
|
+
cxx: cppParser,
|
|
29
|
+
hpp: cppParser,
|
|
30
|
+
hxx: cppParser,
|
|
31
|
+
m: cppParser,
|
|
32
|
+
mm: cppParser,
|
|
33
|
+
// JSON
|
|
34
|
+
json: jsonParser,
|
|
35
|
+
// CSS
|
|
36
|
+
css: cssParser,
|
|
37
|
+
scss: cssParser,
|
|
38
|
+
// HTML
|
|
39
|
+
html: htmlParser,
|
|
40
|
+
htm: htmlParser,
|
|
41
|
+
// XML
|
|
42
|
+
xml: xmlParser,
|
|
43
|
+
// Java
|
|
44
|
+
java: javaParser,
|
|
45
|
+
// Python
|
|
46
|
+
py: pythonParser,
|
|
47
|
+
// Go
|
|
48
|
+
go: goParser,
|
|
49
|
+
// PHP
|
|
50
|
+
php: phpParser,
|
|
51
|
+
// YAML
|
|
52
|
+
yaml: yamlParser,
|
|
53
|
+
yml: yamlParser,
|
|
54
|
+
// Rust
|
|
55
|
+
rs: rustParser,
|
|
56
|
+
// Elixir
|
|
57
|
+
ex: elixirParser,
|
|
58
|
+
exs: elixirParser,
|
|
59
|
+
// Markdown
|
|
60
|
+
md: markdownParser,
|
|
61
|
+
mdx: markdownParser,
|
|
62
|
+
};
|
|
63
|
+
export function getParserForFile(filename) {
|
|
64
|
+
const ext = filename.split(".").pop()?.toLowerCase();
|
|
65
|
+
if (!ext)
|
|
66
|
+
return null;
|
|
67
|
+
return parsersByExtension[ext] ?? null;
|
|
68
|
+
}
|
|
69
|
+
export function isLanguageSupported(filename) {
|
|
70
|
+
return getParserForFile(filename) !== null;
|
|
71
|
+
}
|
|
72
|
+
export function getSupportedExtensions() {
|
|
73
|
+
return Object.keys(parsersByExtension);
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=parsers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parsers.js","sourceRoot":"","sources":["../src/parsers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,MAAM,IAAI,SAAS,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EAAE,MAAM,IAAI,SAAS,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,EAAE,MAAM,IAAI,QAAQ,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,EAAE,MAAM,IAAI,YAAY,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,E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M;IACN,GAAG,EAAE,SAAS;IACd,OAAO;IACP,IAAI,EAAE,UAAU;IAChB,GAAG,EAAE,UAAU;IACf,OAAO;IACP,EAAE,EAAE,UAAU;IACd,SAAS;IACT,EAAE,EAAE,YAAY;IAChB,GAAG,EAAE,YAAY;IACjB,WAAW;IACX,EAAE,EAAE,cAAc;IAClB,GAAG,EAAE,cAAc;CACpB,CAAC;AAEF,MAAM,UAAU,gBAAgB,CAAC,QAAgB;IAC/C,MAAM,GAAG,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,WAAW,EAAE,CAAC;IACrD,IAAI,CAAC,GAAG;QAAE,OAAO,IAAI,CAAC;IACtB,OAAO,kBAAkB,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC;AACzC,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,QAAgB;IAClD,OAAO,gBAAgB,CAAC,QAAQ,CAAC,KAAK,IAAI,CAAC;AAC7C,CAAC;AAED,MAAM,UAAU,sBAAsB;IACpC,OAAO,MAAM,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;AACzC,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type HighlightStyle = "keyword" | "comment" | "string" | "number" | "literal" | "function" | "definition" | "class" | "type" | "tag" | "attribute" | "property" | "variable" | "operator" | "punctuation" | "regexp" | "escape" | "meta" | "heading" | "link";
|
|
2
|
+
export interface HighlightToken {
|
|
3
|
+
text: string;
|
|
4
|
+
style: HighlightStyle | null;
|
|
5
|
+
}
|
|
6
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,cAAc,GACtB,SAAS,GACT,SAAS,GACT,QAAQ,GACR,QAAQ,GACR,SAAS,GACT,UAAU,GACV,YAAY,GACZ,OAAO,GACP,MAAM,GACN,KAAK,GACL,WAAW,GACX,UAAU,GACV,UAAU,GACV,UAAU,GACV,aAAa,GACb,QAAQ,GACR,QAAQ,GACR,MAAM,GACN,SAAS,GACT,MAAM,CAAC;AAEX,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,cAAc,GAAG,IAAI,CAAC;CAC9B"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@getpaseo/highlight",
|
|
3
|
+
"version": "0.1.32",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"publishConfig": {
|
|
6
|
+
"access": "public"
|
|
7
|
+
},
|
|
8
|
+
"main": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"files": [
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "node -e \"require('node:fs').rmSync('dist',{ recursive: true, force: true })\" && tsc -p tsconfig.json --incremental false",
|
|
15
|
+
"prepack": "npm run build",
|
|
16
|
+
"test": "vitest run",
|
|
17
|
+
"typecheck": "tsc --noEmit"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@lezer/common": "^1.5.0",
|
|
21
|
+
"@lezer/cpp": "^1.1.5",
|
|
22
|
+
"@lezer/css": "^1.3.0",
|
|
23
|
+
"@lezer/go": "^1.0.1",
|
|
24
|
+
"@lezer/highlight": "^1.2.3",
|
|
25
|
+
"@lezer/html": "^1.3.13",
|
|
26
|
+
"@lezer/java": "^1.1.3",
|
|
27
|
+
"@lezer/javascript": "^1.5.4",
|
|
28
|
+
"@lezer/json": "^1.0.3",
|
|
29
|
+
"@lezer/markdown": "^1.6.2",
|
|
30
|
+
"@lezer/php": "^1.0.5",
|
|
31
|
+
"@lezer/python": "^1.1.18",
|
|
32
|
+
"@lezer/rust": "^1.0.2",
|
|
33
|
+
"@lezer/xml": "^1.0.6",
|
|
34
|
+
"@lezer/yaml": "^1.0.4",
|
|
35
|
+
"lezer-elixir": "^1.1.2"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"typescript": "^5.9.2",
|
|
39
|
+
"vitest": "^3.2.4"
|
|
40
|
+
}
|
|
41
|
+
}
|