@doist/typist 9.0.3 → 10.0.0-next.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (236) hide show
  1. package/dist/components/typist-editor.d.ts +126 -123
  2. package/dist/components/typist-editor.d.ts.map +1 -1
  3. package/dist/components/typist-editor.helper.d.ts +8 -11
  4. package/dist/components/typist-editor.helper.d.ts.map +1 -1
  5. package/dist/components/typist-editor.helper.js +21 -19
  6. package/dist/components/typist-editor.helper.js.map +1 -0
  7. package/dist/components/typist-editor.js +133 -135
  8. package/dist/components/typist-editor.js.map +1 -0
  9. package/dist/constants/common.js +9 -5
  10. package/dist/constants/common.js.map +1 -0
  11. package/dist/constants/extension-priorities.d.ts +3 -1
  12. package/dist/constants/extension-priorities.d.ts.map +1 -1
  13. package/dist/constants/extension-priorities.js +34 -30
  14. package/dist/constants/extension-priorities.js.map +1 -0
  15. package/dist/constants/regular-expressions.js +14 -10
  16. package/dist/constants/regular-expressions.js.map +1 -0
  17. package/dist/extensions/core/extra-editor-commands/commands/create-paragraph-end.d.ts +12 -9
  18. package/dist/extensions/core/extra-editor-commands/commands/create-paragraph-end.d.ts.map +1 -1
  19. package/dist/extensions/core/extra-editor-commands/commands/create-paragraph-end.js +16 -19
  20. package/dist/extensions/core/extra-editor-commands/commands/create-paragraph-end.js.map +1 -0
  21. package/dist/extensions/core/extra-editor-commands/commands/extend-word-range.d.ts +12 -9
  22. package/dist/extensions/core/extra-editor-commands/commands/extend-word-range.d.ts.map +1 -1
  23. package/dist/extensions/core/extra-editor-commands/commands/extend-word-range.js +25 -28
  24. package/dist/extensions/core/extra-editor-commands/commands/extend-word-range.js.map +1 -0
  25. package/dist/extensions/core/extra-editor-commands/commands/insert-markdown-content-at.d.ts +24 -22
  26. package/dist/extensions/core/extra-editor-commands/commands/insert-markdown-content-at.d.ts.map +1 -1
  27. package/dist/extensions/core/extra-editor-commands/commands/insert-markdown-content-at.js +34 -36
  28. package/dist/extensions/core/extra-editor-commands/commands/insert-markdown-content-at.js.map +1 -0
  29. package/dist/extensions/core/extra-editor-commands/commands/insert-markdown-content.d.ts +23 -20
  30. package/dist/extensions/core/extra-editor-commands/commands/insert-markdown-content.d.ts.map +1 -1
  31. package/dist/extensions/core/extra-editor-commands/commands/insert-markdown-content.js +15 -8
  32. package/dist/extensions/core/extra-editor-commands/commands/insert-markdown-content.js.map +1 -0
  33. package/dist/extensions/core/extra-editor-commands/extra-editor-commands.js +22 -18
  34. package/dist/extensions/core/extra-editor-commands/extra-editor-commands.js.map +1 -0
  35. package/dist/extensions/core/view-event-handlers.d.ts +14 -13
  36. package/dist/extensions/core/view-event-handlers.d.ts.map +1 -1
  37. package/dist/extensions/core/view-event-handlers.js +33 -31
  38. package/dist/extensions/core/view-event-handlers.js.map +1 -0
  39. package/dist/extensions/plain-text/paste-multiline-text.js +45 -59
  40. package/dist/extensions/plain-text/paste-multiline-text.js.map +1 -0
  41. package/dist/extensions/plain-text/plain-text-document.d.ts +7 -7
  42. package/dist/extensions/plain-text/plain-text-document.d.ts.map +1 -1
  43. package/dist/extensions/plain-text/plain-text-document.js +14 -13
  44. package/dist/extensions/plain-text/plain-text-document.js.map +1 -0
  45. package/dist/extensions/plain-text/plain-text-kit.d.ts +35 -33
  46. package/dist/extensions/plain-text/plain-text-kit.d.ts.map +1 -1
  47. package/dist/extensions/plain-text/plain-text-kit.js +33 -48
  48. package/dist/extensions/plain-text/plain-text-kit.js.map +1 -0
  49. package/dist/extensions/plain-text/plain-text-paragraph.d.ts +2 -9
  50. package/dist/extensions/plain-text/plain-text-paragraph.js +11 -11
  51. package/dist/extensions/plain-text/plain-text-paragraph.js.map +1 -0
  52. package/dist/extensions/plain-text/smart-markdown-typing/plugins/smart-lists.js +37 -81
  53. package/dist/extensions/plain-text/smart-markdown-typing/plugins/smart-lists.js.map +1 -0
  54. package/dist/extensions/plain-text/smart-markdown-typing/plugins/smart-select-wrap.js +32 -42
  55. package/dist/extensions/plain-text/smart-markdown-typing/plugins/smart-select-wrap.js.map +1 -0
  56. package/dist/extensions/plain-text/smart-markdown-typing/plugins/smart-url-pasting.js +24 -37
  57. package/dist/extensions/plain-text/smart-markdown-typing/plugins/smart-url-pasting.js.map +1 -0
  58. package/dist/extensions/plain-text/smart-markdown-typing/smart-markdown-typing.js +21 -13
  59. package/dist/extensions/plain-text/smart-markdown-typing/smart-markdown-typing.js.map +1 -0
  60. package/dist/extensions/rich-text/bold-and-italics.js +42 -40
  61. package/dist/extensions/rich-text/bold-and-italics.js.map +1 -0
  62. package/dist/extensions/rich-text/curvenote-codemark.js +16 -14
  63. package/dist/extensions/rich-text/curvenote-codemark.js.map +1 -0
  64. package/dist/extensions/rich-text/paste-emojis.js +20 -22
  65. package/dist/extensions/rich-text/paste-emojis.js.map +1 -0
  66. package/dist/extensions/rich-text/paste-markdown.js +46 -86
  67. package/dist/extensions/rich-text/paste-markdown.js.map +1 -0
  68. package/dist/extensions/rich-text/rich-text-bullet-list.d.ts +10 -9
  69. package/dist/extensions/rich-text/rich-text-bullet-list.d.ts.map +1 -1
  70. package/dist/extensions/rich-text/rich-text-bullet-list.js +42 -56
  71. package/dist/extensions/rich-text/rich-text-bullet-list.js.map +1 -0
  72. package/dist/extensions/rich-text/rich-text-code.js +34 -34
  73. package/dist/extensions/rich-text/rich-text-code.js.map +1 -0
  74. package/dist/extensions/rich-text/rich-text-document.d.ts +7 -7
  75. package/dist/extensions/rich-text/rich-text-document.d.ts.map +1 -1
  76. package/dist/extensions/rich-text/rich-text-document.js +14 -13
  77. package/dist/extensions/rich-text/rich-text-document.js.map +1 -0
  78. package/dist/extensions/rich-text/rich-text-heading.d.ts +5 -4
  79. package/dist/extensions/rich-text/rich-text-heading.d.ts.map +1 -1
  80. package/dist/extensions/rich-text/rich-text-heading.js +25 -25
  81. package/dist/extensions/rich-text/rich-text-heading.js.map +1 -0
  82. package/dist/extensions/rich-text/rich-text-image.d.ts +53 -52
  83. package/dist/extensions/rich-text/rich-text-image.d.ts.map +1 -1
  84. package/dist/extensions/rich-text/rich-text-image.js +88 -105
  85. package/dist/extensions/rich-text/rich-text-image.js.map +1 -0
  86. package/dist/extensions/rich-text/rich-text-kit.d.ts +127 -125
  87. package/dist/extensions/rich-text/rich-text-kit.d.ts.map +1 -1
  88. package/dist/extensions/rich-text/rich-text-kit.js +73 -135
  89. package/dist/extensions/rich-text/rich-text-kit.js.map +1 -0
  90. package/dist/extensions/rich-text/rich-text-link.d.ts +5 -4
  91. package/dist/extensions/rich-text/rich-text-link.d.ts.map +1 -1
  92. package/dist/extensions/rich-text/rich-text-link.js +82 -90
  93. package/dist/extensions/rich-text/rich-text-link.js.map +1 -0
  94. package/dist/extensions/rich-text/rich-text-ordered-list.d.ts +10 -9
  95. package/dist/extensions/rich-text/rich-text-ordered-list.d.ts.map +1 -1
  96. package/dist/extensions/rich-text/rich-text-ordered-list.js +42 -56
  97. package/dist/extensions/rich-text/rich-text-ordered-list.js.map +1 -0
  98. package/dist/extensions/rich-text/rich-text-strikethrough.d.ts +5 -4
  99. package/dist/extensions/rich-text/rich-text-strikethrough.d.ts.map +1 -1
  100. package/dist/extensions/rich-text/rich-text-strikethrough.js +10 -10
  101. package/dist/extensions/rich-text/rich-text-strikethrough.js.map +1 -0
  102. package/dist/extensions/shared/copy-markdown-source.js +22 -31
  103. package/dist/extensions/shared/copy-markdown-source.js.map +1 -0
  104. package/dist/extensions/shared/paste-html-table-as-string.js +47 -60
  105. package/dist/extensions/shared/paste-html-table-as-string.js.map +1 -0
  106. package/dist/extensions/shared/paste-singleline-text.js +31 -39
  107. package/dist/extensions/shared/paste-singleline-text.js.map +1 -0
  108. package/dist/factories/create-suggestion-extension.d.ts +74 -74
  109. package/dist/factories/create-suggestion-extension.d.ts.map +1 -1
  110. package/dist/factories/create-suggestion-extension.js +139 -161
  111. package/dist/factories/create-suggestion-extension.js.map +1 -0
  112. package/dist/helpers/dom.js +9 -5
  113. package/dist/helpers/dom.js.map +1 -0
  114. package/dist/helpers/schema.d.ts +5 -3
  115. package/dist/helpers/schema.d.ts.map +1 -1
  116. package/dist/helpers/schema.js +25 -21
  117. package/dist/helpers/schema.js.map +1 -0
  118. package/dist/helpers/serializer.js +24 -28
  119. package/dist/helpers/serializer.js.map +1 -0
  120. package/dist/helpers/unified.js +24 -17
  121. package/dist/helpers/unified.js.map +1 -0
  122. package/dist/hooks/use-editor.js +50 -53
  123. package/dist/hooks/use-editor.js.map +1 -0
  124. package/dist/index.d.ts +25 -31
  125. package/dist/index.js +24 -24
  126. package/dist/serializers/html/html.d.ts +12 -10
  127. package/dist/serializers/html/html.d.ts.map +1 -1
  128. package/dist/serializers/html/html.js +67 -127
  129. package/dist/serializers/html/html.js.map +1 -0
  130. package/dist/serializers/html/plugins/rehype-code-block.js +17 -17
  131. package/dist/serializers/html/plugins/rehype-code-block.js.map +1 -0
  132. package/dist/serializers/html/plugins/rehype-image.js +20 -30
  133. package/dist/serializers/html/plugins/rehype-image.js.map +1 -0
  134. package/dist/serializers/html/plugins/rehype-suggestions.js +31 -32
  135. package/dist/serializers/html/plugins/rehype-suggestions.js.map +1 -0
  136. package/dist/serializers/html/plugins/rehype-task-list.js +31 -32
  137. package/dist/serializers/html/plugins/rehype-task-list.js.map +1 -0
  138. package/dist/serializers/html/plugins/remark-autolink-literal.d.ts +4 -1
  139. package/dist/serializers/html/plugins/remark-autolink-literal.d.ts.map +1 -1
  140. package/dist/serializers/html/plugins/remark-autolink-literal.js +25 -21
  141. package/dist/serializers/html/plugins/remark-autolink-literal.js.map +1 -0
  142. package/dist/serializers/html/plugins/remark-disable-constructs.js +21 -41
  143. package/dist/serializers/html/plugins/remark-disable-constructs.js.map +1 -0
  144. package/dist/serializers/html/plugins/remark-strikethrough.d.ts +5 -2
  145. package/dist/serializers/html/plugins/remark-strikethrough.d.ts.map +1 -1
  146. package/dist/serializers/html/plugins/remark-strikethrough.js +25 -21
  147. package/dist/serializers/html/plugins/remark-strikethrough.js.map +1 -0
  148. package/dist/serializers/markdown/markdown.d.ts +13 -12
  149. package/dist/serializers/markdown/markdown.d.ts.map +1 -1
  150. package/dist/serializers/markdown/markdown.js +78 -154
  151. package/dist/serializers/markdown/markdown.js.map +1 -0
  152. package/dist/serializers/markdown/plugins/image.js +27 -24
  153. package/dist/serializers/markdown/plugins/image.js.map +1 -0
  154. package/dist/serializers/markdown/plugins/list-item.js +32 -37
  155. package/dist/serializers/markdown/plugins/list-item.js.map +1 -0
  156. package/dist/serializers/markdown/plugins/paragraph.js +19 -19
  157. package/dist/serializers/markdown/plugins/paragraph.js.map +1 -0
  158. package/dist/serializers/markdown/plugins/strikethrough.js +23 -19
  159. package/dist/serializers/markdown/plugins/strikethrough.js.map +1 -0
  160. package/dist/serializers/markdown/plugins/suggestion.js +21 -19
  161. package/dist/serializers/markdown/plugins/suggestion.js.map +1 -0
  162. package/dist/serializers/markdown/plugins/task-item.js +31 -35
  163. package/dist/serializers/markdown/plugins/task-item.js.map +1 -0
  164. package/dist/utilities/can-insert-node-at.d.ts +12 -5
  165. package/dist/utilities/can-insert-node-at.d.ts.map +1 -1
  166. package/dist/utilities/can-insert-node-at.js +10 -8
  167. package/dist/utilities/can-insert-node-at.js.map +1 -0
  168. package/dist/utilities/can-insert-suggestion.d.ts +11 -5
  169. package/dist/utilities/can-insert-suggestion.d.ts.map +1 -1
  170. package/dist/utilities/can-insert-suggestion.js +15 -12
  171. package/dist/utilities/can-insert-suggestion.js.map +1 -0
  172. package/package.json +26 -13
  173. package/dist/constants/common.d.ts +0 -10
  174. package/dist/constants/common.d.ts.map +0 -1
  175. package/dist/constants/regular-expressions.d.ts +0 -18
  176. package/dist/constants/regular-expressions.d.ts.map +0 -1
  177. package/dist/extensions/core/extra-editor-commands/extra-editor-commands.d.ts +0 -9
  178. package/dist/extensions/core/extra-editor-commands/extra-editor-commands.d.ts.map +0 -1
  179. package/dist/extensions/plain-text/paste-multiline-text.d.ts +0 -10
  180. package/dist/extensions/plain-text/paste-multiline-text.d.ts.map +0 -1
  181. package/dist/extensions/plain-text/plain-text-paragraph.d.ts.map +0 -1
  182. package/dist/extensions/plain-text/smart-markdown-typing/plugins/smart-lists.d.ts +0 -9
  183. package/dist/extensions/plain-text/smart-markdown-typing/plugins/smart-lists.d.ts.map +0 -1
  184. package/dist/extensions/plain-text/smart-markdown-typing/plugins/smart-select-wrap.d.ts +0 -9
  185. package/dist/extensions/plain-text/smart-markdown-typing/plugins/smart-select-wrap.d.ts.map +0 -1
  186. package/dist/extensions/plain-text/smart-markdown-typing/plugins/smart-url-pasting.d.ts +0 -9
  187. package/dist/extensions/plain-text/smart-markdown-typing/plugins/smart-url-pasting.d.ts.map +0 -1
  188. package/dist/extensions/plain-text/smart-markdown-typing/smart-markdown-typing.d.ts +0 -8
  189. package/dist/extensions/plain-text/smart-markdown-typing/smart-markdown-typing.d.ts.map +0 -1
  190. package/dist/extensions/rich-text/bold-and-italics.d.ts +0 -8
  191. package/dist/extensions/rich-text/bold-and-italics.d.ts.map +0 -1
  192. package/dist/extensions/rich-text/curvenote-codemark.d.ts +0 -11
  193. package/dist/extensions/rich-text/curvenote-codemark.d.ts.map +0 -1
  194. package/dist/extensions/rich-text/paste-emojis.d.ts +0 -9
  195. package/dist/extensions/rich-text/paste-emojis.d.ts.map +0 -1
  196. package/dist/extensions/rich-text/paste-markdown.d.ts +0 -11
  197. package/dist/extensions/rich-text/paste-markdown.d.ts.map +0 -1
  198. package/dist/extensions/rich-text/rich-text-code.d.ts +0 -17
  199. package/dist/extensions/rich-text/rich-text-code.d.ts.map +0 -1
  200. package/dist/extensions/shared/copy-markdown-source.d.ts +0 -20
  201. package/dist/extensions/shared/copy-markdown-source.d.ts.map +0 -1
  202. package/dist/extensions/shared/paste-html-table-as-string.d.ts +0 -20
  203. package/dist/extensions/shared/paste-html-table-as-string.d.ts.map +0 -1
  204. package/dist/extensions/shared/paste-singleline-text.d.ts +0 -10
  205. package/dist/extensions/shared/paste-singleline-text.d.ts.map +0 -1
  206. package/dist/helpers/dom.d.ts +0 -8
  207. package/dist/helpers/dom.d.ts.map +0 -1
  208. package/dist/helpers/serializer.d.ts +0 -21
  209. package/dist/helpers/serializer.d.ts.map +0 -1
  210. package/dist/helpers/unified.d.ts +0 -21
  211. package/dist/helpers/unified.d.ts.map +0 -1
  212. package/dist/hooks/use-editor.d.ts +0 -19
  213. package/dist/hooks/use-editor.d.ts.map +0 -1
  214. package/dist/index.d.ts.map +0 -1
  215. package/dist/serializers/html/plugins/rehype-code-block.d.ts +0 -10
  216. package/dist/serializers/html/plugins/rehype-code-block.d.ts.map +0 -1
  217. package/dist/serializers/html/plugins/rehype-image.d.ts +0 -11
  218. package/dist/serializers/html/plugins/rehype-image.d.ts.map +0 -1
  219. package/dist/serializers/html/plugins/rehype-suggestions.d.ts +0 -10
  220. package/dist/serializers/html/plugins/rehype-suggestions.d.ts.map +0 -1
  221. package/dist/serializers/html/plugins/rehype-task-list.d.ts +0 -7
  222. package/dist/serializers/html/plugins/rehype-task-list.d.ts.map +0 -1
  223. package/dist/serializers/html/plugins/remark-disable-constructs.d.ts +0 -11
  224. package/dist/serializers/html/plugins/remark-disable-constructs.d.ts.map +0 -1
  225. package/dist/serializers/markdown/plugins/image.d.ts +0 -12
  226. package/dist/serializers/markdown/plugins/image.d.ts.map +0 -1
  227. package/dist/serializers/markdown/plugins/list-item.d.ts +0 -14
  228. package/dist/serializers/markdown/plugins/list-item.d.ts.map +0 -1
  229. package/dist/serializers/markdown/plugins/paragraph.d.ts +0 -13
  230. package/dist/serializers/markdown/plugins/paragraph.d.ts.map +0 -1
  231. package/dist/serializers/markdown/plugins/strikethrough.d.ts +0 -13
  232. package/dist/serializers/markdown/plugins/strikethrough.d.ts.map +0 -1
  233. package/dist/serializers/markdown/plugins/suggestion.d.ts +0 -11
  234. package/dist/serializers/markdown/plugins/suggestion.d.ts.map +0 -1
  235. package/dist/serializers/markdown/plugins/task-item.d.ts +0 -14
  236. package/dist/serializers/markdown/plugins/task-item.d.ts.map +0 -1
