@grafctory/clay-markdown 0.4.1 → 0.6.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 CHANGED
@@ -1,14 +1,22 @@
1
1
  # @grafctory/clay-markdown
2
2
 
3
- [![npm](https://img.shields.io/npm/v/@grafctory/clay-markdown)](https://www.npmjs.com/package/@grafctory/clay-markdown)
3
+ [![npm][npm-badge]][npm] [![Grafctory][grafctory-badge]][grafctory]
4
4
 
5
- Preact Markdown documents for [@grafctory/clay](https://github.com/grafctory/clay).
5
+ [npm-badge]: https://img.shields.io/npm/v/@grafctory/clay-markdown
6
+ [npm]: https://www.npmjs.com/package/@grafctory/clay-markdown
7
+ [grafctory-badge]: https://img.shields.io/badge/part%20of-Grafctory-blue
8
+ [grafctory]: https://github.com/grafctory
9
+
10
+ Preact Markdown documents for [@grafctory/clay].
6
11
 
7
12
  Markdown sources rendered as the documents they describe, with a table of contents leading into their sections and the
8
13
  values their front matter declares, so a page built from Markdown needs no rendering pipeline of its own.
9
14
 
10
15
  Styling is structural only: what a widget needs to work, with colour, type and spacing left to
11
- [@grafctory/skin](https://github.com/grafctory/skin) or to whoever styles the app.
16
+ [@grafctory/skin] or to whoever styles the app.
17
+
18
+ [@grafctory/clay]: https://github.com/grafctory/clay
19
+ [@grafctory/skin]: https://github.com/grafctory/skin
12
20
 
13
21
  # Installation
14
22
 
@@ -40,3 +48,5 @@ npm install preact # peer dependency
40
48
 
41
49
  This project is licensed under the Apache 2.0 License –
42
50
  see [LICENSE](https://github.com/grafctory/clay?tab=Apache-2.0-1-ov-file) file for details.
51
+
52
+ <sub>Grafctory™ is a trademark of Metreeca srl.</sub>
@@ -0,0 +1,97 @@
1
+ /**
2
+ * Markdown document processing.
3
+ *
4
+ * Turns a Markdown text into the document it describes, leaving a view nothing to do but render it. The reading
5
+ * follows GitHub, from the Markdown it flavours to the ids it gives headings, and the document carries what
6
+ * assistive technologies and keyboard users are owed beyond what a text states. A link naming an unsafe protocol
7
+ * is dropped, raw HTML is never carried through, and a link to a Markdown file points at the route serving it.
8
+ *
9
+ * Colouring fenced code and reading emoji shortcodes call for data a text names rather than carries, so a reader
10
+ * downloads the grammar of a language, or the table naming the shortcodes, only once a text they are reading states
11
+ * one, and never for the languages and the shortcodes they never meet. A document is ready before any of that
12
+ * arrives, stating its code and its shortcodes as the text does, and ready again the moment it lands. Nothing a
13
+ * reader needs is ever held back for a download, and data that cannot be reached leaves the text exactly as written.
14
+ *
15
+ * Code is coloured in the languages highlight.js itself curates as common, together with the configuration formats a
16
+ * technical text fences, and code in any other language reads exactly as the text states it.
17
+ *
18
+ * @module index.core
19
+ */
20
+ import { type Optional } from "@grafctory/core";
21
+ import type { Root as Tree } from "hast";
22
+ import type { LanguageFn } from "highlight.js";
23
+ /**
24
+ * The languages a code block may be coloured in, keyed by the name highlight.js draws each under, each stating the
25
+ * aliases a block may name it by and the import bringing its grammar in. The catalogue covers the languages
26
+ * highlight.js curates as common together with the configuration formats a technical text fences, and code in any
27
+ * other language reads exactly as the text states it, with no grammar ever fetched for it.
28
+ *
29
+ * @hidden
30
+ */
31
+ export declare const Grammars: Readonly<Record<string, readonly [string, () => Promise<{
32
+ default: LanguageFn;
33
+ }>]>>;
34
+ /**
35
+ * Front matter values.
36
+ *
37
+ * Maps each key a Markdown text declares in its YAML front matter to the value it is given, read as a plain string.
38
+ */
39
+ export interface Meta {
40
+ readonly [key: string]: string;
41
+ }
42
+ /**
43
+ * Deferred document resources.
44
+ *
45
+ * Tells a widget that a document can now be shown more completely than it was. Every load that lands moves these
46
+ * resources on, so the widget renders the text again and the code and the shortcodes it was showing plainly take
47
+ * the form the text asked for, one load at a time and without the reader waiting on any of them.
48
+ */
49
+ export interface Resources {
50
+ /**
51
+ * How far the resources have moved on, growing with every load that lands. A document rendered at a higher count
52
+ * shows everything the loads up to that point brought in, and nothing of the loads after it.
53
+ */
54
+ readonly loads: number;
55
+ /**
56
+ * Takes in a load that has landed.
57
+ *
58
+ * @returns Resources standing one load further on than these
59
+ */
60
+ loaded(): this;
61
+ }
62
+ /**
63
+ * Creates deferred document resources.
64
+ *
65
+ * @returns Immutable {@link Resources} with no load yet taken in
66
+ */
67
+ export declare function createResources(): Resources;
68
+ /**
69
+ * Fetches what a text names but does not carry.
70
+ *
71
+ * Brings in the grammar of every language the fenced code blocks of `text` name, under that name or under the
72
+ * language it is an alias of. Brings in the table naming the emoji too, if `text` carries a shortcode. A language
73
+ * the catalogue does not colour is passed over, and the code blocks naming it stay as the text states them.
74
+ *
75
+ * @param text The Markdown text about to be rendered
76
+ *
77
+ * @returns A promise settled once everything `text` names is in place, or `undefined` if all of it already was, so
78
+ * that a caller renders a second time only when the first rendering of the text fell short of what it states
79
+ */
80
+ export declare function fetchResources(text: string): Optional<Promise<void>>;
81
+ /**
82
+ * Reads a Markdown text as the document it describes.
83
+ *
84
+ * @param text The Markdown text to read, front matter included
85
+ *
86
+ * @returns The document `text` describes, ready to be rendered as it stands
87
+ */
88
+ export declare function transform(text: string): Tree;
89
+ /**
90
+ * Reads the values a Markdown text declares in its front matter.
91
+ *
92
+ * @param text The Markdown text to read, front matter included
93
+ *
94
+ * @returns An immutable {@link Meta} of the values `text` declares in its YAML front matter, empty if it declares none
95
+ */
96
+ export declare function frontmatter(text: string): Meta;
97
+ //# sourceMappingURL=index.core.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.core.d.ts","sourceRoot":"","sources":["../src/index.core.ts"],"names":[],"mappings":"AAgBA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAIhD,OAAO,KAAK,EAAwC,IAAI,IAAI,IAAI,EAAE,MAAM,MAAM,CAAC;AAE/E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAgB/C;;;;;;;GAOG;AACH,eAAO,MAAM,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,OAAO,CAAC;IAAE,OAAO,EAAE,UAAU,CAAA;CAAE,CAAC,CAAC,CAAC,CA6CxG,CAAC;AA+FF;;;;GAIG;AACH,MAAM,WAAW,IAAI;IAEpB,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CAE9B;AAGD;;;;;;GAMG;AACH,MAAM,WAAW,SAAS;IAEzB;;;OAGG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;IAEtB;;;;OAIG;IACH,MAAM,IAAI,IAAI,CAAA;CAEd;AAKD;;;;GAIG;AACH,wBAAgB,eAAe,IAAI,SAAS,CAU3C;AAGD;;;;;;;;;;;GAWG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CASpE;AAGD;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAE5C;AAGD;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAS9C"}
@@ -0,0 +1,437 @@
1
+ /*
2
+ * Copyright © 2026 Metreeca srl
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { unique } from "@grafctory/core/arrays";
17
+ import { createState } from "@grafctory/core/state";
18
+ import { immutable } from "@grafctory/core/values";
19
+ import { headingRank } from "hast-util-heading-rank";
20
+ import { createLowlight } from "lowlight";
21
+ import { findAndReplace } from "mdast-util-find-and-replace";
22
+ import { gfmFromMarkdown } from "mdast-util-gfm";
23
+ import { gfm } from "micromark-extension-gfm";
24
+ import rehypeSlug from "rehype-slug";
25
+ import remarkFrontmatter from "remark-frontmatter";
26
+ import { remarkAlert } from "remark-github-blockquote-alert";
27
+ import remarkParse from "remark-parse";
28
+ import remarkRehype from "remark-rehype";
29
+ import { unified } from "unified";
30
+ import { visit } from "unist-util-visit";
31
+ /**
32
+ * The languages a code block may be coloured in, keyed by the name highlight.js draws each under, each stating the
33
+ * aliases a block may name it by and the import bringing its grammar in. The catalogue covers the languages
34
+ * highlight.js curates as common together with the configuration formats a technical text fences, and code in any
35
+ * other language reads exactly as the text states it, with no grammar ever fetched for it.
36
+ *
37
+ * @hidden
38
+ */
39
+ export const Grammars = {
40
+ "apache": ["apacheconf", () => import("highlight.js/lib/languages/apache")],
41
+ "bash": ["sh zsh", () => import("highlight.js/lib/languages/bash")],
42
+ "c": ["h", () => import("highlight.js/lib/languages/c")],
43
+ "cpp": ["cc c++ h++ hpp hh hxx cxx", () => import("highlight.js/lib/languages/cpp")],
44
+ "csharp": ["cs c#", () => import("highlight.js/lib/languages/csharp")],
45
+ "css": ["", () => import("highlight.js/lib/languages/css")],
46
+ "diff": ["patch", () => import("highlight.js/lib/languages/diff")],
47
+ "dockerfile": ["docker", () => import("highlight.js/lib/languages/dockerfile")],
48
+ "go": ["golang", () => import("highlight.js/lib/languages/go")],
49
+ "graphql": ["gql", () => import("highlight.js/lib/languages/graphql")],
50
+ "http": ["https", () => import("highlight.js/lib/languages/http")],
51
+ "ini": ["toml", () => import("highlight.js/lib/languages/ini")],
52
+ "java": ["jsp", () => import("highlight.js/lib/languages/java")],
53
+ "javascript": ["js jsx mjs cjs", () => import("highlight.js/lib/languages/javascript")],
54
+ "json": ["jsonc json5", () => import("highlight.js/lib/languages/json")],
55
+ "kotlin": ["kt kts", () => import("highlight.js/lib/languages/kotlin")],
56
+ "less": ["", () => import("highlight.js/lib/languages/less")],
57
+ "lua": ["pluto", () => import("highlight.js/lib/languages/lua")],
58
+ "makefile": ["mk mak make", () => import("highlight.js/lib/languages/makefile")],
59
+ "markdown": ["md mkdown mkd", () => import("highlight.js/lib/languages/markdown")],
60
+ "nginx": ["nginxconf", () => import("highlight.js/lib/languages/nginx")],
61
+ "objectivec": ["mm objc obj-c obj-c++ objective-c++", () => import("highlight.js/lib/languages/objectivec")],
62
+ "perl": ["pl pm", () => import("highlight.js/lib/languages/perl")],
63
+ "php": ["", () => import("highlight.js/lib/languages/php")],
64
+ "php-template": ["", () => import("highlight.js/lib/languages/php-template")],
65
+ "plaintext": ["text txt", () => import("highlight.js/lib/languages/plaintext")],
66
+ "properties": ["", () => import("highlight.js/lib/languages/properties")],
67
+ "protobuf": ["proto", () => import("highlight.js/lib/languages/protobuf")],
68
+ "python": ["py gyp ipython", () => import("highlight.js/lib/languages/python")],
69
+ "python-repl": ["pycon", () => import("highlight.js/lib/languages/python-repl")],
70
+ "r": ["", () => import("highlight.js/lib/languages/r")],
71
+ "ruby": ["rb gemspec podspec thor irb", () => import("highlight.js/lib/languages/ruby")],
72
+ "rust": ["rs", () => import("highlight.js/lib/languages/rust")],
73
+ "scss": ["", () => import("highlight.js/lib/languages/scss")],
74
+ "shell": ["console shellsession", () => import("highlight.js/lib/languages/shell")],
75
+ "sql": ["", () => import("highlight.js/lib/languages/sql")],
76
+ "swift": ["", () => import("highlight.js/lib/languages/swift")],
77
+ "typescript": ["ts tsx mts cts", () => import("highlight.js/lib/languages/typescript")],
78
+ "vbnet": ["vb", () => import("highlight.js/lib/languages/vbnet")],
79
+ "wasm": ["", () => import("highlight.js/lib/languages/wasm")],
80
+ "xml": ["html xhtml rss atom xjb xsd xsl plist wsf svg", () => import("highlight.js/lib/languages/xml")],
81
+ "yaml": ["yml", () => import("highlight.js/lib/languages/yaml")],
82
+ };
83
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
84
+ /**
85
+ * The shortcodes a text states, naming the emoji each stands for, as the `gemoji` table names them.
86
+ */
87
+ const Shortcode = /:(\+1|[-\w]+):/;
88
+ /**
89
+ * The language a fenced code block opens with, delimited as CommonMark delimits a fence, so that a text can be asked
90
+ * what it names before it is parsed. A word matched here that names no grammar is passed over, so a reading that
91
+ * finds a language the text never states costs nothing beyond the lookup that turns it away.
92
+ */
93
+ const Fence = /^ {0,3}(?:`{3,}|~{3,})[ \t]*([^\s`]+)/gm;
94
+ /**
95
+ * The language a fenced code block states, as `remark-rehype` classes it.
96
+ */
97
+ const Language = /^language-(.+)$/;
98
+ /**
99
+ * The key the shortcode table is loaded under, which no grammar name can take.
100
+ */
101
+ const Emoji = "";
102
+ /**
103
+ * The protocols a link or a source may name; anything else could run script or load content from outside the page.
104
+ */
105
+ const SafeProtocol = /^(https?|ircs?|mailto|xmpp)$/i;
106
+ /**
107
+ * An image source ending with a percentage of the width of the block holding the image, from `#1` to `#100`.
108
+ */
109
+ const WidthHint = /^(.*)#([1-9]\d?|100)$/;
110
+ /**
111
+ * A list nested in a task list item, whose text labels the checkboxes of its own items rather than the one above them.
112
+ */
113
+ const NestedList = /^(ul|ol)$/;
114
+ /**
115
+ * A key and the value a line of YAML front matter declares for it.
116
+ */
117
+ const Declaration = /^\s*(\w+)\s*:\s*(.*?)\s*$/gm;
118
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
119
+ const pipeline = unified()
120
+ .use(remarkParse)
121
+ .use(remarkFrontmatter)
122
+ .use(remarkGFM)
123
+ .use(remarkAlert)
124
+ .use(remarkEmoji)
125
+ .use(remarkCode)
126
+ .use(remarkRehype)
127
+ .use(rehypeSlug)
128
+ .use(rehypeHighlights)
129
+ .use(rehypeAlerts)
130
+ .use(rehypeLinks)
131
+ .use(rehypeImages)
132
+ .use(rehypeAccess);
133
+ const lowlight = createLowlight();
134
+ /**
135
+ * The loads taken on so far, keyed by the grammar they bring in or by {@link Emoji}, each settled once what it brought
136
+ * in is in place. A key is kept whether its load succeeded or failed, so a resource that cannot be reached is asked
137
+ * for once only, and the documents naming it stay readable without it rather than retrying on every render.
138
+ */
139
+ const loads = new Map();
140
+ /**
141
+ * The keys of the loads that have settled.
142
+ */
143
+ const settled = new Set();
144
+ /**
145
+ * The emoji each shortcode names, filled in once the table has been loaded.
146
+ */
147
+ const shortcodes = new Map();
148
+ /**
149
+ * The language a code block states, read under its own name and under every alias the catalogue gives it.
150
+ */
151
+ const names = new Map(Object.entries(Grammars).flatMap(([name, [aliases]]) => [name, ...aliases.split(" ").filter(alias => alias !== "")].map((stated) => [stated, name])));
152
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
153
+ /**
154
+ * Creates deferred document resources.
155
+ *
156
+ * @returns Immutable {@link Resources} with no load yet taken in
157
+ */
158
+ export function createResources() {
159
+ return createState({
160
+ loads: 0,
161
+ loaded() {
162
+ return { loads: this.loads + 1 };
163
+ }
164
+ });
165
+ }
166
+ /**
167
+ * Fetches what a text names but does not carry.
168
+ *
169
+ * Brings in the grammar of every language the fenced code blocks of `text` name, under that name or under the
170
+ * language it is an alias of. Brings in the table naming the emoji too, if `text` carries a shortcode. A language
171
+ * the catalogue does not colour is passed over, and the code blocks naming it stay as the text states them.
172
+ *
173
+ * @param text The Markdown text about to be rendered
174
+ *
175
+ * @returns A promise settled once everything `text` names is in place, or `undefined` if all of it already was, so
176
+ * that a caller renders a second time only when the first rendering of the text fell short of what it states
177
+ */
178
+ export function fetchResources(text) {
179
+ const pending = [
180
+ ...languages(text).map(name => once(name, () => grammar(name))),
181
+ ...Shortcode.test(text) ? [once(Emoji, table)] : []
182
+ ].filter(load => load !== undefined);
183
+ return pending.length === 0 ? undefined : Promise.all(pending).then(() => undefined);
184
+ }
185
+ /**
186
+ * Reads a Markdown text as the document it describes.
187
+ *
188
+ * @param text The Markdown text to read, front matter included
189
+ *
190
+ * @returns The document `text` describes, ready to be rendered as it stands
191
+ */
192
+ export function transform(text) {
193
+ return pipeline.runSync(pipeline.parse(text));
194
+ }
195
+ /**
196
+ * Reads the values a Markdown text declares in its front matter.
197
+ *
198
+ * @param text The Markdown text to read, front matter included
199
+ *
200
+ * @returns An immutable {@link Meta} of the values `text` declares in its YAML front matter, empty if it declares none
201
+ */
202
+ export function frontmatter(text) {
203
+ const yaml = pipeline.parse(text).children.find(node => node.type === "yaml");
204
+ return immutable(Object.fromEntries(Array.from(yaml?.value.matchAll(Declaration) ?? [], ([, key, value]) => [key, value])));
205
+ }
206
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
207
+ /**
208
+ * Reads the GitHub Flavored Markdown a text states, its tables, task lists, footnotes and autolinks included.
209
+ *
210
+ * Only the reading of it is wired. `remark-gfm` wires the writing of Markdown alongside, which a document never does,
211
+ * and charges every consumer for a serialiser that no part of this package ever reaches.
212
+ */
213
+ function remarkGFM() {
214
+ // ;(mutation) unified plugins declare their extensions by adding to the data of the processor they run on
215
+ const data = this.data();
216
+ data.micromarkExtensions = [...data.micromarkExtensions ?? [], gfm()];
217
+ data.fromMarkdownExtensions = [...data.fromMarkdownExtensions ?? [], gfmFromMarkdown()];
218
+ }
219
+ /**
220
+ * Replaces the shortcodes of a document with the emoji they name, once the table has been fetched. A shortcode met
221
+ * before it arrives, and one the table does not name, both stay as the text states them.
222
+ */
223
+ function remarkEmoji() {
224
+ return (tree) => {
225
+ // ;(mutation) unified transformers edit the tree they are handed in place
226
+ if (shortcodes.size > 0) {
227
+ findAndReplace(tree, [
228
+ new RegExp(Shortcode.source, "g"),
229
+ (_, name) => shortcodes.get(name) ?? false
230
+ ]);
231
+ }
232
+ };
233
+ }
234
+ /**
235
+ * Strips fenced code of surrounding blank lines and halves its indentation, so code pasted from a source file
236
+ * reads at the width of the document rather than at the width of the editor it was copied from.
237
+ */
238
+ function remarkCode() {
239
+ return (tree) => visit(tree, "code", node => {
240
+ // ;(mutation) unified transformers edit the tree they are handed in place
241
+ node.value = node.value
242
+ .replace(/^\s+|\s+$/g, "")
243
+ .replace(/^[ \t]+/mg, indent => indent.replace(/ {4}|\t/g, " "));
244
+ });
245
+ }
246
+ /**
247
+ * Marks the code blocks of a document with the token classes a stylesheet colours, for every language whose grammar
248
+ * is already in place. Code in any other language stays exactly as the text states it, so a reader always meets the
249
+ * code itself, coloured wherever a grammar has already arrived and plain everywhere else.
250
+ */
251
+ function rehypeHighlights() {
252
+ return (tree) => visit(tree, "element", node => {
253
+ const name = node.tagName === "code" ? resolved(stated(node)) : undefined;
254
+ // ;(mutation) unified transformers edit the tree they are handed in place
255
+ if (name !== undefined && lowlight.registered(name)) {
256
+ node.properties = { ...node.properties, className: [...classes(node), "hljs"] };
257
+ node.children = lowlight.highlight(name, content(node.children)).children
258
+ .filter((child) => child.type !== "doctype");
259
+ }
260
+ });
261
+ }
262
+ /**
263
+ * Titles GitHub alerts in sentence case, `Caution` rather than `CAUTION`, as GitHub itself renders them.
264
+ */
265
+ function rehypeAlerts() {
266
+ return (tree) => visit(tree, "element", node => {
267
+ // ;(mutation) unified transformers edit the tree they are handed in place
268
+ if (classes(node).includes("markdown-alert-title")) {
269
+ node.children = node.children.map(child => child.type === "text"
270
+ ? { ...child, value: child.value.replace(/\p{L}+/u, word => word[0] + word.slice(1).toLowerCase()) }
271
+ : child);
272
+ }
273
+ });
274
+ }
275
+ /**
276
+ * Drops links and sources naming an unsafe protocol, and rewrites those naming a Markdown file to the route serving
277
+ * it, `guide.md` to `guide` and `index.md` to its folder, fragments preserved, so linked documents read as pages.
278
+ */
279
+ function rehypeLinks() {
280
+ return (tree) => visit(tree, "element", node => {
281
+ // ;(mutation) unified transformers edit the tree they are handed in place
282
+ node.properties = Object.fromEntries(Object.entries(node.properties).map(([name, value]) => [name, (name === "href" || name === "src") && typeof value === "string" ? route(value) : value]));
283
+ });
284
+ }
285
+ /**
286
+ * Sizes images whose source ends with a percentage hint, `chart.png#50` to half the width of the block holding it,
287
+ * dropping the hint from the source, so a text sets the relative size of a picture without resorting to raw HTML.
288
+ */
289
+ function rehypeImages() {
290
+ return (tree) => visit(tree, "element", node => {
291
+ const { src, title, alt } = node.properties;
292
+ const hint = node.tagName === "img" && typeof src === "string" ? WidthHint.exec(src) : null;
293
+ // ;(mutation) unified transformers edit the tree they are handed in place
294
+ if (node.tagName === "img") {
295
+ node.properties = {
296
+ ...node.properties,
297
+ ...hint === null ? {} : { src: hint[1], style: `--clay-markdown-width: ${hint[2]}%` },
298
+ ...alt ? {} : {
299
+ alt: typeof title === "string" && title.trim() ? title.trim()
300
+ : typeof src === "string" ? named(src) : ""
301
+ }
302
+ };
303
+ }
304
+ });
305
+ }
306
+ /**
307
+ * Supplies what the rendered markup owes assistive technologies and keyboard users beyond what Markdown states: a
308
+ * label for the checkbox of a task list item, the keyboard focus for a code block scrolling past the measure, and a
309
+ * focus target for a heading a fragment lands on, reachable by script but kept out of the tab order.
310
+ */
311
+ function rehypeAccess() {
312
+ return (tree) => visit(tree, "element", node => {
313
+ // ;(mutation) unified transformers edit the tree they are handed in place
314
+ if (node.tagName === "li" && classes(node).includes("task-list-item")) {
315
+ const label = text(node.children
316
+ .filter(child => !(child.type === "element" && NestedList.test(child.tagName))));
317
+ node.children = node.children.map(child => child.type === "element" && child.tagName === "input"
318
+ ? { ...child, properties: { ...child.properties, ariaLabel: label } }
319
+ : child);
320
+ }
321
+ else if (node.tagName === "pre") {
322
+ node.properties = { ...node.properties, tabIndex: 0 };
323
+ }
324
+ else if (headingRank(node) !== undefined) {
325
+ node.properties = { ...node.properties, tabIndex: -1 };
326
+ }
327
+ });
328
+ }
329
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
330
+ /**
331
+ * Lists the grammars a text calls for, each under the name it is loaded as, with every language named more than once
332
+ * listed a single time. A language the catalogue does not colour is left out, so no load is taken on for it.
333
+ */
334
+ function languages(text) {
335
+ return unique(Array.from(text.matchAll(Fence), ([, language]) => resolved(language))
336
+ .filter(name => name !== undefined));
337
+ }
338
+ /**
339
+ * Resolves a language a text states to the name its grammar is loaded under, taking the language itself or the one
340
+ * it is an alias of. Returns `undefined` if the catalogue colours no such language.
341
+ */
342
+ function resolved(language) {
343
+ return language === undefined ? undefined : names.get(language.toLowerCase());
344
+ }
345
+ /**
346
+ * Takes a load on once. Returns the load already under way for `key` if there is one, and `undefined` if it has
347
+ * already settled, so that a caller waits only on what is still outstanding and never fetches a resource twice.
348
+ */
349
+ function once(key, load) {
350
+ // ;(mutation) the loads are a cache shared by every document on the page, so each resource is fetched once
351
+ return settled.has(key) ? undefined : loads.get(key) ?? recorded(key, load().finally(() => {
352
+ settled.add(key);
353
+ }));
354
+ }
355
+ /**
356
+ * Keeps a load under its key, so that the documents asking for it later join the one already under way.
357
+ */
358
+ function recorded(key, load) {
359
+ loads.set(key, load);
360
+ return load;
361
+ }
362
+ /**
363
+ * Brings in a grammar. A grammar that cannot be reached leaves the documents naming it uncoloured.
364
+ */
365
+ function grammar(name) {
366
+ const [, load] = Grammars[name];
367
+ return load().then(({ default: language }) => {
368
+ lowlight.register(name, language);
369
+ }, () => undefined);
370
+ }
371
+ /**
372
+ * Brings in the table naming the emoji. A table that cannot be reached leaves the shortcodes as the texts state them.
373
+ */
374
+ function table() {
375
+ return import("gemoji").then(({ nameToEmoji }) => {
376
+ // ;(mutation) the table is a cache shared by every document on the page, filled once it is in hand
377
+ Object.entries(nameToEmoji).forEach(([name, emoji]) => shortcodes.set(name, emoji));
378
+ }, () => undefined);
379
+ }
380
+ /**
381
+ * Reads the language a code element is classed with, `undefined` for one classed with none.
382
+ */
383
+ function stated(node) {
384
+ return classes(node).map(name => Language.exec(name)?.[1]).find(language => language !== undefined);
385
+ }
386
+ /**
387
+ * Lists the classes of an element, stated either as an array or, by plugins setting them directly, as a string.
388
+ */
389
+ function classes(node) {
390
+ const className = node.properties.className;
391
+ return Array.isArray(className) ? className.map(String)
392
+ : typeof className === "string" ? className.split(/\s+/)
393
+ : [];
394
+ }
395
+ /**
396
+ * Rewrites a link or a source naming a Markdown file to the route serving it, dropping one naming an unsafe protocol.
397
+ */
398
+ function route(url) {
399
+ const protocol = /^([^:/?#]*):/.exec(url)?.[1];
400
+ return protocol === undefined || SafeProtocol.test(protocol)
401
+ ? url.replace(/(?<=^|\/)([-\w]+)\.md(?=#|$)/, (_match, name) => name === "index" ? "" : name)
402
+ : "";
403
+ }
404
+ /**
405
+ * Turns the file name an image source ends with into words, dropping its folders, extension, query and fragment.
406
+ */
407
+ function named(src) {
408
+ const file = src.replace(/[?#].*$/, "").split("/").at(-1) ?? "";
409
+ const stem = file.replace(/\.[^.]*$/, "");
410
+ return decoded(stem).replace(/[-_\s]+/g, " ").trim();
411
+ }
412
+ /**
413
+ * Decodes a URI component, keeping it as written where it is not well formed.
414
+ */
415
+ function decoded(component) {
416
+ try {
417
+ return decodeURIComponent(component);
418
+ }
419
+ catch {
420
+ return component;
421
+ }
422
+ }
423
+ /**
424
+ * Reads the text a run of nodes shows, its whitespace collapsed.
425
+ */
426
+ function text(nodes) {
427
+ return content(nodes).replace(/\s+/g, " ").trim();
428
+ }
429
+ /**
430
+ * Reads the text a run of nodes shows, exactly as they state it.
431
+ */
432
+ function content(nodes) {
433
+ return nodes.map(node => node.type === "text" ? node.value
434
+ : node.type === "element" ? content(node.children)
435
+ : "").join("");
436
+ }
437
+ //# sourceMappingURL=index.core.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.core.js","sourceRoot":"","sources":["../src/index.core.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAuBH,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAEnD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAErD,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEjD,OAAO,EAAE,GAAG,EAAE,MAAM,yBAA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;IAC7C,OAAO,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK;QACzD,CAAC,CAAC,IAAI,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC;YACjD,CAAC,CAAC,EAAE,CACL,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACZ,CAAC"}
@@ -1,13 +1,7 @@
1
1
  import { type ComponentChildren } from "preact";
2
- import "./markdown.css";
3
- /**
4
- * Front matter values.
5
- *
6
- * Maps each key a Markdown text declares in its YAML front matter to the value it is given, read as a plain string.
7
- */
8
- export interface Meta {
9
- readonly [key: string]: string;
10
- }
2
+ import { type Meta } from "./index.core.js";
3
+ import "./index.css";
4
+ export type { Meta };
11
5
  /**
12
6
  * Creates a Markdown document.
13
7
  *
@@ -24,6 +18,15 @@ export interface Meta {
24
18
  * heading is below the view. Each entry keeps its heading to one line, ending it with an ellipsis if it is too wide
25
19
  * - **front matter**: the values the YAML front matter declares, the text itself left unrendered
26
20
  *
21
+ * A document is shown as soon as its text is in hand, with any code and shortcodes exactly as the text states them,
22
+ * and shown again the moment the colouring of a language or the table naming the shortcodes arrives. Each of those is
23
+ * downloaded only once a text a reader opens calls for it, and never again, so every document after the first shows
24
+ * them in full straight away. Data that cannot be reached leaves the text as written, so a reader always meets the
25
+ * code and the words themselves whatever the network between them and the page does.
26
+ *
27
+ * Code is coloured in the languages highlight.js curates as common and in the configuration formats a technical text
28
+ * fences, and code in any other language reads exactly as the text states it, with no grammar fetched for it.
29
+ *
27
30
  * Links to Markdown files are rewritten to the route serving them, `guide.md` to `guide` and `index.md` to the folder
28
31
  * holding it, fragments preserved, so a set of documents linking each other by file name reads as a set of pages.
29
32
  * Links and sources whose protocol is unsafe are dropped, and raw HTML in the text is never rendered.
@@ -67,4 +70,4 @@ export declare function Markdown({ meta, name, children }: {
67
70
  */
68
71
  children: string;
69
72
  }): ComponentChildren;
70
- //# sourceMappingURL=markdown.d.ts.map
73
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AA+BA,OAAO,EAAE,KAAK,iBAAiB,EAAiB,MAAM,QAAQ,CAAC;AAI/D,OAAO,EAAgD,KAAK,IAAI,EAAa,MAAM,iBAAiB,CAAC;AACrG,OAAO,aAAa,CAAC;AAErB,YAAY,EAAE,IAAI,EAAE,CAAC;AAWrB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,wBAAgB,QAAQ,CAAC,EAExB,IAAI,EACJ,IAAI,EAEJ,QAAQ,EAER,EAAE;IAEF;;;;;;;;;;;OAWG;IACH,IAAI,CAAC,EAAE,KAAK,GAAG,OAAO,MAAM,EAAE,GAAG,MAAM,GAAG,CAAC,CAAC,IAAI,EAAE,IAAI,KAAK,iBAAiB,CAAC,CAAA;IAE7E;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IAGb;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAA;CAEhB,GAAG,iBAAiB,CAgDpB"}
package/dist/index.js ADDED
@@ -0,0 +1,185 @@
1
+ import { jsx as _jsx } from "preact/jsx-runtime";
2
+ /*
3
+ * Copyright © 2026 Metreeca srl
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ /**
18
+ * Preact Markdown documents.
19
+ *
20
+ * Offers a Markdown text as the document it describes, its outline as links into that document, or the values its
21
+ * front matter declares, so a page built from Markdown sources needs no rendering pipeline of its own.
22
+ *
23
+ * @module index
24
+ */
25
+ import { useModel } from "@grafctory/clay/model";
26
+ import { TOC } from "@grafctory/clay-widgets/toc";
27
+ import { assert } from "@grafctory/core";
28
+ import { headingRank } from "hast-util-heading-rank";
29
+ import { toJsxRuntime } from "hast-util-to-jsx-runtime";
30
+ import { createElement } from "preact";
31
+ import { useEffect, useMemo } from "preact/hooks";
32
+ import { Fragment, jsx, jsxs } from "preact/jsx-runtime";
33
+ import { createResources, fetchResources, frontmatter, transform } from "./index.core.js";
34
+ import "./index.css";
35
+ /**
36
+ * The deepest heading level Markdown offers.
37
+ */
38
+ const Depth = 6;
39
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
40
+ /**
41
+ * Creates a Markdown document.
42
+ *
43
+ * Renders a Markdown text in one of three ways, as `meta` selects:
44
+ *
45
+ * - **document**, the default: the text in full, with GitHub Flavored Markdown tables, task lists and footnotes,
46
+ * GitHub alerts (`> [!NOTE]`), emoji shortcodes, fenced code highlighted by language and stripped of surrounding
47
+ * blank lines, and headings carrying the ids GitHub would give them, so links into the document resolve
48
+ * - **table of contents**: the headings of the outline, at every level or down to the level `meta` names, as a
49
+ * navigation landmark of nested lists linking each to the matching heading. It is set as the design system sets any
50
+ * outline, so it reads as quiet navigation beside the document, and is left out for a text without headings. While
51
+ * the document is on the page, the entry of the heading at the top of the viewport is marked as the current location
52
+ * and followed as the reader scrolls, so the outline shows where they stand; no entry is marked while the first
53
+ * heading is below the view. Each entry keeps its heading to one line, ending it with an ellipsis if it is too wide
54
+ * - **front matter**: the values the YAML front matter declares, the text itself left unrendered
55
+ *
56
+ * A document is shown as soon as its text is in hand, with any code and shortcodes exactly as the text states them,
57
+ * and shown again the moment the colouring of a language or the table naming the shortcodes arrives. Each of those is
58
+ * downloaded only once a text a reader opens calls for it, and never again, so every document after the first shows
59
+ * them in full straight away. Data that cannot be reached leaves the text as written, so a reader always meets the
60
+ * code and the words themselves whatever the network between them and the page does.
61
+ *
62
+ * Code is coloured in the languages highlight.js curates as common and in the configuration formats a technical text
63
+ * fences, and code in any other language reads exactly as the text states it, with no grammar fetched for it.
64
+ *
65
+ * Links to Markdown files are rewritten to the route serving them, `guide.md` to `guide` and `index.md` to the folder
66
+ * holding it, fragments preserved, so a set of documents linking each other by file name reads as a set of pages.
67
+ * Links and sources whose protocol is unsafe are dropped, and raw HTML in the text is never rendered.
68
+ *
69
+ * A document reads the same to every reader. An image the text gives no alt text is described by its title, or by its
70
+ * file name where it has none, so it is never skipped as decoration; the checkbox of a task list item is labelled by
71
+ * the text of its item; a code block takes the keyboard focus, so a reader scrolls code running past the measure
72
+ * without a pointer; and the heading of the footnotes is left to assistive technologies, as GitHub leaves it.
73
+ *
74
+ * A document scrolls the heading named by the location fragment into view as it renders and whenever the fragment
75
+ * changes, and moves the focus to it, so a link into the document lands on its target once the text is in place and
76
+ * keyboard and screen reader users carry on reading from there, rather than from where they followed the link.
77
+ *
78
+ * @param options The widget configuration
79
+ *
80
+ * @returns The rendered document, outline or front matter value
81
+ *
82
+ * @throws {@link !TypeError TypeError} If `meta` names a table of contents depth that is not an integer between 1 and 6
83
+ */
84
+ export function Markdown({ meta, name, children }) {
85
+ const { loads, loaded } = useModel(createResources);
86
+ /*
87
+ * The grammars colouring the code of a text and the table reading its shortcodes are fetched only for the texts
88
+ * naming them, so a document is rendered as soon as its text is in hand and again once they have arrived.
89
+ */
90
+ useEffect(() => {
91
+ void fetchResources(children)?.then(loaded);
92
+ }, [children]);
93
+ /*
94
+ * The heading a link points to exists only once the text is rendered, so landing on it waits for the render,
95
+ * and a fragment changing later never reloads the page, so it is followed on the window.
96
+ */
97
+ useEffect(() => {
98
+ if (meta === undefined) {
99
+ scroll();
100
+ }
101
+ }, [meta, children]);
102
+ useEffect(() => {
103
+ if (meta === undefined) {
104
+ window.addEventListener("hashchange", scroll);
105
+ return () => window.removeEventListener("hashchange", scroll);
106
+ }
107
+ else {
108
+ return undefined;
109
+ }
110
+ }, [meta]);
111
+ return useMemo(() => meta === undefined ? createElement("clay-markdown", {}, render(transform(children)))
112
+ : typeof meta === "function" ? meta(frontmatter(children))
113
+ : meta === "toc" || meta.startsWith("toc-") ? outline(transform(children), depth(meta), name)
114
+ : frontmatter(children)[meta], [meta, children, name, loads]);
115
+ }
116
+ function scroll() {
117
+ const target = document.getElementById(decodeURIComponent(location.hash.slice(1)));
118
+ target?.scrollIntoView();
119
+ target?.focus({ preventScroll: true });
120
+ }
121
+ /**
122
+ * Reads the depth of the outline a `toc` or `toc-{depth}` selector asks for, taking the deepest level Markdown
123
+ * offers where the selector names none, so a plain `toc` lists the whole outline.
124
+ *
125
+ * @throws {@link !TypeError TypeError} If the depth is not a heading level
126
+ */
127
+ function depth(meta) {
128
+ return meta === "toc" ? Depth : assert(Number(meta.slice("toc-".length)), value => Number.isInteger(value) && value >= 1 && value <= Depth, `illegal table of contents depth <${meta}>`);
129
+ }
130
+ /**
131
+ * Reduces a document to its table of contents, with one entry for each heading down to `depth`. Each entry links to its
132
+ * heading and lists the entries of the headings it introduces, so the outline mirrors the nesting of the document.
133
+ *
134
+ * The ids are left to the document, so an outline shown beside it adds no duplicate ids to the page.
135
+ */
136
+ function outline(tree, depth, name) {
137
+ const sections = nest(headings(tree), depth);
138
+ return sections.length > 0 ? _jsx(TOC, { name: name, entries: contents(sections) }) : null;
139
+ }
140
+ function headings(tree) {
141
+ return tree.children.filter((node) => headingRank(node) !== undefined);
142
+ }
143
+ /**
144
+ * Groups headings into nested sections, down to `depth`.
145
+ *
146
+ * A section holds the headings that follow its own, up to the next heading of the same or a higher level. Headings
147
+ * below `depth` are left out of the outline rather than hidden in it, so the page carries no entries for them.
148
+ */
149
+ function nest(headings, depth, level = 1) {
150
+ const [heading, ...rest] = headings;
151
+ if (heading === undefined) {
152
+ return [];
153
+ }
154
+ else {
155
+ const closing = boundary(heading, rest);
156
+ return [
157
+ { heading, nested: level < depth ? nest(rest.slice(0, closing), depth, level + 1) : [] },
158
+ ...nest(rest.slice(closing), depth, level)
159
+ ];
160
+ }
161
+ }
162
+ /**
163
+ * Turns sections into the entries of a table of contents, each linking to its heading by the id the document gives it.
164
+ */
165
+ function contents(sections) {
166
+ return sections.map(({ heading, nested }) => ({
167
+ label: render({ type: "root", children: heading.children }),
168
+ href: `#${String(heading.properties.id)}`,
169
+ entries: contents(nested)
170
+ }));
171
+ }
172
+ /**
173
+ * Locates the first heading closing the section a heading opens, the length of the headings if none does.
174
+ */
175
+ function boundary(heading, rest) {
176
+ const index = rest.findIndex(next => rank(next) <= rank(heading));
177
+ return index < 0 ? rest.length : index;
178
+ }
179
+ function rank(heading) {
180
+ return headingRank(heading) ?? 0;
181
+ }
182
+ function render(tree) {
183
+ return toJsxRuntime(tree, { Fragment, jsx, jsxs, elementAttributeNameCase: "html", stylePropertyNameCase: "css" });
184
+ }
185
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;;;;GAOG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AACjD,OAAO,EAAE,GAAG,EAAiB,MAAM,6BAA6B,CAAC;AACjE,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEzC,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAA0B,aAAa,EAAE,MAAM,QAAQ,CAAC;AAC/D,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAEzD,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,WAAW,EAAa,SAAS,EAAE,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M,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC,EAAE;QACzC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC;KACzB,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,SAAS,QAAQ,CAAC,OAAgB,EAAE,IAAwB;IAE3D,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;IAElE,OAAO,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC;AAExC,CAAC;AAED,SAAS,IAAI,CAAC,OAAgB;IAC7B,OAAO,WAAW,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;AAClC,CAAC;AAED,SAAS,MAAM,CAAC,IAAU;IACzB,OAAO,YAAY,CAAC,IAAI,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,IAAI,EAAE,wBAAwB,EAAE,MAAM,EAAE,qBAAqB,EAAE,KAAK,EAAE,CAAC,CAAC;AACpH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grafctory/clay-markdown",
3
- "version": "0.4.1",
3
+ "version": "0.6.0",
4
4
  "description": "Preact Markdown documents for @grafctory/clay.",
5
5
  "keywords": [
6
6
  "typescript",
@@ -10,7 +10,7 @@
10
10
  "homepage": "https://grafctory.github.io/clay/",
11
11
  "bugs": {
12
12
  "url": "https://github.com/grafctory/clay/issues",
13
- "email": "info@metreeca.com"
13
+ "email": "info@grafctory.dev"
14
14
  },
15
15
  "license": "Apache-2.0",
16
16
  "author": {
@@ -28,15 +28,14 @@
28
28
  "*.css"
29
29
  ],
30
30
  "exports": {
31
- "./*": {
32
- "@grafctory/source": "./src/*.tsx",
33
- "default": "./dist/*.js"
31
+ ".": {
32
+ "@grafctory/source": "./src/index.tsx",
33
+ "default": "./dist/index.js"
34
34
  },
35
- "./*.css": {
36
- "@grafctory/source": "./src/*.css",
37
- "default": "./dist/*.css"
38
- },
39
- "./*.core": null
35
+ "./index.css": {
36
+ "@grafctory/source": "./src/index.css",
37
+ "default": "./dist/index.css"
38
+ }
40
39
  },
41
40
  "files": [
42
41
  "README.md",
@@ -52,15 +51,18 @@
52
51
  "check": "npx vitest --config ../../vitest.config.ts --root . --typecheck --passWithNoTests run"
53
52
  },
54
53
  "dependencies": {
55
- "@grafctory/clay-widgets": "^0.4.1",
56
- "@grafctory/core": "^0.14.0",
54
+ "@grafctory/clay-widgets": "^0.6.0",
55
+ "@grafctory/core": "^0.14.3",
56
+ "gemoji": "^8.1.0",
57
57
  "hast-util-heading-rank": "^3.0.0",
58
58
  "hast-util-to-jsx-runtime": "^2.3.7",
59
- "rehype-highlight": "^7.0.2",
59
+ "highlight.js": "^11.11.2",
60
+ "lowlight": "^3.3.0",
61
+ "mdast-util-find-and-replace": "^3.0.5",
62
+ "mdast-util-gfm": "^3.1.0",
63
+ "micromark-extension-gfm": "^3.0.0",
60
64
  "rehype-slug": "^6.0.0",
61
65
  "remark-frontmatter": "^5.0.0",
62
- "remark-gemoji": "^8.0.0",
63
- "remark-gfm": "^4.0.1",
64
66
  "remark-github-blockquote-alert": "^2.1.0",
65
67
  "remark-parse": "^11.0.0",
66
68
  "remark-rehype": "^11.1.2",
@@ -68,8 +70,10 @@
68
70
  "unist-util-visit": "^5.2.0"
69
71
  },
70
72
  "devDependencies": {
73
+ "@grafctory/clay": "^0.6.0",
71
74
  "@types/hast": "^3.0.5",
72
75
  "@types/mdast": "^4.0.4",
76
+ "@types/node": "^26.6.6",
73
77
  "happy-dom": "^21.0.4",
74
78
  "preact": "^10.29.8",
75
79
  "typescript": "^6.0.3",
@@ -77,6 +81,7 @@
77
81
  "vitest": "^5.0.5"
78
82
  },
79
83
  "peerDependencies": {
84
+ "@grafctory/clay": "^0.6.0",
80
85
  "preact": "^10.27.2"
81
86
  }
82
87
  }
@@ -1 +0,0 @@
1
- {"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../src/markdown.tsx"],"names":[],"mappings":"AA+BA,OAAO,EAAE,KAAK,iBAAiB,EAAiB,MAAM,QAAQ,CAAC;AAa/D,OAAO,gBAAgB,CAAC;AAmDxB;;;;GAIG;AACH,MAAM,WAAW,IAAI;IAEpB,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;CAE/B;AAKD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAgB,QAAQ,CAAC,EAExB,IAAI,EACJ,IAAI,EAEJ,QAAQ,EAER,EAAE;IAEF;;;;;;;;;;;OAWG;IACH,IAAI,CAAC,EAAE,KAAK,GAAG,OAAO,MAAM,EAAE,GAAG,MAAM,GAAG,CAAC,CAAC,IAAI,EAAE,IAAI,KAAK,iBAAiB,CAAC,CAAA;IAE7E;;;OAGG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;IAGb;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAA;CAEhB,GAAG,iBAAiB,CAoCpB"}
package/dist/markdown.js DELETED
@@ -1,335 +0,0 @@
1
- import { jsx as _jsx } from "preact/jsx-runtime";
2
- /*
3
- * Copyright © 2026 Metreeca srl
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- */
17
- /**
18
- * Markdown document.
19
- *
20
- * Offers a Markdown text as the document it describes, its outline as links into that document, or the values its
21
- * front matter declares, so a page built from Markdown sources needs no rendering pipeline of its own.
22
- *
23
- * @module
24
- */
25
- import { TOC } from "@grafctory/clay-widgets/toc";
26
- import { assert } from "@grafctory/core";
27
- import { headingRank } from "hast-util-heading-rank";
28
- import { toJsxRuntime } from "hast-util-to-jsx-runtime";
29
- import { createElement } from "preact";
30
- import { useEffect, useMemo } from "preact/hooks";
31
- import { Fragment, jsx, jsxs } from "preact/jsx-runtime";
32
- import rehypeHighlight from "rehype-highlight";
33
- import rehypeSlug from "rehype-slug";
34
- import remarkFrontmatter from "remark-frontmatter";
35
- import remarkGemoji from "remark-gemoji";
36
- import remarkGfm from "remark-gfm";
37
- import { remarkAlert } from "remark-github-blockquote-alert";
38
- import remarkParse from "remark-parse";
39
- import remarkRehype from "remark-rehype";
40
- import { unified } from "unified";
41
- import { visit } from "unist-util-visit";
42
- import "./markdown.css";
43
- /*
44
- * !!! bundle size: the module adds ~390 kB minified (~125 kB gzipped) to a consumer bundle, mostly highlight.js
45
- * grammars, since rehype-highlight statically imports the 37 lowlight `common` ones as its default `languages`, so
46
- * they ship even when unused. Lazy-loading them takes a lowlight-based highlighter of our own over `createLowlight()`,
47
- * importing grammars on demand for the languages a text names and highlighting again once they are registered.
48
- */
49
- /**
50
- * The protocols a link or a source may name; anything else could run script or load content from outside the page.
51
- */
52
- const SafeProtocol = /^(https?|ircs?|mailto|xmpp)$/i;
53
- /**
54
- * An image source ending with a percentage of the width of the block holding the image, from `#1` to `#100`.
55
- */
56
- const WidthHint = /^(.*)#([1-9]\d?|100)$/;
57
- /**
58
- * The deepest heading level Markdown offers.
59
- */
60
- const Depth = 6;
61
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
62
- const front = unified()
63
- .use(remarkParse)
64
- .use(remarkFrontmatter);
65
- const pipeline = unified()
66
- .use(remarkParse)
67
- .use(remarkFrontmatter)
68
- .use(remarkGfm)
69
- .use(remarkAlert)
70
- .use(remarkGemoji)
71
- .use(remarkCode)
72
- .use(remarkRehype)
73
- .use(rehypeSlug)
74
- .use(rehypeHighlight)
75
- .use(rehypeAlerts)
76
- .use(rehypeLinks)
77
- .use(rehypeImages)
78
- .use(rehypeAccess);
79
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
80
- /**
81
- * Creates a Markdown document.
82
- *
83
- * Renders a Markdown text in one of three ways, as `meta` selects:
84
- *
85
- * - **document**, the default: the text in full, with GitHub Flavored Markdown tables, task lists and footnotes,
86
- * GitHub alerts (`> [!NOTE]`), emoji shortcodes, fenced code highlighted by language and stripped of surrounding
87
- * blank lines, and headings carrying the ids GitHub would give them, so links into the document resolve
88
- * - **table of contents**: the headings of the outline, at every level or down to the level `meta` names, as a
89
- * navigation landmark of nested lists linking each to the matching heading. It is set as the design system sets any
90
- * outline, so it reads as quiet navigation beside the document, and is left out for a text without headings. While
91
- * the document is on the page, the entry of the heading at the top of the viewport is marked as the current location
92
- * and followed as the reader scrolls, so the outline shows where they stand; no entry is marked while the first
93
- * heading is below the view. Each entry keeps its heading to one line, ending it with an ellipsis if it is too wide
94
- * - **front matter**: the values the YAML front matter declares, the text itself left unrendered
95
- *
96
- * Links to Markdown files are rewritten to the route serving them, `guide.md` to `guide` and `index.md` to the folder
97
- * holding it, fragments preserved, so a set of documents linking each other by file name reads as a set of pages.
98
- * Links and sources whose protocol is unsafe are dropped, and raw HTML in the text is never rendered.
99
- *
100
- * A document reads the same to every reader. An image the text gives no alt text is described by its title, or by its
101
- * file name where it has none, so it is never skipped as decoration; the checkbox of a task list item is labelled by
102
- * the text of its item; a code block takes the keyboard focus, so a reader scrolls code running past the measure
103
- * without a pointer; and the heading of the footnotes is left to assistive technologies, as GitHub leaves it.
104
- *
105
- * A document scrolls the heading named by the location fragment into view as it renders and whenever the fragment
106
- * changes, and moves the focus to it, so a link into the document lands on its target once the text is in place and
107
- * keyboard and screen reader users carry on reading from there, rather than from where they followed the link.
108
- *
109
- * @param options The widget configuration
110
- *
111
- * @returns The rendered document, outline or front matter value
112
- *
113
- * @throws {@link !TypeError TypeError} If `meta` names a table of contents depth that is not an integer between 1 and 6
114
- */
115
- export function Markdown({ meta, name, children }) {
116
- /*
117
- * The heading a link points to exists only once the text is rendered, so landing on it waits for the render,
118
- * and a fragment changing later never reloads the page, so it is followed on the window.
119
- */
120
- useEffect(() => {
121
- if (meta === undefined) {
122
- scroll();
123
- }
124
- }, [meta, children]);
125
- useEffect(() => {
126
- if (meta === undefined) {
127
- window.addEventListener("hashchange", scroll);
128
- return () => window.removeEventListener("hashchange", scroll);
129
- }
130
- else {
131
- return undefined;
132
- }
133
- }, [meta]);
134
- return useMemo(() => meta === undefined ? createElement("clay-markdown", {}, render(transform(children)))
135
- : meta === "toc" ? outline(transform(children), Depth, name)
136
- : typeof meta === "function" ? meta(entries(children))
137
- : meta.startsWith("toc-") ? outline(transform(children), depth(meta), name)
138
- : entries(children)[meta], [meta, children, name]);
139
- }
140
- function scroll() {
141
- const target = document.getElementById(decodeURIComponent(location.hash.slice(1)));
142
- target?.scrollIntoView();
143
- target?.focus({ preventScroll: true });
144
- }
145
- function entries(text) {
146
- const yaml = front.parse(text).children.find(node => node.type === "yaml");
147
- return Object.fromEntries(Array.from(yaml?.value.matchAll(/^\s*(\w+)\s*:\s*(.*?)\s*$/gm) ?? [], ([, key, value]) => [key, value]));
148
- }
149
- function transform(text) {
150
- return pipeline.runSync(pipeline.parse(text));
151
- }
152
- /**
153
- * Reads the depth of the outline from a `toc-{depth}` selector.
154
- *
155
- * @throws {@link !TypeError TypeError} If the depth is not a heading level
156
- */
157
- function depth(meta) {
158
- return assert(Number(meta.slice("toc-".length)), value => Number.isInteger(value) && value >= 1 && value <= Depth, `illegal table of contents depth <${meta}>`);
159
- }
160
- /**
161
- * Reduces a document to its table of contents, with one entry for each heading down to `depth`. Each entry links to its
162
- * heading and lists the entries of the headings it introduces, so the outline mirrors the nesting of the document.
163
- *
164
- * The ids are left to the document, so an outline shown beside it adds no duplicate ids to the page.
165
- */
166
- function outline(tree, depth, name) {
167
- const sections = nest(headings(tree), depth);
168
- return sections.length > 0 ? _jsx(TOC, { name: name, entries: contents(sections) }) : null;
169
- }
170
- function headings(tree) {
171
- return tree.children.filter((node) => headingRank(node) !== undefined);
172
- }
173
- /**
174
- * Groups headings into nested sections, down to `depth`.
175
- *
176
- * A section holds the headings that follow its own, up to the next heading of the same or a higher level. Headings
177
- * below `depth` are left out of the outline rather than hidden in it, so the page carries no entries for them.
178
- */
179
- function nest(headings, depth, level = 1) {
180
- const [heading, ...rest] = headings;
181
- return heading === undefined ? [] : [
182
- { heading, nested: level < depth ? nest(rest.slice(0, boundary(heading, rest)), depth, level + 1) : [] },
183
- ...nest(rest.slice(boundary(heading, rest)), depth, level)
184
- ];
185
- }
186
- /**
187
- * Turns sections into the entries of a table of contents, each linking to its heading by the id the document gives it.
188
- */
189
- function contents(sections) {
190
- return sections.map(({ heading, nested }) => ({
191
- label: render({ type: "root", children: heading.children }),
192
- href: `#${String(heading.properties.id)}`,
193
- entries: contents(nested)
194
- }));
195
- }
196
- /**
197
- * Locates the first heading closing the section a heading opens, the length of the headings if none does.
198
- */
199
- function boundary(heading, rest) {
200
- const index = rest.findIndex(next => rank(next) <= rank(heading));
201
- return index < 0 ? rest.length : index;
202
- }
203
- function rank(heading) {
204
- return headingRank(heading) ?? 0;
205
- }
206
- function render(tree) {
207
- return toJsxRuntime(tree, { Fragment, jsx, jsxs, elementAttributeNameCase: "html", stylePropertyNameCase: "css" });
208
- }
209
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
210
- /**
211
- * Strips fenced code of surrounding blank lines and halves its indentation, so code pasted from a source file
212
- * reads at the width of the document rather than at the width of the editor it was copied from.
213
- */
214
- function remarkCode() {
215
- return (tree) => visit(tree, "code", node => {
216
- // ;(mutation) unified transformers edit the tree they are handed in place
217
- node.value = node.value
218
- .replace(/^\s+|\s+$/g, "")
219
- .replace(/^[ \t]+/mg, indent => indent.replace(/ {4}|\t/g, " "));
220
- });
221
- }
222
- /**
223
- * Titles GitHub alerts in sentence case, `Caution` rather than `CAUTION`, as GitHub itself renders them.
224
- */
225
- function rehypeAlerts() {
226
- return (tree) => visit(tree, "element", node => {
227
- // ;(mutation) unified transformers edit the tree they are handed in place
228
- if (classes(node).includes("markdown-alert-title")) {
229
- node.children = node.children.map(child => child.type === "text"
230
- ? { ...child, value: child.value.replace(/\p{L}+/u, word => word[0] + word.slice(1).toLowerCase()) }
231
- : child);
232
- }
233
- });
234
- }
235
- /**
236
- * Lists the classes of an element, stated either as an array or, by plugins setting them directly, as a string.
237
- */
238
- function classes(node) {
239
- const className = node.properties.className;
240
- return Array.isArray(className) ? className
241
- : typeof className === "string" ? className.split(/\s+/)
242
- : [];
243
- }
244
- /**
245
- * Drops links and sources naming an unsafe protocol, and rewrites those naming a Markdown file to the route serving
246
- * it, `guide.md` to `guide` and `index.md` to its folder, fragments preserved, so linked documents read as pages.
247
- */
248
- function rehypeLinks() {
249
- return (tree) => visit(tree, "element", node => {
250
- // ;(mutation) unified transformers edit the tree they are handed in place
251
- node.properties = Object.fromEntries(Object.entries(node.properties).map(([name, value]) => [name, (name === "href" || name === "src") && typeof value === "string" ? route(value) : value]));
252
- });
253
- }
254
- function route(url) {
255
- const protocol = /^([^:/?#]*):/.exec(url)?.[1];
256
- return protocol === undefined || SafeProtocol.test(protocol)
257
- ? url.replace(/(?<=^|\/)([-\w]+)\.md(?=#|$)/, (_match, name) => name === "index" ? "" : name)
258
- : "";
259
- }
260
- /**
261
- * Sizes images whose source ends with a percentage hint, `chart.png#50` to half the width of the block holding it,
262
- * dropping the hint from the source, so a text sets the relative size of a picture without resorting to raw HTML.
263
- */
264
- function rehypeImages() {
265
- return (tree) => visit(tree, "element", node => {
266
- const src = node.properties.src;
267
- const hint = node.tagName === "img" && typeof src === "string" ? WidthHint.exec(src) : null;
268
- // ;(mutation) unified transformers edit the tree they are handed in place
269
- if (hint !== null) {
270
- node.properties = {
271
- ...node.properties,
272
- src: hint[1],
273
- style: `--clay-markdown-width: ${hint[2]}%`
274
- };
275
- }
276
- if (node.tagName === "img" && !node.properties.alt) {
277
- node.properties = {
278
- ...node.properties,
279
- alt: typeof node.properties.title === "string" && node.properties.title.trim()
280
- ? node.properties.title.trim()
281
- : typeof node.properties.src === "string" ? named(node.properties.src) : ""
282
- };
283
- }
284
- });
285
- }
286
- /**
287
- * Turns the file name an image source ends with into words, dropping its folders, extension, query and fragment.
288
- */
289
- function named(src) {
290
- const file = src.replace(/[?#].*$/, "").split("/").at(-1) ?? "";
291
- const stem = file.replace(/\.[^.]*$/, "");
292
- return decoded(stem).replace(/[-_\s]+/g, " ").trim();
293
- }
294
- /**
295
- * Decodes a URI component, keeping it as written where it is not well formed.
296
- */
297
- function decoded(component) {
298
- try {
299
- return decodeURIComponent(component);
300
- }
301
- catch {
302
- return component;
303
- }
304
- }
305
- /**
306
- * Supplies what the rendered markup owes assistive technologies and keyboard users beyond what Markdown states: a
307
- * label for the checkbox of a task list item, the keyboard focus for a code block scrolling past the measure, and a
308
- * focus target for a heading a fragment lands on, reachable by script but kept out of the tab order.
309
- */
310
- function rehypeAccess() {
311
- return (tree) => visit(tree, "element", node => {
312
- // ;(mutation) unified transformers edit the tree they are handed in place
313
- if (node.tagName === "li" && classes(node).includes("task-list-item")) {
314
- const label = text(node.children.filter(child => !(child.type === "element" && /^(ul|ol)$/.test(child.tagName))));
315
- node.children = node.children.map(child => child.type === "element" && child.tagName === "input"
316
- ? { ...child, properties: { ...child.properties, ariaLabel: label } }
317
- : child);
318
- }
319
- else if (node.tagName === "pre") {
320
- node.properties = { ...node.properties, tabIndex: 0 };
321
- }
322
- else if (headingRank(node) !== undefined) {
323
- node.properties = { ...node.properties, tabIndex: -1 };
324
- }
325
- });
326
- }
327
- /**
328
- * Reads the text a run of nodes shows, its whitespace collapsed.
329
- */
330
- function text(nodes) {
331
- return nodes.map(node => node.type === "text" ? node.value
332
- : node.type === "element" ? text(node.children)
333
- : "").join("").replace(/\s+/g, " ").trim();
334
- }
335
- //# sourceMappingURL=markdown.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"markdown.js","sourceRoot":"","sources":["../src/markdown.tsx"],"names":[],"mapp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