@aionbuilders/nabu 0.1.0-alpha.9 → 0.1.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.
Files changed (319) hide show
  1. package/CHANGELOG.md +523 -0
  2. package/LICENSE +21 -0
  3. package/README.md +82 -144
  4. package/dist/behaviors/text/RichText.svelte +25 -2
  5. package/dist/behaviors/text/index.d.ts +2 -0
  6. package/dist/behaviors/text/index.js +2 -0
  7. package/dist/behaviors/text/markdown-shortcuts.extension.d.ts +5 -0
  8. package/dist/behaviors/text/markdown-shortcuts.extension.js +79 -0
  9. package/dist/behaviors/text/markdown-syntax.d.ts +42 -0
  10. package/dist/behaviors/text/markdown-syntax.js +81 -0
  11. package/dist/behaviors/text/rich-text.extension.d.ts +3 -0
  12. package/dist/behaviors/text/rich-text.extension.js +135 -53
  13. package/dist/behaviors/text/text.behavior.svelte.d.ts +217 -42
  14. package/dist/behaviors/text/text.behavior.svelte.js +657 -55
  15. package/dist/behaviors/text/typography.extension.d.ts +7 -0
  16. package/dist/behaviors/text/typography.extension.js +25 -0
  17. package/dist/blocks/Block.svelte +5 -2
  18. package/dist/blocks/BlockList.svelte +48 -0
  19. package/dist/blocks/BlockList.svelte.d.ts +17 -0
  20. package/dist/blocks/Nabu.svelte +180 -14
  21. package/dist/blocks/Nabu.svelte.d.ts +13 -0
  22. package/dist/blocks/block.extension.d.ts +3 -0
  23. package/dist/blocks/block.extension.js +8 -9
  24. package/dist/blocks/block.svelte.d.ts +356 -68
  25. package/dist/blocks/block.svelte.js +388 -42
  26. package/dist/blocks/blockquote/Blockquote.svelte +39 -0
  27. package/dist/blocks/blockquote/Blockquote.svelte.d.ts +11 -0
  28. package/dist/blocks/blockquote/blockquote.extension.d.ts +4 -0
  29. package/dist/blocks/blockquote/blockquote.extension.js +80 -0
  30. package/dist/blocks/blockquote/blockquote.svelte.d.ts +63 -0
  31. package/dist/blocks/blockquote/blockquote.svelte.js +136 -0
  32. package/dist/blocks/blockquote/index.d.ts +3 -0
  33. package/dist/blocks/blockquote/index.js +3 -0
  34. package/dist/blocks/callout/Callout.svelte +67 -0
  35. package/dist/blocks/callout/Callout.svelte.d.ts +11 -0
  36. package/dist/blocks/callout/callout.extension.d.ts +4 -0
  37. package/dist/blocks/callout/callout.extension.js +84 -0
  38. package/dist/blocks/callout/callout.svelte.d.ts +80 -0
  39. package/dist/blocks/callout/callout.svelte.js +189 -0
  40. package/dist/blocks/callout/index.d.ts +3 -0
  41. package/dist/blocks/callout/index.js +3 -0
  42. package/dist/blocks/chunks.d.ts +49 -0
  43. package/dist/blocks/chunks.js +90 -0
  44. package/dist/blocks/code/Code.svelte +84 -0
  45. package/dist/blocks/code/Code.svelte.d.ts +11 -0
  46. package/dist/blocks/code/code.extension.d.ts +4 -0
  47. package/dist/blocks/code/code.extension.js +88 -0
  48. package/dist/blocks/code/code.svelte.d.ts +68 -0
  49. package/dist/blocks/code/code.svelte.js +245 -0
  50. package/dist/blocks/code/index.d.ts +3 -0
  51. package/dist/blocks/code/index.js +3 -0
  52. package/dist/blocks/container.utils.d.ts +85 -13
  53. package/dist/blocks/container.utils.js +338 -178
  54. package/dist/blocks/dialogue/Dialogue.svelte +8 -2
  55. package/dist/blocks/dialogue/dialogue.svelte.d.ts +36 -23
  56. package/dist/blocks/dialogue/dialogue.svelte.js +51 -45
  57. package/dist/blocks/dialogue/hooks/onBeforeInput.hook.d.ts +2 -2
  58. package/dist/blocks/dialogue/hooks/onBeforeInput.hook.js +6 -4
  59. package/dist/blocks/dialogue/index.d.ts +12 -1
  60. package/dist/blocks/dialogue/index.js +51 -35
  61. package/dist/blocks/divider/Divider.svelte +28 -0
  62. package/dist/blocks/divider/Divider.svelte.d.ts +11 -0
  63. package/dist/blocks/divider/divider.extension.d.ts +23 -0
  64. package/dist/blocks/divider/divider.extension.js +153 -0
  65. package/dist/blocks/divider/divider.svelte.d.ts +54 -0
  66. package/dist/blocks/divider/divider.svelte.js +89 -0
  67. package/dist/blocks/divider/index.d.ts +3 -0
  68. package/dist/blocks/divider/index.js +3 -0
  69. package/dist/blocks/file/File.svelte +56 -0
  70. package/dist/blocks/file/File.svelte.d.ts +11 -0
  71. package/dist/blocks/file/file.extension.d.ts +4 -0
  72. package/dist/blocks/file/file.extension.js +27 -0
  73. package/dist/blocks/file/file.svelte.d.ts +29 -0
  74. package/dist/blocks/file/file.svelte.js +77 -0
  75. package/dist/blocks/file/index.d.ts +3 -0
  76. package/dist/blocks/file/index.js +3 -0
  77. package/dist/blocks/heading/Heading.svelte +2 -1
  78. package/dist/blocks/heading/heading.svelte.d.ts +27 -34
  79. package/dist/blocks/heading/heading.svelte.js +72 -60
  80. package/dist/blocks/heading/hooks/onBeforeInput.hook.js +7 -5
  81. package/dist/blocks/heading/index.d.ts +2 -2
  82. package/dist/blocks/heading/index.js +33 -8
  83. package/dist/blocks/image/Image.svelte +41 -0
  84. package/dist/blocks/image/Image.svelte.d.ts +11 -0
  85. package/dist/blocks/image/image.extension.d.ts +5 -0
  86. package/dist/blocks/image/image.extension.js +34 -0
  87. package/dist/blocks/image/image.svelte.d.ts +61 -0
  88. package/dist/blocks/image/image.svelte.js +114 -0
  89. package/dist/blocks/image/index.d.ts +3 -0
  90. package/dist/blocks/image/index.js +3 -0
  91. package/dist/blocks/index.d.ts +11 -1
  92. package/dist/blocks/index.js +11 -1
  93. package/dist/blocks/list/List.svelte +9 -2
  94. package/dist/blocks/list/ListItem.svelte +44 -7
  95. package/dist/blocks/list/convert.d.ts +20 -0
  96. package/dist/blocks/list/convert.js +92 -0
  97. package/dist/blocks/list/hooks/onBeforeInput.hook.js +60 -26
  98. package/dist/blocks/list/html-flat.d.ts +78 -0
  99. package/dist/blocks/list/html-flat.js +244 -0
  100. package/dist/blocks/list/indent.d.ts +86 -0
  101. package/dist/blocks/list/indent.js +205 -0
  102. package/dist/blocks/list/index.d.ts +7 -3
  103. package/dist/blocks/list/index.js +43 -31
  104. package/dist/blocks/list/list-item.svelte.d.ts +43 -17
  105. package/dist/blocks/list/list-item.svelte.js +143 -93
  106. package/dist/blocks/list/list.behavior.svelte.d.ts +7 -4
  107. package/dist/blocks/list/list.behavior.svelte.js +10 -5
  108. package/dist/blocks/list/list.svelte.d.ts +101 -23
  109. package/dist/blocks/list/list.svelte.js +136 -114
  110. package/dist/blocks/list/markdown.d.ts +149 -0
  111. package/dist/blocks/list/markdown.js +442 -0
  112. package/dist/blocks/list/normalize.d.ts +11 -0
  113. package/dist/blocks/list/normalize.js +396 -0
  114. package/dist/blocks/list/paste.d.ts +45 -0
  115. package/dist/blocks/list/paste.js +242 -0
  116. package/dist/blocks/list/step-back.d.ts +24 -0
  117. package/dist/blocks/list/step-back.js +87 -0
  118. package/dist/blocks/list/to-list.d.ts +7 -0
  119. package/dist/blocks/list/to-list.js +44 -0
  120. package/dist/blocks/list/todos-toggle.d.ts +20 -0
  121. package/dist/blocks/list/todos-toggle.js +48 -0
  122. package/dist/blocks/list/todos.svelte.d.ts +35 -0
  123. package/dist/blocks/list/todos.svelte.js +76 -0
  124. package/dist/blocks/media/index.d.ts +2 -0
  125. package/dist/blocks/media/index.js +2 -0
  126. package/dist/blocks/media/markdown.d.ts +12 -0
  127. package/dist/blocks/media/markdown.js +26 -0
  128. package/dist/blocks/media/media-block.svelte.d.ts +107 -0
  129. package/dist/blocks/media/media-block.svelte.js +181 -0
  130. package/dist/blocks/media/media.helpers.d.ts +24 -0
  131. package/dist/blocks/media/media.helpers.js +88 -0
  132. package/dist/blocks/megablock.svelte.d.ts +50 -19
  133. package/dist/blocks/megablock.svelte.js +115 -74
  134. package/dist/blocks/move.d.ts +23 -0
  135. package/dist/blocks/move.js +92 -0
  136. package/dist/blocks/nabu.svelte.d.ts +846 -75
  137. package/dist/blocks/nabu.svelte.js +1990 -182
  138. package/dist/blocks/paragraph/Paragraph.svelte +1 -0
  139. package/dist/blocks/paragraph/index.d.ts +2 -2
  140. package/dist/blocks/paragraph/index.js +35 -16
  141. package/dist/blocks/paragraph/paragraph.svelte.d.ts +49 -35
  142. package/dist/blocks/paragraph/paragraph.svelte.js +81 -69
  143. package/dist/blocks/paragraph/table.html.d.ts +9 -0
  144. package/dist/blocks/paragraph/table.html.js +111 -0
  145. package/dist/blocks/paragraph/table.markdown.d.ts +32 -0
  146. package/dist/blocks/paragraph/table.markdown.js +90 -0
  147. package/dist/blocks/region/Region.svelte +264 -0
  148. package/dist/blocks/region/Region.svelte.d.ts +11 -0
  149. package/dist/blocks/region/actions.d.ts +135 -0
  150. package/dist/blocks/region/actions.js +402 -0
  151. package/dist/blocks/region/close.d.ts +35 -0
  152. package/dist/blocks/region/close.js +130 -0
  153. package/dist/blocks/region/commands.d.ts +6 -0
  154. package/dist/blocks/region/commands.js +277 -0
  155. package/dist/blocks/region/create.d.ts +72 -0
  156. package/dist/blocks/region/create.js +208 -0
  157. package/dist/blocks/region/end-marker.d.ts +35 -0
  158. package/dist/blocks/region/end-marker.js +51 -0
  159. package/dist/blocks/region/facts.d.ts +69 -0
  160. package/dist/blocks/region/facts.js +152 -0
  161. package/dist/blocks/region/format.d.ts +91 -0
  162. package/dist/blocks/region/format.js +260 -0
  163. package/dist/blocks/region/index.d.ts +14 -0
  164. package/dist/blocks/region/index.js +14 -0
  165. package/dist/blocks/region/insert.d.ts +59 -0
  166. package/dist/blocks/region/insert.js +102 -0
  167. package/dist/blocks/region/messages.d.ts +254 -0
  168. package/dist/blocks/region/messages.js +131 -0
  169. package/dist/blocks/region/normalize.d.ts +7 -0
  170. package/dist/blocks/region/normalize.js +170 -0
  171. package/dist/blocks/region/region.extension.d.ts +58 -0
  172. package/dist/blocks/region/region.extension.js +119 -0
  173. package/dist/blocks/region/region.svelte.d.ts +221 -0
  174. package/dist/blocks/region/region.svelte.js +582 -0
  175. package/dist/blocks/region/regions.svelte.d.ts +141 -0
  176. package/dist/blocks/region/regions.svelte.js +276 -0
  177. package/dist/blocks/region/serialize.d.ts +57 -0
  178. package/dist/blocks/region/serialize.js +112 -0
  179. package/dist/blocks/region/types.d.ts +255 -0
  180. package/dist/blocks/region/types.js +204 -0
  181. package/dist/blocks/selection.svelte.d.ts +106 -8
  182. package/dist/blocks/selection.svelte.js +632 -74
  183. package/dist/blocks/subthread.d.ts +80 -0
  184. package/dist/blocks/subthread.js +167 -0
  185. package/dist/blocks/text-block.svelte.d.ts +70 -0
  186. package/dist/blocks/text-block.svelte.js +108 -0
  187. package/dist/blocks/toggle/Toggle.svelte +73 -0
  188. package/dist/blocks/toggle/Toggle.svelte.d.ts +11 -0
  189. package/dist/blocks/toggle/index.d.ts +3 -0
  190. package/dist/blocks/toggle/index.js +3 -0
  191. package/dist/blocks/toggle/markdown.d.ts +20 -0
  192. package/dist/blocks/toggle/markdown.js +112 -0
  193. package/dist/blocks/toggle/toggle.extension.d.ts +4 -0
  194. package/dist/blocks/toggle/toggle.extension.js +18 -0
  195. package/dist/blocks/toggle/toggle.svelte.d.ts +135 -0
  196. package/dist/blocks/toggle/toggle.svelte.js +352 -0
  197. package/dist/blocks/undo-selection.d.ts +175 -0
  198. package/dist/blocks/undo-selection.js +360 -0
  199. package/dist/blocks/video/Video.svelte +42 -0
  200. package/dist/blocks/video/Video.svelte.d.ts +11 -0
  201. package/dist/blocks/video/index.d.ts +3 -0
  202. package/dist/blocks/video/index.js +3 -0
  203. package/dist/blocks/video/video.extension.d.ts +4 -0
  204. package/dist/blocks/video/video.extension.js +27 -0
  205. package/dist/blocks/video/video.svelte.d.ts +29 -0
  206. package/dist/blocks/video/video.svelte.js +80 -0
  207. package/dist/extend.d.ts +55 -0
  208. package/dist/extend.js +88 -0
  209. package/dist/files/assets.clipboard.d.ts +77 -0
  210. package/dist/files/assets.clipboard.js +152 -0
  211. package/dist/files/files.svelte.d.ts +363 -0
  212. package/dist/files/files.svelte.js +897 -0
  213. package/dist/files/index.d.ts +3 -0
  214. package/dist/files/index.js +3 -0
  215. package/dist/files/outbox.d.ts +69 -0
  216. package/dist/files/outbox.js +48 -0
  217. package/dist/files/status.d.ts +65 -0
  218. package/dist/files/status.js +87 -0
  219. package/dist/files/store.d.ts +97 -0
  220. package/dist/files/store.js +65 -0
  221. package/dist/files/uploads.svelte.d.ts +174 -0
  222. package/dist/files/uploads.svelte.js +504 -0
  223. package/dist/index.d.ts +68 -6
  224. package/dist/index.js +117 -7
  225. package/dist/nabu-theme.css +112 -0
  226. package/dist/paste/html.paste.d.ts +74 -3
  227. package/dist/paste/html.paste.js +555 -83
  228. package/dist/paste/markdown-inline.d.ts +86 -0
  229. package/dist/paste/markdown-inline.js +528 -0
  230. package/dist/paste/markdown.paste.d.ts +2 -8
  231. package/dist/paste/markdown.paste.js +78 -94
  232. package/dist/paste/nabu.paste.d.ts +3 -0
  233. package/dist/paste/nabu.paste.js +29 -3
  234. package/dist/paste/plain-text.paste.d.ts +2 -2
  235. package/dist/paste/plain-text.paste.js +3 -3
  236. package/dist/persistence/asset-store.d.ts +51 -0
  237. package/dist/persistence/asset-store.js +103 -0
  238. package/dist/persistence/autosave.d.ts +53 -0
  239. package/dist/persistence/autosave.js +62 -0
  240. package/dist/persistence/compact.d.ts +162 -0
  241. package/dist/persistence/compact.js +141 -0
  242. package/dist/persistence/history.d.ts +77 -0
  243. package/dist/persistence/history.js +176 -0
  244. package/dist/persistence/indexeddb.d.ts +190 -4
  245. package/dist/persistence/indexeddb.js +333 -29
  246. package/dist/persistence/merge.d.ts +38 -0
  247. package/dist/persistence/merge.js +36 -0
  248. package/dist/persistence/outbox.d.ts +25 -0
  249. package/dist/persistence/outbox.js +40 -0
  250. package/dist/persistence/persistence.d.ts +70 -9
  251. package/dist/persistence/persistence.js +507 -35
  252. package/dist/persistence/recovery.d.ts +79 -0
  253. package/dist/persistence/recovery.js +79 -0
  254. package/dist/persistence/release.d.ts +34 -0
  255. package/dist/persistence/release.js +64 -0
  256. package/dist/persistence/state.svelte.d.ts +53 -0
  257. package/dist/persistence/state.svelte.js +48 -0
  258. package/dist/persistence/sync.d.ts +39 -0
  259. package/dist/persistence/sync.js +138 -0
  260. package/dist/persistence/tail.d.ts +42 -0
  261. package/dist/persistence/tail.js +103 -0
  262. package/dist/presets.d.ts +29 -24
  263. package/dist/presets.js +51 -14
  264. package/dist/themes/atelier.css +318 -0
  265. package/dist/ui/CommandChooser.svelte +153 -0
  266. package/dist/ui/CommandChooser.svelte.d.ts +13 -0
  267. package/dist/ui/CommandInvite.svelte +99 -0
  268. package/dist/ui/CommandInvite.svelte.d.ts +12 -0
  269. package/dist/ui/DragHandle.svelte +217 -0
  270. package/dist/ui/DragHandle.svelte.d.ts +11 -0
  271. package/dist/ui/FloatingToolbar.svelte +165 -0
  272. package/dist/ui/FloatingToolbar.svelte.d.ts +27 -0
  273. package/dist/ui/SlashMenu.svelte +215 -0
  274. package/dist/ui/SlashMenu.svelte.d.ts +33 -0
  275. package/dist/ui/anchor.d.ts +112 -0
  276. package/dist/ui/anchor.js +136 -0
  277. package/dist/ui/index.d.ts +10 -0
  278. package/dist/ui/index.js +15 -0
  279. package/dist/ui/slash-menu.svelte.d.ts +112 -0
  280. package/dist/ui/slash-menu.svelte.js +150 -0
  281. package/dist/utils/command-confirm.svelte.d.ts +349 -0
  282. package/dist/utils/command-confirm.svelte.js +673 -0
  283. package/dist/utils/commands.d.ts +328 -0
  284. package/dist/utils/commands.js +416 -0
  285. package/dist/utils/dom-scope.d.ts +14 -0
  286. package/dist/utils/dom-scope.js +20 -0
  287. package/dist/utils/drop.d.ts +160 -0
  288. package/dist/utils/drop.js +305 -0
  289. package/dist/utils/extensions.d.ts +488 -40
  290. package/dist/utils/extensions.js +300 -19
  291. package/dist/utils/html.d.ts +44 -0
  292. package/dist/utils/html.js +183 -0
  293. package/dist/utils/index.d.ts +4 -0
  294. package/dist/utils/index.js +4 -0
  295. package/dist/utils/keys.d.ts +120 -0
  296. package/dist/utils/keys.js +248 -0
  297. package/dist/utils/links.d.ts +22 -0
  298. package/dist/utils/links.js +34 -0
  299. package/dist/utils/placeholders.d.ts +88 -0
  300. package/dist/utils/placeholders.js +91 -0
  301. package/dist/utils/selection.svelte.d.ts +47 -19
  302. package/dist/utils/selection.svelte.js +60 -10
  303. package/dist/utils/spellcheck.d.ts +9 -0
  304. package/dist/utils/spellcheck.js +17 -0
  305. package/dist/utils/tab.d.ts +31 -0
  306. package/dist/utils/tab.js +117 -0
  307. package/dist/utils/words.d.ts +7 -0
  308. package/dist/utils/words.js +62 -0
  309. package/dist/vite.d.ts +22 -0
  310. package/dist/vite.js +34 -0
  311. package/package.json +61 -22
  312. package/dist/blocks/zone/Zone.svelte +0 -258
  313. package/dist/blocks/zone/Zone.svelte.d.ts +0 -11
  314. package/dist/blocks/zone/index.d.ts +0 -2
  315. package/dist/blocks/zone/index.js +0 -2
  316. package/dist/blocks/zone/zone.extension.d.ts +0 -2
  317. package/dist/blocks/zone/zone.extension.js +0 -221
  318. package/dist/blocks/zone/zone.svelte.d.ts +0 -112
  319. package/dist/blocks/zone/zone.svelte.js +0 -321