@@ -1,165 +1,89 @@
1
- import Turndown from 'turndown';
2
- import { REGEX_PUNCTUATION } from '../../constants/regular-expressions';
3
- import { computeSchemaId, isPlainTextDocument } from '../../helpers/schema';
4
- import { image } from './plugins/image';
5
- import { listItem } from './plugins/list-item';
6
- import { paragraph } from './plugins/paragraph';
7
- import { strikethrough } from './plugins/strikethrough';
8
- import { suggestion } from './plugins/suggestion';
9
- import { taskItem } from './plugins/task-item';
1
+ import { computeSchemaId, isPlainTextDocument } from "../../helpers/schema.js";
2
+ import { REGEX_PUNCTUATION } from "../../constants/regular-expressions.js";
3
+ import { image } from "./plugins/image.js";
4
+ import { listItem } from "./plugins/list-item.js";
5
+ import { paragraph } from "./plugins/paragraph.js";
6
+ import { strikethrough } from "./plugins/strikethrough.js";
7
+ import { suggestion } from "./plugins/suggestion.js";
8
+ import { taskItem } from "./plugins/task-item.js";
9
+ import Turndown from "turndown";
10
10
  /**
11
- * The bullet list marker for both standard and task list items.
12
- */
13
- const BULLET_LIST_MARKER = '-';
14
- /**
15
- * Sensible default options to initialize the Turndown with.
16
- *
17
- * @see https://github.com/mixmark-io/turndown#options
18
- */
11
+ * Sensible default options to initialize the Turndown with.
12
+ *
13
+ * @see https://github.com/mixmark-io/turndown#options
14
+ */
19
15
  const INITIAL_TURNDOWN_OPTIONS = {
20
- headingStyle: 'atx',
21
- hr: '---',
22
- bulletListMarker: BULLET_LIST_MARKER,
23
- codeBlockStyle: 'fenced',
24
- fence: '```',
25
- emDelimiter: '*',
26
- strongDelimiter: '**',
27
- linkStyle: 'inlined',
28
- /**
29
- * Special rule to handle blank elements (overrides EVERY rule).
30
- *
31
- * @see https://github.com/mixmark-io/turndown#special-rules
32
- */
33
- blankReplacement(_, node) {
34
- const parentNode = node.parentNode;
35
- // Return the list marker for empty bullet list items
36
- if (node.nodeName === 'UL' || (parentNode?.nodeName === 'UL' && node.nodeName === 'LI')) {
37
- return `${BULLET_LIST_MARKER} \n`;
38
- }
39
- // Return the list marker for empty ordered list items
40
- if (node.nodeName === 'OL' || (parentNode?.nodeName === 'OL' && node.nodeName === 'LI')) {
41
- const start = node.nodeName === 'LI'
42
- ? parentNode.getAttribute('start')
43
- : node.getAttribute('start');
44
- const index = Array.prototype.indexOf.call(parentNode.children, node);
45
- return `${start ? Number(start) + index : index + 1}. \n`;
46
- }
47
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
48
- // @ts-ignore: The `Turndown.Node` type does not include `isBlock`
49
- return node.isBlock ? '\n\n' : '';
50
- },
16
+ headingStyle: "atx",
17
+ hr: "---",
18
+ bulletListMarker: "-",
19
+ codeBlockStyle: "fenced",
20
+ fence: "```",
21
+ emDelimiter: "*",
22
+ strongDelimiter: "**",
23
+ linkStyle: "inlined",
24
+ blankReplacement(_, node) {
25
+ const parentNode = node.parentNode;
26
+ if (node.nodeName === "UL" || parentNode?.nodeName === "UL" && node.nodeName === "LI") return `- \n`;
27
+ if (node.nodeName === "OL" || parentNode?.nodeName === "OL" && node.nodeName === "LI") {
28
+ const start = node.nodeName === "LI" ? parentNode.getAttribute("start") : node.getAttribute("start");
29
+ const index = Array.prototype.indexOf.call(parentNode.children, node);
30
+ return `${start ? Number(start) + index : index + 1}. \n`;
31
+ }
32
+ return node.isBlock ? "\n\n" : "";
33
+ }
51
34
  };
