diff --git a/.changeset/plain-peas-cough.md b/.changeset/plain-peas-cough.md new file mode 100644 index 00000000..907cb150 --- /dev/null +++ b/.changeset/plain-peas-cough.md @@ -0,0 +1,5 @@ +--- +'@fuzdev/fuz_code': minor +--- + +refactor: make `sh` the primary shell lang, with `bash` and `shell` as aliases diff --git a/CLAUDE.md b/CLAUDE.md index a07283c3..5105a2bb 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -3,10 +3,9 @@ > Syntax highlighting - hand-written single-pass lexers fuz_code (`@fuzdev/fuz_code`) is a runtime syntax highlighting library optimized -for HTML generation with CSS classes. It originated as a PrismJS fork and keeps -its `.token_*` class vocabulary, but the tokenizer is a full rewrite — one -hand-written single-pass lexer per language emitting a flat token event stream, -with zero regular expressions. +for HTML generation with CSS classes. It originated as a PrismJS fork, but the +tokenizer is a full rewrite — one hand-written single-pass lexer per language +emitting a flat token event stream, without regular expressions. For coding conventions, see Skill(fuz-stack). @@ -73,7 +72,9 @@ src/ │ ├── lexer_*.ts # hand-written lexers (json, ts, css, bash, markup, svelte, md) │ ├── Code.svelte # main Svelte component │ ├── CodeHighlight.svelte # experimental CSS Highlight API +│ ├── CodeTextarea.svelte # experimental live-highlighted textarea │ ├── highlight_manager.ts # CSS Highlight API manager +│ ├── range_highlighting.svelte.ts # shared range-highlighting helper │ ├── highlight_priorities.ts # generated token priorities │ ├── theme.css # token CSS classes │ ├── theme_variables.css # CSS variable fallbacks @@ -89,9 +90,9 @@ src/ │ ├── check.test.ts # fixture validation │ └── update.task.ts # fixture regeneration task └── routes/ # demo/docs site - ├── samples/ # language samples showcase + ├── samples/ # shared sample data (all.gen.ts) ├── benchmark/ # interactive benchmark UI - └── docs/ # API documentation + └── docs/ # tomes: usage, samples, textarea, benchmark, api ``` ### Core system @@ -125,8 +126,9 @@ One `SyntaxLang` lexer per language, registered via `add_lang`: - `lexer_ts.ts` - TypeScript; also registers the `js`/`javascript` aliases (TS is a syntactic superset — there is no separate JS lexer) - `lexer_css.ts` - CSS (including native nesting) -- `lexer_bash.ts` - Bash; also registers the `sh`/`shell` aliases (POSIX sh - is a syntactic subset for highlighting — bash-family only, no fish etc.) +- `lexer_bash.ts` - the bash-family shell lexer, registered as `sh` with + `bash`/`shell` as aliases (POSIX sh is a syntactic subset for highlighting — + bash-family only, no fish etc.) - `lexer_markup.ts` - HTML (`markup`/`html`/`mathml`/`svg`: rawtext script/style/textarea/title, `style=`/`on*=` attribute embedding) and XML (`xml`/`ssml`/`atom`/`rss`: plain tag scanning), one shared scanner @@ -162,15 +164,17 @@ can't overflow the call stack; past the cap a region stays plain text. **Code.svelte props:** -- `content` (required) - source code to highlight -- `lang` - language identifier (default: 'svelte') +- `content` - source code to highlight (or pass `dangerous_raw_html` from the + preprocessor instead) +- `lang` - language identifier (default: 'svelte'; `null` disables highlighting) - `inline` - boolean for inline vs block - `wrap` - boolean for text wrapping - `nomargin` - boolean for margin control +- `syntax_styler` - custom `SyntaxStyler` (default: `syntax_styler_global`) ## Supported languages -`ts`, `js`, `css`, `html`, `json`, `svelte`, `md`, `bash` +`ts`, `js`, `css`, `html`, `json`, `svelte`, `md`, `sh` ## Testing @@ -214,8 +218,8 @@ engines). ### Updating committed result snapshots `benchmark/compare/results.md` is linked from `README.md` as evidence for -the "vastly faster than Shiki" claim — it's load-bearing for the public -narrative, not just incidental output. `benchmark/results.md` is referenced +the "about two orders of magnitude faster" claim vs Shiki — it's load-bearing +for the public narrative, not just incidental output. `benchmark/results.md` is referenced locally as a perf baseline. `benchmark/baseline.json` is the machine-readable counterpart used by `benchmark_baseline_compare` for regression detection. It's **gitignored** (per the fuz_util/fuz_ui convention) — perf numbers @@ -223,15 +227,6 @@ vary across machines, so the baseline is a per-developer local tracker, re-seeded on each machine that runs benchmarks. PR review still relies on the committed `results.md`. -Workflow: - -```bash -npm run benchmark # check current perf against your local baseline -npm run benchmark:save # accept the change: rewrites results.md + baseline.json -npm run benchmark:clean # nuke the local baseline (re-seed on next --save) -npm run benchmark:vs:write # full overwrite of benchmark/compare/results.md -``` - `--save` is a single switch by design — accepting a perf change should update both the doc artifact and the local regression baseline atomically, so they can't drift apart. @@ -269,6 +264,7 @@ If the baseline schema version in `@fuzdev/fuz_util` advances, a stale highlighting. Limited browser support - use `Code.svelte` for production. - `mode` prop: 'auto', 'ranges', or 'html' +- `CodeTextarea.svelte` - editable `