@canofold/markdown 0.3.0 → 0.3.2

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.
Files changed (41) hide show
  1. package/README.md +2 -0
  2. package/README.zh-CN.md +2 -0
  3. package/dist/ImageGallery-Bcpjlfh9.js +569 -0
  4. package/dist/Markdown-607_slPB.js +117 -0
  5. package/dist/assets-CqlggKr8.js +77 -0
  6. package/dist/base.css +1 -1
  7. package/dist/client/bundler.js +308 -0
  8. package/dist/client/chunks/{client-kVNIqHQd.js → client-CHUUETWE.js} +3 -3
  9. package/dist/client/chunks/{gallery-BTg1qJjd.js → gallery-Cr0TgC1h.js} +2 -2
  10. package/dist/client/chunks/{image-BuMCsr5L.js → image-6_o7fPkU.js} +3 -3
  11. package/dist/client/chunks/provider-k1N-5njv.js +1037 -0
  12. package/dist/client/chunks/react-runtime-DRPMrVPX.js +12062 -0
  13. package/dist/client/chunks/{serialized-T1PzI4rG.js → serialized-Chn9ydGA.js} +270 -220
  14. package/dist/client/chunks/{table-JOSJsHgy.js → table-D99-Zhc8.js} +3 -3
  15. package/dist/client/index.js +1 -1
  16. package/dist/compiler/fenceMetadata.d.ts +7 -0
  17. package/dist/compiler/normalizeOptions.d.ts +2 -1
  18. package/dist/compiler/plugins/code.d.ts +1 -1
  19. package/dist/compiler/prepareMarkdown.d.ts +1 -1
  20. package/dist/compiler/types.d.ts +3 -0
  21. package/dist/componentMap-CKSUGzQH.js +1483 -0
  22. package/dist/components/blocks/MarkdownCodeBlock.d.ts +3 -1
  23. package/dist/copyText-C0ZgrMnH.js +18 -0
  24. package/dist/{directiveValidation-BdVbgcY_.js → directiveValidation-B7LY-R5p.js} +187 -248
  25. package/dist/fileKinds-BPzIxbaS.js +170 -0
  26. package/dist/gallery-BqQ-i0TC.js +42 -0
  27. package/dist/image-CiPni6Az.js +38 -0
  28. package/dist/index.d.ts +1 -1
  29. package/dist/index.js +2 -2
  30. package/dist/plugins-CXYBB-oH.js +130 -0
  31. package/dist/{prepareMarkdown-D-bFl1_V.js → prepareMarkdown-CS6sALIb.js} +344 -329
  32. package/dist/provider-BJDHf4Z_.js +8 -0
  33. package/dist/serialized-DFiNQYA5.js +39 -0
  34. package/dist/server/analyze.js +11 -11
  35. package/dist/server.js +30 -28
  36. package/dist/table-DQSeLjVL.js +32 -0
  37. package/package.json +14 -9
  38. package/dist/Markdown-C7O01MRv.js +0 -2116
  39. package/dist/client/chunks/provider-DNSHvvN7.js +0 -841
  40. package/dist/client/chunks/react-runtime-Dzgdzn6D.js +0 -10571
  41. package/dist/plugins-StkCS2su.js +0 -298