52
35
  /**
53
- * Create an HTML to Markdown serializer with the Turndown library for both a rich-text editor, and
54
- * a plain-text editor. The editor schema is used to detect which nodes and marks are available in
55
- * the editor, and only parses the input with the minimal required rules.
56
- *
57
- * **Note:** Unlike the HTML serializer, built-in rules that are not supported by the schema are not
58
- * disabled because if the schema does not support certain nodes/marks, the parsing rules don't have
59
- * valid HTML elements to match in the editor HTML output.
60
- *
61
- * @param schema The editor schema to be used for nodes and marks detection.
62
- *
63
- * @returns A normalized object for the Markdown serializer.
64
- */
36
+ * Create an HTML to Markdown serializer with the Turndown library for both a rich-text editor, and
37
+ * a plain-text editor. The editor schema is used to detect which nodes and marks are available in
38
+ * the editor, and only parses the input with the minimal required rules.
39
+ *
40
+ * **Note:** Unlike the HTML serializer, built-in rules that are not supported by the schema are not
41
+ * disabled because if the schema does not support certain nodes/marks, the parsing rules don't have
42
+ * valid HTML elements to match in the editor HTML output.
43
+ *
44
+ * @param schema The editor schema to be used for nodes and marks detection.
45
+ *
46
+ * @returns A normalized object for the Markdown serializer.
47
+ */
65
48
  function createMarkdownSerializer(schema) {
66
- // Initialize Turndown with custom options
67
- const turndown = new Turndown(INITIAL_TURNDOWN_OPTIONS);
68
- // Turndown ensures Markdown characters are escaped (i.e. `\`) by default, so they are not
69
- // interpreted as Markdown when the output is compiled back to HTML. However, for plain-text
70
- // editors, we need to override the `escape` function to return the input as-is (effectively
71
- // disabling the escaping behaviour), so that all characters are interpreted as Markdown.
72
- if (isPlainTextDocument(schema)) {
73
- turndown.escape = (str) => str;
74
- }
75
- // As for rich-text editors, we need to override the built-in escaping behaviour with a custom
76
- // implementation to suit our requirements. Please note that the `escape` function takes the
77
- // text content of each HTML element, with the exception of code elements, so we can be sure
78
- // that the escaping behaviour will only touch relevant Markdown characters.
79
- else {
80
- turndown.escape = (str) => {
81
- return (str
82
- // Escape all backslash characters that precede any punctuation marks, to
83
- // prevent the backslash itself from being interpreted as an escape sequence
84
- // for the subsequent character. It's important to apply this rule first to
85
- // avoid double escaping.
86
- .replace(new RegExp(`(\\\\${REGEX_PUNCTUATION.source})`, 'g'), '\\$1')
87
- // Although the CommonMark specification allows for bulleted or ordered lists
88
- // inside other bulleted or ordered lists (i.e. `- 1. - 1. Item`), the markup
89
- // generated by Markdown compilers is not supported by Tiptap, and we need to
90
- // make sure that text context that matches the ordered list syntax is
91
- // correctly escaped in order to be interpreted as text.
92
- .replace(/^(\d+)\.(\s.+|$)/, '$1\\.$2'));
93
- };
94
- }
95
- // Overwrite some built-in rules for handling of special behaviours
96
- // (see documentation for each extension for more details)
97
- turndown.use(paragraph(schema.nodes.paragraph, isPlainTextDocument(schema)));
98
- // Overwrite the built-in `image` rule if the corresponding node exists in the schema
99
- if (schema.nodes.image) {
100
- turndown.use(image(schema.nodes.image));
101
- }
102
- // Overwrite the built-in `listItem` rule if the corresponding node exists in the schema
103
- if ((schema.nodes.bulletList || schema.nodes.orderedList) && schema.nodes.listItem) {
104
- turndown.use(listItem(schema.nodes.listItem));
105
- }
106
- // Add a rule for `strikethrough` if the corresponding node exists in the schema
107
- if (schema.marks.strike) {
108
- turndown.use(strikethrough(schema.marks.strike));
109
- }
110
- // Add a rule for `taskItem` if the corresponding nodes exists in the schema
111
- if (schema.nodes.taskList && schema.nodes.taskItem) {
112
- turndown.use(taskItem(schema.nodes.taskItem));
113
- }
114
- // Add a custom rule for all suggestion nodes available in the schema
115
- Object.values(schema.nodes)
116
- .filter((node) => node.name.endsWith('Suggestion'))
117
- .forEach((suggestionNode) => {
118
- turndown.use(suggestion(suggestionNode));
119
- });
120
- // Return a normalized `serialize` function
121
- return {
122
- serialize(html) {
123
- let markdownResult = html;
124
- // Turndown was built to convert HTML into Markdown, expecting the input to be
125
- // standard-compliant HTML. As such, it collapses all whitespace by default, and there's
126
- // currently no way to opt-out of this behavior. However, for plain-text editors, we
127
- // need to preserve Markdown whitespace (otherwise we lose syntax like nested lists) by
128
- // replacing all instances of the space character (but only if it's preceded by another
129
- // space character) by the non-breaking space character, and after processing the input
130
- // with Turndown, we restore the original space character.
131
- if (isPlainTextDocument(schema)) {
132
- markdownResult = markdownResult.replace(/ {2,}/g, (m) => m.replace(/ /g, '\u00a0'));
133
- }
134
- // Get the serialized Markdown parsed with Turndown
135
- markdownResult = turndown.turndown(markdownResult);
136
- // Restore the original space character for plain-text editors (as mentioned above),
137
- // after Markdown serialization has been performed
138
- if (isPlainTextDocument(schema)) {
139
- markdownResult = markdownResult.replace(/\u00a0/g, ' ');
140
- }
141
- // Return the serialized Markdown parsed with Turndown, and with trailing space
142
- // characters removed
143
- return markdownResult.replace(/ +$/gm, '');
144
- },
145
- };
49
+ const turndown = new Turndown(INITIAL_TURNDOWN_OPTIONS);
50
+ if (isPlainTextDocument(schema)) turndown.escape = (str) => str;
51
+ else turndown.escape = (str) => {
52
+ return str.replace(new RegExp(`(\\\\${REGEX_PUNCTUATION.source})`, "g"), "\\$1").replace(/^(\d+)\.(\s.+|$)/, "$1\\.$2");
53
+ };
54
+ turndown.use(paragraph(schema.nodes.paragraph, isPlainTextDocument(schema)));
55
+ if (schema.nodes.image) turndown.use(image(schema.nodes.image));
56
+ if ((schema.nodes.bulletList || schema.nodes.orderedList) && schema.nodes.listItem) turndown.use(listItem(schema.nodes.listItem));
57
+ if (schema.marks.strike) turndown.use(strikethrough(schema.marks.strike));
58
+ if (schema.nodes.taskList && schema.nodes.taskItem) turndown.use(taskItem(schema.nodes.taskItem));
59
+ Object.values(schema.nodes).filter((node) => node.name.endsWith("Suggestion")).forEach((suggestionNode) => {
60
+ turndown.use(suggestion(suggestionNode));
61
+ });
62
+ return { serialize(html) {
63
+ let markdownResult = html;
64
+ if (isPlainTextDocument(schema)) markdownResult = markdownResult.replace(/ {2,}/g, (m) => m.replace(/ /g, "\xA0"));
65
+ markdownResult = turndown.turndown(markdownResult);
66
+ if (isPlainTextDocument(schema)) markdownResult = markdownResult.replace(/\u00a0/g, " ");
67
+ return markdownResult.replace(/ +$/gm, "");
68
+ } };
146
69
  }
