@blcklab/yuirinx 0.1.1 → 0.1.2
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/README.md +47 -64
- package/dist/cjs/core/index.cjs +36 -7
- package/dist/cjs/index.cjs +37 -8
- package/dist/cjs/languages/c.cjs +1 -1
- package/dist/cjs/languages/cpp.cjs +1 -1
- package/dist/cjs/languages/csharp.cjs +1 -1
- package/dist/cjs/languages/css.cjs +2 -2
- package/dist/cjs/languages/dart.cjs +1 -1
- package/dist/cjs/languages/go.cjs +1 -1
- package/dist/cjs/languages/java.cjs +1 -1
- package/dist/cjs/languages/javascript.cjs +65 -6
- package/dist/cjs/languages/jsx.cjs +65 -6
- package/dist/cjs/languages/kotlin.cjs +1 -1
- package/dist/cjs/languages/markdown.cjs +30 -6
- package/dist/cjs/languages/php.cjs +1 -1
- package/dist/cjs/languages/python.cjs +1 -1
- package/dist/cjs/languages/ruby.cjs +1 -1
- package/dist/cjs/languages/rust.cjs +1 -1
- package/dist/cjs/languages/scss.cjs +2 -2
- package/dist/cjs/languages/sql.cjs +1 -1
- package/dist/cjs/languages/swift.cjs +1 -1
- package/dist/cjs/languages/tsx.cjs +65 -6
- package/dist/cjs/languages/typescript.cjs +65 -6
- package/dist/esm/core/create-highlighter.js +132 -0
- package/dist/esm/core/errors.js +10 -0
- package/dist/esm/core/escape.js +17 -0
- package/dist/esm/core/grammar.js +103 -0
- package/dist/esm/core/index.js +4 -536
- package/dist/esm/core/renderer.js +215 -0
- package/dist/esm/core/tokenizer.js +107 -0
- package/dist/esm/core/types.js +0 -0
- package/dist/esm/index.js +8 -558
- package/dist/esm/languages/bash.js +9 -21
- package/dist/esm/languages/c.js +2 -82
- package/dist/esm/languages/cpp.js +2 -82
- package/dist/esm/languages/csharp.js +2 -82
- package/dist/esm/languages/css.js +2 -64
- package/dist/esm/languages/dart.js +2 -82
- package/dist/esm/languages/dockerfile.js +3 -12
- package/dist/esm/languages/go.js +2 -82
- package/dist/esm/languages/graphql.js +8 -20
- package/dist/esm/languages/html.js +2 -44
- package/dist/esm/languages/ini.js +2 -5
- package/dist/esm/languages/java.js +2 -82
- package/dist/esm/languages/javascript.js +2 -229
- package/dist/esm/languages/json.js +2 -5
- package/dist/esm/languages/jsx.js +2 -229
- package/dist/esm/languages/kotlin.js +2 -82
- package/dist/esm/languages/markdown.js +32 -11
- package/dist/esm/languages/nginx.js +2 -5
- package/dist/esm/languages/php.js +3 -83
- package/dist/esm/languages/plaintext.js +1 -2
- package/dist/esm/languages/python.js +10 -25
- package/dist/esm/languages/ruby.js +9 -24
- package/dist/esm/languages/rust.js +2 -82
- package/dist/esm/languages/scss.js +2 -64
- package/dist/esm/languages/shared/c-family.js +55 -0
- package/dist/esm/languages/shared/css.js +48 -0
- package/dist/esm/languages/shared/ecmascript.js +261 -0
- package/dist/esm/languages/shared/helpers.js +52 -0
- package/dist/esm/languages/shared/markup.js +41 -0
- package/dist/esm/languages/shell.js +1 -115
- package/dist/esm/languages/sql.js +11 -32
- package/dist/esm/languages/svelte.js +2 -44
- package/dist/esm/languages/swift.js +2 -82
- package/dist/esm/languages/toml.js +2 -5
- package/dist/esm/languages/tsx.js +2 -229
- package/dist/esm/languages/typescript.js +2 -229
- package/dist/esm/languages/vue.js +2 -44
- package/dist/esm/languages/xml.js +2 -44
- package/dist/esm/languages/yaml.js +2 -5
- package/dist/esm/singleton.js +24 -0
- package/dist/esm/themes/index.js +3 -188
- package/dist/esm/themes/yuirinx-aurora.js +1 -2
- package/dist/esm/themes/yuirinx-noir.js +1 -2
- package/dist/esm/themes/yuirinx-pearl.js +1 -2
- package/dist/types/core/errors.d.cts +1 -1
- package/dist/types/core/errors.d.ts +1 -1
- package/dist/types/core/index.d.cts +1 -1
- package/dist/types/core/index.d.ts +1 -1
- package/dist/types/core/types.d.cts +5 -1
- package/dist/types/core/types.d.ts +5 -1
- package/dist/types/singleton.d.cts +1 -1
- package/dist/types/singleton.d.ts +1 -1
- package/package.json +4 -4
package/dist/esm/themes/index.js
CHANGED
|
@@ -1,191 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
name: "Yuirinx Aurora",
|
|
5
|
-
type: "dark",
|
|
6
|
-
foreground: "#e5e8f4",
|
|
7
|
-
background: "#0d0b18",
|
|
8
|
-
selection: "#32284f",
|
|
9
|
-
lineHighlight: "#151126",
|
|
10
|
-
fallbackPalette: [
|
|
11
|
-
"#67dcff",
|
|
12
|
-
"#c99cff",
|
|
13
|
-
"#7ee0b8",
|
|
14
|
-
"#ffbd70",
|
|
15
|
-
"#ff78ae",
|
|
16
|
-
"#9bbcff"
|
|
17
|
-
],
|
|
18
|
-
tokens: {
|
|
19
|
-
comment: { color: "#756f91", fontStyle: "italic" },
|
|
20
|
-
keyword: { color: "#ff78ae", fontWeight: "semibold" },
|
|
21
|
-
operator: { color: "#a9a1c2" },
|
|
22
|
-
punctuation: { color: "#8983a0" },
|
|
23
|
-
string: { color: "#7ee0b8" },
|
|
24
|
-
"string.escape": { color: "#ffd479", fontWeight: "semibold" },
|
|
25
|
-
"string.interpolation": { color: "#e69cff" },
|
|
26
|
-
number: { color: "#ffbd70" },
|
|
27
|
-
boolean: { color: "#ffbd70", fontWeight: "semibold" },
|
|
28
|
-
null: { color: "#ffbd70", fontStyle: "italic" },
|
|
29
|
-
regex: { color: "#64ddd0" },
|
|
30
|
-
function: { color: "#67dcff" },
|
|
31
|
-
variable: { color: "#e5e8f4" },
|
|
32
|
-
property: { color: "#9bbcff" },
|
|
33
|
-
constant: { color: "#ffd479" },
|
|
34
|
-
type: { color: "#c99cff" },
|
|
35
|
-
class: { color: "#c99cff", fontWeight: "semibold" },
|
|
36
|
-
namespace: { color: "#b596e8" },
|
|
37
|
-
builtin: { color: "#83c9ff" },
|
|
38
|
-
tag: { color: "#ff78ae" },
|
|
39
|
-
attribute: { color: "#ffbd70" },
|
|
40
|
-
"attribute.value": { color: "#7ee0b8" },
|
|
41
|
-
selector: { color: "#ff8bb7" },
|
|
42
|
-
"property.css": { color: "#83c9ff" },
|
|
43
|
-
value: { color: "#64ddd0" },
|
|
44
|
-
unit: { color: "#d8a3ff" },
|
|
45
|
-
"at-rule": { color: "#e69cff" },
|
|
46
|
-
heading: { color: "#67dcff", fontWeight: "bold" },
|
|
47
|
-
emphasis: { color: "#c99cff", fontStyle: "italic" },
|
|
48
|
-
strong: { color: "#ffd479", fontWeight: "bold" },
|
|
49
|
-
link: { color: "#83c9ff", textDecoration: "underline" },
|
|
50
|
-
url: { color: "#64ddd0" },
|
|
51
|
-
code: { color: "#7ee0b8" },
|
|
52
|
-
quote: { color: "#a9a1c2", fontStyle: "italic" },
|
|
53
|
-
list: { color: "#ffbd70" },
|
|
54
|
-
inserted: { color: "#7ee0b8" },
|
|
55
|
-
deleted: { color: "#ff78ae" },
|
|
56
|
-
important: { color: "#ff9f6b", fontWeight: "bold" },
|
|
57
|
-
meta: { color: "#8983a0" },
|
|
58
|
-
decorator: { color: "#e69cff" },
|
|
59
|
-
annotation: { color: "#e69cff" },
|
|
60
|
-
label: { color: "#67dcff" }
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
// src/themes/yuirinx-noir.ts
|
|
65
|
-
var yuirinxNoir = {
|
|
66
|
-
id: "yuirinx-noir",
|
|
67
|
-
name: "Yuirinx Noir",
|
|
68
|
-
type: "dark",
|
|
69
|
-
foreground: "#d7deea",
|
|
70
|
-
background: "#0a0d14",
|
|
71
|
-
selection: "#24314b",
|
|
72
|
-
lineHighlight: "#111722",
|
|
73
|
-
fallbackPalette: [
|
|
74
|
-
"#73d7e7",
|
|
75
|
-
"#c5a5f5",
|
|
76
|
-
"#9fd5a9",
|
|
77
|
-
"#e8bd72",
|
|
78
|
-
"#f07f9f",
|
|
79
|
-
"#a8c7fa"
|
|
80
|
-
],
|
|
81
|
-
tokens: {
|
|
82
|
-
comment: { color: "#667085", fontStyle: "italic" },
|
|
83
|
-
keyword: { color: "#f07f9f", fontWeight: "semibold" },
|
|
84
|
-
operator: { color: "#9ba8bd" },
|
|
85
|
-
punctuation: { color: "#7f8ba0" },
|
|
86
|
-
string: { color: "#9fd5a9" },
|
|
87
|
-
"string.escape": { color: "#f2c879", fontWeight: "semibold" },
|
|
88
|
-
"string.interpolation": { color: "#e4a6ff" },
|
|
89
|
-
number: { color: "#e8bd72" },
|
|
90
|
-
boolean: { color: "#e8bd72", fontWeight: "semibold" },
|
|
91
|
-
null: { color: "#e8bd72", fontStyle: "italic" },
|
|
92
|
-
regex: { color: "#a8d8d1" },
|
|
93
|
-
function: { color: "#73d7e7" },
|
|
94
|
-
variable: { color: "#d7deea" },
|
|
95
|
-
property: { color: "#a8c7fa" },
|
|
96
|
-
constant: { color: "#f1ca86" },
|
|
97
|
-
type: { color: "#c5a5f5" },
|
|
98
|
-
class: { color: "#c5a5f5", fontWeight: "semibold" },
|
|
99
|
-
namespace: { color: "#a78bda" },
|
|
100
|
-
builtin: { color: "#8fc8ff" },
|
|
101
|
-
tag: { color: "#f07f9f" },
|
|
102
|
-
attribute: { color: "#e8bd72" },
|
|
103
|
-
"attribute.value": { color: "#9fd5a9" },
|
|
104
|
-
selector: { color: "#f29bb2" },
|
|
105
|
-
"property.css": { color: "#8fc8ff" },
|
|
106
|
-
value: { color: "#a8d8d1" },
|
|
107
|
-
unit: { color: "#d5a4f5" },
|
|
108
|
-
"at-rule": { color: "#e4a6ff" },
|
|
109
|
-
heading: { color: "#73d7e7", fontWeight: "bold" },
|
|
110
|
-
emphasis: { color: "#c5a5f5", fontStyle: "italic" },
|
|
111
|
-
strong: { color: "#f1ca86", fontWeight: "bold" },
|
|
112
|
-
link: { color: "#8fc8ff", textDecoration: "underline" },
|
|
113
|
-
url: { color: "#7fc8b2" },
|
|
114
|
-
code: { color: "#9fd5a9" },
|
|
115
|
-
quote: { color: "#9ba8bd", fontStyle: "italic" },
|
|
116
|
-
list: { color: "#e8bd72" },
|
|
117
|
-
inserted: { color: "#9fd5a9" },
|
|
118
|
-
deleted: { color: "#f07f9f" },
|
|
119
|
-
important: { color: "#ffb86b", fontWeight: "bold" },
|
|
120
|
-
meta: { color: "#7f8ba0" },
|
|
121
|
-
decorator: { color: "#e4a6ff" },
|
|
122
|
-
annotation: { color: "#e4a6ff" },
|
|
123
|
-
label: { color: "#73d7e7" }
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
// src/themes/yuirinx-pearl.ts
|
|
128
|
-
var yuirinxPearl = {
|
|
129
|
-
id: "yuirinx-pearl",
|
|
130
|
-
name: "Yuirinx Pearl",
|
|
131
|
-
type: "light",
|
|
132
|
-
foreground: "#29313d",
|
|
133
|
-
background: "#fbfaf7",
|
|
134
|
-
selection: "#dce8f8",
|
|
135
|
-
lineHighlight: "#f1efe9",
|
|
136
|
-
fallbackPalette: [
|
|
137
|
-
"#006d83",
|
|
138
|
-
"#6941a5",
|
|
139
|
-
"#347551",
|
|
140
|
-
"#9a6200",
|
|
141
|
-
"#b4235a",
|
|
142
|
-
"#285f9a"
|
|
143
|
-
],
|
|
144
|
-
tokens: {
|
|
145
|
-
comment: { color: "#7b8492", fontStyle: "italic" },
|
|
146
|
-
keyword: { color: "#b4235a", fontWeight: "semibold" },
|
|
147
|
-
operator: { color: "#596579" },
|
|
148
|
-
punctuation: { color: "#727d8c" },
|
|
149
|
-
string: { color: "#347551" },
|
|
150
|
-
"string.escape": { color: "#9c6500", fontWeight: "semibold" },
|
|
151
|
-
"string.interpolation": { color: "#7846a8" },
|
|
152
|
-
number: { color: "#9a6200" },
|
|
153
|
-
boolean: { color: "#9a6200", fontWeight: "semibold" },
|
|
154
|
-
null: { color: "#9a6200", fontStyle: "italic" },
|
|
155
|
-
regex: { color: "#28776f" },
|
|
156
|
-
function: { color: "#006d83" },
|
|
157
|
-
variable: { color: "#29313d" },
|
|
158
|
-
property: { color: "#285f9a" },
|
|
159
|
-
constant: { color: "#8e5d00" },
|
|
160
|
-
type: { color: "#6941a5" },
|
|
161
|
-
class: { color: "#6941a5", fontWeight: "semibold" },
|
|
162
|
-
namespace: { color: "#72549a" },
|
|
163
|
-
builtin: { color: "#1f659f" },
|
|
164
|
-
tag: { color: "#b4235a" },
|
|
165
|
-
attribute: { color: "#956000" },
|
|
166
|
-
"attribute.value": { color: "#347551" },
|
|
167
|
-
selector: { color: "#a92f5c" },
|
|
168
|
-
"property.css": { color: "#24689f" },
|
|
169
|
-
value: { color: "#28776f" },
|
|
170
|
-
unit: { color: "#7449a6" },
|
|
171
|
-
"at-rule": { color: "#7846a8" },
|
|
172
|
-
heading: { color: "#006d83", fontWeight: "bold" },
|
|
173
|
-
emphasis: { color: "#6941a5", fontStyle: "italic" },
|
|
174
|
-
strong: { color: "#8e5d00", fontWeight: "bold" },
|
|
175
|
-
link: { color: "#1f659f", textDecoration: "underline" },
|
|
176
|
-
url: { color: "#28776f" },
|
|
177
|
-
code: { color: "#347551" },
|
|
178
|
-
quote: { color: "#6b7480", fontStyle: "italic" },
|
|
179
|
-
list: { color: "#956000" },
|
|
180
|
-
inserted: { color: "#347551" },
|
|
181
|
-
deleted: { color: "#b4235a" },
|
|
182
|
-
important: { color: "#a94b00", fontWeight: "bold" },
|
|
183
|
-
meta: { color: "#727d8c" },
|
|
184
|
-
decorator: { color: "#7846a8" },
|
|
185
|
-
annotation: { color: "#7846a8" },
|
|
186
|
-
label: { color: "#006d83" }
|
|
187
|
-
}
|
|
188
|
-
};
|
|
1
|
+
import { yuirinxAurora } from "./yuirinx-aurora.js";
|
|
2
|
+
import { yuirinxNoir } from "./yuirinx-noir.js";
|
|
3
|
+
import { yuirinxPearl } from "./yuirinx-pearl.js";
|
|
189
4
|
export {
|
|
190
5
|
yuirinxAurora,
|
|
191
6
|
yuirinxNoir,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type YuirinxErrorCode = "YUIRINX_INVALID_GRAMMAR" | "YUIRINX_EMPTY_PATTERN" | "YUIRINX_DUPLICATE_LANGUAGE" | "YUIRINX_DUPLICATE_ALIAS" | "YUIRINX_DUPLICATE_THEME" | "YUIRINX_UNKNOWN_STATE" | "YUIRINX_INCLUDE_CYCLE" | "YUIRINX_STATE_DEPTH_EXCEEDED";
|
|
1
|
+
export type YuirinxErrorCode = "YUIRINX_INVALID_OPTION" | "YUIRINX_INVALID_GRAMMAR" | "YUIRINX_EMPTY_PATTERN" | "YUIRINX_DUPLICATE_LANGUAGE" | "YUIRINX_DUPLICATE_ALIAS" | "YUIRINX_DUPLICATE_THEME" | "YUIRINX_UNKNOWN_STATE" | "YUIRINX_INCLUDE_CYCLE" | "YUIRINX_STATE_DEPTH_EXCEEDED";
|
|
2
2
|
/** Configuration or tokenizer error produced by Yuirinx. */
|
|
3
3
|
export declare class YuirinxError extends Error {
|
|
4
4
|
readonly code: YuirinxErrorCode;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type YuirinxErrorCode = "YUIRINX_INVALID_GRAMMAR" | "YUIRINX_EMPTY_PATTERN" | "YUIRINX_DUPLICATE_LANGUAGE" | "YUIRINX_DUPLICATE_ALIAS" | "YUIRINX_DUPLICATE_THEME" | "YUIRINX_UNKNOWN_STATE" | "YUIRINX_INCLUDE_CYCLE" | "YUIRINX_STATE_DEPTH_EXCEEDED";
|
|
1
|
+
export type YuirinxErrorCode = "YUIRINX_INVALID_OPTION" | "YUIRINX_INVALID_GRAMMAR" | "YUIRINX_EMPTY_PATTERN" | "YUIRINX_DUPLICATE_LANGUAGE" | "YUIRINX_DUPLICATE_ALIAS" | "YUIRINX_DUPLICATE_THEME" | "YUIRINX_UNKNOWN_STATE" | "YUIRINX_INCLUDE_CYCLE" | "YUIRINX_STATE_DEPTH_EXCEEDED";
|
|
2
2
|
/** Configuration or tokenizer error produced by Yuirinx. */
|
|
3
3
|
export declare class YuirinxError extends Error {
|
|
4
4
|
readonly code: YuirinxErrorCode;
|
|
@@ -3,4 +3,4 @@ export { escapeHtml } from "./escape.cjs";
|
|
|
3
3
|
export { YuirinxError } from "./errors.cjs";
|
|
4
4
|
export { themeToCss } from "./renderer.cjs";
|
|
5
5
|
export type { YuirinxErrorCode } from "./errors.cjs";
|
|
6
|
-
export type { FallbackMode, Grammar, GrammarRule, GrammarState, Highlighter, HighlighterOptions, HighlightOptions, IncludeRule, LanguageId, MatchRule, RenderMode, RenderOptions, StateName, Theme, ThemeCssOptions, ThemeId, Token, TokenStyle, TokenizerContext, TokenizerState, TokenType, TokenTypeResolver, } from "./types.cjs";
|
|
6
|
+
export type { FallbackMode, Grammar, GrammarRule, GrammarState, Highlighter, HighlighterOptions, HighlightOptions, IncludeRule, LanguageId, MatchPredicate, MatchRule, RenderMode, RenderOptions, StateName, Theme, ThemeCssOptions, ThemeId, Token, TokenStyle, TokenizerContext, TokenizerState, TokenType, TokenTypeResolver, } from "./types.cjs";
|
|
@@ -3,4 +3,4 @@ export { escapeHtml } from "./escape.js";
|
|
|
3
3
|
export { YuirinxError } from "./errors.js";
|
|
4
4
|
export { themeToCss } from "./renderer.js";
|
|
5
5
|
export type { YuirinxErrorCode } from "./errors.js";
|
|
6
|
-
export type { FallbackMode, Grammar, GrammarRule, GrammarState, Highlighter, HighlighterOptions, HighlightOptions, IncludeRule, LanguageId, MatchRule, RenderMode, RenderOptions, StateName, Theme, ThemeCssOptions, ThemeId, Token, TokenStyle, TokenizerContext, TokenizerState, TokenType, TokenTypeResolver, } from "./types.js";
|
|
6
|
+
export type { FallbackMode, Grammar, GrammarRule, GrammarState, Highlighter, HighlighterOptions, HighlightOptions, IncludeRule, LanguageId, MatchPredicate, MatchRule, RenderMode, RenderOptions, StateName, Theme, ThemeCssOptions, ThemeId, Token, TokenStyle, TokenizerContext, TokenizerState, TokenType, TokenTypeResolver, } from "./types.js";
|
|
@@ -20,11 +20,14 @@ export interface TokenizerState {
|
|
|
20
20
|
}
|
|
21
21
|
/** Read-only context passed to dynamic grammar rule resolvers. */
|
|
22
22
|
export interface TokenizerContext {
|
|
23
|
+
readonly source: string;
|
|
23
24
|
readonly language: LanguageId;
|
|
24
25
|
readonly state: StateName;
|
|
25
26
|
readonly stack: readonly TokenizerState[];
|
|
26
27
|
readonly offset: number;
|
|
27
28
|
}
|
|
29
|
+
/** Optional condition evaluated after a rule matches at the current offset. */
|
|
30
|
+
export type MatchPredicate = (match: RegExpExecArray, context: TokenizerContext) => boolean;
|
|
28
31
|
/** Static token type or a resolver based on the current regex match. */
|
|
29
32
|
export type TokenTypeResolver = TokenType | ((match: RegExpExecArray, context: TokenizerContext) => TokenType);
|
|
30
33
|
/** Static state name or a resolver based on the current regex match. */
|
|
@@ -32,6 +35,7 @@ export type StateResolver = StateName | ((match: RegExpExecArray, context: Token
|
|
|
32
35
|
/** A matching grammar rule. Patterns are automatically made sticky. */
|
|
33
36
|
export interface MatchRule {
|
|
34
37
|
readonly pattern: RegExp;
|
|
38
|
+
readonly when?: MatchPredicate;
|
|
35
39
|
readonly type?: TokenTypeResolver;
|
|
36
40
|
readonly push?: StateResolver;
|
|
37
41
|
readonly next?: StateResolver;
|
|
@@ -120,7 +124,7 @@ export interface HighlighterOptions {
|
|
|
120
124
|
}
|
|
121
125
|
/** Isolated registry, tokenizer, and renderer facade. */
|
|
122
126
|
export interface Highlighter {
|
|
123
|
-
highlight(code: string, options
|
|
127
|
+
highlight(code: string, options?: HighlightOptions): string;
|
|
124
128
|
tokenize(code: string, language: LanguageId | Grammar): Token[];
|
|
125
129
|
render(tokens: readonly Token[], options?: RenderOptions): string;
|
|
126
130
|
registerLanguage(grammar: Grammar): void;
|
|
@@ -20,11 +20,14 @@ export interface TokenizerState {
|
|
|
20
20
|
}
|
|
21
21
|
/** Read-only context passed to dynamic grammar rule resolvers. */
|
|
22
22
|
export interface TokenizerContext {
|
|
23
|
+
readonly source: string;
|
|
23
24
|
readonly language: LanguageId;
|
|
24
25
|
readonly state: StateName;
|
|
25
26
|
readonly stack: readonly TokenizerState[];
|
|
26
27
|
readonly offset: number;
|
|
27
28
|
}
|
|
29
|
+
/** Optional condition evaluated after a rule matches at the current offset. */
|
|
30
|
+
export type MatchPredicate = (match: RegExpExecArray, context: TokenizerContext) => boolean;
|
|
28
31
|
/** Static token type or a resolver based on the current regex match. */
|
|
29
32
|
export type TokenTypeResolver = TokenType | ((match: RegExpExecArray, context: TokenizerContext) => TokenType);
|
|
30
33
|
/** Static state name or a resolver based on the current regex match. */
|
|
@@ -32,6 +35,7 @@ export type StateResolver = StateName | ((match: RegExpExecArray, context: Token
|
|
|
32
35
|
/** A matching grammar rule. Patterns are automatically made sticky. */
|
|
33
36
|
export interface MatchRule {
|
|
34
37
|
readonly pattern: RegExp;
|
|
38
|
+
readonly when?: MatchPredicate;
|
|
35
39
|
readonly type?: TokenTypeResolver;
|
|
36
40
|
readonly push?: StateResolver;
|
|
37
41
|
readonly next?: StateResolver;
|
|
@@ -120,7 +124,7 @@ export interface HighlighterOptions {
|
|
|
120
124
|
}
|
|
121
125
|
/** Isolated registry, tokenizer, and renderer facade. */
|
|
122
126
|
export interface Highlighter {
|
|
123
|
-
highlight(code: string, options
|
|
127
|
+
highlight(code: string, options?: HighlightOptions): string;
|
|
124
128
|
tokenize(code: string, language: LanguageId | Grammar): Token[];
|
|
125
129
|
render(tokens: readonly Token[], options?: RenderOptions): string;
|
|
126
130
|
registerLanguage(grammar: Grammar): void;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Grammar, HighlightOptions, RenderOptions, Theme, Token } from "./core/types.cjs";
|
|
2
2
|
/** Highlights code through Yuirinx's convenience singleton registry. */
|
|
3
|
-
export declare function highlight(code: string, options
|
|
3
|
+
export declare function highlight(code: string, options?: HighlightOptions): string;
|
|
4
4
|
/** Tokenizes code through Yuirinx's convenience singleton registry. */
|
|
5
5
|
export declare function tokenize(code: string, language: string | Grammar): Token[];
|
|
6
6
|
/** Renders tokens through Yuirinx's convenience singleton registry. */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Grammar, HighlightOptions, RenderOptions, Theme, Token } from "./core/types.js";
|
|
2
2
|
/** Highlights code through Yuirinx's convenience singleton registry. */
|
|
3
|
-
export declare function highlight(code: string, options
|
|
3
|
+
export declare function highlight(code: string, options?: HighlightOptions): string;
|
|
4
4
|
/** Tokenizes code through Yuirinx's convenience singleton registry. */
|
|
5
5
|
export declare function tokenize(code: string, language: string | Grammar): Token[];
|
|
6
6
|
/** Renders tokens through Yuirinx's convenience singleton registry. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blcklab/yuirinx",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Small zero-dependency syntax highlighter for the modern web.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"syntax-highlighter",
|
|
@@ -433,7 +433,7 @@
|
|
|
433
433
|
"dist"
|
|
434
434
|
],
|
|
435
435
|
"engines": {
|
|
436
|
-
"node": ">=
|
|
436
|
+
"node": ">=18"
|
|
437
437
|
},
|
|
438
438
|
"publishConfig": {
|
|
439
439
|
"access": "public",
|
|
@@ -464,8 +464,8 @@
|
|
|
464
464
|
"check:exports": "node scripts/check-exports.mjs",
|
|
465
465
|
"check:tree-shaking": "node scripts/check-tree-shaking.mjs",
|
|
466
466
|
"check:package": "npm run build && npm run check:exports && publint && node scripts/verify-package.mjs",
|
|
467
|
-
"check": "npm run lint && npm test && npm run build && npm run check:exports && npm run check:tree-shaking && npm run size && publint && node scripts/verify-package.mjs",
|
|
468
|
-
"check:all": "npm run
|
|
467
|
+
"check": "npm run format:check && npm run lint && npm test && npm run build && npm run check:exports && npm run check:tree-shaking && npm run size && publint && node scripts/verify-package.mjs",
|
|
468
|
+
"check:all": "npm run check",
|
|
469
469
|
"prepublishOnly": "npm run check"
|
|
470
470
|
}
|
|
471
471
|
}
|