@@ -0,0 +1,170 @@
1
+ const r = {
2
+ "package.json": "package",
3
+ "package-lock.json": "package",
4
+ "pnpm-lock.yaml": "package",
5
+ "yarn.lock": "package",
6
+ "bun.lock": "package",
7
+ "bun.lockb": "package",
8
+ "deno.json": "package",
9
+ "deno.jsonc": "package",
10
+ "pnpm-workspace.yaml": "package",
11
+ ".gitignore": "config",
12
+ ".editorconfig": "config",
13
+ ".npmrc": "config",
14
+ ".nvmrc": "config",
15
+ ".prettierrc": "config",
16
+ "biome.json": "config",
17
+ dockerfile: "container",
18
+ containerfile: "container",
19
+ "tsconfig.json": "config",
20
+ "jsconfig.json": "config",
21
+ "turbo.json": "config",
22
+ "vite.config.ts": "config",
23
+ "vite.config.js": "config"
24
+ }, i = {
25
+ ts: "typescript",
26
+ tsx: "typescript",
27
+ mts: "typescript",
28
+ cts: "typescript",
29
+ js: "javascript",
30
+ jsx: "javascript",
31
+ mjs: "javascript",
32
+ cjs: "javascript",
33
+ md: "markdown",
34
+ mdx: "markdown",
35
+ css: "style",
36
+ conf: "config",
37
+ scss: "style",
38
+ sass: "style",
39
+ less: "style",
40
+ json: "data",
41
+ jsonc: "data",
42
+ yaml: "data",
43
+ yml: "data",
44
+ toml: "data",
45
+ sql: "database",
46
+ diff: "diff",
47
+ patch: "diff",
48
+ sh: "shell",
49
+ bash: "shell",
50
+ zsh: "shell",
51
+ fish: "shell",
52
+ vue: "component",
53
+ svelte: "component",
54
+ astro: "component",
55
+ py: "source",
56
+ go: "source",
57
+ rs: "source"
58
+ }, l = {
59
+ typescript: "typescript",
60
+ ts: "typescript",
61
+ tsx: "typescript",
62
+ javascript: "javascript",
63
+ js: "javascript",
64
+ jsx: "javascript",
65
+ markdown: "markdown",
66
+ md: "markdown",
67
+ mdx: "markdown",
68
+ css: "style",
69
+ scss: "style",
70
+ sass: "style",
71
+ less: "style",
72
+ json: "data",
73
+ jsonc: "data",
74
+ yaml: "data",
75
+ yml: "data",
76
+ toml: "data",
77
+ sql: "database",
78
+ diff: "diff",
79
+ docker: "container",
80
+ dockerfile: "container",
81
+ nginx: "config",
82
+ shell: "shell",
83
+ sh: "shell",
84
+ bash: "shell",
85
+ zsh: "shell",
86
+ terminal: "shell",
87
+ vue: "component",
88
+ svelte: "component",
89
+ astro: "component",
90
+ python: "source",
91
+ py: "source",
92
+ go: "source",
93
+ rust: "source",
94
+ rs: "source"
95
+ };
96
+ function p(o, t = "") {
97
+ const e = o.split(/[\\/]/).pop()?.toLowerCase() || "", s = r[e];
98
+ if (s) return s;
99
+ if (/^\.env(?:\..+)?$/.test(e)) return "environment";
100
+ if (/(^|\.)config\.[^.]+$/.test(e) || /^\.[a-z0-9-]+rc(?:\.[^.]+)?$/.test(e))
101
+ return "config";
102
+ const n = e.includes(".") && e.split(".").pop() || "";
103
+ return i[n] || l[t.toLowerCase()] || "file";
104
+ }
105
+ const a = {
106
+ astro: "astro",
107
+ bash: "console",
108
+ css: "css",
109
+ diff: "diff",
110
+ docker: "docker",
111
+ dockerfile: "docker",
112
+ go: "go",
113
+ javascript: "javascript",
114
+ js: "javascript",
115
+ jsx: "javascript",
116
+ json: "json",
117
+ jsonc: "json",
118
+ markdown: "markdown",
119
+ md: "markdown",
120
+ mdx: "markdown",
121
+ python: "python",
122
+ py: "python",
123
+ rust: "rust",
124
+ rs: "rust",
125
+ sass: "sass",
126
+ scss: "sass",
127
+ shell: "console",
128
+ sh: "console",
129
+ sql: "database",
130
+ svelte: "svelte",
131
+ terminal: "console",
132
+ typescript: "typescript",
133
+ ts: "typescript",
134
+ tsx: "typescript",
135
+ vue: "vue",
136
+ yaml: "yaml",
137
+ yml: "yaml",
138
+ zsh: "console"
139
+ };
140
+ function f(o, t = "") {
141
+ const e = o.replace(/\\/g, "/").toLowerCase(), s = e.split("/").pop() || "";
142
+ if (/^canofold\.config\.(?:[cm]?[jt]s)$/.test(s)) return "canofold";
143
+ if (/^(?:.*\/)?\.github\/workflows\/[^/]+\.ya?ml$/.test(e)) return "github-actions";
144
+ if (["npm", "pnpm", "yarn", "bun", "deno"].includes(s))
145
+ return s;
146
+ if (s === "package.json") return "nodejs";
147
+ if (s.startsWith("pnpm-") || s === "pnpm-lock.yaml") return "pnpm";
148
+ if (s === "package-lock.json" || s === ".npmrc") return "npm";
149
+ if (s === "yarn.lock") return "yarn";
150
+ if (s === "bun.lock" || s === "bun.lockb") return "bun";
151
+ if (s === "deno.json" || s === "deno.jsonc") return "deno";
152
+ if (s === "dockerfile" || s === "containerfile") return "docker";
153
+ if (s === ".gitignore" || s === ".gitattributes" || s === ".gitmodules")
154
+ return "git";
155
+ if (/^\.env(?:\.|$)/.test(s)) return "environment";
156
+ if (s === "tsconfig.json" || s === "jsconfig.json") return "typescript";
157
+ if (/\.(?:jsx|tsx)$/.test(s)) return "react";
158
+ const n = p(s, t);
159
+ if (n === "config") return "config";
160
+ if (n === "database") return "database";
161
+ if (n === "diff") return "diff";
162
+ if (n === "shell") return "console";
163
+ if (n === "container") return "docker";
164
+ const c = s.includes(".") && s.split(".").pop() || "";
165
+ return a[c] || a[t.toLowerCase()] || "document";
166
+ }
167
+ export {
168
+ f as a,
169
+ p as m
170
+ };
@@ -0,0 +1,42 @@
1
+ import { jsx as r } from "react/jsx-runtime";
2
+ import { hydrateRoot as s } from "react-dom/client";
3
+ import { I as l } from "./ImageGallery-Bcpjlfh9.js";
4
+ import { w as i } from "./provider-BJDHf4Z_.js";
5
+ function n(e) {
6
+ try {
7
+ const a = JSON.parse(e.dataset.cfGalleryItems ?? "[]");
8
+ return Array.isArray(a) ? a.filter(
9
+ (t) => !!(t && typeof t == "object" && typeof t.src == "string" && typeof t.alt == "string")
10
+ ) : [];
11
+ } catch {
12
+ return [];
13
+ }
14
+ }
15
+ function u(e, a) {
16
+ return s(
17
+ e,
18
+ i(
19
+ /* @__PURE__ */ r(
20
+ l,
21
+ {
22
+ items: n(e),
23
+ className: e.className || void 0,
24
+ role: e.getAttribute("role") === "region" ? "region" : "group",
25
+ labels: {
26
+ gallery: e.dataset.cfGalleryLabel,
27
+ close: e.dataset.cfCloseLabel,
28
+ previous: e.dataset.cfPreviousLabel,
29
+ next: e.dataset.cfNextLabel,
30
+ thumbnails: e.dataset.cfThumbnailsLabel,
31
+ image: e.dataset.cfImageLabel
32
+ },
33
+ inner: !0
34
+ }
35
+ ),
36
+ a
37
+ )
38
+ );
39
+ }
40
+ export {
41
+ u as hydrate
42
+ };
@@ -0,0 +1,38 @@
1
+ import { jsx as r } from "react/jsx-runtime";
2
+ import { hydrateRoot as d } from "react-dom/client";
3
+ import { M as o } from "./componentMap-CKSUGzQH.js";
4
+ import { r as s } from "./serialized-DFiNQYA5.js";
5
+ import { w as l } from "./provider-BJDHf4Z_.js";
6
+ function u(i, a) {
7
+ const t = i.querySelector("img");
8
+ if (!t) return;
9
+ const e = s(i.dataset.cfIslandData, a);
10
+ return d(
11
+ i,
12
+ l(
13
+ /* @__PURE__ */ r(
14
+ o,
15
+ {
16
+ src: e ? void 0 : t.getAttribute("src") ?? "",
17
+ alt: e ? void 0 : t.getAttribute("alt") ?? "",
18
+ title: e ? void 0 : t.getAttribute("title") ?? void 0,
19
+ width: e ? void 0 : t.getAttribute("width") ?? void 0,
20
+ height: e ? void 0 : t.getAttribute("height") ?? void 0,
21
+ loading: e || !t.hasAttribute("loading") ? void 0 : t.getAttribute("loading") === "eager" ? "eager" : "lazy",
22
+ srcSet: e ? void 0 : t.getAttribute("srcset") ?? void 0,
23
+ sizes: e ? void 0 : t.getAttribute("sizes") ?? void 0,
24
+ caption: e ? void 0 : i.querySelector("figcaption")?.textContent ?? void 0,
25
+ className: i.className || void 0,
26
+ zoomLabel: i.dataset.cfZoomLabel,
27
+ closeLabel: i.dataset.cfCloseLabel,
28
+ inner: !0,
29
+ children: e
30
+ }
31
+ ),
32
+ a
33
+ )
34
+ );
35
+ }
36
+ export {
37
+ u as hydrate
38
+ };
package/dist/index.d.ts CHANGED
@@ -4,4 +4,4 @@ export type { MarkdownClassNames, MarkdownComponents, MarkdownIntrinsicComponent
4
4
  export type { MarkdownCaptionSlotProps, MarkdownIconName, MarkdownIconSlotProps, MarkdownSlots } from './react/slots';
5
5
  export type { MarkdownUrlProperty, MarkdownUrlTransform } from './react/urlTransform';
6
6
  export { defineMarkdownPlugin } from './compiler/plugins';
7
- export type { MarkdownCodeOptions, MarkdownFeatureOptions, MarkdownHtmlPolicy, MarkdownLabels, MarkdownPlugin, MarkdownPluginBrowserCompiler, MarkdownPluginCacheValue, MarkdownPluginClientAsset, MarkdownPluginClientResource, MarkdownPluginClientResourceDirectory, MarkdownPluginContext, MarkdownPluginStyleAsset, MarkdownUnknownLanguagePolicy, RenderMarkdownOptions } from './compiler/prepareMarkdown';
7
+ export type { MarkdownCodeOverflow, MarkdownCodeOptions, MarkdownFeatureOptions, MarkdownHtmlPolicy, MarkdownLabels, MarkdownPlugin, MarkdownPluginBrowserCompiler, MarkdownPluginCacheValue, MarkdownPluginClientAsset, MarkdownPluginClientResource, MarkdownPluginClientResourceDirectory, MarkdownPluginContext, MarkdownPluginStyleAsset, MarkdownUnknownLanguagePolicy, RenderMarkdownOptions } from './compiler/prepareMarkdown';
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { M as a } from "./Markdown-C7O01MRv.js";
2
- import { d as e } from "./plugins-StkCS2su.js";
1
+ import { M as a } from "./Markdown-607_slPB.js";
2
+ import { d as e } from "./plugins-CXYBB-oH.js";
3
3
  export {
4
4
  a as Markdown,
5
5
  e as defineMarkdownPlugin
@@ -0,0 +1,130 @@
1
+ function c(e, r) {
2
+ if (e === null || typeof e == "string" || typeof e == "boolean") return JSON.stringify(e);
3
+ if (typeof e == "number") {
4
+ if (!Number.isFinite(e)) throw new TypeError("Numbers must be finite");
5
+ return String(e);
6
+ }
7
+ if (typeof e != "object") throw new TypeError("Value is not JSON serializable");
8
+ if (r.has(e)) throw new TypeError("Circular JSON value");
9
+ const o = Object.getPrototypeOf(e);
10
+ if (!Array.isArray(e) && o !== Object.prototype && o !== null)
11
+ throw new TypeError("Only plain objects are JSON serializable");
12
+ r.add(e);
13
+ try {
14
+ if (Array.isArray(e)) {
15
+ if (Object.keys(e).length !== e.length) throw new TypeError("Sparse arrays are not supported");
16
+ return `[${e.map((t) => c(t, r)).join(",")}]`;
17
+ }
18
+ return `{${Object.keys(e).sort().map((t) => `${JSON.stringify(t)}:${c(e[t], r)}`).join(",")}}`;
19
+ } finally {
20
+ r.delete(e);
21
+ }
22
+ }
23
+ function w(e) {
24
+ try {
25
+ return c(e, /* @__PURE__ */ new WeakSet());
26
+ } catch {
27
+ return;
28
+ }
29
+ }
30
+ const m = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/, d = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
31
+ function u(e) {
32
+ if (typeof e != "string" || !m.test(e))
33
+ throw new Error(
34
+ `Markdown plugin names must be lowercase kebab-case slugs (e.g. "external-links"), got ${JSON.stringify(e)}`
35
+ );
36
+ }
37
+ function g(e) {
38
+ if (e.cacheKey !== void 0 && w(e.cacheKey) === void 0)
39
+ throw new Error(`Markdown plugin "${e.name}" cacheKey must be JSON-serializable`);
40
+ }
41
+ function l(e) {
42
+ const r = e.browserCompiler;
43
+ if (r) {
44
+ if (typeof r.module != "string" || r.module.trim() === "")
45
+ throw new Error(`Markdown plugin "${e.name}" browserCompiler.module must be a non-empty string`);
46
+ if (typeof r.exportName != "string" || !d.test(r.exportName))
47
+ throw new Error(
48
+ `Markdown plugin "${e.name}" browserCompiler.exportName must be a named JavaScript export`
49
+ );
50
+ if (r.options !== void 0 && w(r.options) === void 0)
51
+ throw new Error(`Markdown plugin "${e.name}" browserCompiler.options must be JSON-serializable`);
52
+ }
53
+ }
54
+ function f(e) {
55
+ return (e.directiveNames ?? []).map((r) => {
56
+ const o = r.trim().toLowerCase();
57
+ if (r !== o || !m.test(o))
58
+ throw new Error(
59
+ `Markdown plugin "${e.name}" directive names must be lowercase kebab-case slugs, got ${JSON.stringify(r)}`
60
+ );
61
+ return o;
62
+ });
63
+ }
64
+ function p(e = []) {
65
+ const r = /* @__PURE__ */ new Set(), o = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new Map();
66
+ for (const n of e) {
67
+ if (u(n?.name), g(n), l(n), r.has(n.name))
68
+ throw new Error(`Markdown plugins must have unique names, got "${n.name}" twice`);
69
+ r.add(n.name);
70
+ for (const i of n.fenceLanguages ?? []) {
71
+ const a = i.trim().toLowerCase();
72
+ if (!a) continue;
73
+ const s = o.get(a);
74
+ if (s && s !== n.name)
75
+ throw new Error(`Fence language "${a}" is owned by both "${s}" and "${n.name}"`);
76
+ o.set(a, n.name);
77
+ }
78
+ for (const i of f(n)) {
79
+ const a = t.get(i);
80
+ if (a && a !== n.name)
81
+ throw new Error(`Directive "${i}" is owned by both "${a}" and "${n.name}"`);
82
+ t.set(i, n.name);
83
+ }
84
+ }
85
+ return e;
86
+ }
87
+ function y(e = []) {
88
+ return e.map((r) => ({
89
+ name: r.name,
90
+ version: r.version ?? "",
91
+ cacheKey: r.cacheKey ?? null
92
+ }));
93
+ }
94
+ function b(e) {
95
+ return u(e?.name), g(e), l(e), f(e), e;
96
+ }
97
+ function h(e, r) {
98
+ return e.filter((o) => o.appliesTo?.(r) !== !1);
99
+ }
100
+ function N(e) {
101
+ const r = /* @__PURE__ */ new Set();
102
+ for (const o of e)
103
+ for (const t of o.fenceLanguages ?? []) {
104
+ const n = t.trim().toLowerCase();
105
+ n && r.add(n);
106
+ }
107
+ return r;
108
+ }
109
+ function $(e) {
110
+ const r = /* @__PURE__ */ new Set();
111
+ for (const o of e)
112
+ for (const t of o.highlightLanguages ?? []) {
113
+ const n = t.trim().toLowerCase();
114
+ n && r.add(n);
115
+ }
116
+ return [...r];
117
+ }
118
+ function k(e) {
119
+ return new Set(e.flatMap((r) => f(r)));
120
+ }
121
+ export {
122
+ h as a,
123
+ N as b,
124
+ $ as c,
125
+ b as d,
126
+ y as e,
127
+ k as m,
128
+ p as n,
129
+ w as s
130
+ };