@cocoar/vue-markdown 1.13.0-beta.6 → 1.13.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.css CHANGED
@@ -1,2 +1,2 @@
1
- .coar-markdown{--coar-markdown-text:var(--coar-text-neutral-primary);--coar-markdown-link:var(--coar-text-brand-primary,var(--coar-text-neutral-primary));--coar-markdown-muted-text:var(--coar-text-neutral-tertiary);--coar-markdown-border:var(--coar-border-neutral-tertiary);--coar-markdown-surface:var(--coar-background-neutral-primary);--coar-markdown-surface-muted:var(--coar-background-neutral-tertiary,var(--coar-background-neutral-primary));--coar-markdown-radius:var(--coar-radius-xs);--coar-markdown-space-1:var(--coar-spacing-s,.5rem);--coar-markdown-space-2:var(--coar-spacing-m,1rem);--coar-markdown-heading-block-start:var(--coar-spacing-xxxl,4rem);color:var(--coar-markdown-text);display:block}.coar-markdown :where(h1,h2,h3,h4,h5,h6){font-family:var(--coar-font-family-title,inherit);color:var(--coar-markdown-text)}.coar-markdown h1{font-size:var(--coar-font-size-xl);font-weight:var(--coar-font-weight-bold);line-height:var(--coar-line-height-tight)}.coar-markdown h2{font-size:var(--coar-font-size-l);font-weight:var(--coar-font-weight-bold);line-height:1.25}.coar-markdown h3{font-size:var(--coar-font-size-m);font-weight:var(--coar-font-weight-semi-bold);line-height:var(--coar-line-height-snug)}.coar-markdown h4{font-size:var(--coar-font-size-s);font-weight:var(--coar-font-weight-semi-bold);line-height:1.35}.coar-markdown h5{font-size:var(--coar-font-size-xs);font-weight:var(--coar-font-weight-semi-bold);line-height:var(--coar-line-height-normal)}.coar-markdown h6{font-size:var(--coar-font-size-xxs);font-weight:var(--coar-font-weight-medium);line-height:1.45}.coar-markdown-heading,.coar-markdown-paragraph,.coar-markdown-blockquote,.coar-markdown-list,.coar-markdown-code-block,.coar-markdown-table,.coar-markdown-hr{margin:0}.coar-markdown>:where(h1,h2,h3,h4,h5,h6,p,blockquote,ul,ol,pre,table,hr,.coar-code-block-host,.coar-table-host){margin-block:0 var(--coar-markdown-space-2)}.coar-markdown>:where(h1,h2,h3,h4,h5,h6){margin-block-start:var(--coar-markdown-heading-block-start)}.coar-markdown>:where(h1,h2,h3,h4,h5,h6)+:where(h1,h2,h3,h4,h5,h6){margin-block-start:var(--coar-markdown-space-1)}.coar-markdown>:where(h1,h2,h3,h4,h5,h6):first-child{margin-block-start:0}.coar-markdown-blockquote{padding-inline:var(--coar-markdown-space-2);border-left:2px solid var(--coar-markdown-border)}.coar-markdown-list{padding-inline-start:var(--coar-spacing-l,1.5rem);list-style-position:outside}.coar-markdown-list--unordered{list-style-type:disc}.coar-markdown-list--ordered{list-style-type:decimal}.coar-markdown-list-item{margin-block:.25em;display:list-item}.coar-markdown-list-item--task{align-items:flex-start;gap:var(--coar-spacing-s,.5rem);list-style:none;display:flex}.coar-markdown-list-item-content{min-width:0}.coar-markdown-task-checkbox{margin-top:.15em}.coar-markdown-code-block,.coar-markdown-code{display:block}.coar-markdown-inline-code{color:var(--coar-text-accent-secondary,var(--coar-markdown-link));background:0 0;border:0;border-radius:0;padding:0}.coar-markdown-link{color:var(--coar-markdown-link);text-decoration:underline}.coar-markdown-image{vertical-align:middle;max-width:100%;height:auto}.coar-markdown-table{border:1px solid var(--coar-markdown-border);border-radius:var(--coar-markdown-radius);border-collapse:separate;border-spacing:0;width:100%;overflow:hidden}.coar-markdown-table-cell{padding:var(--coar-markdown-space-1);vertical-align:top;border-right:1px solid var(--coar-markdown-border);border-bottom:1px solid var(--coar-markdown-border)}.coar-markdown-table :where(tr) .coar-markdown-table-cell:last-child{border-right:0}.coar-markdown-table :where(tbody) tr:last-child .coar-markdown-table-cell{border-bottom:0}.coar-markdown-table :where(thead) .coar-markdown-table-cell{background:var(--coar-markdown-surface-muted);font-weight:600}.coar-markdown-hr{border:0;border-top:1px solid var(--coar-markdown-border)}.coar-markdown-unsupported,.coar-markdown-unsupported-inline{color:var(--coar-markdown-muted-text);font-style:italic}.coar-markdown-unsupported{padding:var(--coar-markdown-space-1);border:1px dashed var(--coar-markdown-border);border-radius:var(--coar-markdown-radius);background:var(--coar-markdown-surface)}
1
+ .coar-markdown{--coar-markdown-text:var(--coar-text-neutral-primary);--coar-markdown-link:var(--coar-text-brand-primary,var(--coar-text-neutral-primary));--coar-markdown-muted-text:var(--coar-text-neutral-tertiary);--coar-markdown-border:var(--coar-border-neutral-tertiary);--coar-markdown-surface:var(--coar-background-neutral-primary);--coar-markdown-surface-muted:var(--coar-background-neutral-tertiary,var(--coar-background-neutral-primary));--coar-markdown-radius:var(--coar-radius-xs);--coar-markdown-space-1:var(--coar-spacing-s,.5rem);--coar-markdown-space-2:var(--coar-spacing-m,1rem);--coar-markdown-heading-block-start:var(--coar-spacing-xxxl,4rem);color:var(--coar-markdown-text);display:block}.coar-markdown :where(h1,h2,h3,h4,h5,h6){font-family:var(--coar-font-family-title,inherit);color:var(--coar-markdown-text)}.coar-markdown h1{font-size:var(--coar-font-size-xl);font-weight:var(--coar-font-weight-bold);line-height:var(--coar-line-height-tight)}.coar-markdown h2{font-size:var(--coar-font-size-l);font-weight:var(--coar-font-weight-bold);line-height:1.25}.coar-markdown h3{font-size:var(--coar-font-size-m);font-weight:var(--coar-font-weight-semi-bold);line-height:var(--coar-line-height-snug)}.coar-markdown h4{font-size:var(--coar-font-size-s);font-weight:var(--coar-font-weight-semi-bold);line-height:1.35}.coar-markdown h5{font-size:var(--coar-font-size-xs);font-weight:var(--coar-font-weight-semi-bold);line-height:var(--coar-line-height-normal)}.coar-markdown h6{font-size:var(--coar-font-size-xxs);font-weight:var(--coar-font-weight-medium);line-height:1.45}.coar-markdown-heading,.coar-markdown-paragraph,.coar-markdown-blockquote,.coar-markdown-list,.coar-markdown-code-block,.coar-markdown-table,.coar-markdown-hr{margin:0}.coar-markdown>:where(h1,h2,h3,h4,h5,h6,p,blockquote,ul,ol,pre,table,hr,.coar-code-block-host,.coar-table-host){margin-block:0 var(--coar-markdown-space-2)}.coar-markdown>:where(h1,h2,h3,h4,h5,h6){margin-block-start:var(--coar-markdown-heading-block-start)}.coar-markdown>:where(h1,h2,h3,h4,h5,h6)+:where(h1,h2,h3,h4,h5,h6){margin-block-start:var(--coar-markdown-space-1)}.coar-markdown>:where(h1,h2,h3,h4,h5,h6):first-child{margin-block-start:0}.coar-markdown-blockquote{padding-inline:var(--coar-markdown-space-2);border-left:2px solid var(--coar-markdown-border)}.coar-markdown-list{padding-inline-start:var(--coar-spacing-l,1.5rem);list-style-position:outside}.coar-markdown-list--unordered{list-style-type:disc}.coar-markdown-list--ordered{list-style-type:decimal}.coar-markdown-list-item{margin-block:.25em;display:list-item}.coar-markdown-list-item--task{align-items:flex-start;gap:var(--coar-spacing-s,.5rem);list-style:none;display:flex}.coar-markdown-list-item-content{min-width:0}.coar-markdown-task-checkbox{margin-top:.15em}.coar-markdown-code-block,.coar-markdown-code{display:block}.coar-markdown-inline-code{color:var(--coar-text-accent-secondary,var(--coar-markdown-link));background:0 0;border:0;border-radius:0;padding:0}.coar-markdown-link{color:var(--coar-markdown-link);text-decoration:underline}.coar-markdown-image{vertical-align:middle;max-width:100%;height:auto}.coar-markdown :where(table),.coar-markdown-table{border-collapse:collapse;border-spacing:0;width:100%;font-size:var(--coar-body-small-base-size,.9rem);line-height:var(--coar-line-height-relaxed,1.5);display:table}.coar-markdown :where(table thead),.coar-markdown-table>thead{background:var(--coar-markdown-surface-muted)}.coar-markdown :where(table th),.coar-markdown-table>thead th{padding:.625rem var(--coar-markdown-space-2);text-align:left;vertical-align:top;font-weight:var(--coar-font-weight-semi-bold,600);font-size:var(--coar-component-s-font-size,.85em);color:var(--coar-markdown-text);border-bottom:1px solid var(--coar-markdown-border);text-transform:uppercase;letter-spacing:.025em}.coar-markdown :where(table td),.coar-markdown-table>tbody td{padding:.625rem var(--coar-markdown-space-2);text-align:left;vertical-align:top;color:var(--coar-text-neutral-secondary,var(--coar-markdown-text));border-bottom:1px solid var(--coar-markdown-border)}.coar-markdown :where(table tbody tr:nth-child(odd)),.coar-markdown-table>tbody tr:nth-child(odd){background:var(--coar-markdown-surface)}.coar-markdown :where(table tbody tr:nth-child(2n)),.coar-markdown-table>tbody tr:nth-child(2n){background:var(--coar-markdown-surface-muted)}.coar-markdown :where(table tbody tr:last-child td),.coar-markdown-table>tbody tr:last-child td{border-bottom:0}.coar-markdown-table-cell{padding:var(--coar-markdown-space-1);vertical-align:top;border-right:1px solid var(--coar-markdown-border);border-bottom:1px solid var(--coar-markdown-border)}.coar-markdown-hr{border:0;border-top:1px solid var(--coar-markdown-border)}.coar-markdown-unsupported,.coar-markdown-unsupported-inline{color:var(--coar-markdown-muted-text);font-style:italic}.coar-markdown-unsupported{padding:var(--coar-markdown-space-1);border:1px dashed var(--coar-markdown-border);border-radius:var(--coar-markdown-radius);background:var(--coar-markdown-surface)}
2
2
  /*$vite$:1*/
