@canofold/markdown 0.2.1 → 0.3.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/dist/{Markdown-DgolXL7g.js → Markdown-C7O01MRv.js} +2 -2
- package/dist/compiler/analyze.d.ts +11 -0
- package/dist/compiler/plugins.d.ts +2 -0
- package/dist/compiler/types.d.ts +6 -0
- package/dist/{directiveValidation-CwXRsn5k.js → directiveValidation-BdVbgcY_.js} +1 -1
- package/dist/index.js +2 -2
- package/dist/{plugins-CeQ-Bo89.js → plugins-StkCS2su.js} +18 -8
- package/dist/{prepareMarkdown-Bug1ncYk.js → prepareMarkdown-D-bFl1_V.js} +303 -298
- package/dist/server/analyze.d.ts +1 -1
- package/dist/server/analyze.js +104 -86
- package/dist/server.js +60 -55
- package/package.json +2 -2
package/dist/server/analyze.d.ts
CHANGED
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
export { detectMarkdownAssets } from '../compiler/assets';
|
|
3
3
|
export { analyzeMarkdown } from '../compiler/analyze';
|
|
4
4
|
export { analyzeMdxModuleBoundary } from '../compiler/mdxModules';
|
|
5
|
-
export type { AnalyzeMarkdownOptions, MarkdownAnalysis, MarkdownCodeExample, MarkdownHeading } from '../compiler/analyze';
|
|
5
|
+
export type { AnalyzeMarkdownOptions, MarkdownAnalysis, MarkdownCodeExample, MarkdownDirective, MarkdownHeading } from '../compiler/analyze';
|
|
6
6
|
export type { MdxImportBinding, MdxImportDeclaration, MdxModuleBoundary } from '../compiler/mdxModules';
|
package/dist/server/analyze.js
CHANGED
|
@@ -1,132 +1,150 @@
|
|
|
1
|
-
import { n as
|
|
2
|
-
import { d as
|
|
3
|
-
import
|
|
4
|
-
import { remarkDefinitionList as
|
|
5
|
-
import
|
|
6
|
-
import
|
|
1
|
+
import { n as w, c as x } from "../directiveValidation-BdVbgcY_.js";
|
|
2
|
+
import { d as V } from "../directiveValidation-BdVbgcY_.js";
|
|
3
|
+
import b from "github-slugger";
|
|
4
|
+
import { remarkDefinitionList as D } from "remark-definition-list";
|
|
5
|
+
import M from "remark-directive";
|
|
6
|
+
import E from "remark-gfm";
|
|
7
7
|
import S from "remark-parse";
|
|
8
|
-
import { unified as
|
|
9
|
-
import { visit as
|
|
10
|
-
import { a as
|
|
11
|
-
import { createProcessor as
|
|
12
|
-
function
|
|
8
|
+
import { unified as I } from "unified";
|
|
9
|
+
import { visit as k } from "unist-util-visit";
|
|
10
|
+
import { a as j, n as C, m as A } from "../plugins-StkCS2su.js";
|
|
11
|
+
import { createProcessor as L } from "@mdx-js/mdx";
|
|
12
|
+
function P(t) {
|
|
13
13
|
return "children" in t && Array.isArray(t.children);
|
|
14
14
|
}
|
|
15
|
-
function
|
|
16
|
-
return t.type === "text" || t.type === "inlineCode" ? String(t.value ?? "") : t.type === "image" ? String(t.alt ?? "") : t.type === "code" || t.type === "html" || t.type === "definition" ? "" :
|
|
15
|
+
function l(t) {
|
|
16
|
+
return t.type === "text" || t.type === "inlineCode" ? String(t.value ?? "") : t.type === "image" ? String(t.alt ?? "") : t.type === "code" || t.type === "html" || t.type === "definition" ? "" : P(t) ? t.children.map(l).join(" ") : "";
|
|
17
17
|
}
|
|
18
|
-
function
|
|
19
|
-
const
|
|
18
|
+
function H(t, i = {}) {
|
|
19
|
+
const n = I().use(S).use(D).use(E).use(M).parse(w(t)), c = new b(), f = [], s = [], o = [], m = [], y = [];
|
|
20
20
|
let g = 0;
|
|
21
21
|
const u = /* @__PURE__ */ new Map();
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}),
|
|
25
|
-
if (
|
|
26
|
-
const
|
|
27
|
-
|
|
22
|
+
k(n, "definition", (r) => {
|
|
23
|
+
r.url && u.set(r.identifier.toLowerCase(), r.url);
|
|
24
|
+
}), k(n, (r) => {
|
|
25
|
+
if (r.type === "heading") {
|
|
26
|
+
const e = r, a = l(e).replace(/\s+/g, " ").trim();
|
|
27
|
+
f.push({ level: e.depth, text: a, slug: c.slug(a) });
|
|
28
28
|
}
|
|
29
|
-
if (
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
language:
|
|
33
|
-
...
|
|
34
|
-
code:
|
|
29
|
+
if (r.type === "code") {
|
|
30
|
+
const e = r;
|
|
31
|
+
e.lang || (g += 1), s.push({
|
|
32
|
+
language: e.lang || "text",
|
|
33
|
+
...e.meta ? { meta: e.meta } : {},
|
|
34
|
+
code: e.value
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
|
-
if (
|
|
38
|
-
const
|
|
39
|
-
|
|
37
|
+
if (r.type === "link") {
|
|
38
|
+
const e = r;
|
|
39
|
+
e.url && o.push(e.url);
|
|
40
|
+
}
|
|
41
|
+
if (r.type === "image") {
|
|
42
|
+
const e = r;
|
|
43
|
+
e.url && m.push(e.url);
|
|
40
44
|
}
|
|
41
|
-
if (
|
|
42
|
-
const
|
|
43
|
-
|
|
45
|
+
if (r.type === "linkReference") {
|
|
46
|
+
const e = r, a = u.get(e.identifier.toLowerCase());
|
|
47
|
+
a && o.push(a);
|
|
44
48
|
}
|
|
45
|
-
if (
|
|
46
|
-
const
|
|
47
|
-
a &&
|
|
49
|
+
if (r.type === "imageReference") {
|
|
50
|
+
const e = r, a = u.get(e.identifier.toLowerCase());
|
|
51
|
+
a && m.push(a);
|
|
48
52
|
}
|
|
49
|
-
if (
|
|
50
|
-
const
|
|
51
|
-
|
|
53
|
+
if (r.type === "containerDirective" || r.type === "leafDirective" || r.type === "textDirective") {
|
|
54
|
+
const e = r;
|
|
55
|
+
y.push({
|
|
56
|
+
name: e.name,
|
|
57
|
+
type: e.type,
|
|
58
|
+
label: l(e).replace(/\s+/g, " ").trim(),
|
|
59
|
+
attributes: Object.fromEntries(
|
|
60
|
+
Object.entries(e.attributes ?? {}).flatMap(
|
|
61
|
+
([a, h]) => typeof h == "string" ? [[a, h]] : []
|
|
62
|
+
)
|
|
63
|
+
),
|
|
64
|
+
...e.position?.start.line === void 0 ? {} : { line: e.position.start.line },
|
|
65
|
+
...e.position?.start.column === void 0 ? {} : { column: e.position.start.column },
|
|
66
|
+
...e.position?.start.offset === void 0 ? {} : { offset: e.position.start.offset },
|
|
67
|
+
...e.position?.end.offset === void 0 ? {} : { endOffset: e.position.end.offset }
|
|
68
|
+
});
|
|
52
69
|
}
|
|
53
70
|
});
|
|
54
|
-
const
|
|
71
|
+
const v = j(C(i.plugins), {
|
|
55
72
|
source: t,
|
|
56
73
|
mode: "markdown"
|
|
57
74
|
});
|
|
58
75
|
return {
|
|
59
|
-
text:
|
|
60
|
-
headings:
|
|
61
|
-
codeExamples:
|
|
62
|
-
links:
|
|
63
|
-
images:
|
|
76
|
+
text: l(n).replace(/\s+/g, " ").trim(),
|
|
77
|
+
headings: f,
|
|
78
|
+
codeExamples: s,
|
|
79
|
+
links: o,
|
|
80
|
+
images: m,
|
|
64
81
|
missingCodeBlockLanguages: g,
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
82
|
+
directives: y,
|
|
83
|
+
directiveIssues: x(n, A(v)).map(
|
|
84
|
+
({ message: r, line: e, column: a }) => ({
|
|
85
|
+
message: r,
|
|
86
|
+
line: e,
|
|
69
87
|
column: a
|
|
70
88
|
})
|
|
71
89
|
)
|
|
72
90
|
};
|
|
73
91
|
}
|
|
74
|
-
function
|
|
75
|
-
return t.specifiers.map((
|
|
76
|
-
imported:
|
|
77
|
-
local:
|
|
92
|
+
function O(t) {
|
|
93
|
+
return t.specifiers.map((i) => i.type === "ImportDefaultSpecifier" ? { imported: "default", local: i.local.name } : i.type === "ImportNamespaceSpecifier" ? { imported: "*", local: i.local.name, namespace: !0 } : {
|
|
94
|
+
imported: i.type === "ImportSpecifier" ? "name" in i.imported ? i.imported.name : String(i.imported.value ?? "") : "",
|
|
95
|
+
local: i.local.name
|
|
78
96
|
});
|
|
79
97
|
}
|
|
80
|
-
function
|
|
98
|
+
function R(t) {
|
|
81
99
|
return !!(t && typeof t == "object" && typeof t.type == "string");
|
|
82
100
|
}
|
|
83
|
-
function
|
|
84
|
-
const
|
|
85
|
-
return typeof
|
|
101
|
+
function z(t) {
|
|
102
|
+
const i = t;
|
|
103
|
+
return typeof i.start == "number" && typeof i.end == "number";
|
|
86
104
|
}
|
|
87
|
-
function d(t,
|
|
105
|
+
function d(t, i) {
|
|
88
106
|
if (!t || typeof t != "object") return;
|
|
89
107
|
if (Array.isArray(t)) {
|
|
90
|
-
for (const
|
|
108
|
+
for (const n of t) d(n, i);
|
|
91
109
|
return;
|
|
92
110
|
}
|
|
93
111
|
const p = t;
|
|
94
|
-
|
|
95
|
-
for (const [
|
|
96
|
-
|
|
112
|
+
R(t) && i(t);
|
|
113
|
+
for (const [n, c] of Object.entries(p))
|
|
114
|
+
n === "loc" || n === "position" || d(c, i);
|
|
97
115
|
}
|
|
98
|
-
function
|
|
99
|
-
const
|
|
100
|
-
d(
|
|
101
|
-
if (
|
|
102
|
-
const
|
|
103
|
-
|
|
116
|
+
function J(t) {
|
|
117
|
+
const i = L().parse(t), p = [], n = [], c = [];
|
|
118
|
+
d(i, (s) => {
|
|
119
|
+
if (s.type === "ImportExpression") {
|
|
120
|
+
const o = s.source.type === "Literal" && typeof s.source.value == "string" ? s.source.value : void 0;
|
|
121
|
+
n.push({
|
|
104
122
|
kind: "dynamic-import",
|
|
105
|
-
specifier:
|
|
123
|
+
specifier: o
|
|
106
124
|
});
|
|
107
125
|
}
|
|
108
126
|
});
|
|
109
|
-
for (const
|
|
110
|
-
if (
|
|
111
|
-
for (const
|
|
112
|
-
if (
|
|
127
|
+
for (const s of i.children ?? [])
|
|
128
|
+
if (s.type === "mdxjsEsm")
|
|
129
|
+
for (const o of s.data?.estree?.body ?? [])
|
|
130
|
+
if (o.type === "ImportDeclaration") {
|
|
113
131
|
if (p.push({
|
|
114
|
-
specifier: String(
|
|
115
|
-
bindings:
|
|
116
|
-
}), !
|
|
132
|
+
specifier: String(o.source.value),
|
|
133
|
+
bindings: O(o)
|
|
134
|
+
}), !z(o))
|
|
117
135
|
throw new Error("Unable to locate an MDX import declaration in the source document");
|
|
118
|
-
c.push({ start:
|
|
119
|
-
} else (
|
|
136
|
+
c.push({ start: o.start, end: o.end });
|
|
137
|
+
} else (o.type === "ExportNamedDeclaration" || o.type === "ExportAllDeclaration") && o.source && n.push({
|
|
120
138
|
kind: "export-from",
|
|
121
|
-
specifier: String(
|
|
139
|
+
specifier: String(o.source.value)
|
|
122
140
|
});
|
|
123
|
-
const
|
|
124
|
-
...new Map(c.map((
|
|
125
|
-
].sort((
|
|
126
|
-
return { imports: p, sourceWithoutImports:
|
|
141
|
+
const f = [
|
|
142
|
+
...new Map(c.map((s) => [`${s.start}:${s.end}`, s])).values()
|
|
143
|
+
].sort((s, o) => o.start - s.start).reduce((s, o) => `${s.slice(0, o.start)}${s.slice(o.end)}`, t).replace(/^\s*\n/, "");
|
|
144
|
+
return { imports: p, sourceWithoutImports: f, unsupportedReferences: n };
|
|
127
145
|
}
|
|
128
146
|
export {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
147
|
+
H as analyzeMarkdown,
|
|
148
|
+
J as analyzeMdxModuleBoundary,
|
|
149
|
+
V as detectMarkdownAssets
|
|
132
150
|
};
|
package/dist/server.js
CHANGED
|
@@ -1,63 +1,68 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as f from "react/jsx-runtime";
|
|
2
2
|
import { jsx as i } from "react/jsx-runtime";
|
|
3
|
-
import { evaluate as
|
|
4
|
-
import { c as
|
|
5
|
-
import { a as
|
|
6
|
-
import { n as
|
|
7
|
-
import { a as
|
|
8
|
-
import { d as
|
|
9
|
-
import { createHash as
|
|
10
|
-
async function
|
|
11
|
-
const n =
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
3
|
+
import { evaluate as h } from "@mdx-js/mdx";
|
|
4
|
+
import { c as k, a as M, b as P } from "./Markdown-C7O01MRv.js";
|
|
5
|
+
import { a as x, n as v } from "./directiveValidation-BdVbgcY_.js";
|
|
6
|
+
import { n as y, d as L, c as N, a as S, p as b } from "./prepareMarkdown-D-bFl1_V.js";
|
|
7
|
+
import { a as C, b as T, c as z, s as H, e as O } from "./plugins-StkCS2su.js";
|
|
8
|
+
import { d as W } from "./plugins-StkCS2su.js";
|
|
9
|
+
import { createHash as R } from "node:crypto";
|
|
10
|
+
async function A(a = {}, r, s = { warnedLanguages: /* @__PURE__ */ new Set() }) {
|
|
11
|
+
const n = y(a), e = x(), t = r ?? "", o = C(n.plugins, { source: t, mode: "mdx" }), l = T(o), d = { ...n, plugins: o }, g = L(t, l), m = [
|
|
12
|
+
.../* @__PURE__ */ new Set([...g.codeLanguages, ...z(o)])
|
|
13
|
+
], c = {
|
|
14
|
+
highlightedCode: m.length > 0,
|
|
15
|
+
codeLanguages: m
|
|
16
|
+
};
|
|
17
|
+
o.forEach((w) => e.markPluginAssets(w));
|
|
18
|
+
const p = c.highlightedCode ? await N(
|
|
19
|
+
c.codeLanguages,
|
|
15
20
|
d,
|
|
16
|
-
|
|
21
|
+
s.warnedLanguages,
|
|
17
22
|
l
|
|
18
|
-
) : void 0,
|
|
23
|
+
) : void 0, u = S("mdx", e, d, c, p);
|
|
19
24
|
return {
|
|
20
|
-
remarkPlugins:
|
|
21
|
-
rehypePlugins:
|
|
22
|
-
remarkRehypeOptions: { handlers:
|
|
25
|
+
remarkPlugins: u.remarkPlugins,
|
|
26
|
+
rehypePlugins: u.rehypePlugins,
|
|
27
|
+
remarkRehypeOptions: { handlers: u.handlers },
|
|
23
28
|
getAssets: () => e.snapshot()
|
|
24
29
|
};
|
|
25
30
|
}
|
|
26
|
-
function
|
|
27
|
-
const { plugins:
|
|
31
|
+
function F(a, r) {
|
|
32
|
+
const { plugins: s, ...n } = r ?? {}, e = H({ ...n, plugins: O(s) });
|
|
28
33
|
if (e !== void 0)
|
|
29
|
-
return
|
|
34
|
+
return R("sha256").update(a).update("\0").update(e).digest("hex");
|
|
30
35
|
}
|
|
31
|
-
function
|
|
32
|
-
for (a.delete(r), a.set(r,
|
|
36
|
+
function D(a, r, s, n) {
|
|
37
|
+
for (a.delete(r), a.set(r, s); a.size > n; ) {
|
|
33
38
|
const e = a.keys().next().value;
|
|
34
39
|
if (e === void 0) break;
|
|
35
40
|
a.delete(e);
|
|
36
41
|
}
|
|
37
|
-
return
|
|
42
|
+
return s;
|
|
38
43
|
}
|
|
39
|
-
function
|
|
40
|
-
if (!r) return
|
|
44
|
+
function J(a, r, s, n) {
|
|
45
|
+
if (!r) return s();
|
|
41
46
|
const e = a.get(r);
|
|
42
47
|
if (e)
|
|
43
48
|
return a.delete(r), a.set(r, e), e;
|
|
44
|
-
const
|
|
45
|
-
throw a.get(r) ===
|
|
49
|
+
const t = s().catch((o) => {
|
|
50
|
+
throw a.get(r) === t && a.delete(r), o;
|
|
46
51
|
});
|
|
47
|
-
return
|
|
52
|
+
return D(a, r, t, n);
|
|
48
53
|
}
|
|
49
|
-
function
|
|
54
|
+
function K({
|
|
50
55
|
maxEntries: a = 64,
|
|
51
56
|
warningState: r = /* @__PURE__ */ new Set()
|
|
52
57
|
} = {}) {
|
|
53
|
-
const
|
|
58
|
+
const s = Number.isFinite(a) && a > 0 ? Math.floor(a) : 64, n = /* @__PURE__ */ new Map();
|
|
54
59
|
return {
|
|
55
|
-
prepare(e,
|
|
56
|
-
return
|
|
60
|
+
prepare(e, t) {
|
|
61
|
+
return J(
|
|
57
62
|
n,
|
|
58
|
-
|
|
59
|
-
() =>
|
|
60
|
-
|
|
63
|
+
F(e, t),
|
|
64
|
+
() => b(e, t, { warnedLanguages: r }),
|
|
65
|
+
s
|
|
61
66
|
);
|
|
62
67
|
},
|
|
63
68
|
clear() {
|
|
@@ -65,16 +70,16 @@ function F({
|
|
|
65
70
|
}
|
|
66
71
|
};
|
|
67
72
|
}
|
|
68
|
-
function
|
|
69
|
-
const r = /* @__PURE__ */ new Set(),
|
|
73
|
+
function G(a = {}) {
|
|
74
|
+
const r = /* @__PURE__ */ new Set(), s = K({ ...a, warningState: r });
|
|
70
75
|
return {
|
|
71
76
|
async render(n, e = {}) {
|
|
72
|
-
const
|
|
77
|
+
const t = await s.prepare(n, e.markdown);
|
|
73
78
|
return {
|
|
74
79
|
content: /* @__PURE__ */ i(
|
|
75
|
-
|
|
80
|
+
P,
|
|
76
81
|
{
|
|
77
|
-
document:
|
|
82
|
+
document: t.document,
|
|
78
83
|
classNames: e.classNames,
|
|
79
84
|
components: e.components,
|
|
80
85
|
slots: e.slots,
|
|
@@ -84,27 +89,27 @@ function q(a = {}) {
|
|
|
84
89
|
urlTransform: e.urlTransform
|
|
85
90
|
}
|
|
86
91
|
),
|
|
87
|
-
assets:
|
|
92
|
+
assets: t.assets
|
|
88
93
|
};
|
|
89
94
|
},
|
|
90
95
|
async renderMdx(n, e = {}) {
|
|
91
96
|
if (e.markdown?.html && e.markdown.html !== "trusted")
|
|
92
97
|
throw new Error("MDX executes trusted JSX and does not support sanitize or strip HTML policies");
|
|
93
|
-
const
|
|
98
|
+
const t = await A(e.markdown, n, {
|
|
94
99
|
warnedLanguages: r
|
|
95
|
-
}), l = (await
|
|
100
|
+
}), l = (await h(
|
|
96
101
|
{
|
|
97
|
-
value:
|
|
102
|
+
value: v(n),
|
|
98
103
|
data: { canofoldLocale: e.markdown?.locale?.trim() || void 0 }
|
|
99
104
|
},
|
|
100
105
|
{
|
|
101
|
-
...
|
|
102
|
-
remarkPlugins:
|
|
103
|
-
rehypePlugins:
|
|
104
|
-
remarkRehypeOptions:
|
|
106
|
+
...f,
|
|
107
|
+
remarkPlugins: t.remarkPlugins,
|
|
108
|
+
rehypePlugins: t.rehypePlugins,
|
|
109
|
+
remarkRehypeOptions: t.remarkRehypeOptions,
|
|
105
110
|
baseUrl: e.baseUrl ?? import.meta.url
|
|
106
111
|
}
|
|
107
|
-
)).default, d =
|
|
112
|
+
)).default, d = k(
|
|
108
113
|
e.classNames,
|
|
109
114
|
e.slots,
|
|
110
115
|
e.components,
|
|
@@ -112,7 +117,7 @@ function q(a = {}) {
|
|
|
112
117
|
);
|
|
113
118
|
return {
|
|
114
119
|
content: /* @__PURE__ */ i(
|
|
115
|
-
|
|
120
|
+
M,
|
|
116
121
|
{
|
|
117
122
|
"data-cf-runtime": "static",
|
|
118
123
|
as: e.as,
|
|
@@ -123,15 +128,15 @@ function q(a = {}) {
|
|
|
123
128
|
children: /* @__PURE__ */ i(l, { components: d })
|
|
124
129
|
}
|
|
125
130
|
),
|
|
126
|
-
assets:
|
|
131
|
+
assets: t.getAssets()
|
|
127
132
|
};
|
|
128
133
|
},
|
|
129
134
|
clear() {
|
|
130
|
-
|
|
135
|
+
s.clear();
|
|
131
136
|
}
|
|
132
137
|
};
|
|
133
138
|
}
|
|
134
139
|
export {
|
|
135
|
-
|
|
136
|
-
|
|
140
|
+
G as createMarkdownRenderer,
|
|
141
|
+
W as defineMarkdownPlugin
|
|
137
142
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@canofold/markdown",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "An interactive, themeable Markdown renderer for knowledge and documentation sites.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Canofold Contributors",
|
|
@@ -90,7 +90,7 @@
|
|
|
90
90
|
"@types/mdast": "^4.0.4",
|
|
91
91
|
"@types/node": "^22.10.0",
|
|
92
92
|
"@types/react": "^19.2.18",
|
|
93
|
-
"@types/react-dom": "^19.2.
|
|
93
|
+
"@types/react-dom": "^19.2.7",
|
|
94
94
|
"@types/unist": "^3.0.3",
|
|
95
95
|
"mdast-util-directive": "^3.1.0",
|
|
96
96
|
"mdast-util-to-hast": "^13.2.1",
|