147
70
  /**
148
- * Object that holds multiple Markdown serializer instances based on a given ID.
149
- */
71
+ * Object that holds multiple Markdown serializer instances based on a given ID.
72
+ */
150
73
  const markdownSerializerInstanceById = {};
151
74
  /**
152
- * Returns a singleton instance of a Markdown serializer based on the provided editor schema.
153
- *
154
- * @param schema The editor schema connected to the Markdown serializer instance.
155
- *
156
- * @returns The Markdown serializer instance for the given editor schema.
157
- */
75
+ * Returns a singleton instance of a Markdown serializer based on the provided editor schema.
76
+ *
77
+ * @param schema The editor schema connected to the Markdown serializer instance.
78
+ *
79
+ * @returns The Markdown serializer instance for the given editor schema.
80
+ */
158
81
  function getMarkdownSerializerInstance(schema) {
159
- const id = computeSchemaId(schema);
160
- if (!markdownSerializerInstanceById[id]) {
161
- markdownSerializerInstanceById[id] = createMarkdownSerializer(schema);
162
- }
163
- return markdownSerializerInstanceById[id];
82
+ const id = computeSchemaId(schema);
83
+ if (!markdownSerializerInstanceById[id]) markdownSerializerInstanceById[id] = createMarkdownSerializer(schema);
84
+ return markdownSerializerInstanceById[id];
164
85
  }