package/dist/index.d.ts CHANGED
@@ -1,3 +1,22 @@
1
+ /**
2
+ * Public surface for `@cocoar/vue-markdown`.
3
+ *
4
+ * The package contains both:
5
+ * - The user-facing `<CoarMarkdown>` viewer component.
6
+ * - The shared **rendering registry** (`MarkdownViewerRenderers`,
7
+ * `defaultMarkdownRenderers`, `RenderNode`, …) — same registry the editor
8
+ * (`@cocoar/vue-markdown-editor`) consumes so a code block, table, etc.
9
+ * looks identical whether the user is reading or writing.
10
+ *
11
+ * Apps overriding renderers can either:
12
+ * - Pass a `renderers` prop to `<CoarMarkdown>` for a per-instance override.
13
+ * - Call `app.provide(MARKDOWN_RENDERERS_KEY, ...)` for an app-wide default.
14
+ */
1
15
  export { default as CoarMarkdown } from './CoarMarkdown.vue';
2
16
  export type { CoarMarkdownProps } from './CoarMarkdown.vue';
17
+ export { MARKDOWN_RENDERERS_KEY, rendererNameFor } from './registry';
18
+ export type { MarkdownEditorNodeViewSpec, MarkdownEditorNodeViews, MarkdownRendererName, MarkdownRendererProps, MarkdownViewerRenderers, } from './registry';
19
+ export { defaultMarkdownRenderers, DefaultBlockquote, DefaultCodeBlock, DefaultEmphasis, DefaultHeading, DefaultImage, DefaultInlineCode, DefaultLineBreak, DefaultLink, DefaultList, DefaultListItem, DefaultParagraph, DefaultStrikethrough, DefaultStrong, DefaultTable, DefaultTableCell, DefaultTableRow, DefaultText, DefaultThematicBreak, DefaultUnsupported, } from './default-renderers';
20
+ export { RenderNode, renderMarkdownNodes } from './RenderNode';
21
+ export * from './helpers';
3
22
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC7D,YAAY,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAC7D,YAAY,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAG5D,OAAO,EAAE,sBAAsB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AACrE,YAAY,EACV,0BAA0B,EAC1B,uBAAuB,EACvB,oBAAoB,EACpB,qBAAqB,EACrB,uBAAuB,GACxB,MAAM,YAAY,CAAC;AAIpB,OAAO,EACL,wBAAwB,EACxB,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EACf,cAAc,EACd,YAAY,EACZ,iBAAiB,EACjB,gBAAgB,EAChB,WAAW,EACX,WAAW,EACX,eAAe,EACf,gBAAgB,EAChB,oBAAoB,EACpB,aAAa,EACb,YAAY,EACZ,gBAAgB,EAChB,eAAe,EACf,WAAW,EACX,oBAAoB,EACpB,kBAAkB,GACnB,MAAM,qBAAqB,CAAC;AAI7B,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AAI/D,cAAc,WAAW,CAAC"}
package/dist/index.js CHANGED
@@ -1,209 +1,363 @@
1
- import { Fragment as e, createBlock as t, createCommentVNode as n, createElementBlock as r, createElementVNode as i, createTextVNode as a, createVNode as o, defineComponent as s, normalizeClass as c, openBlock as l, renderList as u, resolveComponent as d, resolveDynamicComponent as f, toDisplayString as p, unref as m, withCtx as h } from "vue";
2
- import { CoarCodeBlock as g, CoarTable as _ } from "@cocoar/vue-ui";
1
+ import { Fragment as e, createBlock as t, createElementBlock as n, defineComponent as r, h as i, inject as a, openBlock as o, provide as ee, renderList as s, unref as c } from "vue";
2
+ import { CoarCodeBlock as l } from "@cocoar/vue-ui";
3
3
  //#region src/helpers.ts
