@fuzdev/fuz_code 0.45.0 → 0.46.0
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 +2 -1
- package/dist/Code.svelte +2 -2
- package/dist/Code.svelte.d.ts +2 -2
- package/dist/CodeHighlight.svelte +4 -4
- package/dist/CodeHighlight.svelte.d.ts +3 -3
- package/dist/code_sample.d.ts +1 -1
- package/dist/code_sample.d.ts.map +1 -1
- package/dist/code_sample.js +1 -1
- package/dist/grammar_bash.d.ts +17 -0
- package/dist/grammar_bash.d.ts.map +1 -0
- package/dist/grammar_bash.js +153 -0
- package/dist/grammar_markdown.d.ts.map +1 -1
- package/dist/grammar_markdown.js +4 -3
- package/dist/grammar_markup.d.ts +8 -7
- package/dist/grammar_markup.d.ts.map +1 -1
- package/dist/grammar_markup.js +8 -7
- package/dist/highlight_manager.d.ts +4 -4
- package/dist/highlight_manager.js +6 -6
- package/dist/svelte_preprocess_fuz_code.d.ts +4 -4
- package/dist/svelte_preprocess_fuz_code.d.ts.map +1 -1
- package/dist/svelte_preprocess_fuz_code.js +3 -3
- package/dist/syntax_styler.d.ts +28 -32
- package/dist/syntax_styler.d.ts.map +1 -1
- package/dist/syntax_styler.js +32 -36
- package/dist/syntax_styler_global.d.ts.map +1 -1
- package/dist/syntax_styler_global.js +2 -0
- package/dist/syntax_token.d.ts +4 -4
- package/dist/syntax_token.js +2 -2
- package/dist/tokenize_syntax.d.ts +2 -4
- package/dist/tokenize_syntax.d.ts.map +1 -1
- package/dist/tokenize_syntax.js +2 -4
- package/package.json +27 -31
- package/src/lib/code_sample.ts +1 -1
- package/src/lib/grammar_bash.ts +175 -0
- package/src/lib/grammar_markdown.ts +4 -3
- package/src/lib/grammar_markup.ts +8 -7
- package/src/lib/highlight_manager.ts +6 -6
- package/src/lib/svelte_preprocess_fuz_code.ts +6 -6
- package/src/lib/syntax_styler.ts +35 -39
- package/src/lib/syntax_styler_global.ts +2 -0
- package/src/lib/syntax_token.ts +4 -4
- package/src/lib/tokenize_syntax.ts +2 -4
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[<img src="static/logo.svg" alt="a friendly pink spider facing you" align="right" width="192" height="192">](https://code.fuz.dev/)
|
|
4
4
|
|
|
5
|
-
> syntax styling utilities and components for TypeScript, Svelte, and
|
|
5
|
+
> syntax styling utilities and components for TypeScript, Svelte, Markdown, and more 🎨
|
|
6
6
|
|
|
7
7
|
**[code.fuz.dev](https://code.fuz.dev/)**
|
|
8
8
|
|
|
@@ -116,6 +116,7 @@ Enabled by default in `syntax_styler_global`:
|
|
|
116
116
|
- [`js`](src/lib/grammar_js.ts)
|
|
117
117
|
- [`json`](src/lib/grammar_json.ts)
|
|
118
118
|
- [`clike`](src/lib/grammar_clike.ts)
|
|
119
|
+
- [`bash`](src/lib/grammar_bash.ts)
|
|
119
120
|
|
|
120
121
|
### More
|
|
121
122
|
|
package/dist/Code.svelte
CHANGED
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
*/
|
|
56
56
|
lang?: string | null;
|
|
57
57
|
/**
|
|
58
|
-
* Optional custom
|
|
58
|
+
* Optional custom `SyntaxGrammar` object for syntax tokenization.
|
|
59
59
|
*
|
|
60
60
|
* **When to use:**
|
|
61
61
|
* - To provide a custom language definition not registered in `syntax_styler.langs`
|
|
@@ -100,7 +100,7 @@
|
|
|
100
100
|
*/
|
|
101
101
|
nomargin?: boolean;
|
|
102
102
|
/**
|
|
103
|
-
* Custom SyntaxStyler instance to use for highlighting.
|
|
103
|
+
* Custom `SyntaxStyler` instance to use for highlighting.
|
|
104
104
|
* Allows using a different styler with custom grammars or configuration.
|
|
105
105
|
*
|
|
106
106
|
* @default syntax_styler_global
|
package/dist/Code.svelte.d.ts
CHANGED
|
@@ -35,7 +35,7 @@ type $$ComponentProps = SvelteHTMLElements['code'] & ({
|
|
|
35
35
|
*/
|
|
36
36
|
lang?: string | null;
|
|
37
37
|
/**
|
|
38
|
-
* Optional custom
|
|
38
|
+
* Optional custom `SyntaxGrammar` object for syntax tokenization.
|
|
39
39
|
*
|
|
40
40
|
* **When to use:**
|
|
41
41
|
* - To provide a custom language definition not registered in `syntax_styler.langs`
|
|
@@ -80,7 +80,7 @@ type $$ComponentProps = SvelteHTMLElements['code'] & ({
|
|
|
80
80
|
*/
|
|
81
81
|
nomargin?: boolean;
|
|
82
82
|
/**
|
|
83
|
-
* Custom SyntaxStyler instance to use for highlighting.
|
|
83
|
+
* Custom `SyntaxStyler` instance to use for highlighting.
|
|
84
84
|
* Allows using a different styler with custom grammars or configuration.
|
|
85
85
|
*
|
|
86
86
|
* @default syntax_styler_global
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Uses the CSS Custom Highlight API when available --
|
|
4
4
|
* https://developer.mozilla.org/en-US/docs/Web/API/CSS_Custom_Highlight_API
|
|
5
5
|
*
|
|
6
|
-
* Requires importing theme_highlight.css instead of theme.css
|
|
6
|
+
* Requires importing `theme_highlight.css` instead of `theme.css`.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import {onDestroy, type Snippet} from 'svelte';
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
*/
|
|
66
66
|
mode?: HighlightMode;
|
|
67
67
|
/**
|
|
68
|
-
* Optional custom
|
|
68
|
+
* Optional custom `SyntaxGrammar` object for syntax tokenization.
|
|
69
69
|
*
|
|
70
70
|
* **When to use:**
|
|
71
71
|
* - To provide a custom language definition not registered in `syntax_styler.langs`
|
|
@@ -103,7 +103,7 @@
|
|
|
103
103
|
*/
|
|
104
104
|
wrap?: boolean;
|
|
105
105
|
/**
|
|
106
|
-
* Custom SyntaxStyler instance to use for highlighting.
|
|
106
|
+
* Custom `SyntaxStyler` instance to use for highlighting.
|
|
107
107
|
* Allows using a different styler with custom grammars or configuration.
|
|
108
108
|
*
|
|
109
109
|
* @default syntax_styler_global
|
|
@@ -117,7 +117,7 @@
|
|
|
117
117
|
children?: Snippet<[markup: string]>;
|
|
118
118
|
} = $props();
|
|
119
119
|
|
|
120
|
-
let code_element: HTMLElement | undefined = $state();
|
|
120
|
+
let code_element: HTMLElement | undefined = $state.raw();
|
|
121
121
|
|
|
122
122
|
const supports_ranges = supports_css_highlight_api();
|
|
123
123
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Uses the CSS Custom Highlight API when available --
|
|
3
3
|
* https://developer.mozilla.org/en-US/docs/Web/API/CSS_Custom_Highlight_API
|
|
4
4
|
*
|
|
5
|
-
* Requires importing theme_highlight.css instead of theme.css
|
|
5
|
+
* Requires importing `theme_highlight.css` instead of `theme.css`.
|
|
6
6
|
*/
|
|
7
7
|
import { type Snippet } from 'svelte';
|
|
8
8
|
import type { SvelteHTMLElements } from 'svelte/elements';
|
|
@@ -44,7 +44,7 @@ type $$ComponentProps = SvelteHTMLElements['code'] & {
|
|
|
44
44
|
*/
|
|
45
45
|
mode?: HighlightMode;
|
|
46
46
|
/**
|
|
47
|
-
* Optional custom
|
|
47
|
+
* Optional custom `SyntaxGrammar` object for syntax tokenization.
|
|
48
48
|
*
|
|
49
49
|
* **When to use:**
|
|
50
50
|
* - To provide a custom language definition not registered in `syntax_styler.langs`
|
|
@@ -82,7 +82,7 @@ type $$ComponentProps = SvelteHTMLElements['code'] & {
|
|
|
82
82
|
*/
|
|
83
83
|
wrap?: boolean;
|
|
84
84
|
/**
|
|
85
|
-
* Custom SyntaxStyler instance to use for highlighting.
|
|
85
|
+
* Custom `SyntaxStyler` instance to use for highlighting.
|
|
86
86
|
* Allows using a different styler with custom grammars or configuration.
|
|
87
87
|
*
|
|
88
88
|
* @default syntax_styler_global
|
package/dist/code_sample.d.ts
CHANGED
|
@@ -3,6 +3,6 @@ export interface CodeSample {
|
|
|
3
3
|
lang: string;
|
|
4
4
|
content: string;
|
|
5
5
|
}
|
|
6
|
-
export declare const sample_langs: readonly ["json", "css", "ts", "html", "svelte", "md"];
|
|
6
|
+
export declare const sample_langs: readonly ["json", "css", "ts", "html", "svelte", "md", "bash"];
|
|
7
7
|
export type SampleLang = (typeof sample_langs)[number];
|
|
8
8
|
//# sourceMappingURL=code_sample.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code_sample.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/code_sample.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CAChB;AAGD,eAAO,MAAM,YAAY,
|
|
1
|
+
{"version":3,"file":"code_sample.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/code_sample.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CAChB;AAGD,eAAO,MAAM,YAAY,gEAAiE,CAAC;AAE3F,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC"}
|
package/dist/code_sample.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Languages ordered from simple to complex
|
|
2
|
-
export const sample_langs = ['json', 'css', 'ts', 'html', 'svelte', 'md'];
|
|
2
|
+
export const sample_langs = ['json', 'css', 'ts', 'html', 'svelte', 'md', 'bash'];
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { AddSyntaxGrammar } from './syntax_styler.js';
|
|
2
|
+
/**
|
|
3
|
+
* Bash/shell grammar for syntax highlighting.
|
|
4
|
+
*
|
|
5
|
+
* Standalone grammar (no base extension). Covers core bash syntax:
|
|
6
|
+
* comments, strings, variables, functions, keywords, builtins,
|
|
7
|
+
* operators, and redirections.
|
|
8
|
+
*
|
|
9
|
+
* Based on Prism (https://github.com/PrismJS/prism)
|
|
10
|
+
* by Lea Verou (https://lea.verou.me/)
|
|
11
|
+
*
|
|
12
|
+
* MIT license
|
|
13
|
+
*
|
|
14
|
+
* @see LICENSE
|
|
15
|
+
*/
|
|
16
|
+
export declare const add_grammar_bash: AddSyntaxGrammar;
|
|
17
|
+
//# sourceMappingURL=grammar_bash.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grammar_bash.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/grammar_bash.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,gBAAgB,EAAmB,MAAM,oBAAoB,CAAC;AAE3E;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,gBAAgB,EAAE,gBA8J9B,CAAC"}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Bash/shell grammar for syntax highlighting.
|
|
3
|
+
*
|
|
4
|
+
* Standalone grammar (no base extension). Covers core bash syntax:
|
|
5
|
+
* comments, strings, variables, functions, keywords, builtins,
|
|
6
|
+
* operators, and redirections.
|
|
7
|
+
*
|
|
8
|
+
* Based on Prism (https://github.com/PrismJS/prism)
|
|
9
|
+
* by Lea Verou (https://lea.verou.me/)
|
|
10
|
+
*
|
|
11
|
+
* MIT license
|
|
12
|
+
*
|
|
13
|
+
* @see LICENSE
|
|
14
|
+
*/
|
|
15
|
+
export const add_grammar_bash = (syntax_styler) => {
|
|
16
|
+
// Shared inside grammar for command substitution — `rest` wired after construction
|
|
17
|
+
const command_sub_inside = {
|
|
18
|
+
punctuation: /^\$\(|\)$/,
|
|
19
|
+
};
|
|
20
|
+
// Reusable balanced-paren pattern for $(...) — handles 2 levels of inner () nesting,
|
|
21
|
+
// which supports up to 3 levels of $() command substitution (4+ is vanishingly rare)
|
|
22
|
+
const command_sub_pattern = /\$\((?:[^()]*|\((?:[^()]*|\([^()]*\))*\))*\)/;
|
|
23
|
+
const grammar_bash = {
|
|
24
|
+
// Shebang at file start — matched before general comments
|
|
25
|
+
shebang: {
|
|
26
|
+
pattern: /^#!.*/,
|
|
27
|
+
alias: 'comment',
|
|
28
|
+
},
|
|
29
|
+
// Line comments — require whitespace or start-of-string before #
|
|
30
|
+
comment: {
|
|
31
|
+
pattern: /(^|\s)#.*/,
|
|
32
|
+
lookbehind: true,
|
|
33
|
+
greedy: true,
|
|
34
|
+
},
|
|
35
|
+
// Here-documents — must precede string to avoid delimiter consumption
|
|
36
|
+
heredoc: [
|
|
37
|
+
// Quoted delimiter (<<'DELIM' or <<"DELIM") — no expansion
|
|
38
|
+
{
|
|
39
|
+
pattern: /(^|[^<])<<-?\s*(?:['"])(\w+)(?:['"])[\t ]*\n[\s\S]*?\n[\t ]*\2(?=\s*$)/m,
|
|
40
|
+
lookbehind: true,
|
|
41
|
+
greedy: true,
|
|
42
|
+
alias: 'string',
|
|
43
|
+
inside: {
|
|
44
|
+
// No `m` flag — `^` matches start-of-string (opening) and `$` matches
|
|
45
|
+
// end-of-string (closing), so single-word content lines can't false-positive
|
|
46
|
+
heredoc_delimiter: [
|
|
47
|
+
{
|
|
48
|
+
pattern: /^<<-?\s*(?:['"])\w+(?:['"])/,
|
|
49
|
+
alias: 'punctuation',
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
pattern: /\w+$/,
|
|
53
|
+
alias: 'punctuation',
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
// Unquoted delimiter (<<DELIM) — with variable/command expansion
|
|
59
|
+
{
|
|
60
|
+
pattern: /(^|[^<])<<-?\s*(\w+)[\t ]*\n[\s\S]*?\n[\t ]*\2(?=\s*$)/m,
|
|
61
|
+
lookbehind: true,
|
|
62
|
+
greedy: true,
|
|
63
|
+
alias: 'string',
|
|
64
|
+
inside: {
|
|
65
|
+
heredoc_delimiter: [
|
|
66
|
+
{
|
|
67
|
+
pattern: /^<<-?\s*\w+/,
|
|
68
|
+
alias: 'punctuation',
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
pattern: /\w+$/,
|
|
72
|
+
alias: 'punctuation',
|
|
73
|
+
},
|
|
74
|
+
],
|
|
75
|
+
command_substitution: {
|
|
76
|
+
pattern: command_sub_pattern,
|
|
77
|
+
greedy: true,
|
|
78
|
+
inside: command_sub_inside,
|
|
79
|
+
},
|
|
80
|
+
variable: /\$\{[^}]+\}|\$(?:\w+|[!@#$*?\-0-9])/,
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
// Strings — three variants
|
|
85
|
+
string: [
|
|
86
|
+
// Double-quoted: supports escape sequences, variable interpolation, command substitution
|
|
87
|
+
{
|
|
88
|
+
pattern: /(^|[^\\](?:\\\\)*)"(?:\\[\s\S]|\$\((?:[^()]*|\((?:[^()]*|\([^()]*\))*\))*\)|\$(?!\()|[^"\\$])*"/,
|
|
89
|
+
lookbehind: true,
|
|
90
|
+
greedy: true,
|
|
91
|
+
inside: {
|
|
92
|
+
command_substitution: {
|
|
93
|
+
pattern: command_sub_pattern,
|
|
94
|
+
greedy: true,
|
|
95
|
+
inside: command_sub_inside,
|
|
96
|
+
},
|
|
97
|
+
variable: /\$\{[^}]+\}|\$(?:\w+|[!@#$*?\-0-9])/,
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
// Single-quoted: completely literal
|
|
101
|
+
{
|
|
102
|
+
pattern: /(^|[^\\](?:\\\\)*)'[^']*'/,
|
|
103
|
+
lookbehind: true,
|
|
104
|
+
greedy: true,
|
|
105
|
+
},
|
|
106
|
+
// ANSI-C quoting: $'...' with C-style escapes
|
|
107
|
+
{
|
|
108
|
+
pattern: /\$'(?:[^'\\]|\\[\s\S])*'/,
|
|
109
|
+
greedy: true,
|
|
110
|
+
},
|
|
111
|
+
],
|
|
112
|
+
// Command substitution $(...) — before variable since both start with $
|
|
113
|
+
command_substitution: {
|
|
114
|
+
pattern: command_sub_pattern,
|
|
115
|
+
greedy: true,
|
|
116
|
+
inside: command_sub_inside,
|
|
117
|
+
},
|
|
118
|
+
// Variables and parameter expansion
|
|
119
|
+
variable: /\$\{[^}]+\}|\$(?:\w+|[!@#$*?\-0-9])/,
|
|
120
|
+
// Function definitions — both styles
|
|
121
|
+
function: [
|
|
122
|
+
// function fname style
|
|
123
|
+
{
|
|
124
|
+
pattern: /(\bfunction\s+)\w+/,
|
|
125
|
+
lookbehind: true,
|
|
126
|
+
},
|
|
127
|
+
// fname() style
|
|
128
|
+
{
|
|
129
|
+
pattern: /\b\w+(?=\s*\(\s*\))/,
|
|
130
|
+
},
|
|
131
|
+
],
|
|
132
|
+
// Shell keywords
|
|
133
|
+
keyword: /\b(?:if|then|else|elif|fi|for|while|until|do|done|case|esac|in|select|function|return|local|export|declare|typeset|readonly|unset|set|shift|trap|break|continue|coproc|time)\b/,
|
|
134
|
+
// Builtin commands
|
|
135
|
+
builtin: /\b(?:echo|printf|cd|pwd|read|test|source|eval|exec|exit|getopts|hash|type|ulimit|umask|wait|kill|jobs|bg|fg|disown|alias|unalias|command|shopt)\b/,
|
|
136
|
+
// Boolean commands
|
|
137
|
+
boolean: /\b(?:true|false)\b/,
|
|
138
|
+
// File descriptors before redirections — must precede number
|
|
139
|
+
file_descriptor: {
|
|
140
|
+
pattern: /\B&\d\b|\b\d(?=>>?|<)/,
|
|
141
|
+
alias: 'important',
|
|
142
|
+
},
|
|
143
|
+
// Numbers: hex, octal, base-N, decimal
|
|
144
|
+
number: /\b(?:0x[\da-fA-F]+|0[0-7]+|\d+#[\da-zA-Z]+|\d+)\b/,
|
|
145
|
+
// Operators — longest first
|
|
146
|
+
operator: /\|\||&&|;;|&>>?|<<<?|>>?|=~|[!=]=|[<>]|[|&!]/,
|
|
147
|
+
// Punctuation
|
|
148
|
+
punctuation: /[{}[\]();,]/,
|
|
149
|
+
};
|
|
150
|
+
// Wire circular reference so command substitutions get full bash highlighting
|
|
151
|
+
command_sub_inside.rest = grammar_bash;
|
|
152
|
+
syntax_styler.add_lang('bash', grammar_bash, ['sh', 'shell']);
|
|
153
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grammar_markdown.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/grammar_markdown.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,gBAAgB,EAIhB,MAAM,oBAAoB,CAAC;AAsF5B;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,EAAE,
|
|
1
|
+
{"version":3,"file":"grammar_markdown.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/grammar_markdown.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,gBAAgB,EAIhB,MAAM,oBAAoB,CAAC;AAsF5B;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,EAAE,gBAiMlC,CAAC"}
|
package/dist/grammar_markdown.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Helper to create fenced code block pattern for a language
|
|
2
|
+
* Helper to create fenced code block pattern for a language.
|
|
3
3
|
*/
|
|
4
4
|
const create_fence_pattern = (backticks, aliases, lang_id, syntax_styler) => {
|
|
5
5
|
const aliases_pattern = aliases.join('|');
|
|
@@ -21,7 +21,7 @@ const create_fence_pattern = (backticks, aliases, lang_id, syntax_styler) => {
|
|
|
21
21
|
};
|
|
22
22
|
};
|
|
23
23
|
/**
|
|
24
|
-
* Helper to create catch-all fence pattern (unknown languages)
|
|
24
|
+
* Helper to create catch-all fence pattern (unknown languages).
|
|
25
25
|
*/
|
|
26
26
|
const create_catchall_fence = (backticks) => {
|
|
27
27
|
const pattern = new RegExp(`^${backticks}[^\\n\\r]*(?:\\r?\\n|\\r)[\\s\\S]*?^${backticks}$`, 'm');
|
|
@@ -38,7 +38,7 @@ const create_catchall_fence = (backticks) => {
|
|
|
38
38
|
};
|
|
39
39
|
};
|
|
40
40
|
/**
|
|
41
|
-
* Helper to create md self-reference placeholder pattern
|
|
41
|
+
* Helper to create md self-reference placeholder pattern.
|
|
42
42
|
*/
|
|
43
43
|
const create_md_placeholder = (backticks) => {
|
|
44
44
|
const pattern = new RegExp(`^${backticks}(?:md|markdown)[^\\n\\r]*(?:\\r?\\n|\\r)[\\s\\S]*?^${backticks}$`, 'm');
|
|
@@ -69,6 +69,7 @@ export const add_grammar_markdown = (syntax_styler) => {
|
|
|
69
69
|
{ aliases: ['html', 'markup'], id: 'markup' },
|
|
70
70
|
{ aliases: ['json'], id: 'json' },
|
|
71
71
|
{ aliases: ['svelte'], id: 'svelte' },
|
|
72
|
+
{ aliases: ['bash', 'sh', 'shell'], id: 'bash' },
|
|
72
73
|
];
|
|
73
74
|
// Fence types: higher counts first (for proper precedence in tokenization)
|
|
74
75
|
const fence_types = [
|
package/dist/grammar_markup.d.ts
CHANGED
|
@@ -13,19 +13,20 @@ export declare const add_grammar_markup: AddSyntaxGrammar;
|
|
|
13
13
|
*
|
|
14
14
|
* An example of an inlined language is CSS with `<style>` tags.
|
|
15
15
|
*
|
|
16
|
-
* @param
|
|
17
|
-
* case insensitive
|
|
18
|
-
* @param lang -
|
|
16
|
+
* @param syntax_styler - the `SyntaxStyler` instance to modify
|
|
17
|
+
* @param tag_name - the name of the tag that contains the inlined language, treated as case insensitive
|
|
18
|
+
* @param lang - the language key
|
|
19
|
+
* @param inside_lang - the language to insert into, defaults to `'markup'`
|
|
19
20
|
*/
|
|
20
21
|
export declare const grammar_markup_add_inlined: (syntax_styler: SyntaxStyler, tag_name: string, lang: string, inside_lang?: string) => void;
|
|
21
22
|
/**
|
|
22
|
-
* Adds
|
|
23
|
+
* Adds a pattern to style languages embedded in HTML attributes.
|
|
23
24
|
*
|
|
24
25
|
* An example of an inlined language is CSS with `style` attributes.
|
|
25
26
|
*
|
|
26
|
-
* @param
|
|
27
|
-
* case insensitive
|
|
28
|
-
* @param lang -
|
|
27
|
+
* @param syntax_styler - the `SyntaxStyler` instance to modify
|
|
28
|
+
* @param attr_name - the name of the attribute that contains the inlined language, treated as case insensitive
|
|
29
|
+
* @param lang - the language key
|
|
29
30
|
*/
|
|
30
31
|
export declare const grammar_markup_add_attribute: (syntax_styler: SyntaxStyler, attr_name: string, lang: string) => void;
|
|
31
32
|
//# sourceMappingURL=grammar_markup.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grammar_markup.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/grammar_markup.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,YAAY,EACZ,gBAAgB,EAIhB,MAAM,oBAAoB,CAAC;AAE5B;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,EAAE,gBA6EhC,CAAC;AAEF
|
|
1
|
+
{"version":3,"file":"grammar_markup.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/grammar_markup.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,YAAY,EACZ,gBAAgB,EAIhB,MAAM,oBAAoB,CAAC;AAE5B;;;;;;;GAOG;AACH,eAAO,MAAM,kBAAkB,EAAE,gBA6EhC,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,0BAA0B,GACtC,eAAe,YAAY,EAC3B,UAAU,MAAM,EAChB,MAAM,MAAM,EACZ,oBAAsB,KACpB,IAmCF,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,4BAA4B,GACxC,eAAe,YAAY,EAC3B,WAAW,MAAM,EACjB,MAAM,MAAM,KACV,IAiEF,CAAC"}
|
package/dist/grammar_markup.js
CHANGED
|
@@ -86,9 +86,10 @@ export const add_grammar_markup = (syntax_styler) => {
|
|
|
86
86
|
*
|
|
87
87
|
* An example of an inlined language is CSS with `<style>` tags.
|
|
88
88
|
*
|
|
89
|
-
* @param
|
|
90
|
-
* case insensitive
|
|
91
|
-
* @param lang -
|
|
89
|
+
* @param syntax_styler - the `SyntaxStyler` instance to modify
|
|
90
|
+
* @param tag_name - the name of the tag that contains the inlined language, treated as case insensitive
|
|
91
|
+
* @param lang - the language key
|
|
92
|
+
* @param inside_lang - the language to insert into, defaults to `'markup'`
|
|
92
93
|
*/
|
|
93
94
|
export const grammar_markup_add_inlined = (syntax_styler, tag_name, lang, inside_lang = 'markup') => {
|
|
94
95
|
const lang_key = 'lang_' + lang;
|
|
@@ -120,13 +121,13 @@ export const grammar_markup_add_inlined = (syntax_styler, tag_name, lang, inside
|
|
|
120
121
|
});
|
|
121
122
|
};
|
|
122
123
|
/**
|
|
123
|
-
* Adds
|
|
124
|
+
* Adds a pattern to style languages embedded in HTML attributes.
|
|
124
125
|
*
|
|
125
126
|
* An example of an inlined language is CSS with `style` attributes.
|
|
126
127
|
*
|
|
127
|
-
* @param
|
|
128
|
-
* case insensitive
|
|
129
|
-
* @param lang -
|
|
128
|
+
* @param syntax_styler - the `SyntaxStyler` instance to modify
|
|
129
|
+
* @param attr_name - the name of the attribute that contains the inlined language, treated as case insensitive
|
|
130
|
+
* @param lang - the language key
|
|
130
131
|
*/
|
|
131
132
|
export const grammar_markup_add_attribute = (syntax_styler, attr_name, lang) => {
|
|
132
133
|
// After normalization, grammar.tag is an array of SyntaxGrammarToken
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import type { SyntaxTokenStream } from './syntax_token.js';
|
|
2
2
|
export type HighlightMode = 'auto' | 'ranges' | 'html';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Checks for CSS Highlights API support.
|
|
5
5
|
*/
|
|
6
6
|
export declare const supports_css_highlight_api: () => boolean;
|
|
7
7
|
/**
|
|
8
8
|
* Manages CSS Custom Highlight API ranges for a single element.
|
|
9
9
|
* Tracks ranges per element and only removes its own ranges when clearing.
|
|
10
10
|
*
|
|
11
|
-
* **Experimental** — limited browser support. Use `Code` for production.
|
|
11
|
+
* **Experimental** — limited browser support. Use `Code.svelte` for production.
|
|
12
12
|
*
|
|
13
13
|
* @example
|
|
14
14
|
* ```ts
|
|
@@ -21,11 +21,11 @@ export declare class HighlightManager {
|
|
|
21
21
|
element_ranges: Map<string, Array<Range>>;
|
|
22
22
|
constructor();
|
|
23
23
|
/**
|
|
24
|
-
*
|
|
24
|
+
* Highlights from a `SyntaxTokenStream` produced by `tokenize_syntax`.
|
|
25
25
|
*/
|
|
26
26
|
highlight_from_syntax_tokens(element: Element, tokens: SyntaxTokenStream): void;
|
|
27
27
|
/**
|
|
28
|
-
*
|
|
28
|
+
* Clears only this element's ranges from highlights.
|
|
29
29
|
*/
|
|
30
30
|
clear_element_ranges(): void;
|
|
31
31
|
destroy(): void;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { highlight_priorities } from './highlight_priorities.js';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Checks for CSS Highlights API support.
|
|
4
4
|
*/
|
|
5
|
-
export const supports_css_highlight_api = () => !!(globalThis.CSS?.highlights && globalThis.Highlight);
|
|
5
|
+
export const supports_css_highlight_api = () => !!(globalThis.CSS?.highlights && globalThis.Highlight);
|
|
6
6
|
/**
|
|
7
7
|
* Manages CSS Custom Highlight API ranges for a single element.
|
|
8
8
|
* Tracks ranges per element and only removes its own ranges when clearing.
|
|
9
9
|
*
|
|
10
|
-
* **Experimental** — limited browser support. Use `Code` for production.
|
|
10
|
+
* **Experimental** — limited browser support. Use `Code.svelte` for production.
|
|
11
11
|
*
|
|
12
12
|
* @example
|
|
13
13
|
* ```ts
|
|
@@ -24,7 +24,7 @@ export class HighlightManager {
|
|
|
24
24
|
this.element_ranges = new Map();
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
27
|
-
*
|
|
27
|
+
* Highlights from a `SyntaxTokenStream` produced by `tokenize_syntax`.
|
|
28
28
|
*/
|
|
29
29
|
highlight_from_syntax_tokens(element, tokens) {
|
|
30
30
|
// Find the text node (it might not be firstChild due to Svelte comment nodes)
|
|
@@ -67,7 +67,7 @@ export class HighlightManager {
|
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
/**
|
|
70
|
-
*
|
|
70
|
+
* Clears only this element's ranges from highlights.
|
|
71
71
|
*/
|
|
72
72
|
clear_element_ranges() {
|
|
73
73
|
for (const [name, ranges] of this.element_ranges) {
|
|
@@ -88,7 +88,7 @@ export class HighlightManager {
|
|
|
88
88
|
this.clear_element_ranges();
|
|
89
89
|
}
|
|
90
90
|
/**
|
|
91
|
-
*
|
|
91
|
+
* Creates ranges for all tokens in the tree.
|
|
92
92
|
*/
|
|
93
93
|
#create_all_ranges(tokens, text_node, ranges_by_type, offset) {
|
|
94
94
|
const text_length = text_node.textContent?.length ?? 0;
|
|
@@ -6,13 +6,13 @@ import type { SyntaxStyler } from './syntax_styler.js';
|
|
|
6
6
|
export interface PreprocessFuzCodeOptions {
|
|
7
7
|
/** File patterns to exclude. */
|
|
8
8
|
exclude?: Array<string | RegExp>;
|
|
9
|
-
/** Custom
|
|
9
|
+
/** Custom `SyntaxStyler` instance. @default syntax_styler_global */
|
|
10
10
|
syntax_styler?: SyntaxStyler;
|
|
11
11
|
/** Enable in-memory caching. @default true */
|
|
12
12
|
cache?: boolean;
|
|
13
13
|
/**
|
|
14
|
-
* Import sources that resolve to the Code component.
|
|
15
|
-
* Used to verify that `<Code>` in templates actually refers to
|
|
14
|
+
* Import sources that resolve to the `Code` component.
|
|
15
|
+
* Used to verify that `<Code>` in templates actually refers to `Code.svelte`.
|
|
16
16
|
*
|
|
17
17
|
* @default ['@fuzdev/fuz_code/Code.svelte']
|
|
18
18
|
*/
|
|
@@ -27,7 +27,7 @@ export interface PreprocessFuzCodeOptions {
|
|
|
27
27
|
* Svelte preprocessor that compiles static `Code` component content at build time,
|
|
28
28
|
* replacing runtime syntax highlighting with pre-rendered HTML.
|
|
29
29
|
*
|
|
30
|
-
* @param options
|
|
30
|
+
* @param options - `PreprocessFuzCodeOptions` configuration
|
|
31
31
|
* @returns a Svelte preprocessor group
|
|
32
32
|
*
|
|
33
33
|
* @example
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"svelte_preprocess_fuz_code.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/svelte_preprocess_fuz_code.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,iBAAiB,EAAW,MAAM,iBAAiB,CAAC;AAgBxE,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAErD;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACxC,gCAAgC;IAChC,OAAO,CAAC,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;IAEjC,
|
|
1
|
+
{"version":3,"file":"svelte_preprocess_fuz_code.d.ts","sourceRoot":"../src/lib/","sources":["../src/lib/svelte_preprocess_fuz_code.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,iBAAiB,EAAW,MAAM,iBAAiB,CAAC;AAgBxE,OAAO,KAAK,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAErD;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACxC,gCAAgC;IAChC,OAAO,CAAC,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC;IAEjC,oEAAoE;IACpE,aAAa,CAAC,EAAE,YAAY,CAAC;IAE7B,8CAA8C;IAC9C,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;IAElC;;;OAGG;IACH,QAAQ,CAAC,EAAE,KAAK,GAAG,OAAO,CAAC;CAC3B;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,0BAA0B,GACtC,UAAS,wBAA6B,KACpC,iBA6DF,CAAC"}
|
|
@@ -9,7 +9,7 @@ import { syntax_styler_global } from './syntax_styler_global.js';
|
|
|
9
9
|
* Svelte preprocessor that compiles static `Code` component content at build time,
|
|
10
10
|
* replacing runtime syntax highlighting with pre-rendered HTML.
|
|
11
11
|
*
|
|
12
|
-
* @param options
|
|
12
|
+
* @param options - `PreprocessFuzCodeOptions` configuration
|
|
13
13
|
* @returns a Svelte preprocessor group
|
|
14
14
|
*
|
|
15
15
|
* @example
|
|
@@ -68,7 +68,7 @@ export const svelte_preprocess_fuz_code = (options = {}) => {
|
|
|
68
68
|
};
|
|
69
69
|
};
|
|
70
70
|
/**
|
|
71
|
-
*
|
|
71
|
+
* Attempts to highlight content, using cache if available.
|
|
72
72
|
* Returns the highlighted HTML, or `null` on error.
|
|
73
73
|
*/
|
|
74
74
|
const try_highlight = (text, lang, syntax_styler, options) => {
|
|
@@ -87,7 +87,7 @@ const try_highlight = (text, lang, syntax_styler, options) => {
|
|
|
87
87
|
return html;
|
|
88
88
|
};
|
|
89
89
|
/**
|
|
90
|
-
* Walks the AST to find Code component usages with static `content` props
|
|
90
|
+
* Walks the AST to find `Code` component usages with static `content` props
|
|
91
91
|
* and generates transformations to replace them with `dangerous_raw_html`.
|
|
92
92
|
*/
|
|
93
93
|
const find_code_usages = (ast, syntax_styler, code_names, options) => {
|