165
- export { BULLET_LIST_MARKER, createMarkdownSerializer, getMarkdownSerializerInstance };
86
+ //#endregion
87
+ export { createMarkdownSerializer, getMarkdownSerializerInstance };
88
+
89
+ //# sourceMappingURL=markdown.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"markdown.js","names":[],"sources":["../../../src/serializers/markdown/markdown.ts"],"sourcesContent":["import Turndown from 'turndown'\n\nimport { REGEX_PUNCTUATION } from '../../constants/regular-expressions'\nimport { computeSchemaId, isPlainTextDocument } from '../../helpers/schema'\n\nimport { image } from './plugins/image'\nimport { listItem } from './plugins/list-item'\nimport { paragraph } from './plugins/paragraph'\nimport { strikethrough } from './plugins/strikethrough'\nimport { suggestion } from './plugins/suggestion'\nimport { taskItem } from './plugins/task-item'\n\nimport type { Schema } from '@tiptap/pm/model'\n\n/**\n * The return type for the `createMarkdownSerializer` function.\n */\ntype MarkdownSerializerReturnType = {\n /**\n * Serializes an input HTML string to an output Markdown string.\n *\n * @param html The HTML string to serialize.\n *\n * @returns The serialized Markdown.\n */\n serialize: (html: string) => string\n}\n\n/**\n * The type for the object that holds multiple Markdown serializer instances.\n */\ntype MarkdownSerializerInstanceById = {\n [id: string]: MarkdownSerializerReturnType\n}\n\n/**\n * The bullet list marker for both standard and task list items.\n */\nconst BULLET_LIST_MARKER = '-'\n\n/**\n * Sensible default options to initialize the Turndown with.\n *\n * @see https://github.com/mixmark-io/turndown#options\n */\nconst INITIAL_TURNDOWN_OPTIONS: Turndown.Options = {\n headingStyle: 'atx',\n hr: '---',\n bulletListMarker: BULLET_LIST_MARKER,\n codeBlockStyle: 'fenced',\n fence: '```',\n emDelimiter: '*',\n strongDelimiter: '**',\n linkStyle: 'inlined',\n /**\n * Special rule to handle blank elements (overrides EVERY rule).\n *\n * @see https://github.com/mixmark-io/turndown#special-rules\n */\n blankReplacement(_, node) {\n const parentNode = node.parentNode as HTMLElement\n\n // Return the list marker for empty bullet list items\n if (node.nodeName === 'UL' || (parentNode?.nodeName === 'UL' && node.nodeName === 'LI')) {\n return `${BULLET_LIST_MARKER} \\n`\n }\n\n // Return the list marker for empty ordered list items\n if (node.nodeName === 'OL' || (parentNode?.nodeName === 'OL' && node.nodeName === 'LI')) {\n const start =\n node.nodeName === 'LI'\n ? parentNode.getAttribute('start')\n : node.getAttribute('start')\n const index = Array.prototype.indexOf.call(parentNode.children, node)\n\n return `${start ? Number(start) + index : index + 1}. \\n`\n }\n\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore: The `Turndown.Node` type does not include `isBlock`\n return node.isBlock ? '\\n\\n' : ''\n },\n}\n\n/**\n * Create an HTML to Markdown serializer with the Turndown library for both a rich-text editor, and\n * a plain-text editor. The editor schema is used to detect which nodes and marks are available in\n * the editor, and only parses the input with the minimal required rules.\n *\n * **Note:** Unlike the HTML serializer, built-in rules that are not supported by the schema are not\n * disabled because if the schema does not support certain nodes/marks, the parsing rules don't have\n * valid HTML elements to match in the editor HTML output.\n *\n * @param schema The editor schema to be used for nodes and marks detection.\n *\n * @returns A normalized object for the Markdown serializer.\n */\nfunction createMarkdownSerializer(schema: Schema): MarkdownSerializerReturnType {\n // Initialize Turndown with custom options\n const turndown = new Turndown(INITIAL_TURNDOWN_OPTIONS)\n\n // Turndown ensures Markdown characters are escaped (i.e. `\\`) by default, so they are not\n // interpreted as Markdown when the output is compiled back to HTML. However, for plain-text\n // editors, we need to override the `escape` function to return the input as-is (effectively\n // disabling the escaping behaviour), so that all characters are interpreted as Markdown.\n if (isPlainTextDocument(schema)) {\n turndown.escape = (str) => str\n }\n // As for rich-text editors, we need to override the built-in escaping behaviour with a custom\n // implementation to suit our requirements. Please note that the `escape` function takes the\n // text content of each HTML element, with the exception of code elements, so we can be sure\n // that the escaping behaviour will only touch relevant Markdown characters.\n else {\n turndown.escape = (str) => {\n return (\n str\n // Escape all backslash characters that precede any punctuation marks, to\n // prevent the backslash itself from being interpreted as an escape sequence\n // for the subsequent character. It's important to apply this rule first to\n // avoid double escaping.\n .replace(new RegExp(`(\\\\\\\\${REGEX_PUNCTUATION.source})`, 'g'), '\\\\$1')\n\n // Although the CommonMark specification allows for bulleted or ordered lists\n // inside other bulleted or ordered lists (i.e. `- 1. - 1. Item`), the markup\n // generated by Markdown compilers is not supported by Tiptap, and we need to\n // make sure that text context that matches the ordered list syntax is\n // correctly escaped in order to be interpreted as text.\n .replace(/^(\\d+)\\.(\\s.+|$)/, '$1\\\\.$2')\n )\n }\n }\n\n // Overwrite some built-in rules for handling of special behaviours\n // (see documentation for each extension for more details)\n turndown.use(paragraph(schema.nodes.paragraph, isPlainTextDocument(schema)))\n\n // Overwrite the built-in `image` rule if the corresponding node exists in the schema\n if (schema.nodes.image) {\n turndown.use(image(schema.nodes.image))\n }\n\n // Overwrite the built-in `listItem` rule if the corresponding node exists in the schema\n if ((schema.nodes.bulletList || schema.nodes.orderedList) && schema.nodes.listItem) {\n turndown.use(listItem(schema.nodes.listItem))\n }\n\n // Add a rule for `strikethrough` if the corresponding node exists in the schema\n if (schema.marks.strike) {\n turndown.use(strikethrough(schema.marks.strike))\n }\n\n // Add a rule for `taskItem` if the corresponding nodes exists in the schema\n if (schema.nodes.taskList && schema.nodes.taskItem) {\n turndown.use(taskItem(schema.nodes.taskItem))\n }\n\n // Add a custom rule for all suggestion nodes available in the schema\n Object.values(schema.nodes)\n .filter((node) => node.name.endsWith('Suggestion'))\n .forEach((suggestionNode) => {\n turndown.use(suggestion(suggestionNode))\n })\n\n // Return a normalized `serialize` function\n return {\n serialize(html: string) {\n let markdownResult = html\n\n // Turndown was built to convert HTML into Markdown, expecting the input to be\n // standard-compliant HTML. As such, it collapses all whitespace by default, and there's\n // currently no way to opt-out of this behavior. However, for plain-text editors, we\n // need to preserve Markdown whitespace (otherwise we lose syntax like nested lists) by\n // replacing all instances of the space character (but only if it's preceded by another\n // space character) by the non-breaking space character, and after processing the input\n // with Turndown, we restore the original space character.\n if (isPlainTextDocument(schema)) {\n markdownResult = markdownResult.replace(/ {2,}/g, (m) => m.replace(/ /g, '\\u00a0'))\n }\n\n // Get the serialized Markdown parsed with Turndown\n markdownResult = turndown.turndown(markdownResult)\n\n // Restore the original space character for plain-text editors (as mentioned above),\n // after Markdown serialization has been performed\n if (isPlainTextDocument(schema)) {\n markdownResult = markdownResult.replace(/\\u00a0/g, ' ')\n }\n\n // Return the serialized Markdown parsed with Turndown, and with trailing space\n // characters removed\n return markdownResult.replace(/ +$/gm, '')\n },\n }\n}\n\n/**\n * Object that holds multiple Markdown serializer instances based on a given ID.\n */\nconst markdownSerializerInstanceById: MarkdownSerializerInstanceById = {}\n\n/**\n * Returns a singleton instance of a Markdown serializer based on the provided editor schema.\n *\n * @param schema The editor schema connected to the Markdown serializer instance.\n *\n * @returns The Markdown serializer instance for the given editor schema.\n */\nfunction getMarkdownSerializerInstance(schema: Schema) {\n const id = computeSchemaId(schema)\n\n if (!markdownSerializerInstanceById[id]) {\n markdownSerializerInstanceById[id] = createMarkdownSerializer(schema)\n }\n\n return markdownSerializerInstanceById[id]\n}\n\nexport { BULLET_LIST_MARKER, createMarkdownSerializer, getMarkdownSerializerInstance }\n\nexport type { MarkdownSerializerReturnType }\n"],"mappings":";;;;;;;;;;;;;;AA6CA,MAAM,2BAA6C;CAC/C,cAAc;CACd,IAAI;CACJ,kBAAA;CACA,gBAAgB;CAChB,OAAO;CACP,aAAa;CACb,iBAAiB;CACjB,WAAW;CAMX,iBAAiB,GAAG,MAAM;EACtB,MAAM,aAAa,KAAK;AAGxB,MAAI,KAAK,aAAa,QAAS,YAAY,aAAa,QAAQ,KAAK,aAAa,KAC9E,QAAO;AAIX,MAAI,KAAK,aAAa,QAAS,YAAY,aAAa,QAAQ,KAAK,aAAa,MAAO;GACrF,MAAM,QACF,KAAK,aAAa,OACZ,WAAW,aAAa,QAAQ,GAChC,KAAK,aAAa,QAAQ;GACpC,MAAM,QAAQ,MAAM,UAAU,QAAQ,KAAK,WAAW,UAAU,KAAK;AAErE,UAAO,GAAG,QAAQ,OAAO,MAAM,GAAG,QAAQ,QAAQ,EAAE;;AAKxD,SAAO,KAAK,UAAU,SAAS;;CAEtC;;;;;;;;;;;;;;AAeD,SAAS,yBAAyB,QAA8C;CAE5E,MAAM,WAAW,IAAI,SAAS,yBAAyB;AAMvD,KAAI,oBAAoB,OAAO,CAC3B,UAAS,UAAU,QAAQ;KAO3B,UAAS,UAAU,QAAQ;AACvB,SACI,IAKK,QAAQ,IAAI,OAAO,QAAQ,kBAAkB,OAAO,IAAI,IAAI,EAAE,OAAO,CAOrE,QAAQ,oBAAoB,UAAU;;AAOvD,UAAS,IAAI,UAAU,OAAO,MAAM,WAAW,oBAAoB,OAAO,CAAC,CAAC;AAG5E,KAAI,OAAO,MAAM,MACb,UAAS,IAAI,MAAM,OAAO,MAAM,MAAM,CAAC;AAI3C,MAAK,OAAO,MAAM,cAAc,OAAO,MAAM,gBAAgB,OAAO,MAAM,SACtE,UAAS,IAAI,SAAS,OAAO,MAAM,SAAS,CAAC;AAIjD,KAAI,OAAO,MAAM,OACb,UAAS,IAAI,cAAc,OAAO,MAAM,OAAO,CAAC;AAIpD,KAAI,OAAO,MAAM,YAAY,OAAO,MAAM,SACtC,UAAS,IAAI,SAAS,OAAO,MAAM,SAAS,CAAC;AAIjD,QAAO,OAAO,OAAO,MAAM,CACtB,QAAQ,SAAS,KAAK,KAAK,SAAS,aAAa,CAAC,CAClD,SAAS,mBAAmB;AACzB,WAAS,IAAI,WAAW,eAAe,CAAC;GAC1C;AAGN,QAAO,EACH,UAAU,MAAc;EACpB,IAAI,iBAAiB;AASrB,MAAI,oBAAoB,OAAO,CAC3B,kBAAiB,eAAe,QAAQ,WAAW,MAAM,EAAE,QAAQ,MAAM,OAAS,CAAC;AAIvF,mBAAiB,SAAS,SAAS,eAAe;AAIlD,MAAI,oBAAoB,OAAO,CAC3B,kBAAiB,eAAe,QAAQ,WAAW,IAAI;AAK3D,SAAO,eAAe,QAAQ,SAAS,GAAG;IAEjD;;;;;AAML,MAAM,iCAAiE,EAAE;;;;;;;;AASzE,SAAS,8BAA8B,QAAgB;CACnD,MAAM,KAAK,gBAAgB,OAAO;AAElC,KAAI,CAAC,+BAA+B,IAChC,gCAA+B,MAAM,yBAAyB,OAAO;AAGzE,QAAO,+BAA+B"}
@@ -1,31 +1,34 @@
1
+ //#region src/serializers/markdown/plugins/image.ts
1
2
  /**
2
- * Cleans an attribute value by replacing multiple newlines with a single one.
3
- *
4
- * @param attribute The attribute value to clean.
5
- */
3
+ * Cleans an attribute value by replacing multiple newlines with a single one.
4
+ *
5
+ * @param attribute The attribute value to clean.
6
+ */
6
7
  function cleanAttribute(attribute) {
7
- return attribute ? attribute.replace(/(\n+\s*)+/g, '\n') : '';
8
+ return attribute ? attribute.replace(/(\n+\s*)+/g, "\n") : "";
8
9
  }
