@godxjp/markdown 33.21.0 → 33.22.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/README.md +58 -2
- package/dist/chunk-AKKOCR2Y.js +79 -0
- package/dist/chunk-ANYWBQJT.js +21 -0
- package/dist/chunk-JJ2A3D7U.js +14 -0
- package/dist/chunk-RRNN4HLQ.js +940 -0
- package/dist/chunk-XXBFDQOW.js +118 -0
- package/dist/codec/index.js +97 -66
- package/dist/fixtures-CKcZEUes.d.ts +246 -0
- package/dist/highlight-TYIW3L3V.js +11 -0
- package/dist/index.d.ts +10 -213
- package/dist/index.js +24 -1004
- package/dist/katex-styles-JVRNFDYG.js +4 -0
- package/dist/lazy.d.ts +16 -0
- package/dist/lazy.js +126 -0
- package/dist/math-DOI7WLLZ.js +13 -0
- package/package.json +7 -2
- package/dist/codec/index.d.ts +0 -71
package/dist/index.d.ts
CHANGED
|
@@ -1,218 +1,15 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
import
|
|
2
|
+
import { f as MarkdownProps } from './fixtures-CKcZEUes.js';
|
|
3
|
+
export { D as DirectiveBlock, a as DirectiveRenderProps, b as DirectiveRenderer, H as HeadingIdResolver, c as HeadingInfo, M as MARKDOWN_FIXTURES, d as MARKDOWN_FORMAT, e as MarkdownFixture, g as MermaidDiagram, h as MermaidDiagramProps, i as MermaidSvgCheck, R as RENDERER_VERSION, S as SchemaExtension, j as checkMermaidSvg, k as extendSchema, m as markdownSchema, r as rehypeHeadingIds, s as safeUrl } from './fixtures-CKcZEUes.js';
|
|
4
|
+
import 'react-markdown';
|
|
5
|
+
import 'hast';
|
|
6
|
+
import 'rehype-sanitize';
|
|
5
7
|
|
|
6
|
-
/** What a host is told about each heading, in document order. */
|
|
7
|
-
type HeadingInfo = {
|
|
8
|
-
depth: number;
|
|
9
|
-
text: string;
|
|
10
|
-
index: number;
|
|
11
|
-
};
|
|
12
8
|
/**
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* in document order (`a`, `a-1`, `a-2`). A host whose server already assigned anchors (godx-task
|
|
17
|
-
* keeps its outline server-side, so a link and the page agree) passes its own: computing "the same"
|
|
18
|
-
* slug in two languages is one rule written twice, and it drifts.
|
|
9
|
+
* THE ONE RENDERER (gh#1108) — the deterministic entry: math and code colour are drawn in the same
|
|
10
|
+
* synchronous render, on a server, in a Worker and in a browser alike. `@godxjp/markdown/lazy` is
|
|
11
|
+
* the same component with those two engines loaded only when a body needs them.
|
|
19
12
|
*/
|
|
20
|
-
|
|
21
|
-
/** rehype plugin: an `id` on every heading. Runs BEFORE the sanitiser, which allows `id` on h1–h6. */
|
|
22
|
-
declare function rehypeHeadingIds(options?: {
|
|
23
|
-
resolve?: HeadingIdResolver;
|
|
24
|
-
}): (tree: Root) => void;
|
|
13
|
+
declare function Markdown(props: MarkdownProps): React.JSX.Element;
|
|
25
14
|
|
|
26
|
-
|
|
27
|
-
* THE ONE SANITISER SCHEMA (gh#1108). godx-task and godx-content each carried their own copy of
|
|
28
|
-
* this; every consumer now renders through this one, so a policy change happens once.
|
|
29
|
-
*
|
|
30
|
-
* Built on `rehype-sanitize`'s `defaultSchema` (GitHub's), with three deliberate changes:
|
|
31
|
-
*
|
|
32
|
-
* - `clobberPrefix: ""`. The default re-prefixes every `id`, but remark-gfm already writes footnote
|
|
33
|
-
* ids and their `href`s as a matched `user-content-` pair, so the second prefix split the pair and
|
|
34
|
-
* footnote links went nowhere (measured in godx-task). The clobber exists to stop a body minting
|
|
35
|
-
* an id that collides with the host's; this renderer never parses raw HTML (no `rehype-raw`), so
|
|
36
|
-
* the only ids in the tree are the ones the pipeline generated. `raw-html.test` pins that.
|
|
37
|
-
* - `protocols`: links and images allow only `http`, `https`, `mailto` (links) and relative URLs.
|
|
38
|
-
* `javascript:`, `data:`, `vbscript:` and every other scheme are dropped.
|
|
39
|
-
* - Task-list checkboxes stay `disabled` (the default): ticking one would be a write to the body.
|
|
40
|
-
* - KaTeX's output (math.ts `katexSchema`: MathML, its own classes, geometry-only inline styles,
|
|
41
|
-
* `svg` paths for radicals and stretchy arrows) and the code tokens (`data-code-token`, the kit's
|
|
42
|
-
* twelve names) — both produced by the pipeline before this schema judges them (renderer v6).
|
|
43
|
-
*
|
|
44
|
-
* Hosts extend it with `extendSchema`, never by editing a copy.
|
|
45
|
-
*/
|
|
46
|
-
declare const markdownSchema: Options;
|
|
47
|
-
/** Extra tags / attributes a host needs (a callout marker, a section element). Additive only. */
|
|
48
|
-
type SchemaExtension = {
|
|
49
|
-
tagNames?: string[];
|
|
50
|
-
attributes?: Record<string, NonNullable<Options["attributes"]>[string]>;
|
|
51
|
-
};
|
|
52
|
-
/**
|
|
53
|
-
* The schema plus a host's additions. ADDITIVE: an extension can allow a tag or an attribute, never
|
|
54
|
-
* widen `protocols` or bring raw HTML back, so a consumer cannot loosen the URL policy by accident.
|
|
55
|
-
*
|
|
56
|
-
* A rule for an attribute the base ALREADY constrains is MERGED into that rule (gh#1116): the
|
|
57
|
-
* sanitiser reads the first rule it finds for an attribute, so appending `["className",
|
|
58
|
-
* "math-inline"]` beside the default `["className", /^language-./]` was silently ignored and the
|
|
59
|
-
* formula class stripped. Merged, it is one rule allowing both. An attribute the base allows with
|
|
60
|
-
* no value constraint stays unconstrained.
|
|
61
|
-
*/
|
|
62
|
-
declare function extendSchema(extension?: SchemaExtension): Options;
|
|
63
|
-
/**
|
|
64
|
-
* react-markdown's `urlTransform`, with the same allow-list as the schema, so a URL is checked
|
|
65
|
-
* where it is written as well as where it is sanitised. Relative URLs (`/x`, `x`, `#a`, `?q`) pass;
|
|
66
|
-
* a scheme outside the list becomes `""`. A host scheme such as `asset:` is resolved by the host's
|
|
67
|
-
* `resolveUrl` BEFORE this check, so it can only turn into an allowed URL or be dropped.
|
|
68
|
-
*/
|
|
69
|
-
declare function safeUrl(url: string, key: string): string;
|
|
70
|
-
|
|
71
|
-
/** GitHub alert kinds, the only callouts v1 knows. Serialized uppercase. */
|
|
72
|
-
declare const CALLOUT_KINDS: readonly ["note", "tip", "important", "warning", "caution"];
|
|
73
|
-
type CalloutKind = (typeof CALLOUT_KINDS)[number];
|
|
74
|
-
|
|
75
|
-
type PluggableList = NonNullable<Options$1["remarkPlugins"]>;
|
|
76
|
-
/**
|
|
77
|
-
* The stored body's format, and the renderer generation that produced its output. A consumer
|
|
78
|
-
* records both on every saved version (content-media contracts § 6.6) and never re-interprets an
|
|
79
|
-
* old version under a different format. `RENDERER_VERSION` moves when the SAME input renders
|
|
80
|
-
* differently — a schema change, a new default plugin — not on every release.
|
|
81
|
-
*/
|
|
82
|
-
declare const MARKDOWN_FORMAT = "md";
|
|
83
|
-
declare const RENDERER_VERSION = 6;
|
|
84
|
-
type MarkdownProps = {
|
|
85
|
-
/** The Markdown source. */
|
|
86
|
-
children: string;
|
|
87
|
-
/**
|
|
88
|
-
* remark plugins run after GFM (a callout or embed marker plugin). Whatever they emit still goes
|
|
89
|
-
* through the sanitiser, so a marker attribute must be allowed with `schema`.
|
|
90
|
-
*/
|
|
91
|
-
remarkPlugins?: PluggableList;
|
|
92
|
-
/**
|
|
93
|
-
* rehype plugins run AFTER the sanitiser, on a tree that is already safe. Presentation only: a
|
|
94
|
-
* plugin here must not introduce URLs, raw HTML or event handlers — it is past the gate.
|
|
95
|
-
*/
|
|
96
|
-
rehypePlugins?: PluggableList;
|
|
97
|
-
/** Tags / attributes a host plugin needs. Additive; cannot widen the URL policy. */
|
|
98
|
-
schema?: SchemaExtension;
|
|
99
|
-
/**
|
|
100
|
-
* Element overrides (react-markdown `components`). A host `pre` renders every fence EXCEPT
|
|
101
|
-
* ```mermaid, which is drawn through the gate first; `mermaid={false}` hands those to it too.
|
|
102
|
-
*/
|
|
103
|
-
components?: Components;
|
|
104
|
-
/**
|
|
105
|
-
* Resolves a host-specific URL (`asset:…`, a wiki link) to a real one. Runs before the sanitiser
|
|
106
|
-
* and the scheme allow-list, so whatever it returns is still checked; `undefined` keeps the URL.
|
|
107
|
-
*/
|
|
108
|
-
resolveUrl?: (url: string, key: "href" | "src" | string) => string | undefined;
|
|
109
|
-
/** Heading anchors: GitHub slugs by default; a host with server-side anchors supplies its own. */
|
|
110
|
-
headingId?: HeadingIdResolver;
|
|
111
|
-
/**
|
|
112
|
-
* Render ```mermaid fences as gated diagrams (default true). They are drawn BEFORE a host `pre`
|
|
113
|
-
* is consulted, so a host code renderer keeps Mermaid; `false` hands mermaid fences to the host
|
|
114
|
-
* `pre` (or plain code) as well (gh#1116).
|
|
115
|
-
*/
|
|
116
|
-
mermaid?: boolean;
|
|
117
|
-
/**
|
|
118
|
-
* Tokenise fenced code in a known language as `<span data-code-token="keyword">` … (default
|
|
119
|
-
* true), which `Prose` colours. `false` leaves the code as plain text — a host `pre` that runs
|
|
120
|
-
* its own highlighter.
|
|
121
|
-
*/
|
|
122
|
-
highlight?: boolean;
|
|
123
|
-
/**
|
|
124
|
-
* NARROW the elements a body may produce — an activity feed that shows only inline formatting.
|
|
125
|
-
* react-markdown's own options, applied after the sanitiser; they can only remove, never allow
|
|
126
|
-
* what the schema strips (gh#1116).
|
|
127
|
-
*/
|
|
128
|
-
allowedElements?: Options$1["allowedElements"];
|
|
129
|
-
disallowedElements?: Options$1["disallowedElements"];
|
|
130
|
-
allowElement?: Options$1["allowElement"];
|
|
131
|
-
/** With an element filter: keep a removed element's children (its text) instead of dropping it. */
|
|
132
|
-
unwrapDisallowed?: boolean;
|
|
133
|
-
/**
|
|
134
|
-
* A table cell whose trimmed text has no whitespace and at most this many characters — a code,
|
|
135
|
-
* an id, a date, 優先度 — is stamped `data-short`, and `Prose` keeps it on one line: CJK otherwise
|
|
136
|
-
* breaks between any two ideographs in a narrow column (gh#1150). A sentence still wraps.
|
|
137
|
-
* Characters are user-perceived (grapheme clusters). Default 24; `false` stamps nothing.
|
|
138
|
-
*/
|
|
139
|
-
shortCellLength?: number | false;
|
|
140
|
-
/**
|
|
141
|
-
* Visible callout titles per kind when a callout has none of its own (`> [!WARNING]`). English by
|
|
142
|
-
* default — this package carries no i18n; a host passes its localized strings.
|
|
143
|
-
*/
|
|
144
|
-
calloutTitles?: Partial<Record<CalloutKind, string>>;
|
|
145
|
-
/**
|
|
146
|
-
* Where an EXTERNAL link opens. An external link is an absolute http(s) URL whose origin differs
|
|
147
|
-
* from `origin`. `"new-tab"` gives it `target="_blank"` and `rel="noopener noreferrer"`. Relative
|
|
148
|
-
* links, `#anchors`, wikilinks resolved to a path, and `mailto:` stay in the tab. The default,
|
|
149
|
-
* `"same-tab"`, changes nothing. Markdown has no syntax for `target`, so this is a renderer policy.
|
|
150
|
-
*/
|
|
151
|
-
externalLinks?: "same-tab" | "new-tab";
|
|
152
|
-
/**
|
|
153
|
-
* The page origin that `externalLinks` compares against. Defaults to `location.origin`. Pass it
|
|
154
|
-
* when rendering on the server, or every absolute link counts as external there and hydration
|
|
155
|
-
* disagrees on same-origin ones.
|
|
156
|
-
*/
|
|
157
|
-
origin?: string;
|
|
158
|
-
};
|
|
159
|
-
/**
|
|
160
|
-
* THE ONE RENDERER (gh#1108). GFM — tables, task lists, fenced code, autolinks, footnotes,
|
|
161
|
-
* strikethrough — plus heading anchors, KaTeX math, highlighted code, sanitised by `markdownSchema`, with ```mermaid drawn only
|
|
162
|
-
* through the SVG gate. Raw HTML in the source is never parsed into elements (no `rehype-raw`): it
|
|
163
|
-
* stays visible text. Output matches `react-markdown` + `remark-gfm` + `rehype-sanitize`, which is
|
|
164
|
-
* what godx-task and godx-content rendered before, so the swap is drop-in.
|
|
165
|
-
*
|
|
166
|
-
* Renders bare elements; the host wraps it (`<Prose>` from `@godxjp/ui/data-display`), so this
|
|
167
|
-
* package carries no UI-kit dependency.
|
|
168
|
-
*/
|
|
169
|
-
declare function Markdown({ children, remarkPlugins, rehypePlugins, schema, components, resolveUrl, headingId, mermaid, highlight, allowedElements, disallowedElements, allowElement, unwrapDisallowed, shortCellLength, calloutTitles, externalLinks, origin, }: MarkdownProps): React.JSX.Element;
|
|
170
|
-
|
|
171
|
-
type MermaidSvgCheck = {
|
|
172
|
-
ok: true;
|
|
173
|
-
svg: SVGSVGElement;
|
|
174
|
-
} | {
|
|
175
|
-
ok: false;
|
|
176
|
-
reason: string;
|
|
177
|
-
};
|
|
178
|
-
/**
|
|
179
|
-
* Parses `svg` as XML and checks every element and attribute. On success returns the PARSED root,
|
|
180
|
-
* which the caller inserts as a node — never re-serialised into HTML, so what was checked is what
|
|
181
|
-
* is shown (an HTML re-parse of an SVG string can differ from the XML parse: mutation XSS).
|
|
182
|
-
*/
|
|
183
|
-
declare function checkMermaidSvg(svg: string): MermaidSvgCheck;
|
|
184
|
-
type MermaidDiagramProps = {
|
|
185
|
-
/** The fence's text. */
|
|
186
|
-
source: string;
|
|
187
|
-
/** Accessible name of the rendered diagram (the figure). */
|
|
188
|
-
label?: string;
|
|
189
|
-
};
|
|
190
|
-
/**
|
|
191
|
-
* A ```mermaid fence. Shows the code until the diagram has rendered AND passed `checkMermaidSvg`,
|
|
192
|
-
* and keeps showing it if either fails — so the page is never blank and never unsafe.
|
|
193
|
-
*/
|
|
194
|
-
declare function MermaidDiagram({ source, label }: MermaidDiagramProps): React.JSX.Element;
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* THE SHARED FIXTURE CORPUS (gh#1108). Input Markdown → the exact sanitised HTML this renderer
|
|
198
|
-
* produces with its defaults. Browser, server and export paths (a PHP exporter included) conform to
|
|
199
|
-
* these rather than to each other: "same output" is checked against one list, not argued about.
|
|
200
|
-
*
|
|
201
|
-
* `hostile` fixtures carry an attack; `forbidden` lists substrings that must never appear in their
|
|
202
|
-
* output, so a schema change that re-opens one fails even if somebody re-blesses the HTML.
|
|
203
|
-
*
|
|
204
|
-
* Changing an expected `html` for an existing input is a renderer change: bump `RENDERER_VERSION`.
|
|
205
|
-
*
|
|
206
|
-
* The HTML is the renderer's, not React's: compare after removing the `<link rel="preload">` React's
|
|
207
|
-
* static renderer adds for each image (`normalizeFixtureHtml` in the tests).
|
|
208
|
-
*/
|
|
209
|
-
type MarkdownFixture = {
|
|
210
|
-
name: string;
|
|
211
|
-
markdown: string;
|
|
212
|
-
html: string;
|
|
213
|
-
hostile?: boolean;
|
|
214
|
-
forbidden?: string[];
|
|
215
|
-
};
|
|
216
|
-
declare const MARKDOWN_FIXTURES: MarkdownFixture[];
|
|
217
|
-
|
|
218
|
-
export { type HeadingIdResolver, type HeadingInfo, MARKDOWN_FIXTURES, MARKDOWN_FORMAT, Markdown, type MarkdownFixture, type MarkdownProps, MermaidDiagram, type MermaidDiagramProps, type MermaidSvgCheck, RENDERER_VERSION, type SchemaExtension, checkMermaidSvg, extendSchema, markdownSchema, rehypeHeadingIds, safeUrl };
|
|
15
|
+
export { Markdown, MarkdownProps };
|