@mainsoft/agent-cms 0.7.0 → 0.10.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.
Files changed (111) hide show
  1. package/CHANGELOG.md +64 -0
  2. package/README.md +291 -32
  3. package/TODO.md +72 -26
  4. package/UPGRADE-0.10.md +36 -0
  5. package/UPGRADE-0.8.md +118 -0
  6. package/dist/agent.cjs +39 -17
  7. package/dist/agent.d.cts +2 -2
  8. package/dist/agent.d.ts +2 -2
  9. package/dist/agent.js +9 -7
  10. package/dist/bin.js +4528 -355
  11. package/dist/{chunk-OQ55GEF3.js → chunk-3OPKTBEI.js} +1 -1
  12. package/dist/chunk-6PB4ZCHH.js +328 -0
  13. package/dist/chunk-7SCYDG2G.js +2943 -0
  14. package/dist/chunk-7WJIIJCI.js +544 -0
  15. package/dist/chunk-7Y6TU2UA.js +150 -0
  16. package/dist/{chunk-QC2M4NZY.js → chunk-BFVBHIHV.js} +72 -1
  17. package/dist/chunk-DSJETZT4.js +493 -0
  18. package/dist/{chunk-IW3D4I7Q.js → chunk-IU2SMWAM.js} +246 -4
  19. package/dist/{chunk-VICZ76TR.js → chunk-KAO3Z3CF.js} +43 -2
  20. package/dist/{chunk-CRDW6Q72.js → chunk-MA6VKJ3F.js} +87 -25
  21. package/dist/{chunk-6K5ZTGHQ.js → chunk-PEQY4N73.js} +16 -0
  22. package/dist/{chunk-DOADAH4L.js → chunk-PGV2QPIL.js} +40 -0
  23. package/dist/{chunk-Y63XQS2J.js → chunk-QMPSOLLH.js} +1 -1
  24. package/dist/{chunk-EXV6JNLY.js → chunk-ZCUJ4MPT.js} +15 -22
  25. package/dist/cli.cjs +4528 -355
  26. package/dist/cli.d.cts +19 -3
  27. package/dist/cli.d.ts +19 -3
  28. package/dist/cli.js +206 -16
  29. package/dist/client.cjs +72 -1
  30. package/dist/client.d.cts +308 -6
  31. package/dist/client.d.ts +308 -6
  32. package/dist/client.js +1 -1
  33. package/dist/cms-C_vkAxYV.d.cts +1537 -0
  34. package/dist/cms-pqJyowu1.d.ts +1537 -0
  35. package/dist/config.d.cts +7 -1
  36. package/dist/config.d.ts +7 -1
  37. package/dist/drizzle-repo-CviH3EX7.d.cts +146 -0
  38. package/dist/drizzle-repo-DWLD0rWe.d.ts +146 -0
  39. package/dist/errors.cjs +82 -1
  40. package/dist/errors.d.cts +43 -3
  41. package/dist/errors.d.ts +43 -3
  42. package/dist/errors.js +2 -2
  43. package/dist/frontmatter.d.cts +5 -4
  44. package/dist/frontmatter.d.ts +5 -4
  45. package/dist/http.cjs +640 -94
  46. package/dist/http.d.cts +51 -2
  47. package/dist/http.d.ts +51 -2
  48. package/dist/http.js +203 -13
  49. package/dist/index.cjs +3759 -575
  50. package/dist/index.d.cts +8 -8
  51. package/dist/index.d.ts +8 -8
  52. package/dist/index.js +226 -30
  53. package/dist/markdown.cjs +89 -25
  54. package/dist/markdown.d.cts +57 -3
  55. package/dist/markdown.d.ts +57 -3
  56. package/dist/markdown.js +5 -1
  57. package/dist/mcp.cjs +314 -37
  58. package/dist/mcp.d.cts +3 -2
  59. package/dist/mcp.d.ts +3 -2
  60. package/dist/mcp.js +12 -9
  61. package/dist/messages/en.cjs +40 -0
  62. package/dist/messages/en.js +1 -1
  63. package/dist/messages/ko.cjs +40 -0
  64. package/dist/messages/ko.js +40 -0
  65. package/dist/registry/cms-audit.json +1 -1
  66. package/dist/registry/cms-doc-editor.json +15 -4
  67. package/dist/registry/cms-doc-list.json +2 -1
  68. package/dist/registry/cms-files.json +29 -0
  69. package/dist/registry/cms-lib.json +3 -3
  70. package/dist/registry/cms-media-picker.json +29 -0
  71. package/dist/registry/cms-media.json +28 -0
  72. package/dist/registry/cms-preview-comments.json +24 -0
  73. package/dist/registry/cms-releases.json +28 -0
  74. package/dist/registry/cms-shell.json +2 -2
  75. package/dist/registry/cms-trash.json +24 -0
  76. package/dist/registry/cms-versions.json +2 -1
  77. package/dist/registry/registry.json +163 -3
  78. package/dist/storage-s3.cjs +168 -0
  79. package/dist/storage-s3.d.cts +53 -0
  80. package/dist/storage-s3.d.ts +53 -0
  81. package/dist/storage-s3.js +143 -0
  82. package/dist/storage.cjs +373 -0
  83. package/dist/storage.d.cts +183 -0
  84. package/dist/storage.d.ts +183 -0
  85. package/dist/storage.js +49 -0
  86. package/dist/tables.cjs +251 -3
  87. package/dist/tables.d.cts +4965 -681
  88. package/dist/tables.d.ts +4965 -681
  89. package/dist/tables.js +14 -2
  90. package/dist/tools.cjs +331 -20
  91. package/dist/tools.d.cts +54 -7
  92. package/dist/tools.d.ts +54 -7
  93. package/dist/tools.js +16 -7
  94. package/dist/types.cjs +99 -1
  95. package/dist/types.d.cts +205 -5
  96. package/dist/types.d.ts +205 -5
  97. package/dist/types.js +5 -3
  98. package/package.json +32 -22
  99. package/dist/ai.cjs +0 -555
  100. package/dist/ai.d.cts +0 -48
  101. package/dist/ai.d.ts +0 -48
  102. package/dist/ai.js +0 -73
  103. package/dist/chunk-52NUUZC7.js +0 -1446
  104. package/dist/chunk-IGL2V6US.js +0 -324
  105. package/dist/chunk-QQV6VLYJ.js +0 -204
  106. package/dist/cms-BPp01z-8.d.ts +0 -411
  107. package/dist/cms-D6D89-qZ.d.cts +0 -411
  108. package/dist/drizzle-repo-B1rt7r4j.d.ts +0 -90
  109. package/dist/drizzle-repo-Cn-kL2FK.d.cts +0 -90
  110. package/dist/repo-BWI2Pkrv.d.ts +0 -162
  111. package/dist/repo-CeDxUxO6.d.cts +0 -162