9
10
  /**
10
- * A Turndown plugin which adds a custom rule for images. This custom rule is required to disable
11
- * support for Data URLs (URLs prefixed with the `data: scheme`), while displaying an explicit
12
- * message in the Markdown output (for debugging and testing).
13
- *
14
- * @param nodeType The node object that matches this rule.
15
- */
11
+ * A Turndown plugin which adds a custom rule for images. This custom rule is required to disable
12
+ * support for Data URLs (URLs prefixed with the `data: scheme`), while displaying an explicit
13
+ * message in the Markdown output (for debugging and testing).
14
+ *
15
+ * @param nodeType The node object that matches this rule.
16
+ */
16
17
  function image(nodeType) {
17
- return (turndown) => {
18
- turndown.addRule(nodeType.name, {
19
- filter: 'img',
20
- replacement(_, node) {
21
- const src = String(node.getAttribute('src'));
22
- // Preserve Data URL image prefix with message about base64 being unsupported
23
- const link = src.startsWith('data:') ? `${src.split(',')[0]},NOT_SUPPORTED` : src;
24
- const alt = cleanAttribute(node.getAttribute('alt'));
25
- const title = cleanAttribute(node.getAttribute('title'));
26
- return src ? `![${alt}](${link}${title.length > 0 ? ` "${title}"` : ''})` : '';
27
- },
28
- });
29
- };
18
+ return (turndown) => {
19
+ turndown.addRule(nodeType.name, {
20
+ filter: "img",
21
+ replacement(_, node) {
22
+ const src = String(node.getAttribute("src"));
23
+ const link = src.startsWith("data:") ? `${src.split(",")[0]},NOT_SUPPORTED` : src;
24
+ const alt = cleanAttribute(node.getAttribute("alt"));
25
+ const title = cleanAttribute(node.getAttribute("title"));
26
+ return src ? `![${alt}](${link}${title.length > 0 ? ` "${title}"` : ""})` : "";
27
+ }
28
+ });
29
+ };
30
30
  }
31
+ //#endregion
31
32
  export { image };
33
+
34
+ //# sourceMappingURL=image.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"image.js","names":[],"sources":["../../../../src/serializers/markdown/plugins/image.ts"],"sourcesContent":["import type { NodeType } from '@tiptap/pm/model'\nimport type Turndown from 'turndown'\n\n/**\n * Cleans an attribute value by replacing multiple newlines with a single one.\n *\n * @param attribute The attribute value to clean.\n */\nfunction cleanAttribute(attribute: string | null): string {\n return attribute ? attribute.replace(/(\\n+\\s*)+/g, '\\n') : ''\n}\n\n/**\n * A Turndown plugin which adds a custom rule for images. This custom rule is required to disable\n * support for Data URLs (URLs prefixed with the `data: scheme`), while displaying an explicit\n * message in the Markdown output (for debugging and testing).\n *\n * @param nodeType The node object that matches this rule.\n */\nfunction image(nodeType: NodeType): Turndown.Plugin {\n return (turndown: Turndown) => {\n turndown.addRule(nodeType.name, {\n filter: 'img',\n replacement(_, node) {\n const src = String((node as Element).getAttribute('src'))\n\n // Preserve Data URL image prefix with message about base64 being unsupported\n const link = src.startsWith('data:') ? `${src.split(',')[0]},NOT_SUPPORTED` : src\n\n const alt = cleanAttribute((node as Element).getAttribute('alt'))\n const title = cleanAttribute((node as Element).getAttribute('title'))\n\n return src ? `![${alt}](${link}${title.length > 0 ? ` \"${title}\"` : ''})` : ''\n },\n })\n }\n}\n\nexport { image }\n"],"mappings":";;;;;;AAQA,SAAS,eAAe,WAAkC;AACtD,QAAO,YAAY,UAAU,QAAQ,cAAc,KAAK,GAAG;;;;;;;;;AAU/D,SAAS,MAAM,UAAqC;AAChD,SAAQ,aAAuB;AAC3B,WAAS,QAAQ,SAAS,MAAM;GAC5B,QAAQ;GACR,YAAY,GAAG,MAAM;IACjB,MAAM,MAAM,OAAQ,KAAiB,aAAa,MAAM,CAAC;IAGzD,MAAM,OAAO,IAAI,WAAW,QAAQ,GAAG,GAAG,IAAI,MAAM,IAAI,CAAC,GAAG,kBAAkB;IAE9E,MAAM,MAAM,eAAgB,KAAiB,aAAa,MAAM,CAAC;IACjE,MAAM,QAAQ,eAAgB,KAAiB,aAAa,QAAQ,CAAC;AAErE,WAAO,MAAM,KAAK,IAAI,IAAI,OAAO,MAAM,SAAS,IAAI,KAAK,MAAM,KAAK,GAAG,KAAK;;GAEnF,CAAC"}
@@ -1,41 +1,36 @@
1
- import { extractTagsFromParseRules } from '../../../helpers/serializer';
2
- import { BULLET_LIST_MARKER } from '../markdown';
1
+ import { extractTagsFromParseRules } from "../../../helpers/serializer.js";
2
+ //#region src/serializers/markdown/plugins/list-item.ts
3
3
  /**
4
- * A Turndown plugin which adds a custom rule for standard list items (i.e., not task list items),
5
- * based on the original list item rule. This custom rule is required to avoid conflicts with task
6
- * list items, and to normalize the Markdown output.
7
- *
8
- * @see https://github.com/mixmark-io/turndown/blob/v7.1.1/src/commonmark-rules.js#L61
9
- *
10
- * @param nodeType The node object that matches this rule.
11
- */
4
+ * A Turndown plugin which adds a custom rule for standard list items (i.e., not task list items),
5
+ * based on the original list item rule. This custom rule is required to avoid conflicts with task
6
+ * list items, and to normalize the Markdown output.
7
+ *
8
+ * @see https://github.com/mixmark-io/turndown/blob/v7.1.1/src/commonmark-rules.js#L61
9
+ *
10
+ * @param nodeType The node object that matches this rule.
11
+ */
12
12
  function listItem(nodeType) {
13
- const tags = extractTagsFromParseRules(nodeType.spec.parseDOM);
14
- return (turndown) => {
15
- turndown.addRule(nodeType.name, {
16
- filter(node) {
17
- return (tags.some((tag) => tag.toUpperCase() === node.nodeName) &&
18
- node.getAttribute('data-type') !== 'taskItem');
19
- },
20
- replacement(content, node) {
21
- const parentNode = node.parentNode;
22
- let listItemMarker = `${BULLET_LIST_MARKER} `;
23
- // Use a sequence of 1–9 digits for the ordered list marker (CommonMark specification)
24
- if (parentNode?.nodeName === 'OL') {
25
- const start = parentNode.getAttribute('start');
26
- const index = Array.prototype.indexOf.call(parentNode.children, node);
27
- listItemMarker = `${start ? Number(start) + index : index + 1}. `;
28
- }
29
- const newContent = content
30
- // Remove leading newlines
31
- .replace(/^\n+/, '')
32
- // Replace trailing newlines with a single one
33
- .replace(/\n+$/, '\n')
34
- // Indent list items with 4 spaces
35
- .replace(/\n/gm, '\n ');
36
- return `${listItemMarker}${newContent.trim()}${node.nextSibling && !newContent.endsWith('\n') ? '\n' : ''}`;
37
- },
38
- });
39
- };
13
+ const tags = extractTagsFromParseRules(nodeType.spec.parseDOM);
14
+ return (turndown) => {
15
+ turndown.addRule(nodeType.name, {
16
+ filter(node) {
17
+ return tags.some((tag) => tag.toUpperCase() === node.nodeName) && node.getAttribute("data-type") !== "taskItem";
18
+ },
19
+ replacement(content, node) {
20
+ const parentNode = node.parentNode;
21
+ let listItemMarker = `- `;
22
+ if (parentNode?.nodeName === "OL") {
23
+ const start = parentNode.getAttribute("start");
24
+ const index = Array.prototype.indexOf.call(parentNode.children, node);
25
+ listItemMarker = `${start ? Number(start) + index : index + 1}. `;
26
+ }
27
+ const newContent = content.replace(/^\n+/, "").replace(/\n+$/, "\n").replace(/\n/gm, "\n ");
28
+ return `${listItemMarker}${newContent.trim()}${node.nextSibling && !newContent.endsWith("\n") ? "\n" : ""}`;
29
+ }
30
+ });
31
+ };
40
32
  }
