@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.
@@ -0,0 +1,4 @@
1
+ "use client";
2
+
3
+ // src/katex-styles.ts
4
+ import "../katex.css";
package/dist/lazy.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ import * as React from 'react';
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';
7
+
8
+ /**
9
+ * Loads the engines a body needs (both when `markdown` is omitted). Await it before a server
10
+ * render or a hydration that must match the eager entry's HTML.
11
+ */
12
+ declare function preloadMarkdownRuntime(markdown?: string): Promise<void>;
13
+ /** `<Markdown>` with its engines loaded on demand (see the module comment). Same props. */
14
+ declare function Markdown(props: MarkdownProps): React.JSX.Element;
15
+
16
+ export { Markdown, MarkdownProps, preloadMarkdownRuntime };
package/dist/lazy.js ADDED
@@ -0,0 +1,126 @@
1
+ "use client";
2
+ import {
3
+ MARKDOWN_FIXTURES,
4
+ MARKDOWN_FORMAT,
5
+ MarkdownCore,
6
+ MermaidDiagram,
7
+ RENDERER_VERSION,
8
+ checkMermaidSvg,
9
+ extendSchema,
10
+ fromMarkdownExtensions,
11
+ markdownSchema,
12
+ micromarkExtensions,
13
+ rehypeHeadingIds,
14
+ safeUrl
15
+ } from "./chunk-RRNN4HLQ.js";
16
+ import "./chunk-ANYWBQJT.js";
17
+ import "./chunk-AKKOCR2Y.js";
18
+
19
+ // src/lazy.tsx
20
+ import * as React from "react";
21
+
22
+ // src/codec/parse.ts
23
+ import { fromMarkdown } from "mdast-util-from-markdown";
24
+ import { toMarkdown } from "mdast-util-to-markdown";
25
+ function parseMdast(markdown) {
26
+ return fromMarkdown(markdown, {
27
+ extensions: micromarkExtensions(),
28
+ mdastExtensions: fromMarkdownExtensions()
29
+ });
30
+ }
31
+
32
+ // src/lazy.tsx
33
+ import { jsx } from "react/jsx-runtime";
34
+ var loaded = {};
35
+ var mathLoad;
36
+ var highlightLoad;
37
+ function loadMath() {
38
+ mathLoad ??= Promise.all([
39
+ import("./math-DOI7WLLZ.js"),
40
+ // The stylesheet only where there is a document to style (a server has none, and cannot
41
+ // import CSS).
42
+ typeof document === "undefined" ? void 0 : import("./katex-styles-JVRNFDYG.js")
43
+ ]).then(
44
+ ([math]) => {
45
+ loaded.math = math.rehypeMath;
46
+ },
47
+ (error) => {
48
+ mathLoad = void 0;
49
+ throw error;
50
+ }
51
+ );
52
+ return mathLoad;
53
+ }
54
+ function loadHighlight() {
55
+ highlightLoad ??= import("./highlight-TYIW3L3V.js").then(
56
+ (highlight) => {
57
+ loaded.highlight = highlight.rehypeHighlight;
58
+ },
59
+ (error) => {
60
+ highlightLoad = void 0;
61
+ throw error;
62
+ }
63
+ );
64
+ return highlightLoad;
65
+ }
66
+ function needsOf(tree) {
67
+ const needs = { math: false, highlight: false };
68
+ const walk = (node) => {
69
+ if (node.type === "inlineMath" || node.type === "math") needs.math = true;
70
+ else if (node.type === "code" && node.lang) {
71
+ if (node.lang === "math") needs.math = true;
72
+ else if (node.lang !== "mermaid") needs.highlight = true;
73
+ }
74
+ if ("children" in node) for (const child of node.children) walk(child);
75
+ };
76
+ walk(tree);
77
+ return needs;
78
+ }
79
+ function preloadMarkdownRuntime(markdown) {
80
+ const needs = markdown === void 0 ? { math: true, highlight: true } : needsOf(parseMdast(markdown));
81
+ return Promise.all([
82
+ needs.math ? loadMath() : void 0,
83
+ needs.highlight ? loadHighlight() : void 0
84
+ ]).then(() => void 0);
85
+ }
86
+ function Markdown(props) {
87
+ const needs = React.useRef({ math: false, highlight: false });
88
+ const [, rerender] = React.useReducer((n) => n + 1, 0);
89
+ const probe = React.useMemo(
90
+ () => () => (tree) => {
91
+ needs.current = needsOf(tree);
92
+ },
93
+ []
94
+ );
95
+ const highlight = props.highlight !== false;
96
+ React.useEffect(() => {
97
+ const pending = [
98
+ needs.current.math && !loaded.math ? loadMath() : void 0,
99
+ highlight && needs.current.highlight && !loaded.highlight ? loadHighlight() : void 0
100
+ ].filter(Boolean);
101
+ if (pending.length === 0) return;
102
+ let mounted = true;
103
+ Promise.all(pending).then(
104
+ () => mounted && rerender(),
105
+ () => void 0
106
+ // the fallback stays: a body without colour is still the body
107
+ );
108
+ return () => {
109
+ mounted = false;
110
+ };
111
+ });
112
+ return /* @__PURE__ */ jsx(MarkdownCore, { ...props, runtime: { math: loaded.math, highlight: loaded.highlight, probe } });
113
+ }
114
+ export {
115
+ MARKDOWN_FIXTURES,
116
+ MARKDOWN_FORMAT,
117
+ Markdown,
118
+ MermaidDiagram,
119
+ RENDERER_VERSION,
120
+ checkMermaidSvg,
121
+ extendSchema,
122
+ markdownSchema,
123
+ preloadMarkdownRuntime,
124
+ rehypeHeadingIds,
125
+ safeUrl
126
+ };
@@ -0,0 +1,13 @@
1
+ "use client";
2
+ import {
3
+ rehypeMath
4
+ } from "./chunk-JJ2A3D7U.js";
5
+ import {
6
+ KATEX_OPTIONS,
7
+ katexSchema
8
+ } from "./chunk-AKKOCR2Y.js";
9
+ export {
10
+ KATEX_OPTIONS,
11
+ katexSchema,
12
+ rehypeMath
13
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@godxjp/markdown",
3
- "version": "33.21.0",
3
+ "version": "33.22.1",
4
4
  "description": "The one Markdown renderer for GoDX apps: GFM + heading anchors, KaTeX math, highlighted code, one sanitiser schema, a shared fixture corpus, and Mermaid drawn only after its SVG passes a fail-closed gate.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -11,6 +11,10 @@
11
11
  "types": "./dist/index.d.ts",
12
12
  "import": "./dist/index.js"
13
13
  },