package/dist/markdown.cjs CHANGED
@@ -23,6 +23,8 @@ __export(markdown_exports, {
23
23
  APP_LINK_RE: () => APP_LINK_RE,
24
24
  anchorOf: () => anchorOf,
25
25
  appLinkKeys: () => appLinkKeys,
26
+ assetUses: () => assetUses,
27
+ externalImages: () => externalImages,
26
28
  extractToc: () => extractToc,
27
29
  inlineText: () => inlineText,
28
30
  parseInline: () => parseInline,
@@ -36,20 +38,45 @@ function anchorOf(text) {
36
38
  const base = text.trim().toLowerCase().replace(/[`*_[\]()<>!?.,:;'"“”‘’/\\|]/g, "").replace(/\s+/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "");
37
39
  return base || "section";
38
40
  }
41
+ var ASSET_TARGET = /^asset:([a-z0-9]{12})(?:\/([^\s)]*))?$/;
42
+ var IMAGE = String.raw`!\[([^\]]*)\]\(\s*((?:[^()\s]|\([^()\s]*\))+)(?:\s+"([^"]*)")?\s*\)`;
43
+ var IMAGE_LINE = new RegExp(`^\\s*${IMAGE}\\s*$`);
44
+ var IMAGE_ANY = new RegExp(IMAGE, "g");
45
+ var ASSET_LINK_ANY = /(^|[^!])\[([^\]]+)\]\(asset:([a-z0-9]{12})(?:\/[^\s)]*)?\)/g;
46
+ var safeDecode = (s) => {
47
+ try {
48
+ return decodeURIComponent(s);
49
+ } catch {
50
+ return s;
51
+ }
52
+ };
53
+ function mediaTarget(target) {
54
+ const a = ASSET_TARGET.exec(target);
55
+ if (a) return { asset: a[1], name: safeDecode(a[2] ?? ""), src: null };
56
+ if (/^https:\/\//i.test(target)) return { asset: null, name: "", src: target };
57
+ return null;
58
+ }
39
59
  function parseInline(src) {
40
60
  const out = [];
41
- const re = /(\[\[link:([a-z0-9][a-z0-9._-]*)\|([^\]]+)\]\]|\*\*([^*]+)\*\*|`([^`]+)`|\[([^\]]+)\]\(((?:[^()\s]|\([^()\s]*\))+)\))/gi;
61
+ const re = new RegExp(String.raw`(\[\[link:(?<key>[a-z0-9][a-z0-9._-]*)\|(?<keyLabel>[^\]]+)\]\]|\*\*(?<strong>[^*]+)\*\*|` + "`(?<code>[^`]+)`" + String.raw`|!\[(?<alt>[^\]]*)\]\(\s*(?<img>(?:[^()\s]|\([^()\s]*\))+)(?:\s+"(?<cap>[^"]*)")?\s*\)|\[(?<label>[^\]]+)\]\((?<href>(?:[^()\s]|\([^()\s]*\))+)\))`, "gi");
42
62
  let last = 0;
43
63
  let m;
44
64
  while (m = re.exec(src)) {
65
+ const g = m.groups;
45
66
  if (m.index > last) out.push({ t: "text", v: src.slice(last, m.index) });
46
- if (m[2]) out.push({ t: "applink", key: m[2], v: m[3] });
47
- else if (m[4] !== void 0) out.push({ t: "strong", v: m[4] });
48
- else if (m[5] !== void 0) out.push({ t: "code", v: m[5] });
49
- else if (m[6] !== void 0) {
50
- const href = m[7];
51
- if (/^(https?:\/\/|mailto:|\/(?!\/)|#)/i.test(href)) out.push({ t: "link", href, v: m[6] });
52
- else out.push({ t: "text", v: m[6] });
67
+ if (g.key) out.push({ t: "applink", key: g.key, v: g.keyLabel });
68
+ else if (g.strong !== void 0) out.push({ t: "strong", v: g.strong });
69
+ else if (g.code !== void 0) out.push({ t: "code", v: g.code });
70
+ else if (g.img !== void 0) {
71
+ const target = mediaTarget(g.img);
72
+ if (target) out.push({ t: "image", ...target, alt: g.alt, v: g.alt });
73
+ else out.push({ t: "text", v: g.alt });
74
+ } else if (g.label !== void 0) {
75
+ const href = g.href;
76
+ const file = ASSET_TARGET.exec(href);
77
+ if (file) out.push({ t: "file", asset: file[1], name: safeDecode(file[2] ?? ""), v: g.label });
78
+ else if (/^(https?:\/\/|mailto:|\/(?!\/)|#)/i.test(href)) out.push({ t: "link", href, v: g.label });
79
+ else out.push({ t: "text", v: g.label });
53
80
  }
54
81
  last = m.index + m[0].length;
55
82
  }
@@ -59,11 +86,13 @@ function parseInline(src) {
59
86
  function inlineText(inline) {
60
87
  return inline.map((i) => i.v).join("");
61
88
  }
62
- function parseMarkdown(source) {
89
+ function parseMarkdown(source, o = {}) {
63
90
  const lines = source.replace(/\r/g, "").split("\n");
64
- const blocks = [];
91
+ const out = [];
92
+ const push = (b, from, to) => out.push(o.lines ? { ...b, line: from + 1, endLine: to + 1 } : b);
65
93
  const used = /* @__PURE__ */ new Map();
66
94
  let para = [];
95
+ let paraAt = [0, 0];
67
96
  let list = null;
68
97
  const uniqueId = (text) => {
69
98
  const base = anchorOf(text);
@@ -79,15 +108,12 @@ function parseMarkdown(source) {
79
108
  const inline = parseInline(text);
80
109
  const onlyLinks = inline.every((i) => i.t === "applink" || i.t === "text" && !i.v.trim());
81
110
  if (onlyLinks && inline.some((i) => i.t === "applink")) {
82
- blocks.push({
83
- t: "links",
84
- items: inline.filter((i) => i.t === "applink").map((i) => ({ key: i.key, v: i.v }))
85
- });
86
- } else blocks.push({ t: "p", inline });
111
+ push({ t: "links", items: inline.filter((i) => i.t === "applink").map((i) => ({ key: i.key, v: i.v })) }, paraAt[0], paraAt[1]);
112
+ } else push({ t: "p", inline }, paraAt[0], paraAt[1]);
87
113
  };
88
114
  const flushList = () => {
89
115
  if (!list) return;
90
- blocks.push({ t: "list", ordered: list.ordered, items: list.items.map(parseInline) });
116
+ push({ t: "list", ordered: list.ordered, items: list.items.map(parseInline) }, list.from, list.to);
91
117
  list = null;
92
118
  };
93
119
  const flush = () => {
@@ -100,9 +126,9 @@ function parseMarkdown(source) {
100
126
  if (fence) {
101
127
  flush();
102
128
  const buf = [];
103
- i++;
129
+ const from = i++;
104
130
  while (i < lines.length && !/^```\s*$/.test(lines[i])) buf.push(lines[i++]);
105
- blocks.push({ t: "code", lang: fence[1] ?? "", v: buf.join("\n") });
131
+ push({ t: "code", lang: fence[1] ?? "", v: buf.join("\n") }, from, Math.min(i, lines.length - 1));
106
132
  continue;
107
133
  }