33
+ //#endregion
41
34
  export { listItem };
35
+
36
+ //# sourceMappingURL=list-item.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"list-item.js","names":[],"sources":["../../../../src/serializers/markdown/plugins/list-item.ts"],"sourcesContent":["import { extractTagsFromParseRules } from '../../../helpers/serializer'\nimport { BULLET_LIST_MARKER } from '../markdown'\n\nimport type { NodeType } from '@tiptap/pm/model'\nimport type Turndown from 'turndown'\n\n/**\n * A Turndown plugin which adds a custom rule for standard list items (i.e., not task list items),\n * based on the original list item rule. This custom rule is required to avoid conflicts with task\n * list items, and to normalize the Markdown output.\n *\n * @see https://github.com/mixmark-io/turndown/blob/v7.1.1/src/commonmark-rules.js#L61\n *\n * @param nodeType The node object that matches this rule.\n */\nfunction listItem(nodeType: NodeType): Turndown.Plugin {\n const tags = extractTagsFromParseRules(nodeType.spec.parseDOM)\n\n return (turndown: Turndown) => {\n turndown.addRule(nodeType.name, {\n filter(node) {\n return (\n tags.some((tag) => tag.toUpperCase() === node.nodeName) &&\n node.getAttribute('data-type') !== 'taskItem'\n )\n },\n replacement(content, node) {\n const parentNode = node.parentNode as HTMLElement\n let listItemMarker = `${BULLET_LIST_MARKER} `\n\n // Use a sequence of 1–9 digits for the ordered list marker (CommonMark specification)\n if (parentNode?.nodeName === 'OL') {\n const start = parentNode.getAttribute('start')\n const index = Array.prototype.indexOf.call(parentNode.children, node)\n\n listItemMarker = `${start ? Number(start) + index : index + 1}. `\n }\n\n const newContent = content\n // Remove leading newlines\n .replace(/^\\n+/, '')\n // Replace trailing newlines with a single one\n .replace(/\\n+$/, '\\n')\n // Indent list items with 4 spaces\n .replace(/\\n/gm, '\\n ')\n\n return `${listItemMarker}${newContent.trim()}${\n node.nextSibling && !newContent.endsWith('\\n') ? '\\n' : ''\n }`\n },\n })\n }\n}\n\nexport { listItem }\n"],"mappings":";;;;;;;;;;;AAeA,SAAS,SAAS,UAAqC;CACnD,MAAM,OAAO,0BAA0B,SAAS,KAAK,SAAS;AAE9D,SAAQ,aAAuB;AAC3B,WAAS,QAAQ,SAAS,MAAM;GAC5B,OAAO,MAAM;AACT,WACI,KAAK,MAAM,QAAQ,IAAI,aAAa,KAAK,KAAK,SAAS,IACvD,KAAK,aAAa,YAAY,KAAK;;GAG3C,YAAY,SAAS,MAAM;IACvB,MAAM,aAAa,KAAK;IACxB,IAAI,iBAAiB;AAGrB,QAAI,YAAY,aAAa,MAAM;KAC/B,MAAM,QAAQ,WAAW,aAAa,QAAQ;KAC9C,MAAM,QAAQ,MAAM,UAAU,QAAQ,KAAK,WAAW,UAAU,KAAK;AAErE,sBAAiB,GAAG,QAAQ,OAAO,MAAM,GAAG,QAAQ,QAAQ,EAAE;;IAGlE,MAAM,aAAa,QAEd,QAAQ,QAAQ,GAAG,CAEnB,QAAQ,QAAQ,KAAK,CAErB,QAAQ,QAAQ,SAAS;AAE9B,WAAO,GAAG,iBAAiB,WAAW,MAAM,GACxC,KAAK,eAAe,CAAC,WAAW,SAAS,KAAK,GAAG,OAAO;;GAGnE,CAAC"}
@@ -1,23 +1,23 @@
1
+ //#region src/serializers/markdown/plugins/paragraph.ts
1
2
  /**
2
- * A Turndown plugin which adds a custom rule for paragraphs. This custom rule is required to avoid
3
- * adding unnecessary blank lines between paragraphs to plain-text documents, and to list items in
4
- * rich-text documents.
5
- *
6
- * @param nodeType The node object that matches this rule.
7
- * @param isPlainText Specifies if the schema represents a plain-text document.
8
- */
3
+ * A Turndown plugin which adds a custom rule for paragraphs. This custom rule is required to avoid
4
+ * adding unnecessary blank lines between paragraphs to plain-text documents, and to list items in
5
+ * rich-text documents.
6
+ *
7
+ * @param nodeType The node object that matches this rule.
8
+ * @param isPlainText Specifies if the schema represents a plain-text document.
9
+ */
9
10
  function paragraph(nodeType, isPlainText) {
10
- return (turndown) => {
11
- turndown.addRule(nodeType.name, {
12
- filter: 'p',
13
- replacement(content, node) {
14
- const useSingleLineSpacing = isPlainText ||
15
- // Paragraphs within list items should be wrapped with a single line feed to
16
- // maintain proper list formatting in rich-text documents.
17
- (!isPlainText && node.parentNode?.nodeName === 'LI');
18
- return useSingleLineSpacing ? `\n${content}\n` : `\n\n${content}\n\n`;
19
- },
20
- });
21
- };
11
+ return (turndown) => {
12
+ turndown.addRule(nodeType.name, {
13
+ filter: "p",
14
+ replacement(content, node) {
15
+ return isPlainText || !isPlainText && node.parentNode?.nodeName === "LI" ? `\n${content}\n` : `\n\n${content}\n\n`;
16
+ }
17
+ });
18
+ };
22
19
  }
20
+ //#endregion
23
21
  export { paragraph };
