@mdsvex/render 0.0.0 → 1.0.0-next.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.
package/package.json CHANGED
@@ -1,15 +1,56 @@
1
1
  {
2
2
  "name": "@mdsvex/render",
3
- "version": "0.0.0",
4
- "description": "Placeholder release so npm trusted publishing can be configured.",
5
- "license": "MIT",
6
- "homepage": "https://mdsvex.pngwn.io",
3
+ "version": "1.0.0-next.1",
7
4
  "repository": {
8
5
  "type": "git",
9
- "url": "https://github.com/pngwn/MDsveX",
6
+ "url": "git+https://github.com/pngwn/MDsveX.git",
10
7
  "directory": "packages/render"
11
8
  },
12
- "publishConfig": {
13
- "access": "public"
9
+ "description": "Renderers for the PFM parser wire format",
10
+ "type": "module",
11
+ "exports": {
12
+ ".": {
13
+ "import": "./dist/index.js",
14
+ "types": "./src/index.ts"
15
+ },
16
+ "./html-cursor": {
17
+ "import": "./dist/html_cursor.js",
18
+ "types": "./src/html_cursor.ts"
19
+ },
20
+ "./component": {
21
+ "import": "./dist/component.js",
22
+ "types": "./src/component.ts"
23
+ },
24
+ "./mappings": {
25
+ "import": "./dist/mappings.js",
26
+ "types": "./src/mappings.ts"
27
+ },
28
+ "./sourcemap": {
29
+ "import": "./dist/sourcemap.js",
30
+ "types": "./src/sourcemap.ts"
31
+ },
32
+ "./Node.svelte": {
33
+ "types": "./src/Node.svelte",
34
+ "svelte": "./src/Node.svelte",
35
+ "import": "./src/Node.svelte"
36
+ }
37
+ },
38
+ "peerDependencies": {
39
+ "svelte": "^5.0.0"
40
+ },
41
+ "peerDependenciesMeta": {
42
+ "svelte": {
43
+ "optional": true
44
+ }
45
+ },
46
+ "dependencies": {
47
+ "@mdsvex/parse": "1.0.0-next.1"
48
+ },
49
+ "author": "pngwn <hello@pngwn.io>",
50
+ "license": "MIT",
51
+ "scripts": {
52
+ "test": "vitest --disableConsoleIntercept",
53
+ "test:run": "vitest run --silent",
54
+ "build": "vite build --config vite.config.build.ts"
14
55
  }
15
56
  }
@@ -0,0 +1,304 @@
1
+ <script lang="ts">
2
+ import type { NodeBuffer } from '@mdsvex/parse/utils';
3
+ import {
4
+ buf_children,
5
+ buf_text,
6
+ buf_text_content,
7
+ } from '@mdsvex/parse/buf-utils';
8
+ import type { Component } from 'svelte';
9
+ import Node from './Node.svelte';
10
+
11
+ type ComponentMap = Record<string, Component<any>>;
12
+
13
+ let {
14
+ buf,
15
+ idx,
16
+ source,
17
+ components,
18
+ }: {
19
+ buf: NodeBuffer;
20
+ idx: number;
21
+ source: string;
22
+ components?: ComponentMap;
23
+ } = $props();
24
+
25
+ const NONE = 0xffffffff;
26
+
27
+ // kind constants
28
+ const K_ROOT = 0;
29
+ const K_TEXT = 1;
30
+ const K_HTML = 2;
31
+ const K_HEADING = 3;
32
+ const K_CODE_FENCE = 5;
33
+ const K_LINE_BREAK = 6;
34
+ const K_PARAGRAPH = 7;
35
+ const K_CODE_SPAN = 8;
36
+ const K_EMPHASIS = 9;
37
+ const K_STRONG = 10;
38
+ const K_THEMATIC_BREAK = 11;
39
+ const K_LINK = 12;
40
+ const K_IMAGE = 13;
41
+ const K_BLOCK_QUOTE = 14;
42
+ const K_LIST = 15;
43
+ const K_LIST_ITEM = 16;
44
+ const K_HARD_BREAK = 17;
45
+ const K_SOFT_BREAK = 18;
46
+ const K_STRIKETHROUGH = 19;
47
+ const K_SUPERSCRIPT = 20;
48
+ const K_SUBSCRIPT = 21;
49
+ const K_TABLE = 22;
50
+ const K_TABLE_HEADER = 23;
51
+ const K_TABLE_ROW = 24;
52
+ // a cell extra is its grid column, merged cells leave gaps in a row
53
+ const K_TABLE_CELL = 25;
54
+ const K_HTML_COMMENT = 26;
55
+ const K_DIRECTIVE_LABEL = 35;
56
+
57
+ const NEWLINE = '\n';
58
+
59
+ /** metadata keys that are structural and should not become html attributes. */
60
+ const INTERNAL_KEYS = new Set([
61
+ 'ordered',
62
+ 'tight',
63
+ 'start',
64
+ 'info',
65
+ 'info_start',
66
+ 'info_end',
67
+ 'tag',
68
+ 'attributes',
69
+ 'self_closing',
70
+ 'alignments',
71
+ 'col_count',
72
+ 'header_columns',
73
+ 'spans',
74
+ 'src',
75
+ ]);
76
+ const LINK_SKIP = new Set(['href', 'title']);
77
+ const IMAGE_SKIP = new Set(['title']);
78
+
79
+ /** extract plugin-set attrs from metadata as a spreadable object. */
80
+ function get_attrs(
81
+ meta: Record<string, unknown> | undefined,
82
+ skip?: Set<string>
83
+ ): Record<string, any> {
84
+ if (!meta) return {};
85
+ const result: Record<string, any> = {};
86
+ for (const key in meta) {
87
+ if (INTERNAL_KEYS.has(key)) continue;
88
+ if (skip !== undefined && skip.has(key)) continue;
89
+ const val = meta[key];
90
+ if (val === true) {
91
+ result[key] = true;
92
+ } else if (val !== false && val != null) {
93
+ result[key] = String(val);
94
+ }
95
+ }
96
+ return result;
97
+ }
98
+
99
+ let kind = $derived(buf.kind_at(idx));
100
+ let extra = $derived(buf.extra_at(idx));
101
+ let meta = $derived(buf.metadata_at(idx));
102
+
103
+ // a pending paragraph inside a list_item is a speculative wrapper for
104
+ // a list that may still become loose. render its children transparently
105
+ // so the tight-list default matches the common case and avoids a
106
+ // <p> flash before the list closes.
107
+ let skip_list_item_paragraph_wrapper = $derived(
108
+ kind === K_PARAGRAPH &&
109
+ buf.pending_at(idx) === 1 &&
110
+ buf.kind_at(buf.parent_at(idx)) === K_LIST_ITEM
111
+ );
112
+ </script>
113
+
114
+ {#snippet child_nodes(parent_idx: number)}
115
+ {#each buf_children(buf, parent_idx) as child_idx (child_idx)}
116
+ {@const kind = buf.kind_at(child_idx)}
117
+ {#if kind === K_TEXT}
118
+ {buf_text(buf, child_idx, source)}
119
+ {:else if kind === K_LINE_BREAK}
120
+ <!-- skip -->
121
+ {:else}
122
+ <Node {buf} idx={child_idx} {source} {components} />
123
+ {/if}
124
+ {/each}
125
+ {/snippet}
126
+
127
+ {#snippet table_body(table_idx: number)}
128
+ {@const meta = buf.metadata_at(table_idx)}
129
+ {@const alignments = (meta?.alignments as string[]) ?? []}
130
+ {@const header_columns = meta?.header_columns as number[] | undefined}
131
+ {@const spans = meta?.spans === true}
132
+ {@const col_count = (meta?.col_count as number | undefined) ?? alignments.length}
133
+ {@const row_l = header_columns ? header_columns[0] : 0}
134
+ {@const row_r = header_columns ? col_count - header_columns[1] : col_count}
135
+ {@const rows = buf_children(buf, table_idx)}
136
+ <table>
137
+ {#each rows as row_idx (row_idx)}
138
+ {#if buf.kind_at(row_idx) === K_TABLE_HEADER}
139
+ <thead>
140
+ <tr>
141
+ {#each buf_children(buf, row_idx).filter((c) => buf.kind_at(c) === K_TABLE_CELL) as cell_idx (cell_idx)}
142
+ {@const align = alignments[buf.extra_at(cell_idx)]}
143
+ {@const cell_meta = spans ? buf.metadata_at(cell_idx) : undefined}
144
+ <th
145
+ align={align && align !== 'none' ? align : undefined}
146
+ colspan={cell_meta?.colspan as number | undefined}
147
+ rowspan={cell_meta?.rowspan as number | undefined}
148
+ >
149
+ {@render child_nodes(cell_idx)}
150
+ </th>
151
+ {/each}
152
+ </tr>
153
+ </thead>
154
+ {/if}
155
+ {/each}
156
+ <tbody>
157
+ {#each rows as row_idx (row_idx)}
158
+ {#if buf.kind_at(row_idx) === K_TABLE_ROW}
159
+ <tr>
160
+ {#each buf_children(buf, row_idx).filter((c) => buf.kind_at(c) === K_TABLE_CELL) as cell_idx (cell_idx)}
161
+ {@const col = buf.extra_at(cell_idx)}
162
+ {@const align = alignments[col]}
163
+ {@const cell_meta = spans ? buf.metadata_at(cell_idx) : undefined}
164
+ {#if col < row_l || col >= row_r}
165
+ <th
166
+ scope="row"
167
+ align={align && align !== 'none' ? align : undefined}
168
+ colspan={cell_meta?.colspan as number | undefined}
169
+ rowspan={cell_meta?.rowspan as number | undefined}
170
+ >
171
+ {@render child_nodes(cell_idx)}
172
+ </th>
173
+ {:else}
174
+ <td
175
+ align={align && align !== 'none' ? align : undefined}
176
+ colspan={cell_meta?.colspan as number | undefined}
177
+ rowspan={cell_meta?.rowspan as number | undefined}
178
+ >
179
+ {@render child_nodes(cell_idx)}
180
+ </td>
181
+ {/if}
182
+ {/each}
183
+ </tr>
184
+ {/if}
185
+ {/each}
186
+ </tbody>
187
+ </table>
188
+ {/snippet}
189
+
190
+ {#if kind === K_ROOT}
191
+ {@render child_nodes(idx)}
192
+ {:else if kind === K_HEADING}
193
+ <svelte:element this={'h' + extra} {...get_attrs(meta)}>
194
+ {@render child_nodes(idx)}
195
+ </svelte:element>
196
+ {:else if kind === K_PARAGRAPH}
197
+ {#if skip_list_item_paragraph_wrapper}
198
+ {@render child_nodes(idx)}
199
+ {:else}
200
+ <p {...get_attrs(meta)}>{@render child_nodes(idx)}</p>
201
+ {/if}
202
+ {:else if kind === K_EMPHASIS}
203
+ <em {...get_attrs(meta)}>{@render child_nodes(idx)}</em>
204
+ {:else if kind === K_STRONG}
205
+ <strong {...get_attrs(meta)}>{@render child_nodes(idx)}</strong>
206
+ {:else if kind === K_CODE_SPAN}
207
+ <code {...get_attrs(meta)}
208
+ >{buf_text(buf, idx, source).replace(/\n/g, ' ')}</code
209
+ >
210
+ {:else if kind === K_CODE_FENCE}
211
+ {@const info =
212
+ (meta?.info as string | undefined) ??
213
+ (meta?.info_start != null
214
+ ? source.slice(meta.info_start as number, meta.info_end as number)
215
+ : undefined)}
216
+ <pre><code class={info ? 'language-' + info : undefined} {...get_attrs(meta)}
217
+ >{buf_text(buf, idx, source)}</code
218
+ ></pre>
219
+ {:else if kind === K_BLOCK_QUOTE}
220
+ <blockquote {...get_attrs(meta)}>{@render child_nodes(idx)}</blockquote>
221
+ {:else if kind === K_LINK}
222
+ <a
223
+ href={meta?.href as string}
224
+ title={(meta?.title as string) || undefined}
225
+ {...get_attrs(meta, LINK_SKIP)}
226
+ >
227
+ {@render child_nodes(idx)}
228
+ </a>
229
+ {:else if kind === K_IMAGE}
230
+ <img
231
+ src={meta?.src as string}
232
+ alt={buf_text_content(buf, idx, source)}
233
+ title={(meta?.title as string) || undefined}
234
+ {...get_attrs(meta, IMAGE_SKIP)}
235
+ />
236
+ {:else if kind === K_LIST}
237
+ {#if meta?.ordered}
238
+ {@const start = meta?.start as number | undefined}
239
+ <ol
240
+ start={start != null && start !== 1 ? start : undefined}
241
+ {...get_attrs(meta)}
242
+ >
243
+ {@render child_nodes(idx)}
244
+ </ol>
245
+ {:else}
246
+ <ul {...get_attrs(meta)}>{@render child_nodes(idx)}</ul>
247
+ {/if}
248
+ {:else if kind === K_LIST_ITEM}
249
+ <li {...get_attrs(meta)}>{@render child_nodes(idx)}</li>
250
+ {:else if kind === K_THEMATIC_BREAK}
251
+ <hr {...get_attrs(meta)} />
252
+ {:else if kind === K_HARD_BREAK}
253
+ <br />
254
+ {:else if kind === K_SOFT_BREAK}
255
+ {NEWLINE}
256
+ {:else if kind === K_STRIKETHROUGH}
257
+ <del {...get_attrs(meta)}>{@render child_nodes(idx)}</del>
258
+ {:else if kind === K_SUPERSCRIPT}
259
+ <sup {...get_attrs(meta)}>{@render child_nodes(idx)}</sup>
260
+ {:else if kind === K_SUBSCRIPT}
261
+ <sub {...get_attrs(meta)}>{@render child_nodes(idx)}</sub>
262
+ {:else if kind === K_HTML}
263
+ {@const tag = meta?.tag as string}
264
+ {@const attrs = meta?.attributes as Record | undefined}
265
+ {@const spread = attrs
266
+ ? Object.fromEntries(
267
+ Object.entries(attrs).map(([k, v]) => [
268
+ k,
269
+ v === true
270
+ ? true
271
+ : typeof v === 'object' && v?.type === 'expression'
272
+ ? v.value
273
+ : v,
274
+ ])
275
+ )
276
+ : {}}
277
+ {@const CustomComponent = components?.[tag]}
278
+ {@const is_raw_text = tag === 'script' || tag === 'style'}
279
+ {#if CustomComponent}
280
+ <CustomComponent {...spread}>
281
+ {#if !meta?.self_closing}
282
+ {@render child_nodes(idx)}
283
+ {/if}
284
+ </CustomComponent>
285
+ {:else}
286
+ <svelte:element this={tag} {...spread}>
287
+ {#if meta?.self_closing}
288
+ <!-- void element -->
289
+ {:else if is_raw_text}
290
+ {buf_text(buf, idx, source)}
291
+ {:else}
292
+ {@render child_nodes(idx)}
293
+ {/if}
294
+ </svelte:element>
295
+ {/if}
296
+ {:else if kind === K_HTML_COMMENT}
297
+ <!-- {buf_text(buf, idx, source)} -->
298
+ {:else if kind === K_TABLE}
299
+ {@render table_body(idx)}
300
+ {:else if kind === K_DIRECTIVE_LABEL}
301
+ <!-- a directive renders as its children, its label is not one of them -->
302
+ {:else}
303
+ {@render child_nodes(idx)}
304
+ {/if}
@@ -0,0 +1,88 @@
1
+ /**
2
+ * PFM Component Renderer
3
+ *
4
+ * Maintains a stable list of block-level entries for a NodeBuffer,
5
+ * each holding a buffer index and a version counter.
6
+ *
7
+ * Designed for use with the <Node> Svelte component:
8
+ *
9
+ * {#each renderer.blocks as block (block.idx)}
10
+ * {#key block.v}
11
+ * <Node buf={renderer.buf} idx={block.idx} source={renderer.source} />
12
+ * {/key}
13
+ * {/each}
14
+ *
15
+ * Closed blocks have a frozen version, {#key} keeps them stable.
16
+ * Open (streaming) blocks get bumped, {#key} recreates the subtree
17
+ * with fresh content.
18
+ */
19
+
20
+ import type { NodeBuffer } from '@mdsvex/parse/utils';
21
+
22
+ const NONE = 0xffffffff;
23
+ const K_LINE_BREAK = 6;
24
+
25
+ // block entry
26
+
27
+ export interface ComponentBlock {
28
+ /** Buffer index, use as Svelte each key. */
29
+ idx: number;
30
+ /** Version counter, bumped on each update while the block is open. */
31
+ v: number;
32
+ }
33
+
34
+ // componentrenderer
35
+
36
+ export class ComponentRenderer {
37
+ blocks: ComponentBlock[] = [];
38
+ /** The current buffer reference (for passing to Node.svelte). */
39
+ buf: NodeBuffer | null = null;
40
+ /** The current source/text string (for passing to Node.svelte). */
41
+ source = '';
42
+ private closed: Set<number> = new Set();
43
+
44
+ update(buf: NodeBuffer, source: string): ComponentBlock[] {
45
+ this.buf = buf;
46
+ this.source = source;
47
+
48
+ let block_idx = 0;
49
+ let changed = false;
50
+
51
+ // walk root's children via sibling chain
52
+ let child = buf.first_child_at(0);
53
+ while (child !== NONE) {
54
+ const kind = buf.kind_at(child);
55
+ const next = buf.next_at(child);
56
+ const is_sibling = next !== NONE && buf.parent_at(next) === 0;
57
+
58
+ if (kind !== K_LINE_BREAK) {
59
+ const closed = buf.end_at(child) !== NONE;
60
+
61
+ if (block_idx >= this.blocks.length) {
62
+ this.blocks.push({ idx: child, v: 0 });
63
+ changed = true;
64
+ } else if (!this.closed.has(child)) {
65
+ this.blocks[block_idx].v++;
66
+ changed = true;
67
+ }
68
+
69
+ if (closed && !this.closed.has(child)) {
70
+ this.closed.add(child);
71
+ }
72
+
73
+ block_idx++;
74
+ }
75
+
76
+ child = is_sibling ? next : NONE;
77
+ }
78
+
79
+ return changed ? (this.blocks = [...this.blocks]) : this.blocks;
80
+ }
81
+
82
+ reset(): void {
83
+ this.blocks = [];
84
+ this.buf = null;
85
+ this.source = '';
86
+ this.closed.clear();
87
+ }
88
+ }
@@ -0,0 +1,226 @@
1
+ // the html5 named character references that end in a semicolon, as commonmark
2
+ // accepts them in text, from character-entities 2.0.2
3
+ const NAMES = `
4
+ AElig AMP Aacute Abreve Acirc Acy Afr Agrave Alpha Amacr And Aogon Aopf
5
+ ApplyFunction Aring Ascr Assign Atilde Auml Backslash Barv Barwed Bcy Because
6
+ Bernoullis Beta Bfr Bopf Breve Bscr Bumpeq CHcy COPY Cacute Cap
7
+ CapitalDifferentialD Cayleys Ccaron Ccedil Ccirc Cconint Cdot Cedilla CenterDot
8
+ Cfr Chi CircleDot CircleMinus CirclePlus CircleTimes ClockwiseContourIntegral
9
+ CloseCurlyDoubleQuote CloseCurlyQuote Colon Colone Congruent Conint
10
+ ContourIntegral Copf Coproduct CounterClockwiseContourIntegral Cross Cscr Cup
11
+ CupCap DD DDotrahd DJcy DScy DZcy Dagger Darr Dashv Dcaron Dcy Del Delta Dfr
12
+ DiacriticalAcute DiacriticalDot DiacriticalDoubleAcute DiacriticalGrave
13
+ DiacriticalTilde Diamond DifferentialD Dopf Dot DotDot DotEqual
14
+ DoubleContourIntegral DoubleDot DoubleDownArrow DoubleLeftArrow
15
+ DoubleLeftRightArrow DoubleLeftTee DoubleLongLeftArrow DoubleLongLeftRightArrow
16
+ DoubleLongRightArrow DoubleRightArrow DoubleRightTee DoubleUpArrow
17
+ DoubleUpDownArrow DoubleVerticalBar DownArrow DownArrowBar DownArrowUpArrow
18
+ DownBreve DownLeftRightVector DownLeftTeeVector DownLeftVector
19
+ DownLeftVectorBar DownRightTeeVector DownRightVector DownRightVectorBar DownTee
20
+ DownTeeArrow Downarrow Dscr Dstrok ENG ETH Eacute Ecaron Ecirc Ecy Edot Efr
21
+ Egrave Element Emacr EmptySmallSquare EmptyVerySmallSquare Eogon Eopf Epsilon
22
+ Equal EqualTilde Equilibrium Escr Esim Eta Euml Exists ExponentialE Fcy Ffr
23
+ FilledSmallSquare FilledVerySmallSquare Fopf ForAll Fouriertrf Fscr GJcy GT
24
+ Gamma Gammad Gbreve Gcedil Gcirc Gcy Gdot Gfr Gg Gopf GreaterEqual
25
+ GreaterEqualLess GreaterFullEqual GreaterGreater GreaterLess GreaterSlantEqual
26
+ GreaterTilde Gscr Gt HARDcy Hacek Hat Hcirc Hfr HilbertSpace Hopf
27
+ HorizontalLine Hscr Hstrok HumpDownHump HumpEqual IEcy IJlig IOcy Iacute Icirc
28
+ Icy Idot Ifr Igrave Im Imacr ImaginaryI Implies Int Integral Intersection
29
+ InvisibleComma InvisibleTimes Iogon Iopf Iota Iscr Itilde Iukcy Iuml Jcirc Jcy
30
+ Jfr Jopf Jscr Jsercy Jukcy KHcy KJcy Kappa Kcedil Kcy Kfr Kopf Kscr LJcy LT
31
+ Lacute Lambda Lang Laplacetrf Larr Lcaron Lcedil Lcy LeftAngleBracket LeftArrow
32
+ LeftArrowBar LeftArrowRightArrow LeftCeiling LeftDoubleBracket
33
+ LeftDownTeeVector LeftDownVector LeftDownVectorBar LeftFloor LeftRightArrow
34
+ LeftRightVector LeftTee LeftTeeArrow LeftTeeVector LeftTriangle LeftTriangleBar
35
+ LeftTriangleEqual LeftUpDownVector LeftUpTeeVector LeftUpVector LeftUpVectorBar
36
+ LeftVector LeftVectorBar Leftarrow Leftrightarrow LessEqualGreater
37
+ LessFullEqual LessGreater LessLess LessSlantEqual LessTilde Lfr Ll Lleftarrow
38
+ Lmidot LongLeftArrow LongLeftRightArrow LongRightArrow Longleftarrow
39
+ Longleftrightarrow Longrightarrow Lopf LowerLeftArrow LowerRightArrow Lscr Lsh
40
+ Lstrok Lt Map Mcy MediumSpace Mellintrf Mfr MinusPlus Mopf Mscr Mu NJcy Nacute
41
+ Ncaron Ncedil Ncy NegativeMediumSpace NegativeThickSpace NegativeThinSpace
42
+ NegativeVeryThinSpace NestedGreaterGreater NestedLessLess NewLine Nfr NoBreak
43
+ NonBreakingSpace Nopf Not NotCongruent NotCupCap NotDoubleVerticalBar
44
+ NotElement NotEqual NotEqualTilde NotExists NotGreater NotGreaterEqual
45
+ NotGreaterFullEqual NotGreaterGreater NotGreaterLess NotGreaterSlantEqual
46
+ NotGreaterTilde NotHumpDownHump NotHumpEqual NotLeftTriangle NotLeftTriangleBar
47
+ NotLeftTriangleEqual NotLess NotLessEqual NotLessGreater NotLessLess
48
+ NotLessSlantEqual NotLessTilde NotNestedGreaterGreater NotNestedLessLess
49
+ NotPrecedes NotPrecedesEqual NotPrecedesSlantEqual NotReverseElement
50
+ NotRightTriangle NotRightTriangleBar NotRightTriangleEqual NotSquareSubset
51
+ NotSquareSubsetEqual NotSquareSuperset NotSquareSupersetEqual NotSubset
52
+ NotSubsetEqual NotSucceeds NotSucceedsEqual NotSucceedsSlantEqual
53
+ NotSucceedsTilde NotSuperset NotSupersetEqual NotTilde NotTildeEqual
54
+ NotTildeFullEqual NotTildeTilde NotVerticalBar Nscr Ntilde Nu OElig Oacute
55
+ Ocirc Ocy Odblac Ofr Ograve Omacr Omega Omicron Oopf OpenCurlyDoubleQuote
56
+ OpenCurlyQuote Or Oscr Oslash Otilde Otimes Ouml OverBar OverBrace OverBracket
57
+ OverParenthesis PartialD Pcy Pfr Phi Pi PlusMinus Poincareplane Popf Pr
58
+ Precedes PrecedesEqual PrecedesSlantEqual PrecedesTilde Prime Product
59
+ Proportion Proportional Pscr Psi QUOT Qfr Qopf Qscr RBarr REG Racute Rang Rarr
60
+ Rarrtl Rcaron Rcedil Rcy Re ReverseElement ReverseEquilibrium
61
+ ReverseUpEquilibrium Rfr Rho RightAngleBracket RightArrow RightArrowBar
62
+ RightArrowLeftArrow RightCeiling RightDoubleBracket RightDownTeeVector
63
+ RightDownVector RightDownVectorBar RightFloor RightTee RightTeeArrow
64
+ RightTeeVector RightTriangle RightTriangleBar RightTriangleEqual
65
+ RightUpDownVector RightUpTeeVector RightUpVector RightUpVectorBar RightVector
66
+ RightVectorBar Rightarrow Ropf RoundImplies Rrightarrow Rscr Rsh RuleDelayed
67
+ SHCHcy SHcy SOFTcy Sacute Sc Scaron Scedil Scirc Scy Sfr ShortDownArrow
68
+ ShortLeftArrow ShortRightArrow ShortUpArrow Sigma SmallCircle Sopf Sqrt Square
69
+ SquareIntersection SquareSubset SquareSubsetEqual SquareSuperset
70
+ SquareSupersetEqual SquareUnion Sscr Star Sub Subset SubsetEqual Succeeds
71
+ SucceedsEqual SucceedsSlantEqual SucceedsTilde SuchThat Sum Sup Superset
72
+ SupersetEqual Supset THORN TRADE TSHcy TScy Tab Tau Tcaron Tcedil Tcy Tfr
73
+ Therefore Theta ThickSpace ThinSpace Tilde TildeEqual TildeFullEqual TildeTilde
74
+ Topf TripleDot Tscr Tstrok Uacute Uarr Uarrocir Ubrcy Ubreve Ucirc Ucy Udblac
75
+ Ufr Ugrave Umacr UnderBar UnderBrace UnderBracket UnderParenthesis Union
76
+ UnionPlus Uogon Uopf UpArrow UpArrowBar UpArrowDownArrow UpDownArrow
77
+ UpEquilibrium UpTee UpTeeArrow Uparrow Updownarrow UpperLeftArrow
78
+ UpperRightArrow Upsi Upsilon Uring Uscr Utilde Uuml VDash Vbar Vcy Vdash Vdashl
79
+ Vee Verbar Vert VerticalBar VerticalLine VerticalSeparator VerticalTilde
80
+ VeryThinSpace Vfr Vopf Vscr Vvdash Wcirc Wedge Wfr Wopf Wscr Xfr Xi Xopf Xscr
81
+ YAcy YIcy YUcy Yacute Ycirc Ycy Yfr Yopf Yscr Yuml ZHcy Zacute Zcaron Zcy Zdot
82
+ ZeroWidthSpace Zeta Zfr Zopf Zscr aacute abreve ac acE acd acirc acute acy
83
+ aelig af afr agrave alefsym aleph alpha amacr amalg amp and andand andd
84
+ andslope andv ang ange angle angmsd angmsdaa angmsdab angmsdac angmsdad
85
+ angmsdae angmsdaf angmsdag angmsdah angrt angrtvb angrtvbd angsph angst angzarr
86
+ aogon aopf ap apE apacir ape apid apos approx approxeq aring ascr ast asymp
87
+ asympeq atilde auml awconint awint bNot backcong backepsilon backprime backsim
88
+ backsimeq barvee barwed barwedge bbrk bbrktbrk bcong bcy bdquo becaus because
89
+ bemptyv bepsi bernou beta beth between bfr bigcap bigcirc bigcup bigodot
90
+ bigoplus bigotimes bigsqcup bigstar bigtriangledown bigtriangleup biguplus
91
+ bigvee bigwedge bkarow blacklozenge blacksquare blacktriangle blacktriangledown
92
+ blacktriangleleft blacktriangleright blank blk12 blk14 blk34 block bne bnequiv
93
+ bnot bopf bot bottom bowtie boxDL boxDR boxDl boxDr boxH boxHD boxHU boxHd
94
+ boxHu boxUL boxUR boxUl boxUr boxV boxVH boxVL boxVR boxVh boxVl boxVr boxbox
95
+ boxdL boxdR boxdl boxdr boxh boxhD boxhU boxhd boxhu boxminus boxplus boxtimes
96
+ boxuL boxuR boxul boxur boxv boxvH boxvL boxvR boxvh boxvl boxvr bprime breve
97
+ brvbar bscr bsemi bsim bsime bsol bsolb bsolhsub bull bullet bump bumpE bumpe
98
+ bumpeq cacute cap capand capbrcup capcap capcup capdot caps caret caron ccaps
99
+ ccaron ccedil ccirc ccups ccupssm cdot cedil cemptyv cent centerdot cfr chcy
100
+ check checkmark chi cir cirE circ circeq circlearrowleft circlearrowright
101
+ circledR circledS circledast circledcirc circleddash cire cirfnint cirmid
102
+ cirscir clubs clubsuit colon colone coloneq comma commat comp compfn complement
103
+ complexes cong congdot conint copf coprod copy copysr crarr cross cscr csub
104
+ csube csup csupe ctdot cudarrl cudarrr cuepr cuesc cularr cularrp cup cupbrcap
105
+ cupcap cupcup cupdot cupor cups curarr curarrm curlyeqprec curlyeqsucc curlyvee
106
+ curlywedge curren curvearrowleft curvearrowright cuvee cuwed cwconint cwint
107
+ cylcty dArr dHar dagger daleth darr dash dashv dbkarow dblac dcaron dcy dd
108
+ ddagger ddarr ddotseq deg delta demptyv dfisht dfr dharl dharr diam diamond
109
+ diamondsuit diams die digamma disin div divide divideontimes divonx djcy dlcorn
110
+ dlcrop dollar dopf dot doteq doteqdot dotminus dotplus dotsquare doublebarwedge
111
+ downarrow downdownarrows downharpoonleft downharpoonright drbkarow drcorn
112
+ drcrop dscr dscy dsol dstrok dtdot dtri dtrif duarr duhar dwangle dzcy dzigrarr
113
+ eDDot eDot eacute easter ecaron ecir ecirc ecolon ecy edot ee efDot efr eg
114
+ egrave egs egsdot el elinters ell els elsdot emacr empty emptyset emptyv emsp
115
+ emsp13 emsp14 eng ensp eogon eopf epar eparsl eplus epsi epsilon epsiv eqcirc
116
+ eqcolon eqsim eqslantgtr eqslantless equals equest equiv equivDD eqvparsl erDot
117
+ erarr escr esdot esim eta eth euml euro excl exist expectation exponentiale
118
+ fallingdotseq fcy female ffilig fflig ffllig ffr filig fjlig flat fllig fltns
119
+ fnof fopf forall fork forkv fpartint frac12 frac13 frac14 frac15 frac16 frac18
120
+ frac23 frac25 frac34 frac35 frac38 frac45 frac56 frac58 frac78 frasl frown fscr
121
+ gE gEl gacute gamma gammad gap gbreve gcirc gcy gdot ge gel geq geqq geqslant
122
+ ges gescc gesdot gesdoto gesdotol gesl gesles gfr gg ggg gimel gjcy gl glE gla
123
+ glj gnE gnap gnapprox gne gneq gneqq gnsim gopf grave gscr gsim gsime gsiml gt
124
+ gtcc gtcir gtdot gtlPar gtquest gtrapprox gtrarr gtrdot gtreqless gtreqqless
125
+ gtrless gtrsim gvertneqq gvnE hArr hairsp half hamilt hardcy harr harrcir harrw
126
+ hbar hcirc hearts heartsuit hellip hercon hfr hksearow hkswarow hoarr homtht
127
+ hookleftarrow hookrightarrow hopf horbar hscr hslash hstrok hybull hyphen
128
+ iacute ic icirc icy iecy iexcl iff ifr igrave ii iiiint iiint iinfin iiota
129
+ ijlig imacr image imagline imagpart imath imof imped in incare infin infintie
130
+ inodot int intcal integers intercal intlarhk intprod iocy iogon iopf iota iprod
131
+ iquest iscr isin isinE isindot isins isinsv isinv it itilde iukcy iuml jcirc
132
+ jcy jfr jmath jopf jscr jsercy jukcy kappa kappav kcedil kcy kfr kgreen khcy
133
+ kjcy kopf kscr lAarr lArr lAtail lBarr lE lEg lHar lacute laemptyv lagran
134
+ lambda lang langd langle lap laquo larr larrb larrbfs larrfs larrhk larrlp
135
+ larrpl larrsim larrtl lat latail late lates lbarr lbbrk lbrace lbrack lbrke
136
+ lbrksld lbrkslu lcaron lcedil lceil lcub lcy ldca ldquo ldquor ldrdhar ldrushar
137
+ ldsh le leftarrow leftarrowtail leftharpoondown leftharpoonup leftleftarrows
138
+ leftrightarrow leftrightarrows leftrightharpoons leftrightsquigarrow
139
+ leftthreetimes leg leq leqq leqslant les lescc lesdot lesdoto lesdotor lesg
140
+ lesges lessapprox lessdot lesseqgtr lesseqqgtr lessgtr lesssim lfisht lfloor
141
+ lfr lg lgE lhard lharu lharul lhblk ljcy ll llarr llcorner llhard lltri lmidot
142
+ lmoust lmoustache lnE lnap lnapprox lne lneq lneqq lnsim loang loarr lobrk
143
+ longleftarrow longleftrightarrow longmapsto longrightarrow looparrowleft
144
+ looparrowright lopar lopf loplus lotimes lowast lowbar loz lozenge lozf lpar
145
+ lparlt lrarr lrcorner lrhar lrhard lrm lrtri lsaquo lscr lsh lsim lsime lsimg
146
+ lsqb lsquo lsquor lstrok lt ltcc ltcir ltdot lthree ltimes ltlarr ltquest
147
+ ltrPar ltri ltrie ltrif lurdshar luruhar lvertneqq lvnE mDDot macr male malt
148
+ maltese map mapsto mapstodown mapstoleft mapstoup marker mcomma mcy mdash
149
+ measuredangle mfr mho micro mid midast midcir middot minus minusb minusd
150
+ minusdu mlcp mldr mnplus models mopf mp mscr mstpos mu multimap mumap nGg nGt
151
+ nGtv nLeftarrow nLeftrightarrow nLl nLt nLtv nRightarrow nVDash nVdash nabla
152
+ nacute nang nap napE napid napos napprox natur natural naturals nbsp nbump
153
+ nbumpe ncap ncaron ncedil ncong ncongdot ncup ncy ndash ne neArr nearhk nearr
154
+ nearrow nedot nequiv nesear nesim nexist nexists nfr ngE nge ngeq ngeqq
155
+ ngeqslant nges ngsim ngt ngtr nhArr nharr nhpar ni nis nisd niv njcy nlArr nlE
156
+ nlarr nldr nle nleftarrow nleftrightarrow nleq nleqq nleqslant nles nless nlsim
157
+ nlt nltri nltrie nmid nopf not notin notinE notindot notinva notinvb notinvc
158
+ notni notniva notnivb notnivc npar nparallel nparsl npart npolint npr nprcue
159
+ npre nprec npreceq nrArr nrarr nrarrc nrarrw nrightarrow nrtri nrtrie nsc
160
+ nsccue nsce nscr nshortmid nshortparallel nsim nsime nsimeq nsmid nspar nsqsube
161
+ nsqsupe nsub nsubE nsube nsubset nsubseteq nsubseteqq nsucc nsucceq nsup nsupE
162
+ nsupe nsupset nsupseteq nsupseteqq ntgl ntilde ntlg ntriangleleft
163
+ ntrianglelefteq ntriangleright ntrianglerighteq nu num numero numsp nvDash
164
+ nvHarr nvap nvdash nvge nvgt nvinfin nvlArr nvle nvlt nvltrie nvrArr nvrtrie
165
+ nvsim nwArr nwarhk nwarr nwarrow nwnear oS oacute oast ocir ocirc ocy odash
166
+ odblac odiv odot odsold oelig ofcir ofr ogon ograve ogt ohbar ohm oint olarr
167
+ olcir olcross oline olt omacr omega omicron omid ominus oopf opar operp oplus
168
+ or orarr ord order orderof ordf ordm origof oror orslope orv oscr oslash osol
169
+ otilde otimes otimesas ouml ovbar par para parallel parsim parsl part pcy
170
+ percnt period permil perp pertenk pfr phi phiv phmmat phone pi pitchfork piv
171
+ planck planckh plankv plus plusacir plusb pluscir plusdo plusdu pluse plusmn
172
+ plussim plustwo pm pointint popf pound pr prE prap prcue pre prec precapprox
173
+ preccurlyeq preceq precnapprox precneqq precnsim precsim prime primes prnE
174
+ prnap prnsim prod profalar profline profsurf prop propto prsim prurel pscr psi
175
+ puncsp qfr qint qopf qprime qscr quaternions quatint quest questeq quot rAarr
176
+ rArr rAtail rBarr rHar race racute radic raemptyv rang rangd range rangle raquo
177
+ rarr rarrap rarrb rarrbfs rarrc rarrfs rarrhk rarrlp rarrpl rarrsim rarrtl
178
+ rarrw ratail ratio rationals rbarr rbbrk rbrace rbrack rbrke rbrksld rbrkslu
179
+ rcaron rcedil rceil rcub rcy rdca rdldhar rdquo rdquor rdsh real realine
180
+ realpart reals rect reg rfisht rfloor rfr rhard rharu rharul rho rhov
181
+ rightarrow rightarrowtail rightharpoondown rightharpoonup rightleftarrows
182
+ rightleftharpoons rightrightarrows rightsquigarrow rightthreetimes ring
183
+ risingdotseq rlarr rlhar rlm rmoust rmoustache rnmid roang roarr robrk ropar
184
+ ropf roplus rotimes rpar rpargt rppolint rrarr rsaquo rscr rsh rsqb rsquo
185
+ rsquor rthree rtimes rtri rtrie rtrif rtriltri ruluhar rx sacute sbquo sc scE
186
+ scap scaron sccue sce scedil scirc scnE scnap scnsim scpolint scsim scy sdot
187
+ sdotb sdote seArr searhk searr searrow sect semi seswar setminus setmn sext sfr
188
+ sfrown sharp shchcy shcy shortmid shortparallel shy sigma sigmaf sigmav sim
189
+ simdot sime simeq simg simgE siml simlE simne simplus simrarr slarr
190
+ smallsetminus smashp smeparsl smid smile smt smte smtes softcy sol solb solbar
191
+ sopf spades spadesuit spar sqcap sqcaps sqcup sqcups sqsub sqsube sqsubset
192
+ sqsubseteq sqsup sqsupe sqsupset sqsupseteq squ square squarf squf srarr sscr
193
+ ssetmn ssmile sstarf star starf straightepsilon straightphi strns sub subE
194
+ subdot sube subedot submult subnE subne subplus subrarr subset subseteq
195
+ subseteqq subsetneq subsetneqq subsim subsub subsup succ succapprox succcurlyeq
196
+ succeq succnapprox succneqq succnsim succsim sum sung sup sup1 sup2 sup3 supE
197
+ supdot supdsub supe supedot suphsol suphsub suplarr supmult supnE supne supplus
198
+ supset supseteq supseteqq supsetneq supsetneqq supsim supsub supsup swArr
199
+ swarhk swarr swarrow swnwar szlig target tau tbrk tcaron tcedil tcy tdot telrec
200
+ tfr there4 therefore theta thetasym thetav thickapprox thicksim thinsp thkap
201
+ thksim thorn tilde times timesb timesbar timesd tint toea top topbot topcir
202
+ topf topfork tosa tprime trade triangle triangledown triangleleft
203
+ trianglelefteq triangleq triangleright trianglerighteq tridot trie triminus
204
+ triplus trisb tritime trpezium tscr tscy tshcy tstrok twixt twoheadleftarrow
205
+ twoheadrightarrow uArr uHar uacute uarr ubrcy ubreve ucirc ucy udarr udblac
206
+ udhar ufisht ufr ugrave uharl uharr uhblk ulcorn ulcorner ulcrop ultri umacr
207
+ uml uogon uopf uparrow updownarrow upharpoonleft upharpoonright uplus upsi
208
+ upsih upsilon upuparrows urcorn urcorner urcrop uring urtri uscr utdot utilde
209
+ utri utrif uuarr uuml uwangle vArr vBar vBarv vDash vangrt varepsilon varkappa
210
+ varnothing varphi varpi varpropto varr varrho varsigma varsubsetneq
211
+ varsubsetneqq varsupsetneq varsupsetneqq vartheta vartriangleleft
212
+ vartriangleright vcy vdash vee veebar veeeq vellip verbar vert vfr vltri vnsub
213
+ vnsup vopf vprop vrtri vscr vsubnE vsubne vsupnE vsupne vzigzag wcirc wedbar
214
+ wedge wedgeq weierp wfr wopf wp wr wreath wscr xcap xcirc xcup xdtri xfr xhArr
215
+ xharr xi xlArr xlarr xmap xnis xodot xopf xoplus xotime xrArr xrarr xscr xsqcup
216
+ xuplus xutri xvee xwedge yacute yacy ycirc ycy yen yfr yicy yopf yscr yucy yuml
217
+ zacute zcaron zcy zdot zeetrf zeta zfr zhcy zigrarr zopf zscr zwj zwnj
218
+ `;
219
+
220
+ let names: Set<string> | null = null;
221
+
222
+ /** whether name is a named character reference */
223
+ export function is_entity_name(name: string): boolean {
224
+ if (names === null) names = new Set(NAMES.trim().split(/\s+/));
225
+ return names.has(name);
226
+ }