@@ -0,0 +1,86 @@
1
+ /** @param {string} s */
2
+ export function normalizeLabel(s: string): string;
3
+ /**
4
+ * Pull the link reference definitions (`[ref]: url "title"`, one line each) out of the markdown lines. Fenced code is
5
+ * left untouched, footnote definitions (`[^1]:`) are not links. The first definition of a label wins.
6
+ * @param {string[]} lines
7
+ * @returns {{ lines: string[], resolveRef: ((label: string) => LinkReference | null) | undefined }}
8
+ */
9
+ export function extractLinkDefinitions(lines: string[]): {
10
+ lines: string[];
11
+ resolveRef: ((label: string) => LinkReference | null) | undefined;
12
+ };
13
+ /**
14
+ * Parse inline markdown into a sequence of text segments (a Loro delta each) and image segments: an image splits
15
+ * the text around it. Unsafe image URLs stay as their alt text.
16
+ * @param {string} text
17
+ * @param {InlineOptions} [options]
18
+ * @returns {InlineSegment[]}
19
+ */
20
+ export function parseMarkdownSegments(text: string, options?: InlineOptions): InlineSegment[];
21
+ /**
22
+ * Parse inline markdown text into a Loro-compatible delta array:
23
+ * `**bold *italic* still bold**` → [bold, bold+italic, bold]; `[t](url)` → text with a `link` mark.
24
+ * An image becomes its alt text (use {@link parseMarkdownSegments} to keep images as blocks).
25
+ *
26
+ * @param {string} text
27
+ * @param {Record<string, any>} [marks] marks inherited by every run
28
+ * @param {InlineOptions} [options]
29
+ * @returns {import('loro-crdt').Delta<string>[]}
30
+ */
31
+ export function parseMarkdownInline(text: string, marks?: Record<string, any>, options?: InlineOptions): import("loro-crdt").Delta<string>[];
32
+ export type Node = {
33
+ t: "text";
34
+ s: string;
35
+ } | {
36
+ t: "code";
37
+ s: string;
38
+ } | {
39
+ t: "br";
40
+ } | {
41
+ t: "delim";
42
+ ch: string;
43
+ len: number;
44
+ orig: number;
45
+ canOpen: boolean;
46
+ canClose: boolean;
47
+ } | {
48
+ t: "em";
49
+ mark: string;
50
+ children: Node[];
51
+ } | {
52
+ t: "link";
53
+ href: string;
54
+ children: Node[];
55
+ } | {
56
+ t: "image";
57
+ href: string;
58
+ children: Node[];
59
+ };
60
+ export type Item = {
61
+ insert: string;
62
+ attributes?: Record<string, any>;
63
+ } | {
64
+ image: {
65
+ alt: string;
66
+ ref: string;
67
+ };
68
+ marks: Record<string, any>;
69
+ };
70
+ export type LinkReference = {
71
+ href: string;
72
+ title?: string;
73
+ };
74
+ export type InlineOptions = {
75
+ resolveRef?: (label: string) => LinkReference | null;
76
+ };
77
+ export type ImageSegment = {
78
+ image: {
79
+ alt: string;
80
+ ref: string;
81
+ };
82
+ };
83
+ export type TextSegment = {
84
+ delta: import("loro-crdt").Delta<string>[];
85
+ };
86
+ export type InlineSegment = TextSegment | ImageSegment;
@@ -0,0 +1,528 @@
1
+ /**
2
+ * Inline markdown parser (CommonMark / GFM level) used by markdown paste and `importMarkdown`.
3
+ *
4
+ * Approach: one left-to-right scan builds a flat node list (text, code spans, delimiter runs, links, images…), then
5
+ * CommonMark's delimiter-stack algorithm pairs the emphasis delimiters; links / images are resolved when their `]` is
6
+ * met (inline destination, full / collapsed / shortcut reference). The tree is finally flattened to a Loro delta.
7
+ *
8
+ * Covered: `*em*` `**strong**` `***both***` `_em_` `__strong__` `~~strike~~` `<u>underline</u>`, code spans (any
9
+ * backtick run length), backslash escapes, hard line breaks, inline links (`[t](url "title")`, `<dest with spaces>`,
10
+ * balanced parentheses in URLs), reference links (`[t][ref]`, `[t][]`, `[t]`), autolinks (`<https://…>`, `<a@b.c>`),
11
+ * GFM bare URLs (`https://…`, `www.…`, trailing punctuation excluded), images (`![alt](url)`, `![alt][ref]`).
12
+ * Emphasis flanking is shared with the typing shortcuts (`behaviors/text/markdown-syntax.js`).
13
+ *
14
+ * Every URL goes through `sanitizeUrl`: an unsafe link keeps its text and loses the link; an unsafe image keeps its
15
+ * alt text.
16
+ *
17
+ * Pure functions, no DOM, no runes.
18
+ */
19
+
20
+ import { sanitizeUrl } from '../utils/html.js';
21
+ import { ASCII_PUNCTUATION, delimiterFlags } from '../behaviors/text/markdown-syntax.js';
22
+
23
+ /**
24
+ * @typedef {{ href: string, title?: string }} LinkReference
25
+ * @typedef {{ resolveRef?: (label: string) => LinkReference | null }} InlineOptions
26
+ * @typedef {{ image: { alt: string, ref: string } }} ImageSegment
27
+ * @typedef {{ delta: import('loro-crdt').Delta<string>[] }} TextSegment
28
+ * @typedef {TextSegment | ImageSegment} InlineSegment
29
+ */
30
+
31
+ // ── Link reference definitions ───────────────────────────────────────────────
32
+
33
+ const DEFINITION_RE = /^ {0,3}\[((?:[^\[\]\\]|\\.)+)\]:[ \t]*(<(?:[^<>\n\\]|\\.)*>|[^\s<]\S*)(?:[ \t]+(?:"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|\((?:[^()\\]|\\.)*\)))?[ \t]*$/;
34
+ /** An opening code fence: 3+ backticks (no backtick in the info string) or 3+ tildes. */
35
+ const FENCE_OPEN_RE = /^ {0,3}(`{3,}(?=[^`]*$)|~{3,})/;
36
+
37
+ /** @param {string} s */
38
+ export function normalizeLabel(s) {
39
+ return s.trim().replace(/\s+/g, ' ').toLowerCase();
40
+ }
41
+
42
+ /** @param {string} s */
43
+ function unescapeMarkdown(s) {
44
+ return s.replace(/\\([!-/:-@[-`{-~])/g, '$1');
45
+ }
46
+
47
+ /**
48
+ * Pull the link reference definitions (`[ref]: url "title"`, one line each) out of the markdown lines. Fenced code is
49
+ * left untouched, footnote definitions (`[^1]:`) are not links. The first definition of a label wins.
50
+ * @param {string[]} lines
51
+ * @returns {{ lines: string[], resolveRef: ((label: string) => LinkReference | null) | undefined }}
52
+ */
53
+ export function extractLinkDefinitions(lines) {
54
+ /** @type {Map<string, LinkReference>} */
55
+ const defs = new Map();
56
+ /** @type {string[]} */
57
+ const kept = [];
58
+ let fence = '';
59
+ for (const line of lines) {
60
+ if (fence) {
61
+ // closing fence: the same character, at least as long, nothing but spaces after it
62
+ const close = /^ {0,3}(`+|~+)[ \t]*$/.exec(line);
63
+ if (close && close[1][0] === fence[0] && close[1].length >= fence.length) fence = '';
64
+ kept.push(line);
65
+ continue;
66
+ }
67
+ const open = FENCE_OPEN_RE.exec(line);
68
+ if (open) { fence = open[1]; kept.push(line); continue; }
69
+ const m = !fence && line.includes(']:') ? DEFINITION_RE.exec(line) : null;
70
+ if (!m || m[1].startsWith('^')) { kept.push(line); continue; }
71
+ const key = normalizeLabel(m[1]);
72
+ let dest = m[2];
73
+ dest = dest.startsWith('<') ? dest.slice(1, -1) : dest;
74
+ if (key && !defs.has(key)) defs.set(key, { href: unescapeMarkdown(dest) });
75
+ }
76
+ return { lines: kept, resolveRef: defs.size ? (label) => defs.get(normalizeLabel(label)) ?? null : undefined };
77
+ }
78
+
79
+ // ── Scanner ──────────────────────────────────────────────────────────────────
80
+
81
+ const AUTOLINK_RE = /<([A-Za-z][A-Za-z0-9+.-]{1,31}:[^\s<>]*)>/y;
82
+ const EMAIL_RE = /<([A-Za-z0-9.!#$%&'*+/=?^_`{|}~-]+@[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?(?:\.[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?)*)>/y;
83
+ const UNDERLINE_TAG_RE = /<(\/?)u>/y;
84
+ const BARE_URL_RE = /(?:https?:\/\/[\p{L}\p{N}][^\s<]*|www\.[A-Za-z0-9][^\s<]*)/iuy;
85
+ const BARE_MIN_RE = /^(?:https?:\/\/[\p{L}\p{N}]|www\.[A-Za-z0-9])/iu;
86
+ /** A bare URL starts at the line start, after whitespace, or after one of these. */
87
+ const BARE_BOUNDARY = '*_~(';
88
+ const TRAILING_PUNCT = '?!.,:;*_~\'"';
89
+
90
+ /**
91
+ * @typedef {{ t: 'text', s: string }
92
+ * | { t: 'code', s: string }
93
+ * | { t: 'br' }
94
+ * | { t: 'delim', ch: string, len: number, orig: number, canOpen: boolean, canClose: boolean }
95
+ * | { t: 'em', mark: string, children: Node[] }
96
+ * | { t: 'link', href: string, children: Node[] }
97
+ * | { t: 'image', href: string, children: Node[] }} Node
98
+ */
99
+
100
+ /**
101
+ * Parse the destination (and ignored title) of an inline link, starting right after the `(`.
102
+ * @param {string} src
103
+ * @param {number} p
104
+ * @returns {{ href: string, end: number } | null}
105
+ */
106
+ function parseDestination(src, p) {
107
+ const n = src.length;
108
+ let i = p;
109
+ while (i < n && /\s/.test(src[i])) i++;
110
+ let href = '';
111
+ if (src[i] === '<') {
112
+ i++;
113
+ while (i < n && src[i] !== '>') {
114
+ const ch = src[i];
115
+ if (ch === '\n' || ch === '<') return null;
116
+ if (ch === '\\' && ASCII_PUNCTUATION.includes(src[i + 1] ?? '')) { href += src[i + 1]; i += 2; continue; }
117
+ href += ch;
118
+ i++;
119
+ }
120
+ if (src[i] !== '>') return null;
121
+ i++;
122
+ } else {
123
+ let depth = 0;
124
+ while (i < n) {
125
+ const ch = src[i];
126
+ if (ch === '\\' && ASCII_PUNCTUATION.includes(src[i + 1] ?? '')) { href += src[i + 1]; i += 2; continue; }
127
+ if (/[\s\u0000-\u001f]/.test(ch)) break;
128
+ if (ch === '(') depth++;
129
+ else if (ch === ')') { if (depth === 0) break; depth--; }
130
+ href += ch;
131
+ i++;
132
+ }
133
+ if (depth !== 0) return null;
134
+ }
135
+ let j = i;
136
+ while (j < n && /\s/.test(src[j])) j++;
137
+ if (j > i && (src[j] === '"' || src[j] === "'" || src[j] === '(')) {
138
+ const close = src[j] === '(' ? ')' : src[j];
139
+ let k = j + 1;
140
+ while (k < n && src[k] !== close) k += src[k] === '\\' ? 2 : 1;
141
+ if (k >= n) return null;
142
+ j = k + 1;
143
+ while (j < n && /\s/.test(src[j])) j++;
144
+ }
145
+ if (src[j] !== ')') return null;
146
+ return { href, end: j + 1 };
147
+ }
148
+
149
+ /**
150
+ * Resolve the `]` at `close` into a link / image destination, or null (literal).
151
+ * @param {string} src
152
+ * @param {number} close
153
+ * @param {{ start: number }} opener
154
+ * @param {InlineOptions} opts
155
+ * @returns {{ href: string, end: number } | null}
156
+ */
157
+ function resolveBracket(src, close, opener, opts) {
158
+ const after = close + 1;
159
+ if (src[after] === '(') {
160
+ const d = parseDestination(src, after + 1);
161
+ if (d) return d;
162
+ }
163
+ const resolve = opts.resolveRef;
164
+ if (!resolve) return null;
165
+ const label = src.slice(opener.start, close);
166
+ if (!label.trim()) return null;
167
+ if (src[after] === '[') {
168
+ const m = /^\[((?:[^\[\]\\]|\\.)*)\]/.exec(src.slice(after, after + 1002));
169
+ if (m) {
170
+ const ref = resolve(m[1].trim() ? m[1] : label);
171
+ return ref ? { href: ref.href, end: after + m[0].length } : null; // followed by a label: never a shortcut
172
+ }
173
+ }
174
+ const ref = resolve(label);
175
+ return ref ? { href: ref.href, end: after } : null;
176
+ }
177
+
178
+ /**
179
+ * CommonMark's "process emphasis" on a node list: pair closing delimiters with the nearest compatible opener.
180
+ * Unmatched delimiters are left in place (flattened to literal text later).
181
+ * @param {Node[]} nodes mutated
182
+ */
183
+ function processEmphasis(nodes) {
184
+ let ci = 0;
185
+ while (ci < nodes.length) {
186
+ const closer = nodes[ci];
187
+ if (closer.t !== 'delim' || !closer.canClose || closer.len === 0) { ci++; continue; }
188
+ let oi = -1;
189
+ for (let k = ci - 1; k >= 0; k--) {
190
+ const o = nodes[k];
191
+ if (o.t !== 'delim' || o.ch !== closer.ch || !o.canOpen || o.len === 0) continue;
192
+ if (o.ch === '~') { if (o.len === 2 && closer.len === 2) { oi = k; break; } continue; }
193
+ // "Multiple of 3" rule: an opener that can also close (or a closer that can also open) only pairs when
194
+ // the lengths do not sum to a multiple of 3, unless both are.
195
+ if (o.ch !== 'u' && (o.canClose || closer.canOpen) && (o.orig + closer.orig) % 3 === 0 && !(o.orig % 3 === 0 && closer.orig % 3 === 0)) continue;
196
+ oi = k;
197
+ break;
198
+ }
199
+ if (oi < 0) { ci++; continue; }
200
+ const opener = /** @type {Extract<Node, { t: 'delim' }>} */ (nodes[oi]);
201
+ const use = opener.ch === '~' ? 2 : opener.ch === 'u' ? 1 : opener.len >= 2 && closer.len >= 2 ? 2 : 1;
202
+ const mark = opener.ch === '~' ? 'strikethrough' : opener.ch === 'u' ? 'underline' : use === 2 ? 'bold' : 'italic';
203
+ const inner = nodes.slice(oi + 1, ci);
204
+ opener.len -= use;
205
+ closer.len -= use;
206
+ nodes.splice(oi + 1, ci - oi - 1, { t: 'em', mark, children: inner });
207
+ ci = oi + 2;
208
+ if (opener.len === 0) { nodes.splice(oi, 1); ci--; }
209
+ if (closer.len === 0) nodes.splice(ci, 1);
210
+ }
211
+ }
212
+
213
+ /**
214
+ * Strip GFM-excluded trailing punctuation from a bare URL candidate.
215
+ * @param {string} url
216
+ * @returns {string}
217
+ */
218
+ function trimBareUrl(url) {
219
+ for (;;) {
220
+ const last = url[url.length - 1];
221
+ if (!last) return url;
222
+ if (TRAILING_PUNCT.includes(last)) {
223
+ const entity = last === ';' ? /&[A-Za-z0-9]+;$/.exec(url) : null; // `&amp;` is not punctuation… but is not a URL end either
224
+ url = entity ? url.slice(0, -entity[0].length) : url.slice(0, -1);
225
+ } else if (last === ')') {
226
+ const open = (url.match(/\(/g) || []).length;
227
+ const close = (url.match(/\)/g) || []).length;
228
+ if (close > open) url = url.slice(0, -1);
229
+ else return url;
230
+ } else return url;
231
+ }
232
+ }
233
+
234
+ /**
235
+ * @param {string} src
236
+ * @param {InlineOptions} opts
237
+ * @returns {Node[]}
238
+ */
239
+ function scan(src, opts) {
240
+ const n = src.length;
241
+ /** @type {Node[]} */
242
+ const nodes = [];
243
+ /** @type {Array<{ node: Node, image: boolean, active: boolean, start: number }>} */
244
+ const brackets = [];
245
+ let buf = '';
246
+ let i = 0;
247
+
248
+ const flush = () => { if (buf) { nodes.push({ t: 'text', s: buf }); buf = ''; } };
249
+ const skipSpaces = () => { while (src[i] === ' ' || src[i] === '\t') i++; };
250
+ /** Strip the spaces before a newline (from the pending buffer, or the last text node); returns how many. */
251
+ const stripTrailingSpaces = () => {
252
+ let stripped = 0;
253
+ const strip = (/** @type {string} */ s) => {
254
+ const m = / +$/.exec(s);
255
+ if (!m) return s;
256
+ stripped += m[0].length;
257
+ return s.slice(0, -m[0].length);
258
+ };
259
+ buf = strip(buf);
260
+ if (!buf) {
261
+ const last = nodes[nodes.length - 1];
262
+ if (last && last.t === 'text') last.s = strip(last.s);
263
+ }
264
+ return stripped;
265
+ };
266
+
267
+ while (i < n) {
268
+ const c = src[i];
269
+
270
+ // A line break inside the text stays a `\n` of the block (callout / quote bodies are joined with it). Paragraph
271
+ // lines are joined BEFORE parsing (soft break = space, hard break = `\n`), see Paragraph.fromMarkdown.
272
+ if (c === '\n') {
273
+ stripTrailingSpaces();
274
+ i++;
275
+ skipSpaces();
276
+ flush();
277
+ nodes.push({ t: 'br' });
278
+ continue;
279
+ }
280
+
281
+ if (c === '\\') {
282
+ const next = src[i + 1];
283
+ if (next === '\n') { flush(); nodes.push({ t: 'br' }); i += 2; skipSpaces(); continue; }
284
+ if (next !== undefined && ASCII_PUNCTUATION.includes(next)) { buf += next; i += 2; continue; }
285
+ buf += c;
286
+ i++;
287
+ continue;
288
+ }
289
+
290
+ if (c === '`') {
291
+ let j = i;
292
+ while (src[j] === '`') j++;
293
+ const len = j - i;
294
+ let found = -1;
295
+ for (let k = j; k < n;) {
296
+ const p = src.indexOf('`', k);
297
+ if (p < 0) break;
298
+ let q = p;
299
+ while (src[q] === '`') q++;
300
+ if (q - p === len) { found = p; break; }
301
+ k = q;
302
+ }
303
+ if (found < 0) { buf += src.slice(i, j); i = j; continue; }
304
+ let content = src.slice(j, found).replace(/\n/g, ' ');
305
+ if (content.length > 2 && content.startsWith(' ') && content.endsWith(' ') && content.trim()) content = content.slice(1, -1);
306
+ flush();
307
+ nodes.push({ t: 'code', s: content });
308
+ i = found + len;
309
+ continue;
310
+ }
311
+
312
+ if (c === '*' || c === '_' || c === '~') {
313
+ let j = i;
314
+ while (src[j] === c) j++;
315
+ const len = j - i;
316
+ if (c === '~' && len !== 2) { buf += src.slice(i, j); i = j; continue; }
317
+ const { canOpen, canClose } = delimiterFlags(c, src[i - 1] ?? '', src[j] ?? '');
318
+ flush();
319
+ nodes.push({ t: 'delim', ch: c, len, orig: len, canOpen, canClose });
320
+ i = j;
321
+ continue;
322
+ }
323
+
324
+ if (c === '[' || (c === '!' && src[i + 1] === '[')) {
325
+ const image = c === '!';
326
+ flush();
327
+ /** @type {Node} */
328
+ const node = { t: 'text', s: image ? '![' : '[' };
329
+ nodes.push(node);
330
+ i += image ? 2 : 1;
331
+ brackets.push({ node, image, active: true, start: i });
332
+ continue;
333
+ }
334
+
335
+ if (c === ']') {
336
+ const opener = brackets[brackets.length - 1];
337
+ if (!opener) { buf += c; i++; continue; }
338
+ brackets.pop();
339
+ const res = opener.active ? resolveBracket(src, i, opener, opts) : null;
340
+ if (!res) { buf += c; i++; continue; }
341
+ flush();
342
+ const idx = nodes.indexOf(opener.node);
343
+ const children = nodes.splice(idx + 1);
344
+ processEmphasis(children);
345
+ nodes[idx] = opener.image ? { t: 'image', href: res.href, children } : { t: 'link', href: res.href, children };
346
+ if (!opener.image) for (const b of brackets) if (!b.image) b.active = false; // links do not nest
347
+ i = res.end;
348
+ continue;
349
+ }
350
+
351
+ if (c === '<') {
352
+ AUTOLINK_RE.lastIndex = i;
353
+ const auto = AUTOLINK_RE.exec(src);
354
+ if (auto) {
355
+ if (sanitizeUrl(auto[1], { kind: 'link' }) === null) buf += auto[0];
356
+ else { flush(); nodes.push({ t: 'link', href: auto[1], children: [{ t: 'text', s: auto[1] }] }); }
357
+ i += auto[0].length;
358
+ continue;
359
+ }
360
+ EMAIL_RE.lastIndex = i;
361
+ const mail = EMAIL_RE.exec(src);
362
+ if (mail) {
363
+ flush();
364
+ nodes.push({ t: 'link', href: 'mailto:' + mail[1], children: [{ t: 'text', s: mail[1] }] });
365
+ i += mail[0].length;
366
+ continue;
367
+ }
368
+ UNDERLINE_TAG_RE.lastIndex = i;
369
+ const tag = UNDERLINE_TAG_RE.exec(src);
370
+ if (tag) {
371
+ const closing = tag[1] === '/';
372
+ flush();
373
+ nodes.push({ t: 'delim', ch: 'u', len: 1, orig: 1, canOpen: !closing, canClose: closing });
374
+ i += tag[0].length;
375
+ continue;
376
+ }
377
+ buf += c;
378
+ i++;
379
+ continue;
380
+ }
381
+
382
+ if (c === 'h' || c === 'H' || c === 'w' || c === 'W') {
383
+ const prev = src[i - 1];
384
+ if (prev === undefined || /\s/.test(prev) || BARE_BOUNDARY.includes(prev)) {
385
+ BARE_URL_RE.lastIndex = i;
386
+ const m = BARE_URL_RE.exec(src);
387
+ if (m) {
388
+ let url = m[0];
389
+ if (brackets.length) { const cut = url.indexOf(']'); if (cut >= 0) url = url.slice(0, cut); }
390
+ url = trimBareUrl(url);
391
+ if (BARE_MIN_RE.test(url)) {
392
+ flush();
393
+ nodes.push({ t: 'link', href: /^www\./i.test(url) ? 'http://' + url : url, children: [{ t: 'text', s: url }] });
394
+ i += url.length;
395
+ continue;
396
+ }
397
+ }
398
+ }
399
+ }
400
+
401
+ buf += c;
402
+ i++;
403
+ }
404
+
405
+ flush();
406
+ processEmphasis(nodes);
407
+ return nodes;
408
+ }
409
+
410
+ // ── Flatten ──────────────────────────────────────────────────────────────────
411
+
412
+ /** @param {Node[]} nodes @returns {string} */
413
+ function plainText(nodes) {
414
+ let out = '';
415
+ for (const n of nodes) {
416
+ if (n.t === 'text' || n.t === 'code') out += n.s;
417
+ else if (n.t === 'br') out += ' ';
418
+ else if (n.t === 'delim') out += n.ch === 'u' ? '' : n.ch.repeat(n.len);
419
+ else out += plainText(n.children);
420
+ }
421
+ return out;
422
+ }
423
+
424
+ /**
425
+ * @typedef {{ insert: string, attributes?: Record<string, any> } | { image: { alt: string, ref: string }, marks: Record<string, any> }} Item
426
+ */
427
+
428
+ /**
429
+ * @param {Node[]} nodes
430
+ * @param {Record<string, any>} marks
431
+ * @param {Item[]} out
432
+ */
433
+ function flatten(nodes, marks, out) {
434
+ /** @param {string} s @param {Record<string, any>} m */
435
+ const text = (s, m) => { if (s) out.push(Object.keys(m).length ? { insert: s, attributes: { ...m } } : { insert: s }); };
436
+ for (const n of nodes) {
437
+ switch (n.t) {
438
+ case 'text': text(n.s, marks); break;
439
+ case 'code': text(n.s, { ...marks, code: true }); break;
440
+ case 'br': text('\n', marks); break;
441
+ case 'delim': text(n.ch === 'u' ? (n.canOpen ? '<u>' : '</u>') : n.ch.repeat(n.len), marks); break;
442
+ case 'em': flatten(n.children, { ...marks, [n.mark]: true }, out); break;
443
+ case 'link': {
444
+ const safe = n.href && marks.link === undefined ? sanitizeUrl(n.href, { kind: 'link' }) : null;
445
+ flatten(n.children, safe === null ? marks : { ...marks, link: n.href }, out);
446
+ break;
447
+ }
448
+ case 'image': {
449
+ const alt = plainText(n.children);
450
+ if (n.href && sanitizeUrl(n.href, { kind: 'media' }) !== null) out.push({ image: { alt, ref: n.href }, marks });
451
+ else text(alt, marks);
452
+ break;
453
+ }
454
+ }
455
+ }
456
+ }
457
+
458
+ /** @param {Record<string, any> | undefined} a @param {Record<string, any> | undefined} b */
459
+ function sameAttributes(a, b) {
460
+ const ka = Object.keys(a ?? {});
461
+ const kb = Object.keys(b ?? {});
462
+ return ka.length === kb.length && ka.every((k) => a?.[k] === b?.[k]);
463
+ }
464
+
465
+ /**
466
+ * Merge adjacent text ops with identical attributes into one.
467
+ * @param {Item[]} items
468
+ * @returns {import('loro-crdt').Delta<string>[]}
469
+ */
470
+ function toDelta(items) {
471
+ /** @type {import('loro-crdt').Delta<string>[]} */
472
+ const delta = [];
473
+ for (const it of items) {
474
+ if (!('insert' in it) || !it.insert) continue;
475
+ const last = /** @type {any} */ (delta[delta.length - 1]);
476
+ if (last && sameAttributes(last.attributes, it.attributes)) last.insert += it.insert;
477
+ else delta.push(it.attributes ? { insert: it.insert, attributes: { ...it.attributes } } : { insert: it.insert });
478
+ }
479
+ return delta;
480
+ }
481
+
482
+ /**
483
+ * Parse inline markdown into a sequence of text segments (a Loro delta each) and image segments: an image splits
484
+ * the text around it. Unsafe image URLs stay as their alt text.
485
+ * @param {string} text
486
+ * @param {InlineOptions} [options]
487
+ * @returns {InlineSegment[]}
488
+ */
489
+ export function parseMarkdownSegments(text, options = {}) {
490
+ if (!text) return [];
491
+ /** @type {Item[]} */
492
+ const items = [];
493
+ flatten(scan(text, options), {}, items);
494
+ /** @type {InlineSegment[]} */
495
+ const segments = [];
496
+ /** @type {Item[]} */
497
+ let run = [];
498
+ const closeRun = () => {
499
+ const delta = toDelta(run);
500
+ if (delta.length) segments.push({ delta });
501
+ run = [];
502
+ };
503
+ for (const it of items) {
504
+ if ('image' in it) { closeRun(); segments.push({ image: it.image }); } else run.push(it);
505
+ }
506
+ closeRun();
507
+ return segments;
508
+ }
509
+
510
+ /**
511
+ * Parse inline markdown text into a Loro-compatible delta array:
512
+ * `**bold *italic* still bold**` → [bold, bold+italic, bold]; `[t](url)` → text with a `link` mark.
513
+ * An image becomes its alt text (use {@link parseMarkdownSegments} to keep images as blocks).
514
+ *
515
+ * @param {string} text
516
+ * @param {Record<string, any>} [marks] marks inherited by every run
517
+ * @param {InlineOptions} [options]
518
+ * @returns {import('loro-crdt').Delta<string>[]}
519
+ */
520
+ export function parseMarkdownInline(text, marks = {}, options = {}) {
521
+ if (!text) return [];
522
+ /** @type {Item[]} */
523
+ const items = [];
524
+ flatten(scan(text, options), marks, items);
525
+ return toDelta(items.map((it) => ('image' in it
526
+ ? (it.image.alt ? { insert: it.image.alt, ...(Object.keys(it.marks).length ? { attributes: it.marks } : {}) } : { insert: '' })
527
+ : it)));
528
+ }
@@ -1,12 +1,6 @@
1
1
  /**
2
- * Parse inline markdown text into a Loro-compatible delta array.
3
- * Uses a leftmost-match recursive strategy so nested marks work naturally:
4
- * **bold *italic* still bold** → [bold, bold+italic, bold]
5
- *
6
- * @param {string} text
7
- * @param {Record<string, true>} [marks]
8
- * @returns {import('loro-crdt').Delta<string>[]}
2
+ * Paste of markdown typed as `text/plain`: parses it into blocks and inline marks through the rules the registered block classes declare (`markdownRules`). It also powers `importMarkdown()`.
9
3
  */
10
- export function parseMarkdownInline(text: string, marks?: Record<string, true>): import("loro-crdt").Delta<string>[];
11
4
  export const MarkdownPasteExtension: Extension;
12
5
  import { Extension } from '../utils/extensions.js';
6
+ export { parseMarkdownInline, parseMarkdownSegments } from "./markdown-inline.js";