22
+
23
+ //# sourceMappingURL=paragraph.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"paragraph.js","names":[],"sources":["../../../../src/serializers/markdown/plugins/paragraph.ts"],"sourcesContent":["import type { NodeType } from '@tiptap/pm/model'\nimport type Turndown from 'turndown'\n\n/**\n * A Turndown plugin which adds a custom rule for paragraphs. This custom rule is required to avoid\n * adding unnecessary blank lines between paragraphs to plain-text documents, and to list items in\n * rich-text documents.\n *\n * @param nodeType The node object that matches this rule.\n * @param isPlainText Specifies if the schema represents a plain-text document.\n */\nfunction paragraph(nodeType: NodeType, isPlainText: boolean): Turndown.Plugin {\n return (turndown: Turndown) => {\n turndown.addRule(nodeType.name, {\n filter: 'p',\n replacement(content, node) {\n const useSingleLineSpacing =\n isPlainText ||\n // Paragraphs within list items should be wrapped with a single line feed to\n // maintain proper list formatting in rich-text documents.\n (!isPlainText && node.parentNode?.nodeName === 'LI')\n\n return useSingleLineSpacing ? `\\n${content}\\n` : `\\n\\n${content}\\n\\n`\n },\n })\n }\n}\n\nexport { paragraph }\n"],"mappings":";;;;;;;;;AAWA,SAAS,UAAU,UAAoB,aAAuC;AAC1E,SAAQ,aAAuB;AAC3B,WAAS,QAAQ,SAAS,MAAM;GAC5B,QAAQ;GACR,YAAY,SAAS,MAAM;AAOvB,WALI,eAGC,CAAC,eAAe,KAAK,YAAY,aAAa,OAErB,KAAK,QAAQ,MAAM,OAAO,QAAQ;;GAEvE,CAAC"}
@@ -1,23 +1,27 @@
1
- import { extractTagsFromParseRules } from '../../../helpers/serializer';
1
+ import { extractTagsFromParseRules } from "../../../helpers/serializer.js";
2
+ //#region src/serializers/markdown/plugins/strikethrough.ts
2
3
  /**
3
- * A Turndown plugin which adds a rule for strikethrough text, based on the original plugin. This
4
- * rules forces two tildes instead of one.
5
- *
6
- * @see https://github.com/mixmark-io/turndown-plugin-gfm/blob/v1.0.1/src/strikethrough.js
7
- *
8
- * @param markType The mark object that matches this rule.
9
- */
4
+ * A Turndown plugin which adds a rule for strikethrough text, based on the original plugin. This
5
+ * rules forces two tildes instead of one.
6
+ *
7
+ * @see https://github.com/mixmark-io/turndown-plugin-gfm/blob/v1.0.1/src/strikethrough.js
8
+ *
9
+ * @param markType The mark object that matches this rule.
10
+ */
10
11
  function strikethrough(markType) {
11
- const tags = extractTagsFromParseRules(markType.spec.parseDOM);
12
- return (turndown) => {
13
- turndown.addRule(markType.name, {
14
- filter(node) {
15
- return tags.some((tag) => tag.toUpperCase() === node.nodeName);
16
- },
17
- replacement(content) {
18
- return `~~${content}~~`;
19
- },
20
- });
21
- };
12
+ const tags = extractTagsFromParseRules(markType.spec.parseDOM);
13
+ return (turndown) => {
14
+ turndown.addRule(markType.name, {
15
+ filter(node) {
16
+ return tags.some((tag) => tag.toUpperCase() === node.nodeName);
17
+ },
18
+ replacement(content) {
19
+ return `~~${content}~~`;
20
+ }
21
+ });
22
+ };
22
23
  }
24
+ //#endregion
23
25
  export { strikethrough };
26
+
27
+ //# sourceMappingURL=strikethrough.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strikethrough.js","names":[],"sources":["../../../../src/serializers/markdown/plugins/strikethrough.ts"],"sourcesContent":["import { extractTagsFromParseRules } from '../../../helpers/serializer'\n\nimport type { MarkType } from '@tiptap/pm/model'\nimport type Turndown from 'turndown'\n\n/**\n * A Turndown plugin which adds a rule for strikethrough text, based on the original plugin. This\n * rules forces two tildes instead of one.\n *\n * @see https://github.com/mixmark-io/turndown-plugin-gfm/blob/v1.0.1/src/strikethrough.js\n *\n * @param markType The mark object that matches this rule.\n */\nfunction strikethrough(markType: MarkType): Turndown.Plugin {\n const tags = extractTagsFromParseRules(markType.spec.parseDOM)\n\n return (turndown: Turndown) => {\n turndown.addRule(markType.name, {\n filter(node) {\n return tags.some((tag) => tag.toUpperCase() === node.nodeName)\n },\n replacement(content) {\n return `~~${content}~~`\n },\n })\n }\n}\n\nexport { strikethrough }\n"],"mappings":";;;;;;;;;;AAaA,SAAS,cAAc,UAAqC;CACxD,MAAM,OAAO,0BAA0B,SAAS,KAAK,SAAS;AAE9D,SAAQ,aAAuB;AAC3B,WAAS,QAAQ,SAAS,MAAM;GAC5B,OAAO,MAAM;AACT,WAAO,KAAK,MAAM,QAAQ,IAAI,aAAa,KAAK,KAAK,SAAS;;GAElE,YAAY,SAAS;AACjB,WAAO,KAAK,QAAQ;;GAE3B,CAAC"}
@@ -1,23 +1,25 @@
1
- import { kebabCase } from 'lodash-es';
1
+ import { kebabCase } from "lodash-es";
2
+ //#region src/serializers/markdown/plugins/suggestion.ts
2
3
  /**
3
- * A Turndown plugin which adds a custom rule for suggestion nodes created by the suggestion
4
- * extension factory function.
5
- *
6
- * @param nodeType The node object that matches this rule.
7
- */
4
+ * A Turndown plugin which adds a custom rule for suggestion nodes created by the suggestion
5
+ * extension factory function.
6
+ *
7
+ * @param nodeType The node object that matches this rule.
8
+ */
8
9
  function suggestion(nodeType) {
9
- const attributeType = kebabCase(nodeType.name.replace(/Suggestion$/, ''));
10
- return (turndown) => {
11
- turndown.addRule(nodeType.name, {
12
- filter(node) {
13
- return node.hasAttribute(`data-${attributeType}`);
14
- },
15
- replacement(_, node) {
16
- const label = String(node.getAttribute('data-label'));
17
- const id = String(node.getAttribute('data-id'));
18
- return `[${label}](${attributeType}://${id})`;
19
- },
20
- });
21
- };
10
+ const attributeType = kebabCase(nodeType.name.replace(/Suggestion$/, ""));
11
+ return (turndown) => {
12
+ turndown.addRule(nodeType.name, {
13
+ filter(node) {
14
+ return node.hasAttribute(`data-${attributeType}`);
15
+ },
16
+ replacement(_, node) {
17
+ return `[${String(node.getAttribute("data-label"))}](${attributeType}://${String(node.getAttribute("data-id"))})`;
18
+ }
19
+ });
20
+ };
22
21
  }
22
+ //#endregion
23
23
  export { suggestion };
24
+
25
+ //# sourceMappingURL=suggestion.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"suggestion.js","names":[],"sources":["../../../../src/serializers/markdown/plugins/suggestion.ts"],"sourcesContent":["import { kebabCase } from 'lodash-es'\n\nimport type { NodeType } from '@tiptap/pm/model'\nimport type Turndown from 'turndown'\n\n/**\n * A Turndown plugin which adds a custom rule for suggestion nodes created by the suggestion\n * extension factory function.\n *\n * @param nodeType The node object that matches this rule.\n */\nfunction suggestion(nodeType: NodeType): Turndown.Plugin {\n const attributeType = kebabCase(nodeType.name.replace(/Suggestion$/, ''))\n\n return (turndown: Turndown) => {\n turndown.addRule(nodeType.name, {\n filter(node: Element) {\n return node.hasAttribute(`data-${attributeType}`)\n },\n replacement(_, node) {\n const label = String((node as Element).getAttribute('data-label'))\n const id = String((node as Element).getAttribute('data-id'))\n\n return `[${label}](${attributeType}://${id})`\n },\n })\n }\n}\n\nexport { suggestion }\n"],"mappings":";;;;;;;;AAWA,SAAS,WAAW,UAAqC;CACrD,MAAM,gBAAgB,UAAU,SAAS,KAAK,QAAQ,eAAe,GAAG,CAAC;AAEzE,SAAQ,aAAuB;AAC3B,WAAS,QAAQ,SAAS,MAAM;GAC5B,OAAO,MAAe;AAClB,WAAO,KAAK,aAAa,QAAQ,gBAAgB;;GAErD,YAAY,GAAG,MAAM;AAIjB,WAAO,IAHO,OAAQ,KAAiB,aAAa,aAAa,CAAC,CAGjD,IAAI,cAAc,KAFxB,OAAQ,KAAiB,aAAa,UAAU,CAAC,CAEjB;;GAElD,CAAC"}