4
- function v(e) {
4
+ function u(e) {
5
5
  let t = e.attrs?.depth;
6
6
  if (typeof t != "number") return 1;
7
7
  let n = Math.trunc(t);
8
8
  return n <= 1 ? 1 : n === 2 ? 2 : n === 3 ? 3 : n === 4 ? 4 : n === 5 ? 5 : 6;
9
9
  }
10
- function y(e) {
10
+ function d(e) {
11
11
  let t = e.attrs?.anchor;
12
12
  return typeof t == "string" && t.length > 0 ? t : null;
13
13
  }
14
- function b(e) {
14
+ function f(e) {
15
15
  let t = e.attrs?.language;
16
16
  return typeof t == "string" && t.trim().length > 0 ? t.trim() : "text";
17
17
  }
18
- function x(e) {
18
+ function p(e) {
19
19
  return !!e.attrs?.ordered;
20
20
  }
21
- function S(e) {
21
+ function m(e) {
22
22
  let t = e.attrs?.start;
23
23
  return typeof t == "number" ? t : null;
24
24
  }
25
- function C(e) {
25
+ function h(e) {
26
26
  return typeof e.attrs?.checked == "boolean";
27
27
  }
28
- function w(e) {
28
+ function g(e) {
29
29
  return e.attrs?.checked === !0;
30
30
  }
31
- function T(e) {
31
+ function _(e) {
32
32
  let t = e.attrs?.url;
33
33
  return typeof t == "string" && t.length > 0 ? t : null;
34
34
  }
35
- function E(e) {
36
- let t = T(e);
35
+ function v(e) {
36
+ let t = _(e);
37
37
  return t ? t.startsWith("#") && typeof window < "u" ? `${window.location.pathname}${window.location.search}${t}` : t : null;
38
38
  }
39
- function D(e) {
40
- let t = T(e);
41
- return t && I(t) ? "_blank" : null;
39
+ function y(e) {
40
+ let t = _(e);
41
+ return t && O(t) ? "_blank" : null;
42
42
  }
43
- function O(e) {
44
- let t = T(e);
45
- return t && I(t) ? "noopener noreferrer" : null;
43
+ function b(e) {
44
+ let t = _(e);
45
+ return t && O(t) ? "noopener noreferrer" : null;
46
46
  }
47
- function k(e) {
47
+ function x(e) {
48
48
  let t = e.attrs?.url;
49
49
  return typeof t == "string" && t.trim().length > 0 ? t.trim() : null;
50
50
  }
51
- function A(e) {
51
+ function S(e) {
52
52
  let t = e.attrs?.alt;
53
53
  return typeof t == "string" ? t : "";
54
54
  }
55
- function j(e) {
55
+ function C(e) {
56
56
  let t = e.attrs?.title;
57
57
  return typeof t == "string" && t.trim().length > 0 ? t.trim() : null;
58
58
  }
59
- function M(e, t) {
60
- return F(e, t) === "right";
59
+ function w(e, t) {
60
+ return D(e, t) === "right";
61
61
  }
62
- function N(e, t) {
63
- return F(e, t) === "center";
62
+ function T(e, t) {
63
+ return D(e, t) === "center";
64
64
  }
65
- function P(e) {
65
+ function E(e) {
66
66
  let t = e.attrs?.originalType;
67
67
  return typeof t == "string" ? t : String(e.type);
68
68
  }
69
- function F(e, t) {
69
+ function D(e, t) {
70
70
  let n = e.attrs?.align;
71
71
  if (!Array.isArray(n)) return null;
72
72
  let r = n[t];
73
73
  return r === "left" || r === "right" || r === "center" ? r : null;
74
74
  }
75
- function I(e) {
75
+ function O(e) {
76
76
  let t = e.trim();
77
77
  return t.startsWith("#") || t.startsWith("/") || t.startsWith("./") || t.startsWith("../") || t.startsWith("mailto:") || t.startsWith("tel:") ? !1 : t.startsWith("http://") || t.startsWith("https://");
78
78
  }
79
79
  //#endregion
80
- //#region src/MarkdownInlineNode.vue?vue&type=script&setup=true&lang.ts
81
- var L = { key: 1 }, R = { key: 2 }, z = { key: 3 }, B = {
82
- key: 4,
83
- class: "coar-markdown-inline-code"
84
- }, V = { key: 5 }, H = [
85
- "href",
86
- "target",
87
- "rel"
88
- ], U = [
89
- "src",
90
- "alt",
91
- "title"
92
- ], W = {
93
- key: 8,
94
- class: "coar-markdown-unsupported-inline"
95
- }, G = /* @__PURE__ */ s({
96
- __name: "MarkdownInlineNode",
97
- props: { nodes: {} },
98
- setup(i) {
99
- return (s, c) => {
100
- let f = d("MarkdownInlineNode", !0);
101
- return l(!0), r(e, null, u(i.nodes, (i) => (l(), r(e, { key: i.id }, [i.type === "text" ? (l(), r(e, { key: 0 }, [a(p(i.text ?? ""), 1)], 64)) : i.type === "emphasis" ? (l(), r("em", L, [o(f, { nodes: i.children ?? [] }, null, 8, ["nodes"])])) : i.type === "strong" ? (l(), r("strong", R, [o(f, { nodes: i.children ?? [] }, null, 8, ["nodes"])])) : i.type === "strikethrough" ? (l(), r("del", z, [o(f, { nodes: i.children ?? [] }, null, 8, ["nodes"])])) : i.type === "inlineCode" ? (l(), r("code", B, p(i.text ?? ""), 1)) : i.type === "lineBreak" ? (l(), r("br", V)) : i.type === "link" ? (l(), r(e, { key: 6 }, [m(E)(i) ? (l(), r("a", {
102
- key: 0,
80
+ //#region src/default-renderers.ts
81
+ var k = {
82
+ node: {
83
+ type: Object,
84
+ required: !0
85
+ },
86
+ renderChildren: {
87
+ type: Function,
88
+ required: !0
89
+ },
90
+ renderNodes: {
91
+ type: Function,
92
+ required: !0
93
+ }
94
+ }, A = r({
95
+ name: "DefaultHeading",
96
+ props: k,
97
+ setup(e) {
98
+ return () => {
99
+ let t = u(e.node), n = d(e.node);
100
+ return i(`h${t}`, {
101
+ id: n ?? void 0,
102
+ class: "coar-markdown-heading"
103
+ }, e.renderChildren());
104
+ };
105
+ }
106
+ }), j = r({
107
+ name: "DefaultParagraph",
108
+ props: k,
109
+ setup(e) {
110
+ return () => i("p", { class: "coar-markdown-paragraph" }, e.renderChildren());
111
+ }
112
+ }), M = r({
113
+ name: "DefaultBlockquote",
114
+ props: k,
115
+ setup(e) {
116
+ return () => i("blockquote", { class: "coar-markdown-blockquote" }, e.renderChildren());
117
+ }
118
+ }), N = r({
119
+ name: "DefaultList",
120
+ props: k,
121
+ setup(e) {
122
+ return () => {
123
+ let t = p(e.node), n = t ? "ol" : "ul", r = t ? m(e.node) : null;
124
+ return i(n, {
125
+ class: ["coar-markdown-list", t ? "coar-markdown-list--ordered" : "coar-markdown-list--unordered"],
126
+ start: r ?? void 0
127
+ }, e.renderChildren());
128
+ };
129
+ }
130
+ }), P = r({
131
+ name: "DefaultListItem",
132
+ props: k,
133
+ setup(e) {
134
+ return () => {
135
+ let t = h(e.node), n = t && g(e.node), r = [];
136
+ return t && r.push(i("input", {
137
+ class: "coar-markdown-task-checkbox",
138
+ type: "checkbox",
139
+ checked: n,
140
+ disabled: !0,
141
+ "aria-hidden": "true",
142
+ tabindex: -1
143
+ })), r.push(i("div", { class: "coar-markdown-list-item-content" }, e.renderChildren())), i("li", { class: ["coar-markdown-list-item", t ? "coar-markdown-list-item--task" : null] }, r);
144
+ };
145
+ }
146
+ }), F = r({
147
+ name: "DefaultCodeBlock",
148
+ props: k,
149
+ setup(e) {
150
+ return () => i(l, {
151
+ class: "coar-markdown-code-block",
152
+ code: e.node.text ?? "",
153
+ language: f(e.node),
154
+ collapsible: !1,
155
+ showCopy: !0
156
+ });
157
+ }
158
+ }), I = r({
159
+ name: "DefaultTable",
160
+ props: k,
161
+ setup(e) {
162
+ return () => {
163
+ let t = e.node.children ?? [];
164
+ if (t.length === 0) return i("table", { class: "coar-markdown-table" });
165
+ let [n, ...r] = t;
166
+ return i("table", { class: "coar-markdown-table" }, [i("thead", null, [i("tr", null, (n.children ?? []).map((t, n) => i("th", {
167
+ key: t.id,
168
+ class: [w(e.node, n) ? "text-right" : null, T(e.node, n) ? "text-center" : null]
169
+ }, e.renderNodes(t.children ?? []))))]), i("tbody", null, r.map((t) => i("tr", { key: t.id }, (t.children ?? []).map((t, n) => i("td", {
170
+ key: t.id,
171
+ class: [w(e.node, n) ? "text-right" : null, T(e.node, n) ? "text-center" : null]
172
+ }, e.renderNodes(t.children ?? []))))))]);
173
+ };
174
+ }
175
+ }), L = r({
176
+ name: "DefaultTableRow",
177
+ props: k,
178
+ setup(e) {
179
+ return () => i("tr", null, e.renderChildren());
180
+ }
181
+ }), R = r({
182
+ name: "DefaultTableCell",
183
+ props: k,
184
+ setup(e) {
185
+ return () => i("td", { class: "coar-markdown-table-cell" }, e.renderChildren());
186
+ }
187
+ }), z = r({
188
+ name: "DefaultThematicBreak",
189
+ props: k,
190
+ setup() {
191
+ return () => i("hr", { class: "coar-markdown-hr" });
192
+ }
193
+ }), B = r({
194
+ name: "DefaultText",
195
+ props: k,
196
+ setup(e) {
197
+ return () => e.node.text ?? "";
198
+ }
199
+ }), V = r({
200
+ name: "DefaultEmphasis",
201
+ props: k,
202
+ setup(e) {
203
+ return () => i("em", null, e.renderChildren());
204
+ }
205
+ }), H = r({
206
+ name: "DefaultStrong",
207
+ props: k,
208
+ setup(e) {
209
+ return () => i("strong", null, e.renderChildren());
210
+ }
211
+ }), U = r({
212
+ name: "DefaultStrikethrough",
213
+ props: k,
214
+ setup(e) {
215
+ return () => i("del", null, e.renderChildren());
216
+ }
217
+ }), W = r({
218
+ name: "DefaultInlineCode",
219
+ props: k,
220
+ setup(e) {
221
+ return () => i("code", { class: "coar-markdown-inline-code" }, e.node.text ?? "");
222
+ }
223
+ }), G = r({
224
+ name: "DefaultLink",
225
+ props: k,
226
+ setup(e) {
227
+ return () => {
228
+ let t = v(e.node);
229
+ return t ? i("a", {
103
230
  class: "coar-markdown-link",
104
- href: m(E)(i),
105
- target: m(D)(i) ?? void 0,
106
- rel: m(O)(i) ?? void 0
107
- }, [o(f, { nodes: i.children ?? [] }, null, 8, ["nodes"])], 8, H)) : (l(), t(f, {
108
- key: 1,
109
- nodes: i.children ?? []
110
- }, null, 8, ["nodes"]))], 64)) : i.type === "image" ? (l(), r(e, { key: 7 }, [m(k)(i) ? (l(), r("img", {
111
- key: 0,
231
+ href: t,
232
+ target: y(e.node) ?? void 0,
233
+ rel: b(e.node) ?? void 0
234
+ }, e.renderChildren()) : e.renderChildren();
235
+ };
236
+ }
237
+ }), K = r({
238
+ name: "DefaultImage",
239
+ props: k,
240
+ setup(e) {
241
+ return () => {
242
+ let t = x(e.node);
243
+ return t ? i("img", {
112
244
  class: "coar-markdown-image",
113
- src: m(k)(i),
114
- alt: m(A)(i),
115
- title: m(j)(i) ?? void 0,
245
+ src: t,
246
+ alt: S(e.node),
247
+ title: C(e.node) ?? void 0,
116
248
  loading: "lazy"
117
- }, null, 8, U)) : n("", !0)], 64)) : (l(), r("span", W, "[unsupported]"))], 64))), 128);
249
+ }) : null;
118
250
  };
119
251
  }
120
- }), K = {
121
- key: 1,
122
- class: "coar-markdown-paragraph"
123
- }, q = {
124
- key: 2,
125
- class: "coar-markdown-blockquote"
126
- }, J = ["start"], Y = {
127
- key: 1,
128
- class: "coar-markdown-list coar-markdown-list--unordered"
129
- }, X = ["checked"], Z = { class: "coar-markdown-list-item-content" }, Q = {
130
- key: 6,
131
- class: "coar-markdown-hr"
132
- }, $ = {
133
- key: 9,
134
- class: "coar-markdown-table-cell"
135
- }, ee = {
136
- key: 10,
137
- class: "coar-markdown-unsupported"
138
- }, te = /* @__PURE__ */ s({
139
- __name: "MarkdownBlockNode",
252
+ }), q = r({
253
+ name: "DefaultLineBreak",
254
+ props: k,
255
+ setup() {
256
+ return () => i("br");
257
+ }
258
+ }), J = r({
259
+ name: "DefaultUnsupported",
260
+ props: k,
261
+ setup(e) {
262
+ return () => i("div", { class: "coar-markdown-unsupported" }, `Unsupported markdown node: ${E(e.node)}`);
263
+ }
264
+ }), Y = {
265
+ heading: A,
266
+ paragraph: j,
267
+ blockquote: M,
268
+ list: N,
269
+ listItem: P,
270
+ codeBlock: F,
271
+ table: I,
272
+ tableRow: L,
273
+ tableCell: R,
274
+ thematicBreak: z,
275
+ text: B,
276
+ emphasis: V,
277
+ strong: H,
278
+ strikethrough: U,
279
+ inlineCode: W,
280
+ link: G,
281
+ image: K,
282
+ lineBreak: q,
283
+ unsupported: J
284
+ };
285
+ //#endregion
286
+ //#region src/registry.ts
287
+ function X(e) {
288
+ return e in Z ? e : "unsupported";
289
+ }
290
+ var Z = {
291
+ heading: !0,
292
+ paragraph: !0,
293
+ blockquote: !0,
294
+ list: !0,
295
+ listItem: !0,
296
+ codeBlock: !0,
297
+ table: !0,
298
+ tableRow: !0,
299
+ tableCell: !0,
300
+ thematicBreak: !0,
301
+ text: !0,
302
+ emphasis: !0,
303
+ strong: !0,
304
+ strikethrough: !0,
305
+ inlineCode: !0,
306
+ link: !0,
307
+ image: !0,
308
+ lineBreak: !0,
309
+ unsupported: !0
310
+ }, Q = Symbol.for("coar:markdown-renderers"), $ = r({
311
+ name: "RenderNode",
140
312
  props: {
141
- nodes: {},
142
- tableNode: {}
313
+ node: {
314
+ type: Object,
315
+ required: !0
316
+ },
317
+ renderers: {
318
+ type: Object,
319
+ default: void 0
320
+ }
143
321
  },
144
- setup(a) {
145
- return (s, T) => {
146
- let E = d("MarkdownBlockNode", !0);
147
- return l(!0), r(e, null, u(a.nodes, (a) => (l(), r(e, { key: a.id }, [a.type === "heading" ? (l(), t(f("h" + m(v)(a)), {
148
- key: 0,
149
- id: m(y)(a) ?? void 0,
150
- class: "coar-markdown-heading"
151
- }, {
152
- default: h(() => [o(G, { nodes: a.children ?? [] }, null, 8, ["nodes"])]),
153
- _: 2
154
- }, 1032, ["id"])) : a.type === "paragraph" ? (l(), r("p", K, [o(G, { nodes: a.children ?? [] }, null, 8, ["nodes"])])) : a.type === "blockquote" ? (l(), r("blockquote", q, [o(E, { nodes: a.children ?? [] }, null, 8, ["nodes"])])) : a.type === "list" ? (l(), r(e, { key: 3 }, [m(x)(a) ? (l(), r("ol", {
155
- key: 0,
156
- class: "coar-markdown-list coar-markdown-list--ordered",
157
- start: m(S)(a) ?? void 0
158
- }, [o(E, { nodes: a.children ?? [] }, null, 8, ["nodes"])], 8, J)) : (l(), r("ul", Y, [o(E, { nodes: a.children ?? [] }, null, 8, ["nodes"])]))], 64)) : a.type === "listItem" ? (l(), r("li", {
159
- key: 4,
160
- class: c(["coar-markdown-list-item", { "coar-markdown-list-item--task": m(C)(a) }])
161
- }, [m(C)(a) ? (l(), r("input", {
162
- key: 0,
163
- class: "coar-markdown-task-checkbox",
164
- type: "checkbox",
165
- checked: m(w)(a),
166
- disabled: "",
167
- "aria-hidden": "true",
168
- tabindex: "-1"
169
- }, null, 8, X)) : n("", !0), i("div", Z, [o(E, { nodes: a.children ?? [] }, null, 8, ["nodes"])])], 2)) : a.type === "codeBlock" ? (l(), t(m(g), {
170
- key: 5,
171
- class: "coar-markdown-code-block",
172
- code: a.text ?? "",
173
- language: m(b)(a),
174
- collapsible: !1,
175
- "show-copy": !0
176
- }, null, 8, ["code", "language"])) : a.type === "thematicBreak" ? (l(), r("hr", Q)) : a.type === "table" ? (l(), t(m(_), {
177
- key: 7,
178
- variant: "plain",
179
- hover: ""
180
- }, {
181
- default: h(() => [(a.children ?? []).length > 0 ? (l(), r(e, { key: 0 }, [i("thead", null, [i("tr", null, [(l(!0), r(e, null, u((a.children ?? [])[0]?.children ?? [], (e, t) => (l(), r("th", {
182
- key: e.id,
183
- class: c({
184
- "text-right": m(M)(a, t),
185
- "text-center": m(N)(a, t)
186
- })
187
- }, [o(G, { nodes: e.children ?? [] }, null, 8, ["nodes"])], 2))), 128))])]), i("tbody", null, [(l(!0), r(e, null, u((a.children ?? []).slice(1), (t) => (l(), r("tr", { key: t.id }, [(l(!0), r(e, null, u(t.children ?? [], (e, t) => (l(), r("td", {
188
- key: e.id,
189
- class: c({
190
- "text-right": m(M)(a, t),
191
- "text-center": m(N)(a, t)
192
- })
193
- }, [o(G, { nodes: e.children ?? [] }, null, 8, ["nodes"])], 2))), 128))]))), 128))])], 64)) : n("", !0)]),
194
- _: 2
195
- }, 1024)) : a.type === "tableRow" ? (l(), t(E, {
196
- key: 8,
197
- nodes: a.children ?? []
198
- }, null, 8, ["nodes"])) : a.type === "tableCell" ? (l(), r("td", $, [o(G, { nodes: a.children ?? [] }, null, 8, ["nodes"])])) : (l(), r("div", ee, " Unsupported markdown node: " + p(m(P)(a)), 1))], 64))), 128);
322
+ setup(e) {
323
+ let t = a(Q, void 0), n = () => e.renderers ?? t ?? Y;
324
+ e.renderers && ee(Q, e.renderers);
325
+ let r = (e) => e.map((e) => i($, {
326
+ node: e,
327
+ key: e.id
328
+ })), o = () => r(e.node.children ?? []);
329
+ return () => {
330
+ let t = n()[X(e.node.type)];
331
+ return i(t, {
332
+ node: e.node,
333
+ renderChildren: o,
334
+ renderNodes: r
335
+ });
199
336
  };
200
337
  }
201
- }), ne = { class: "coar-markdown" }, re = /* @__PURE__ */ s({
338
+ });
339
+ function te(e, t) {
340
+ return e.map((e) => i($, {
341
+ node: e,
342
+ renderers: t,
343
+ key: e.id
344
+ }));
345
+ }
346
+ //#endregion
347
+ //#region src/CoarMarkdown.vue?vue&type=script&setup=true&lang.ts
348
+ var ne = { class: "coar-markdown" }, re = /* @__PURE__ */ r({
202
349
  __name: "CoarMarkdown",
203
- props: { doc: {} },
204
- setup(e) {
205
- return (t, n) => (l(), r("div", ne, [o(te, { nodes: e.doc.nodes }, null, 8, ["nodes"])]));
350
+ props: {
351
+ doc: {},
352
+ renderers: {}
353
+ },
354
+ setup(r) {
355
+ return (i, a) => (o(), n("div", ne, [(o(!0), n(e, null, s(r.doc.nodes, (e) => (o(), t(c($), {
356
+ key: e.id,
357
+ node: e,
358
+ renderers: r.renderers
359
+ }, null, 8, ["node", "renderers"]))), 128))]));
206
360
  }
207
361
  });
208
362
  //#endregion
209
- export { re as CoarMarkdown };
363
+ export { re as CoarMarkdown, M as DefaultBlockquote, F as DefaultCodeBlock, V as DefaultEmphasis, A as DefaultHeading, K as DefaultImage, W as DefaultInlineCode, q as DefaultLineBreak, G as DefaultLink, N as DefaultList, P as DefaultListItem, j as DefaultParagraph, U as DefaultStrikethrough, H as DefaultStrong, I as DefaultTable, R as DefaultTableCell, L as DefaultTableRow, B as DefaultText, z as DefaultThematicBreak, J as DefaultUnsupported, Q as MARKDOWN_RENDERERS_KEY, $ as RenderNode, f as codeBlockLanguage, Y as defaultMarkdownRenderers, d as headingAnchor, u as headingDepth, S as imageAlt, x as imageSrc, C as imageTitle, p as isOrderedList, T as isTableColumnCenterAligned, w as isTableColumnRightAligned, h as isTaskListItem, v as linkHref, b as linkRel, y as linkTarget, _ as linkUrl, m as listStart, te as renderMarkdownNodes, X as rendererNameFor, g as taskChecked, E as unsupportedType };
@@ -0,0 +1,84 @@
1
+ import { Component, InjectionKey, VNode } from 'vue';
2
+ import { MarkdownNode, MarkdownNodeType } from '@cocoar/vue-markdown-core';
3
+ /**
4
+ * Props every viewer renderer receives.
5
+ *
6
+ * - `renderChildren()` — sugar for `renderNodes(node.children ?? [])`. Use it
7
+ * for the common case of rendering the node's direct children in order.
8
+ * - `renderNodes(arr)` — render any list of `MarkdownNode`s through the
9
+ * registry. Needed for components like `DefaultTable` that emit a non-trivial
10
+ * DOM structure and want to delegate the inline content of *individual cells*
11
+ * back to the registry.
12
+ */
13
+ export interface MarkdownRendererProps<TNode extends MarkdownNode = MarkdownNode> {
14
+ node: TNode;
15
+ renderChildren: () => VNode[];
16
+ renderNodes: (nodes: readonly MarkdownNode[]) => VNode[];
17
+ }
18
+ /**
19
+ * Component map: one renderer per `MarkdownNodeType`. Every type listed in
20
+ * `markdown-core`'s `MarkdownNodeType` union has an entry — explicit completeness
21
+ * keeps the registry honest. `unsupported` is the fallback shown when a node
22
+ * type slips through without a renderer.
23
+ */
24
+ export interface MarkdownViewerRenderers {
25
+ heading: Component<MarkdownRendererProps>;
26
+ paragraph: Component<MarkdownRendererProps>;
27
+ blockquote: Component<MarkdownRendererProps>;
28
+ list: Component<MarkdownRendererProps>;
29
+ listItem: Component<MarkdownRendererProps>;
30
+ codeBlock: Component<MarkdownRendererProps>;
31
+ table: Component<MarkdownRendererProps>;
32
+ tableRow: Component<MarkdownRendererProps>;
33
+ tableCell: Component<MarkdownRendererProps>;
34
+ thematicBreak: Component<MarkdownRendererProps>;
35
+ text: Component<MarkdownRendererProps>;
36
+ emphasis: Component<MarkdownRendererProps>;
37
+ strong: Component<MarkdownRendererProps>;
38
+ strikethrough: Component<MarkdownRendererProps>;
39
+ inlineCode: Component<MarkdownRendererProps>;
40
+ link: Component<MarkdownRendererProps>;
41
+ image: Component<MarkdownRendererProps>;
42
+ lineBreak: Component<MarkdownRendererProps>;
43
+ unsupported: Component<MarkdownRendererProps>;
44
+ }
45
+ export type MarkdownRendererName = keyof MarkdownViewerRenderers;
46
+ /**
47
+ * Map any node `type` string to a known renderer name. Falls back to
48
+ * `'unsupported'` when the type isn't in the registry — happens if
49
+ * `markdown-core` adds a node type before this registry catches up, or if a
50
+ * custom transformer emits a non-standard type. Accepts `string` (not just
51
+ * `MarkdownNodeType`) because `MarkdownNode.type` is widened to allow
52
+ * forward-compatible string literals.
53
+ */
54
+ export declare function rendererNameFor(type: MarkdownNodeType | string): MarkdownRendererName;
55
+ /**
56
+ * Vue inject key. Apps that want to globally override renderers can
57
+ * `app.provide(MARKDOWN_RENDERERS_KEY, ...)` once at startup. The viewer and
58
+ * editor both fall back to {@link defaultMarkdownRenderers} when no provider
59
+ * is present.
60
+ *
61
+ * Per-instance overrides flow through the `renderers` prop on the viewer /
62
+ * editor and win over the inject value, which wins over the default.
63
+ */
64
+ export declare const MARKDOWN_RENDERERS_KEY: InjectionKey<MarkdownViewerRenderers>;
65
+ /**
66
+ * Editor-side counterpart: optional ProseMirror NodeView factories per *PM
67
+ * node name* (note: PM uses snake_case — `code_block`, `table` — not the
68
+ * AST's camelCase). Defined here for completeness; the actual factories live
69
+ * in the editor package because they depend on Milkdown / PM types we don't
70
+ * want to pull into the viewer.
71
+ *
72
+ * Phase-1 scaffolding only — the editor wiring follows in phase 4.
73
+ */
74
+ export interface MarkdownEditorNodeViewSpec {
75
+ /** PM node type name as it appears in the schema (e.g. `code_block`). */
76
+ pmNodeName: string;
77
+ /** Brief description for debugging / dev-tools — never user-facing. */
78
+ description: string;
79
+ }
80
+ export interface MarkdownEditorNodeViews {
81
+ code_block?: MarkdownEditorNodeViewSpec;
82
+ table?: MarkdownEditorNodeViewSpec;
83
+ }
84
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,KAAK,CAAC;AAC1D,OAAO,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAEhF;;;;;;;;;GASG;AACH,MAAM,WAAW,qBAAqB,CAAC,KAAK,SAAS,YAAY,GAAG,YAAY;IAC9E,IAAI,EAAE,KAAK,CAAC;IACZ,cAAc,EAAE,MAAM,KAAK,EAAE,CAAC;IAC9B,WAAW,EAAE,CAAC,KAAK,EAAE,SAAS,YAAY,EAAE,KAAK,KAAK,EAAE,CAAC;CAC1D;AAED;;;;;GAKG;AACH,MAAM,WAAW,uBAAuB;IAEtC,OAAO,EAAE,SAAS,CAAC,qBAAqB,CAAC,CAAC;IAC1C,SAAS,EAAE,SAAS,CAAC,qBAAqB,CAAC,CAAC;IAC5C,UAAU,EAAE,SAAS,CAAC,qBAAqB,CAAC,CAAC;IAC7C,IAAI,EAAE,SAAS,CAAC,qBAAqB,CAAC,CAAC;IACvC,QAAQ,EAAE,SAAS,CAAC,qBAAqB,CAAC,CAAC;IAC3C,SAAS,EAAE,SAAS,CAAC,qBAAqB,CAAC,CAAC;IAC5C,KAAK,EAAE,SAAS,CAAC,qBAAqB,CAAC,CAAC;IACxC,QAAQ,EAAE,SAAS,CAAC,qBAAqB,CAAC,CAAC;IAC3C,SAAS,EAAE,SAAS,CAAC,qBAAqB,CAAC,CAAC;IAC5C,aAAa,EAAE,SAAS,CAAC,qBAAqB,CAAC,CAAC;IAEhD,IAAI,EAAE,SAAS,CAAC,qBAAqB,CAAC,CAAC;IACvC,QAAQ,EAAE,SAAS,CAAC,qBAAqB,CAAC,CAAC;IAC3C,MAAM,EAAE,SAAS,CAAC,qBAAqB,CAAC,CAAC;IACzC,aAAa,EAAE,SAAS,CAAC,qBAAqB,CAAC,CAAC;IAChD,UAAU,EAAE,SAAS,CAAC,qBAAqB,CAAC,CAAC;IAC7C,IAAI,EAAE,SAAS,CAAC,qBAAqB,CAAC,CAAC;IACvC,KAAK,EAAE,SAAS,CAAC,qBAAqB,CAAC,CAAC;IACxC,SAAS,EAAE,SAAS,CAAC,qBAAqB,CAAC,CAAC;IAE5C,WAAW,EAAE,SAAS,CAAC,qBAAqB,CAAC,CAAC;CAC/C;AAED,MAAM,MAAM,oBAAoB,GAAG,MAAM,uBAAuB,CAAC;AAEjE;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,gBAAgB,GAAG,MAAM,GAAG,oBAAoB,CAIrF;AAYD;;;;;;;;GAQG;AACH,eAAO,MAAM,sBAAsB,EAAE,YAAY,CAAC,uBAAuB,CAExE,CAAC;AAEF;;;;;;;;GAQG;AACH,MAAM,WAAW,0BAA0B;IACzC,yEAAyE;IACzE,UAAU,EAAE,MAAM,CAAC;IACnB,uEAAuE;IACvE,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,uBAAuB;IACtC,UAAU,CAAC,EAAE,0BAA0B,CAAC;IACxC,KAAK,CAAC,EAAE,0BAA0B,CAAC;CACpC"}