14
+ "./lazy": {
15
+ "types": "./dist/lazy.d.ts",
16
+ "import": "./dist/lazy.js"
17
+ },
14
18
  "./codec": {
15
19
  "types": "./dist/codec/index.d.ts",
16
20
  "import": "./dist/codec/index.js"
@@ -19,7 +23,8 @@
19
23
  "./package.json": "./package.json"
20
24
  },
21
25
  "sideEffects": [
22
- "*.css"
26
+ "*.css",
27
+ "./dist/katex-styles-*.js"
23
28
  ],
24
29
  "files": [
25
30
  "dist",
@@ -1,71 +0,0 @@
1
- /**
2
- * The codec's document: plain JSON in the ProseMirror/Tiptap shape (`type` / `attrs` / `content` /
3
- * `text` / `marks`), so `@godxjp/block-editor` loads it with `setContent` and hands back what
4
- * `getJSON()` returns. No DOM, no editor instance — this module runs in a Worker (gh#1156).
5
- *
6
- * Node names follow Tiptap's StarterKit / Table / Details extensions where one exists:
7
- * doc · paragraph · heading{level} · blockquote · codeBlock{language} · horizontalRule ·
8
- * bulletList{tight} · orderedList{start,tight} · listItem · taskList{tight} · taskItem{checked} ·
9
- * table · tableRow · tableHeader{align} · tableCell{align} · image{src,alt,title} · hardBreak
10
- * and the kit's own:
11
- * callout{kind,title} · details · detailsSummary · detailsContent · columns · column{width} ·
12
- * embed{target} (block `![[x]]`) · wikilink{target,heading,label} · embedInline{target} ·
13
- * rawBlock{source} · rawInline{source} · frontmatter{source} (YAML, first block only)
14
- * Marks: bold · italic · strike · code · link{href,title}.
15
- */
16
- type Mark = {
17
- type: "bold" | "italic" | "strike" | "code";
18
- } | {
19
- type: "link";
20
- attrs: {
21
- href: string;
22
- title: string | null;
23
- };
24
- };
25
- type DocNode = {
26
- type: string;
27
- attrs?: Record<string, unknown>;
28
- content?: DocNode[];
29
- text?: string;
30
- marks?: Mark[];
31
- };
32
- type Doc = DocNode & {
33
- type: "doc";
34
- content: DocNode[];
35
- };
36
- /** GitHub alert kinds, the only callouts v1 knows. Serialized uppercase. */
37
- declare const CALLOUT_KINDS: readonly ["note", "tip", "important", "warning", "caution"];
38
- type CalloutKind = (typeof CALLOUT_KINDS)[number];
39
- /** Columns per `:::columns` block (grammar v1). */
40
- declare const COLUMNS_MIN = 2;
41
- declare const COLUMNS_MAX = 4;
42
-
43
- /** Markdown → document (plain JSON, ProseMirror/Tiptap shape). Pure: no DOM. */
44
- declare function parse(markdown: string): Doc;
45
-
46
- type OutlineEntry = {
47
- depth: number;
48
- text: string;
49
- id: string;
50
- };
51
- /**
52
- * The body's headings with the ids `<Markdown>` gives them — GitHub slugs, de-duplicated in
53
- * document order, the renderer's default rule — for a table of contents (the kit's `Anchor`). Pure.
54
- * A host that passes its own `headingId` resolver to `<Markdown>` must use that same resolver here.
55
- */
56
- declare function outline(markdown: string): OutlineEntry[];
57
- /** The body's YAML front matter, verbatim (without the `---` fences), or null. Parse it with your YAML library. */
58
- declare function frontmatterOf(markdown: string): string | null;
59
-
60
- /** Document → canonical Markdown. Pure: no DOM. */
61
- declare function serialize(doc: Doc | DocNode): string;
62
-
63
- /**
64
- * Identifies the serializer's output. Bumped whenever `serialize` would write a stored body
65
- * differently, so a host can tell which normalization a saved `normalized_body` came from.
66
- */
67
- declare const CODEC_ID = "kit-md@2";
68
- /** `serialize(parse(markdown))` — the canonical form of a body, exactly what the editor saves. */
69
- declare function normalize(markdown: string): string;
70
-
71
- export { CALLOUT_KINDS, CODEC_ID, COLUMNS_MAX, COLUMNS_MIN, type CalloutKind, type Doc, type DocNode, type Mark, type OutlineEntry, frontmatterOf, normalize, outline, parse, serialize };