108
134
  const h = /^(#{2,3})\s+(.+?)\s*#*\s*$/.exec(line);
@@ -110,23 +136,24 @@ function parseMarkdown(source) {
110
136
  flush();
111
137
  const text = h[2];
112
138
  const inline = parseInline(text);
113
- blocks.push({ t: "heading", level: h[1].length, id: uniqueId(inlineText(inline)), text: inlineText(inline), inline });
139
+ push({ t: "heading", level: h[1].length, id: uniqueId(inlineText(inline)), text: inlineText(inline), inline }, i, i);
114
140
  continue;
115
141
  }
116
142
  if (/^#\s+/.test(line)) {
117
143
  flush();
118
144
  const inline = parseInline(line.replace(/^#\s+/, ""));
119
- blocks.push({ t: "heading", level: 2, id: uniqueId(inlineText(inline)), text: inlineText(inline), inline });
145
+ push({ t: "heading", level: 2, id: uniqueId(inlineText(inline)), text: inlineText(inline), inline }, i, i);
120
146
  continue;
121
147
  }
122
148
  if (/^\s*(---|\*\*\*)\s*$/.test(line)) {
123
149
  flush();
124
- blocks.push({ t: "hr" });
150
+ push({ t: "hr" }, i, i);
125
151
  continue;
126
152
  }
127
153
  if (/^>\s?/.test(line)) {
128
154
  flush();
129
155
  const buf = [];
156
+ const from = i;
130
157
  while (i < lines.length && /^>\s?/.test(lines[i])) buf.push(lines[i++].replace(/^>\s?/, ""));
131
158
  i--;
132
159
  let callout = null;
@@ -136,7 +163,14 @@ function parseMarkdown(source) {
136
163
  buf.shift();
137
164
  }
138
165
  const inner = parseMarkdown(buf.join("\n")).map((b) => b.t === "heading" ? { t: "p", inline: b.inline } : b);
139
- blocks.push({ t: "quote", callout, blocks: inner });
166
+ push({ t: "quote", callout, blocks: inner }, from, i);
167
+ continue;
168
+ }
169
+ const img = IMAGE_LINE.exec(line);
170
+ const target = img ? mediaTarget(img[2]) : null;
171
+ if (img && target) {
172
+ flush();
173
+ push({ t: "media", ...target, alt: img[1].trim(), caption: (img[3] ?? "").trim() }, i, i);
140
174
  continue;
141
175
  }
142
176
  const ul = /^\s*[-*]\s+(.*)$/.exec(line);
@@ -145,8 +179,9 @@ function parseMarkdown(source) {
145
179
  flushPara();
146
180
  const ordered = !!ol;
147
181
  if (list && list.ordered !== ordered) flushList();
148
- if (!list) list = { ordered, items: [] };
182
+ if (!list) list = { ordered, items: [], from: i, to: i };
149
183
  list.items.push((ul ?? ol)[1]);
184
+ list.to = i;
150
185
  continue;
151
186
  }
152
187
  if (!line.trim()) {
@@ -155,13 +190,15 @@ function parseMarkdown(source) {
155
190
  }
156
191
  if (list && /^\s{2,}\S/.test(line)) {
157
192
  list.items[list.items.length - 1] += " " + line.trim();
193
+ list.to = i;
158
194
  continue;
159
195
  }
160
196
  flushList();
197
+ paraAt = para.length ? [paraAt[0], i] : [i, i];
161
198
  para.push(line.trim());
162
199
  }
163
200
  flush();
164
- return blocks;
201
+ return out;
165
202
  }
166
203
  function extractToc(blocks) {
167
204
  return blocks.flatMap((b) => b.t === "heading" ? [{ id: b.id, text: b.text, level: b.level }] : []);
@@ -171,8 +208,33 @@ function appLinkKeys(body) {
171
208
  for (const m of body.matchAll(APP_LINK_RE)) keys.add(m[1]);
172
209
  return [...keys];
173
210
  }
211
+ function assetUses(body) {
212
+ const out = [];
213
+ let inFence = false;
214
+ body.replace(/\r/g, "").split("\n").forEach((line, i) => {
215
+ if (/^```/.test(line)) inFence = !inFence;
216
+ if (inFence) return;
217
+ const whole = IMAGE_LINE.exec(line);
218
+ for (const m of line.matchAll(IMAGE_ANY)) {
219
+ const a = ASSET_TARGET.exec(m[2]);
220
+ if (a) out.push({ id: a[1], as: whole ? "media" : "image", alt: m[1].trim(), line: i + 1 });
221
+ }
222
+ for (const m of line.matchAll(ASSET_LINK_ANY)) out.push({ id: m[3], as: "file", alt: "", line: i + 1 });
223
+ });
224
+ return out;
225
+ }
226
+ function externalImages(body) {
227
+ const out = [];
228
+ let inFence = false;
229
+ body.replace(/\r/g, "").split("\n").forEach((line, i) => {
230
+ if (/^```/.test(line)) inFence = !inFence;
231
+ if (inFence) return;
232
+ for (const m of line.matchAll(IMAGE_ANY)) if (/^https:\/\//i.test(m[2])) out.push({ src: m[2], alt: m[1].trim(), line: i + 1 });
233
+ });
234
+ return out;
235
+ }
174
236
  function plainText(body) {
175
- return body.replace(/```[\s\S]*?```/g, " ").replace(APP_LINK_RE, "$2").replace(/\[([^\]]+)\]\([^)]+\)/g, "$1").replace(/^>\s?\[![a-z]+\]\s*$/gim, "").replace(/[*`>#]/g, "").replace(/^\s*(\d+[.)]|[-*])\s+/gm, "").replace(/[ \t]+/g, " ").trim();
237
+ return body.replace(/```[\s\S]*?```/g, " ").replace(APP_LINK_RE, "$2").replace(IMAGE_ANY, (_m, alt, _t, cap) => ` ${alt} ${cap ?? ""} `).replace(/\[([^\]]+)\]\([^)]+\)/g, "$1").replace(/^>\s?\[![a-z]+\]\s*$/gim, "").replace(/[*`>#]/g, "").replace(/^\s*(\d+[.)]|[-*])\s+/gm, "").replace(/[ \t]+/g, " ").trim();
176
238
  }
177
239
  function splitSections(body) {
178
240
  const lines = body.replace(/\r/g, "").split("\n");
@@ -211,6 +273,8 @@ function splitSections(body) {
211
273
  APP_LINK_RE,
212
274
  anchorOf,
213
275
  appLinkKeys,
276
+ assetUses,
277
+ externalImages,
214
278
  extractToc,
215
279
  inlineText,
216
280
  parseInline,
@@ -6,6 +6,12 @@
6
6
  * Supported: `## / ###` headings, paragraphs, `-`/`*` and `1.` lists, `>`
7
7
  * quotes and `> [!note]` callouts, fenced code, `---`, and inline **bold**,
8
8
  * `code`, [text](url) and the CMS link `[[link:key|label]]`.
9
+ *
10
+ * Files from the media library are named by id: `![alt](asset:ID/name.jpg
11
+ * "caption")` on a line of its own is a media block (an image, a video
12
+ * player or a download card, by the file's type), and `[label](asset:ID/
13
+ * name.pdf)` links to a file. Only the id matters; the name after the slash
14
+ * is there for people. `![alt](https://…)` shows an image from elsewhere.
9
15
  */
10
16
  type Inline = {
11
17
  t: "text";
@@ -21,13 +27,34 @@ type Inline = {
21
27
  href: string;
22
28
  v: string;
23
29
  }
30
+ /** `[label](asset:ID/name)`: a link to a file in the media library. */
31
+ | {
32
+ t: "file";
33
+ asset: string;
34
+ name: string;
35
+ v: string;
36
+ }
37
+ /** An image inside a line of text. `asset` (a media library id) or `src` (https). */
38
+ | {
39
+ t: "image";
40
+ asset: string | null;
41
+ name: string;
42
+ src: string | null;
43
+ alt: string;
44
+ v: string;
45
+ }
24
46
  /** `[[link:key|label]]` — an app screen, resolved by the collection. */
25
47
  | {
26
48
  t: "applink";
27
49
  key: string;
28
50
  v: string;
29
51
  };
30
- type Block = {
52
+ /** With `parseMarkdown(src, { lines: true })` every top-level block says which lines of the source it came from (1-based). */
53
+ type Block = BlockBody & {
54
+ line?: number;
55
+ endLine?: number;
56
+ };
57
+ type BlockBody = {
31
58
  t: "heading";
32
59
  level: 2 | 3;
33
60
  id: string;
@@ -51,6 +78,15 @@ type Block = {
51
78
  } | {
52
79
  t: "hr";
53
80
  }
81
+ /** A line that is only `![alt](asset:ID/name "caption")` or `![alt](https://…)`. */
82
+ | {
83
+ t: "media";
84
+ asset: string | null;
85
+ name: string;
86
+ src: string | null;
87
+ alt: string;
88
+ caption: string;
89
+ }
54
90
  /** A paragraph that is only app links: drawn as link cards. */
55
91
  | {
56
92
  t: "links";
@@ -69,10 +105,28 @@ declare const APP_LINK_RE: RegExp;
69
105
  declare function anchorOf(text: string): string;
70
106
  declare function parseInline(src: string): Inline[];
71
107
  declare function inlineText(inline: Inline[]): string;
72
- declare function parseMarkdown(source: string): Block[];
108
+ declare function parseMarkdown(source: string, o?: {
109
+ lines?: boolean;
110
+ }): Block[];
73
111
  declare function extractToc(blocks: Block[]): TocItem[];
74
112
  /** Every `[[link:key|…]]` key in a body. */
75
113
  declare function appLinkKeys(body: string): string[];
114
+ interface AssetUse {
115
+ id: string;
116
+ /** `media`: a block of its own. `image`: inside a line. `file`: a link. */
117
+ as: "media" | "image" | "file";
118
+ alt: string;
119
+ /** 1-based line in the body. */
120
+ line: number;
121
+ }
122
+ /** Every use of a media library file in a body, in order (code blocks skipped). */
123
+ declare function assetUses(body: string): AssetUse[];
124
+ /** External images (`![alt](https://…)`) in a body: line and alt. */
125
+ declare function externalImages(body: string): {
126
+ src: string;
127
+ alt: string;
128
+ line: number;
129
+ }[];
76
130
  /** Plain text of a body (for search and summaries): no markup, links as labels. */
77
131
  declare function plainText(body: string): string;
78
132
  interface Section {
@@ -85,4 +139,4 @@ interface Section {
85
139
  /** Split a body at `##` headings (### stays inside its section). */
86
140
  declare function splitSections(body: string): Section[];
87
141
 
88
- export { APP_LINK_RE, type Block, type Inline, type Section, type TocItem, anchorOf, appLinkKeys, extractToc, inlineText, parseInline, parseMarkdown, plainText, splitSections };
142
+ export { APP_LINK_RE, type AssetUse, type Block, type Inline, type Section, type TocItem, anchorOf, appLinkKeys, assetUses, externalImages, extractToc, inlineText, parseInline, parseMarkdown, plainText, splitSections };
@@ -6,6 +6,12 @@
6
6
  * Supported: `## / ###` headings, paragraphs, `-`/`*` and `1.` lists, `>`
7
7
  * quotes and `> [!note]` callouts, fenced code, `---`, and inline **bold**,
8
8
  * `code`, [text](url) and the CMS link `[[link:key|label]]`.
9
+ *
10
+ * Files from the media library are named by id: `![alt](asset:ID/name.jpg
11
+ * "caption")` on a line of its own is a media block (an image, a video
12
+ * player or a download card, by the file's type), and `[label](asset:ID/
13
+ * name.pdf)` links to a file. Only the id matters; the name after the slash
14
+ * is there for people. `![alt](https://…)` shows an image from elsewhere.
9
15
  */
10
16
  type Inline = {
11
17
  t: "text";
@@ -21,13 +27,34 @@ type Inline = {
21
27
  href: string;
22
28
  v: string;
23
29
  }
30
+ /** `[label](asset:ID/name)`: a link to a file in the media library. */
31
+ | {
32
+ t: "file";
33
+ asset: string;
34
+ name: string;
35
+ v: string;
36
+ }
37
+ /** An image inside a line of text. `asset` (a media library id) or `src` (https). */
38
+ | {
39
+ t: "image";
40
+ asset: string | null;
41
+ name: string;
42
+ src: string | null;
43
+ alt: string;
44
+ v: string;
45
+ }
24
46
  /** `[[link:key|label]]` — an app screen, resolved by the collection. */
25
47
  | {
26
48
  t: "applink";
27
49
  key: string;
28
50
  v: string;
29
51
  };
30
- type Block = {
52
+ /** With `parseMarkdown(src, { lines: true })` every top-level block says which lines of the source it came from (1-based). */
53
+ type Block = BlockBody & {
54
+ line?: number;
55
+ endLine?: number;
56
+ };
57
+ type BlockBody = {
31
58
  t: "heading";
32
59
  level: 2 | 3;
33
60
  id: string;
@@ -51,6 +78,15 @@ type Block = {
51
78
  } | {
52
79
  t: "hr";
53
80
  }
81
+ /** A line that is only `![alt](asset:ID/name "caption")` or `![alt](https://…)`. */
82
+ | {
83
+ t: "media";
84
+ asset: string | null;
85
+ name: string;
86
+ src: string | null;
87
+ alt: string;
88
+ caption: string;
89
+ }
54
90
  /** A paragraph that is only app links: drawn as link cards. */
55
91
  | {
56
92
  t: "links";
@@ -69,10 +105,28 @@ declare const APP_LINK_RE: RegExp;
69
105
  declare function anchorOf(text: string): string;
70
106
  declare function parseInline(src: string): Inline[];
71
107
  declare function inlineText(inline: Inline[]): string;
72
- declare function parseMarkdown(source: string): Block[];
108
+ declare function parseMarkdown(source: string, o?: {
109
+ lines?: boolean;
110
+ }): Block[];
73
111
  declare function extractToc(blocks: Block[]): TocItem[];
74
112
  /** Every `[[link:key|…]]` key in a body. */
75
113
  declare function appLinkKeys(body: string): string[];
114
+ interface AssetUse {
115
+ id: string;
116
+ /** `media`: a block of its own. `image`: inside a line. `file`: a link. */
117
+ as: "media" | "image" | "file";
118
+ alt: string;
119
+ /** 1-based line in the body. */
120
+ line: number;
121
+ }
122
+ /** Every use of a media library file in a body, in order (code blocks skipped). */
123
+ declare function assetUses(body: string): AssetUse[];
124
+ /** External images (`![alt](https://…)`) in a body: line and alt. */
125
+ declare function externalImages(body: string): {
126
+ src: string;
127
+ alt: string;
128
+ line: number;
129
+ }[];
76
130
  /** Plain text of a body (for search and summaries): no markup, links as labels. */
77
131
  declare function plainText(body: string): string;
78
132
  interface Section {
@@ -85,4 +139,4 @@ interface Section {
85
139
  /** Split a body at `##` headings (### stays inside its section). */
86
140
  declare function splitSections(body: string): Section[];
87
141
 
88
- export { APP_LINK_RE, type Block, type Inline, type Section, type TocItem, anchorOf, appLinkKeys, extractToc, inlineText, parseInline, parseMarkdown, plainText, splitSections };
142
+ export { APP_LINK_RE, type AssetUse, type Block, type Inline, type Section, type TocItem, anchorOf, appLinkKeys, assetUses, externalImages, extractToc, inlineText, parseInline, parseMarkdown, plainText, splitSections };
package/dist/markdown.js CHANGED
@@ -2,18 +2,22 @@ import {
2
2
  APP_LINK_RE,
3
3
  anchorOf,
4
4
  appLinkKeys,
5
+ assetUses,
6
+ externalImages,
5
7
  extractToc,
6
8
  inlineText,
7
9
  parseInline,
8
10
  parseMarkdown,
9
11
  plainText,
10
12
  splitSections
11
- } from "./chunk-CRDW6Q72.js";
13
+ } from "./chunk-MA6VKJ3F.js";
12
14
  import "./chunk-2NTK7H4W.js";
13
15
  export {
14
16
  APP_LINK_RE,
15
17
  anchorOf,
16
18
  appLinkKeys,
19
+ assetUses,
20
+ externalImages,
17
21
  extractToc,
18
22
  inlineText,
19
23
  parseInline,