@sveltia/ui 0.91.0 → 0.92.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (226) hide show
  1. package/dist/components/bottom-navigation/bottom-navigation.svelte +3 -9
  2. package/dist/components/bottom-navigation/bottom-navigation.svelte.d.ts +4 -39
  3. package/dist/components/button/button-group.svelte +2 -4
  4. package/dist/components/button/button-group.svelte.d.ts +3 -19
  5. package/dist/components/button/select-button-group.svelte +2 -13
  6. package/dist/components/button/select-button-group.svelte.d.ts +5 -67
  7. package/dist/components/calendar/calendar.d.ts +9 -0
  8. package/dist/components/calendar/calendar.js +43 -0
  9. package/dist/components/calendar/calendar.svelte +26 -27
  10. package/dist/components/checkbox/checkbox-group.svelte +2 -8
  11. package/dist/components/checkbox/checkbox-group.svelte.d.ts +4 -39
  12. package/dist/components/dialog/alert-dialog.svelte.d.ts +2 -3
  13. package/dist/components/dialog/confirmation-dialog.svelte.d.ts +2 -3
  14. package/dist/components/dialog/dialog.svelte +6 -7
  15. package/dist/components/dialog/dialog.svelte.d.ts +2 -3
  16. package/dist/components/dialog/prompt-dialog.svelte +2 -2
  17. package/dist/components/dialog/prompt-dialog.svelte.d.ts +2 -3
  18. package/dist/components/disclosure/disclosure.svelte +14 -16
  19. package/dist/components/disclosure/disclosure.svelte.d.ts +4 -38
  20. package/dist/components/drawer/drawer.svelte +22 -39
  21. package/dist/components/drawer/drawer.svelte.d.ts +3 -24
  22. package/dist/components/grid/grid-body.svelte +2 -3
  23. package/dist/components/grid/grid-body.svelte.d.ts +3 -18
  24. package/dist/components/grid/grid-cell.svelte +2 -8
  25. package/dist/components/grid/grid-cell.svelte.d.ts +3 -22
  26. package/dist/components/grid/grid-col-header.svelte +2 -4
  27. package/dist/components/grid/grid-col-header.svelte.d.ts +3 -19
  28. package/dist/components/grid/grid-foot.svelte +4 -9
  29. package/dist/components/grid/grid-foot.svelte.d.ts +3 -22
  30. package/dist/components/grid/grid-head.svelte +4 -9
  31. package/dist/components/grid/grid-head.svelte.d.ts +3 -22
  32. package/dist/components/grid/grid-row-header.svelte +2 -8
  33. package/dist/components/grid/grid-row-header.svelte.d.ts +3 -22
  34. package/dist/components/grid/grid-row.svelte +4 -5
  35. package/dist/components/grid/grid-row.svelte.d.ts +3 -19
  36. package/dist/components/grid/grid.d.ts +10 -0
  37. package/dist/components/grid/grid.js +11 -0
  38. package/dist/components/grid/grid.svelte +6 -7
  39. package/dist/components/grid/grid.svelte.d.ts +5 -21
  40. package/dist/components/listbox/listbox.svelte +34 -15
  41. package/dist/components/listbox/listbox.svelte.d.ts +5 -69
  42. package/dist/components/listbox/option-group.svelte +2 -8
  43. package/dist/components/listbox/option-group.svelte.d.ts +4 -39
  44. package/dist/components/listbox/option.svelte +2 -1
  45. package/dist/components/menu/menu-item-group.svelte +2 -6
  46. package/dist/components/menu/menu-item-group.svelte.d.ts +3 -22
  47. package/dist/components/menu/menu-item.svelte +5 -1
  48. package/dist/components/menu/menu.svelte +2 -8
  49. package/dist/components/menu/menu.svelte.d.ts +4 -39
  50. package/dist/components/radio/radio-group.svelte +2 -17
  51. package/dist/components/radio/radio-group.svelte.d.ts +5 -67
  52. package/dist/components/radio/radio.svelte +19 -22
  53. package/dist/components/radio/radio.svelte.d.ts +10 -40
  54. package/dist/components/resizable-pane/resizable-handle.svelte +42 -49
  55. package/dist/components/resizable-pane/resizable-pane-group.svelte +44 -58
  56. package/dist/components/resizable-pane/resizable-pane-group.svelte.d.ts +3 -19
  57. package/dist/components/resizable-pane/resizable-pane.svelte +2 -5
  58. package/dist/components/resizable-pane/resizable-pane.svelte.d.ts +3 -19
  59. package/dist/components/resizable-pane/sizing.d.ts +24 -0
  60. package/dist/components/resizable-pane/sizing.js +83 -0
  61. package/dist/components/select/combobox.svelte +35 -39
  62. package/dist/components/select/select-tags.svelte +3 -13
  63. package/dist/components/select/select-tags.svelte.d.ts +5 -67
  64. package/dist/components/slider/slider.d.ts +5 -4
  65. package/dist/components/slider/slider.js +28 -23
  66. package/dist/components/slider/slider.svelte +64 -62
  67. package/dist/components/slider/slider.svelte.d.ts +4 -37
  68. package/dist/components/switch/switch.svelte +2 -13
  69. package/dist/components/switch/switch.svelte.d.ts +5 -67
  70. package/dist/components/table/table-body.svelte +2 -4
  71. package/dist/components/table/table-body.svelte.d.ts +3 -19
  72. package/dist/components/table/table-cell.svelte +2 -8
  73. package/dist/components/table/table-cell.svelte.d.ts +3 -22
  74. package/dist/components/table/table-col-header.svelte +2 -8
  75. package/dist/components/table/table-col-header.svelte.d.ts +3 -22
  76. package/dist/components/table/table-foot.svelte +2 -8
  77. package/dist/components/table/table-foot.svelte.d.ts +3 -22
  78. package/dist/components/table/table-head.svelte +2 -8
  79. package/dist/components/table/table-head.svelte.d.ts +3 -22
  80. package/dist/components/table/table-part.svelte +2 -4
  81. package/dist/components/table/table-part.svelte.d.ts +3 -19
  82. package/dist/components/table/table-row-header.svelte +2 -8
  83. package/dist/components/table/table-row-header.svelte.d.ts +3 -22
  84. package/dist/components/table/table-row.svelte +2 -8
  85. package/dist/components/table/table-row.svelte.d.ts +3 -22
  86. package/dist/components/table/table.svelte +2 -4
  87. package/dist/components/table/table.svelte.d.ts +3 -19
  88. package/dist/components/tabs/tab-box.svelte +2 -4
  89. package/dist/components/tabs/tab-box.svelte.d.ts +3 -19
  90. package/dist/components/tabs/tab-list.svelte +2 -7
  91. package/dist/components/tabs/tab-list.svelte.d.ts +4 -37
  92. package/dist/components/tabs/tab-panel.svelte +2 -8
  93. package/dist/components/tabs/tab-panel.svelte.d.ts +3 -22
  94. package/dist/components/tabs/tab-panels.svelte +2 -8
  95. package/dist/components/tabs/tab-panels.svelte.d.ts +3 -22
  96. package/dist/components/text-editor/code-editor.js +14 -7
  97. package/dist/components/text-editor/code-editor.svelte +14 -22
  98. package/dist/components/text-editor/code-editor.svelte.d.ts +5 -103
  99. package/dist/components/text-editor/config.d.ts +73 -0
  100. package/dist/components/text-editor/config.js +110 -0
  101. package/dist/components/text-editor/conversion/editor-components.js +4 -4
  102. package/dist/components/text-editor/conversion/html/export.js +1 -1
  103. package/dist/components/text-editor/conversion/import.js +32 -26
  104. package/dist/components/text-editor/conversion/markdown/block-conversion.d.ts +4 -0
  105. package/dist/components/text-editor/conversion/markdown/block-conversion.js +154 -0
  106. package/dist/components/text-editor/conversion/markdown/block-structure.d.ts +16 -0
  107. package/dist/components/text-editor/conversion/markdown/block-structure.js +254 -0
  108. package/dist/components/text-editor/conversion/markdown/code-blocks.d.ts +57 -0
  109. package/dist/components/text-editor/conversion/markdown/code-blocks.js +279 -0
  110. package/dist/components/text-editor/conversion/markdown/code-spans.d.ts +19 -0
  111. package/dist/components/text-editor/conversion/markdown/code-spans.js +71 -0
  112. package/dist/components/text-editor/conversion/markdown/formatting.d.ts +22 -0
  113. package/dist/components/text-editor/conversion/markdown/formatting.js +451 -0
  114. package/dist/components/text-editor/conversion/markdown/index.d.ts +10 -0
  115. package/dist/components/text-editor/conversion/markdown/index.js +55 -0
  116. package/dist/components/text-editor/conversion/markdown/placeholders.d.ts +2 -0
  117. package/dist/components/text-editor/conversion/markdown/placeholders.js +229 -0
  118. package/dist/components/text-editor/conversion/markdown/syntax.d.ts +99 -0
  119. package/dist/components/text-editor/conversion/markdown/syntax.js +206 -0
  120. package/dist/components/text-editor/conversion/placeholder-chars.d.ts +43 -0
  121. package/dist/components/text-editor/conversion/placeholder-chars.js +51 -0
  122. package/dist/components/text-editor/conversion/transformers/block-escape.d.ts +1 -0
  123. package/dist/components/text-editor/conversion/transformers/block-escape.js +53 -26
  124. package/dist/components/text-editor/conversion/transformers/code.d.ts +3 -14
  125. package/dist/components/text-editor/conversion/transformers/code.js +78 -16
  126. package/dist/components/text-editor/conversion/transformers/formatted-code.js +3 -18
  127. package/dist/components/text-editor/conversion/transformers/inline-code.js +3 -1
  128. package/dist/components/text-editor/conversion/transformers/link.js +3 -1
  129. package/dist/components/text-editor/conversion/transformers/raw-syntax.d.ts +0 -19
  130. package/dist/components/text-editor/conversion/transformers/raw-syntax.js +22 -93
  131. package/dist/components/text-editor/conversion/transformers/table.js +57 -16
  132. package/dist/components/text-editor/conversion/update.d.ts +19 -2
  133. package/dist/components/text-editor/conversion/update.js +63 -39
  134. package/dist/components/text-editor/core.d.ts +12 -51
  135. package/dist/components/text-editor/core.js +44 -66
  136. package/dist/components/text-editor/editing/raw-markdown.d.ts +3 -0
  137. package/dist/components/text-editor/editing/raw-markdown.js +46 -2
  138. package/dist/components/text-editor/lexical-root.svelte +49 -47
  139. package/dist/components/text-editor/lexical-root.svelte.d.ts +4 -67
  140. package/dist/components/text-editor/shiki/{facade.d.ts → engine.d.ts} +8 -8
  141. package/dist/components/text-editor/shiki/{facade.js → engine.js} +53 -156
  142. package/dist/components/text-editor/shiki/highlighter.js +5 -5
  143. package/dist/components/text-editor/shiki/lexical.d.ts +6 -0
  144. package/dist/components/text-editor/shiki/lexical.js +165 -0
  145. package/dist/components/text-editor/shiki/preload.js +1 -1
  146. package/dist/components/text-editor/shiki/source-highlight.svelte.d.ts +15 -0
  147. package/dist/components/text-editor/shiki/source-highlight.svelte.js +120 -0
  148. package/dist/components/text-editor/shiki/version.d.ts +1 -1
  149. package/dist/components/text-editor/shiki/version.js +1 -1
  150. package/dist/components/text-editor/store.svelte.js +65 -16
  151. package/dist/components/text-editor/text-editor.svelte +53 -145
  152. package/dist/components/text-editor/text-editor.svelte.d.ts +5 -103
  153. package/dist/components/text-editor/toolbar/actions.d.ts +25 -0
  154. package/dist/components/text-editor/toolbar/actions.js +107 -0
  155. package/dist/components/text-editor/toolbar/align-menu-button.svelte +16 -14
  156. package/dist/components/text-editor/toolbar/format-text-button.svelte +26 -24
  157. package/dist/components/text-editor/toolbar/insert-horizontal-rule-button.svelte +23 -23
  158. package/dist/components/text-editor/toolbar/insert-item-button.svelte +1 -1
  159. package/dist/components/text-editor/toolbar/insert-link-button.svelte +47 -51
  160. package/dist/components/text-editor/toolbar/insert-menu-button.svelte +1 -1
  161. package/dist/components/text-editor/toolbar/insert-table-button.svelte +35 -52
  162. package/dist/components/text-editor/toolbar/table-action-menu.svelte +19 -17
  163. package/dist/components/text-editor/toolbar/text-editor-toolbar.svelte +16 -4
  164. package/dist/components/text-editor/toolbar/text-editor-toolbar.svelte.d.ts +0 -8
  165. package/dist/components/text-editor/toolbar/toggle-block-menu-item.svelte +34 -33
  166. package/dist/components/text-editor/widgets/emoji-autocomplete.svelte +7 -6
  167. package/dist/components/text-editor/widgets/floating-link-editor.svelte +19 -32
  168. package/dist/components/text-editor/widgets/table-cell-menu-button.svelte +28 -32
  169. package/dist/components/text-field/date-time-input.svelte +7 -8
  170. package/dist/components/text-field/date-time-input.svelte.d.ts +3 -32
  171. package/dist/components/text-field/number-input.d.ts +0 -2
  172. package/dist/components/text-field/number-input.js +25 -25
  173. package/dist/components/text-field/number-input.svelte +18 -9
  174. package/dist/components/text-field/number-input.svelte.d.ts +1 -1
  175. package/dist/components/text-field/text-area.d.ts +2 -0
  176. package/dist/components/text-field/text-area.js +31 -0
  177. package/dist/components/text-field/text-area.svelte +12 -25
  178. package/dist/components/text-field/text-area.svelte.d.ts +5 -67
  179. package/dist/components/toast/toast.svelte +31 -8
  180. package/dist/components/toast/toast.svelte.d.ts +6 -6
  181. package/dist/components/toolbar/toolbar.svelte +2 -7
  182. package/dist/components/toolbar/toolbar.svelte.d.ts +4 -37
  183. package/dist/components/tree/tree-item.svelte +2 -6
  184. package/dist/components/tree/tree-item.svelte.d.ts +3 -22
  185. package/dist/components/tree/tree.svelte +3 -10
  186. package/dist/components/tree/tree.svelte.d.ts +4 -39
  187. package/dist/components/util/group.svelte +2 -7
  188. package/dist/components/util/group.svelte.d.ts +4 -37
  189. package/dist/components/util/modal.d.ts +9 -0
  190. package/dist/components/util/modal.js +30 -0
  191. package/dist/components/util/modal.svelte +33 -14
  192. package/dist/index.d.ts +1 -1
  193. package/dist/index.js +1 -1
  194. package/dist/locales/hu.yaml +176 -0
  195. package/dist/services/composite-widget.svelte.d.ts +76 -0
  196. package/dist/services/composite-widget.svelte.js +157 -0
  197. package/dist/services/focus.d.ts +2 -0
  198. package/dist/services/focus.js +68 -0
  199. package/dist/services/group.svelte.d.ts +17 -69
  200. package/dist/services/group.svelte.js +128 -391
  201. package/dist/services/label.d.ts +9 -0
  202. package/dist/services/label.js +22 -0
  203. package/dist/services/menu.d.ts +8 -0
  204. package/dist/services/menu.js +237 -0
  205. package/dist/services/navigation.d.ts +9 -0
  206. package/dist/services/navigation.js +13 -0
  207. package/dist/services/number.d.ts +2 -0
  208. package/dist/services/number.js +27 -0
  209. package/dist/services/pointer-drag.d.ts +14 -0
  210. package/dist/services/pointer-drag.js +89 -0
  211. package/dist/services/popup.svelte.js +123 -103
  212. package/dist/services/text.d.ts +3 -0
  213. package/dist/services/text.js +17 -0
  214. package/dist/services/tree.svelte.d.ts +29 -43
  215. package/dist/services/tree.svelte.js +58 -105
  216. package/dist/services/type-ahead.d.ts +10 -1
  217. package/dist/services/type-ahead.js +56 -34
  218. package/dist/typedefs.d.ts +103 -4
  219. package/dist/typedefs.js +60 -4
  220. package/package.json +2 -2
  221. package/dist/components/text-editor/conversion/markdown.d.ts +0 -56
  222. package/dist/components/text-editor/conversion/markdown.js +0 -949
  223. package/dist/components/text-editor/toolbar/code-editor-toolbar.svelte +0 -28
  224. package/dist/components/text-editor/toolbar/code-editor-toolbar.svelte.d.ts +0 -37
  225. package/dist/components/text-editor/toolbar/insert-component.d.ts +0 -3
  226. package/dist/components/text-editor/toolbar/insert-component.js +0 -37
@@ -0,0 +1,229 @@
1
+ /**
2
+ * Placeholders added to Markdown before it’s imported, so Lexical reads it as CommonMark does,
3
+ * and removed from the imported text.
4
+ */
5
+
6
+ import {
7
+ CODE_SPACE_PLACEHOLDER,
8
+ CODE_TAB_PLACEHOLDER,
9
+ ESCAPED_BACKSLASH_PLACEHOLDER,
10
+ HTML_BLOCK_PLACEHOLDER,
11
+ PUNCTUATION_PLACEHOLDER,
12
+ } from '../placeholder-chars.js';
13
+ import { findHtmlBlockLines } from './block-structure.js';
14
+ import { mapLinesOutsideCodeBlocks, mapOutsideCodeBlocks } from './code-blocks.js';
15
+ import { findCodeSpans, mapCodeSpans } from './code-spans.js';
16
+ import { countBackslashesBefore, INLINE_HTML_REGEX } from './syntax.js';
17
+
18
+ /**
19
+ * @import { CodeSpan } from './code-spans.js';
20
+ */
21
+
22
+ /**
23
+ * Global version of `INLINE_HTML_REGEX`.
24
+ */
25
+ const GLOBAL_INLINE_HTML_REGEX = new RegExp(INLINE_HTML_REGEX, 'g');
26
+
27
+ /**
28
+ * Add placeholders around the backslashes at the end of a line, so Lexical reads them as CommonMark
29
+ * does. Lexical looks for a hard line break, a backslash at the end of a line, after it has removed
30
+ * the escapes from the text, so an escaped backslash, like `foo\\`, `` `foo\` `` in a code span or
31
+ * `_foo\\_`, becomes a hard line break, losing the backslash, and `foo\\\` loses its hard line
32
+ * break. A placeholder after the escaped backslashes, or before the closing backticks of a code
33
+ * span, keeps the backslash from ending the text.
34
+ * @param {string} line Line.
35
+ * @returns {string} Processed line.
36
+ * @see https://spec.commonmark.org/0.31.2/#hard-line-breaks
37
+ */
38
+ const markLineEndBackslashes = (line) => {
39
+ if (!/[\\`][*_~]*$/.test(line)) {
40
+ return line;
41
+ }
42
+
43
+ const codeSpan = findCodeSpans(line).findLast(({ end }) => /^[*_~]*$/.test(line.slice(end)));
44
+
45
+ // Backslashes are literal in a code span
46
+ if (codeSpan) {
47
+ const index = codeSpan.end - codeSpan.fenceLength;
48
+
49
+ return line[index - 1] === '\\'
50
+ ? `${line.slice(0, index)}${ESCAPED_BACKSLASH_PLACEHOLDER}${line.slice(index)}`
51
+ : line;
52
+ }
53
+
54
+ // The escaped backslashes are followed by formatting markers, if any, and the backslash of a hard
55
+ // line break, if any. They’re counted from the end rather than matched with a regular expression,
56
+ // which would take quadratic time on a long run of backslashes or markers
57
+ const index = [true, false]
58
+ .map((hasHardLineBreak) => {
59
+ let end = line.length - (hasHardLineBreak && line.endsWith('\\') ? 1 : 0);
60
+
61
+ while (end > 0 && '*_~'.includes(line[end - 1])) {
62
+ end -= 1;
63
+ }
64
+
65
+ const backslashes = countBackslashesBefore(line, end);
66
+
67
+ return backslashes && backslashes % 2 === 0 ? end : -1;
68
+ })
69
+ .find((end) => end !== -1);
70
+
71
+ return index === undefined
72
+ ? line
73
+ : `${line.slice(0, index)}${ESCAPED_BACKSLASH_PLACEHOLDER}${line.slice(index)}`;
74
+ };
75
+
76
+ /**
77
+ * Regular expression to match the place between a formatting marker run that isn’t escaped and a
78
+ * backslash: after the run, like in `_foo_\`, or before it, after an escaped backslash, like in
79
+ * `\\_foo_`.
80
+ */
81
+ const MARKER_BACKSLASH_REGEX =
82
+ // Each lookahead comes first, so its lookbehind is only tried next to a marker or a backslash
83
+ /(?=\\)(?<=(?:^|[^\\])(?:\\\\)*[*_~])|(?=[*_~])(?<=(?:^|[^\\])(?:\\\\)+)/g;
84
+
85
+ /**
86
+ * Put a period, which Lexical takes as punctuation, between a backslash and a formatting marker.
87
+ * Unlike CommonMark, Lexical doesn’t take a backslash as punctuation, so it reads the marker as
88
+ * being within a word: it doesn’t read `_foo_\` or `**foo.**\` as formatted, as the marker can’t
89
+ * close the formatting there, nor `\\_foo_`, as it can’t open it. The period gives the marker the
90
+ * same neighbor as in CommonMark. A placeholder on the backslash side lets it be removed, and keeps
91
+ * it from being escaped by the backslash.
92
+ * @param {string} line Line.
93
+ * @returns {string} Processed line.
94
+ * @see https://spec.commonmark.org/0.31.2/#left-flanking-delimiter-run
95
+ */
96
+ const markMarkersNextToBackslashes = (line) =>
97
+ /[*_~]\\|\\[*_~]/.test(line)
98
+ ? line.replace(MARKER_BACKSLASH_REGEX, (_match, index) =>
99
+ // The period goes next to the marker
100
+ '*_~'.includes(line[index]) ? `${PUNCTUATION_PLACEHOLDER}.` : `.${PUNCTUATION_PLACEHOLDER}`,
101
+ )
102
+ : line;
103
+
104
+ /**
105
+ * Regular expression to match the place between a formatting marker and a punctuation character or
106
+ * a symbol other than ASCII, like an en dash or a curly quote.
107
+ */
108
+ const MARKER_UNICODE_PUNCTUATION_REGEX =
109
+ /(?<=[*_~])(?=(?![\0-\x7F])[\p{P}\p{S}])|(?<=(?![\0-\x7F])[\p{P}\p{S}])(?=[*_~])/gu;
110
+
111
+ /**
112
+ * Put a period, which Lexical takes as punctuation, between a formatting marker and a punctuation
113
+ * character or a symbol other than ASCII. Unlike CommonMark, Lexical only takes ASCII characters as
114
+ * punctuation, so it reads the marker as being next to a letter: it doesn’t read `**[a](u)**` in
115
+ * `–**[a](u)**` or `“**[a](u)**”` as bold, as the marker can’t open or close the formatting there.
116
+ * The period gives the marker the same neighbor as in CommonMark. A placeholder on the other side
117
+ * lets it be removed.
118
+ * @param {string} line Line.
119
+ * @returns {string} Processed line.
120
+ * @see https://spec.commonmark.org/0.31.2/#unicode-punctuation-character
121
+ * @see https://github.com/sveltia/sveltia-cms/issues/1107
122
+ */
123
+ const markMarkersNextToUnicodePunctuation = (line) =>
124
+ /[^\0-\x7F]/.test(line)
125
+ ? line.replace(MARKER_UNICODE_PUNCTUATION_REGEX, (_match, index) =>
126
+ // The period goes next to the marker
127
+ '*_~'.includes(line[index - 1])
128
+ ? `.${PUNCTUATION_PLACEHOLDER}`
129
+ : `${PUNCTUATION_PLACEHOLDER}.`,
130
+ )
131
+ : line;
132
+
133
+ /**
134
+ * Replace the tabs in the code spans of a line, and the spaces in a code span made only of spaces,
135
+ * with placeholders. Lexical turns a tab into a tab node, which has no format, so a tab in a code
136
+ * span would leave the code span, and a code span with only tabs would be exported as text. Also,
137
+ * Lexical takes a paragraph with up to 3 whitespace characters as empty, and removes it, even if
138
+ * they’re code, like `` ` ` ``. The spaces of other code spans are left alone, as one of them is
139
+ * stripped from both ends of the code span if the code isn’t all spaces.
140
+ * @param {string} line Line.
141
+ * @returns {string} Processed line.
142
+ * @see https://spec.commonmark.org/0.31.2/#code-spans
143
+ */
144
+ const markCodeSpanWhitespace = (line) => {
145
+ if (!/`[ \t]|\t/.test(line)) {
146
+ return line;
147
+ }
148
+
149
+ return mapCodeSpans(line, {
150
+ /**
151
+ * Replace the whitespace in the code of a code span.
152
+ * @param {string} codeSpan Code span, with its backticks.
153
+ * @param {CodeSpan} span Position of the code span.
154
+ * @returns {string} Processed code span.
155
+ */
156
+ inside: (codeSpan, { fenceLength }) => {
157
+ const fence = codeSpan.slice(0, fenceLength);
158
+ const content = codeSpan.slice(fenceLength, -fenceLength);
159
+
160
+ return `${fence}${
161
+ /^ +$/.test(content)
162
+ ? CODE_SPACE_PLACEHOLDER.repeat(content.length)
163
+ : content.replaceAll('\t', CODE_TAB_PLACEHOLDER)
164
+ }${fence}`;
165
+ },
166
+ });
167
+ };
168
+
169
+ /**
170
+ * Mark the lines of the HTML blocks in a part of a Markdown string with a placeholder at the start,
171
+ * so they’re imported as raw HTML, without the Markdown syntax being read; see `RAW_HTML`. Their
172
+ * tabs, and those in the inline HTML of the other lines, are replaced with a placeholder, as
173
+ * Lexical would otherwise split the raw HTML into separate nodes around a tab node.
174
+ * @param {string} part Part of a Markdown string outside fenced code blocks.
175
+ * @returns {string} Processed part.
176
+ * @see https://spec.commonmark.org/0.31.2/#html-blocks
177
+ * @see https://github.com/sveltia/sveltia-cms/issues/1106
178
+ */
179
+ const markHtml = (part) => {
180
+ const lines = part.split('\n');
181
+ const htmlBlockLines = findHtmlBlockLines(lines);
182
+
183
+ return lines
184
+ .map((line, index) => {
185
+ if (htmlBlockLines[index]) {
186
+ return `${HTML_BLOCK_PLACEHOLDER}${line.replaceAll('\t', CODE_TAB_PLACEHOLDER)}`;
187
+ }
188
+
189
+ return line.includes('\t')
190
+ ? line.replace(GLOBAL_INLINE_HTML_REGEX, (tag) =>
191
+ tag.replaceAll('\t', CODE_TAB_PLACEHOLDER),
192
+ )
193
+ : line;
194
+ })
195
+ .join('\n');
196
+ };
197
+
198
+ /**
199
+ * Add placeholders to a Markdown string, so Lexical reads it as CommonMark does; see
200
+ * `markLineEndBackslashes()`, `markMarkersNextToBackslashes()`,
201
+ * `markMarkersNextToUnicodePunctuation()` and `markCodeSpanWhitespace()`.
202
+ * Lines in fenced code blocks are left untouched. The placeholders are removed from the imported
203
+ * text with `removeImportPlaceholders()`.
204
+ * @param {string} value Markdown string to process.
205
+ * @returns {string} Processed Markdown string.
206
+ */
207
+ export const addImportPlaceholders = (value) =>
208
+ mapLinesOutsideCodeBlocks(
209
+ value.includes('<') ? mapOutsideCodeBlocks(value, markHtml) : value,
210
+ (line) =>
211
+ markCodeSpanWhitespace(
212
+ markMarkersNextToUnicodePunctuation(
213
+ markMarkersNextToBackslashes(markLineEndBackslashes(line)),
214
+ ),
215
+ ),
216
+ );
217
+
218
+ /**
219
+ * Remove the placeholders added by `addImportPlaceholders()` from imported text.
220
+ * @param {string} text Text.
221
+ * @returns {string} Text without the placeholders.
222
+ */
223
+ export const removeImportPlaceholders = (text) =>
224
+ text
225
+ .replace(new RegExp(`\\.${PUNCTUATION_PLACEHOLDER}|${PUNCTUATION_PLACEHOLDER}\\.`, 'g'), '')
226
+ .replaceAll(ESCAPED_BACKSLASH_PLACEHOLDER, '')
227
+ .replaceAll(HTML_BLOCK_PLACEHOLDER, '')
228
+ .replaceAll(CODE_TAB_PLACEHOLDER, '\t')
229
+ .replaceAll(CODE_SPACE_PLACEHOLDER, ' ');
@@ -0,0 +1,99 @@
1
+ /**
2
+ * Regular expression source to match the place after a character that isn’t escaped: one preceded
3
+ * by an even number of backslashes, which escape each other.
4
+ */
5
+ export const UNESCAPED_LOOKBEHIND: string;
6
+ export function countBackslashesBefore(text: string, index: number): number;
7
+ /**
8
+ * Regular expression source to match a whitespace, punctuation or symbol character, which can
9
+ * flank a delimiter run as opposed to a word character. It needs the `u` flag.
10
+ * @see https://spec.commonmark.org/0.31.2/#left-flanking-delimiter-run
11
+ */
12
+ export const WHITESPACE_OR_PUNCTUATION: string;
13
+ /**
14
+ * Regular expression to match a {@link WHITESPACE_OR_PUNCTUATION whitespace, punctuation or symbol
15
+ * character}.
16
+ */
17
+ export const WHITESPACE_OR_PUNCTUATION_REGEX: RegExp;
18
+ export function isWordChar(char: string | undefined): boolean;
19
+ /**
20
+ * Regular expression source to match a thematic break after its indentation, like `***` or
21
+ * `- - -`, up to the end of the line. Each character is spelled out rather than matched with a
22
+ * backreference, so the source can be combined with other capturing groups.
23
+ * @see https://spec.commonmark.org/0.31.2/#thematic-breaks
24
+ */
25
+ export const THEMATIC_BREAK: string;
26
+ /**
27
+ * Regular expression source to match a setext heading underline after its indentation, like `===`
28
+ * or `---`, up to the end of the line. A single `-` is also a bullet list item, so where both are
29
+ * matched as alternatives, the list item comes first.
30
+ * @see https://spec.commonmark.org/0.31.2/#setext-headings
31
+ */
32
+ export const SETEXT_UNDERLINE: string;
33
+ /**
34
+ * Regular expression source to match the opening sequence of an ATX heading, like `##`, which has
35
+ * to be followed by {@link MARKER_END}.
36
+ * @see https://spec.commonmark.org/0.31.2/#atx-headings
37
+ */
38
+ export const ATX_HEADING_MARKER: "#{1,6}";
39
+ /**
40
+ * Regular expression source to match a bullet list marker, which has to be followed by
41
+ * {@link MARKER_END}.
42
+ * @see https://spec.commonmark.org/0.31.2/#list-items
43
+ */
44
+ export const BULLET_LIST_MARKER: "[-+*]";
45
+ /**
46
+ * Regular expression source to match the number of an ordered list marker.
47
+ * @see https://spec.commonmark.org/0.31.2/#list-items
48
+ */
49
+ export const ORDERED_LIST_NUMBER: string;
50
+ /**
51
+ * Regular expression source to match the delimiter after the number of an ordered list marker.
52
+ */
53
+ export const ORDERED_LIST_DELIMITER: "[.)]";
54
+ /**
55
+ * Regular expression source to match a bullet or ordered list marker, which has to be followed by
56
+ * {@link MARKER_END}.
57
+ */
58
+ export const LIST_MARKER: string;
59
+ /**
60
+ * Regular expression source to match the place after an ATX heading or list marker: whitespace or
61
+ * the end of the line.
62
+ */
63
+ export const MARKER_END: string;
64
+ /**
65
+ * Regular expression source to match a code fence, made of three or more backticks or tildes.
66
+ * @see https://spec.commonmark.org/0.31.2/#fenced-code-blocks
67
+ */
68
+ export const CODE_FENCE: "(?:`{3,}|~{3,})";
69
+ /**
70
+ * Regular expression source to match an HTML open tag or closing tag.
71
+ * @see https://spec.commonmark.org/0.31.2/#raw-html
72
+ */
73
+ export const HTML_TAG_SOURCE: string;
74
+ /**
75
+ * Regular expression to match inline raw HTML on a line: an open tag, a closing tag, a comment, a
76
+ * processing instruction, a declaration or a CDATA section, which isn’t escaped.
77
+ * @see https://spec.commonmark.org/0.31.2/#raw-html
78
+ */
79
+ export const INLINE_HTML_REGEX: RegExp;
80
+ /**
81
+ * Regular expression to match an autolink, like `<https://example.com>` or `<foo@example.com>`,
82
+ * which isn’t escaped.
83
+ * @see https://spec.commonmark.org/0.31.2/#autolinks
84
+ */
85
+ export const AUTOLINK_REGEX: RegExp;
86
+ /**
87
+ * Regular expression to match a footnote reference, like `[^1]`, which isn’t escaped. Footnotes
88
+ * aren’t supported, but they’re read by GitHub and many other renderers.
89
+ * @see https://github.github.com/gfm/
90
+ */
91
+ export const FOOTNOTE_REFERENCE_REGEX: RegExp;
92
+ /**
93
+ * Regular expression to match a named character reference, like `&copy;`, which isn’t escaped.
94
+ * Lexical imports it as text, the same as the escaped `\&copy;`, which is exported escaped; see
95
+ * `escapeNamedCharacterReferences()`. The lookahead comes first, so the lookbehind is only tried
96
+ * before a `&`.
97
+ * @see https://spec.commonmark.org/0.31.2/#entity-and-numeric-character-references
98
+ */
99
+ export const NAMED_CHARACTER_REFERENCE_REGEX: RegExp;
@@ -0,0 +1,206 @@
1
+ /**
2
+ * Regular expression sources and helpers to read the Markdown syntax, shared by the Markdown
3
+ * processing and the transformers. They don’t depend on Lexical.
4
+ */
5
+
6
+ import { CODE_TAB_PLACEHOLDER } from '../placeholder-chars.js';
7
+
8
+ /**
9
+ * Regular expression source to match the place after a character that isn’t escaped: one preceded
10
+ * by an even number of backslashes, which escape each other.
11
+ */
12
+ export const UNESCAPED_LOOKBEHIND = String.raw`(?<!(?:^|[^\\])(?:\\\\)*\\)`;
13
+
14
+ /**
15
+ * Count the backslashes right before the given index, which escape the character there if their
16
+ * number is odd. They’re counted rather than matched with a regular expression, which would take
17
+ * quadratic time on a long run of backslashes.
18
+ * @param {string} text Text.
19
+ * @param {number} index Index.
20
+ * @returns {number} Number of backslashes.
21
+ */
22
+ export const countBackslashesBefore = (text, index) => {
23
+ let count = 0;
24
+
25
+ while (text[index - count - 1] === '\\') {
26
+ count += 1;
27
+ }
28
+
29
+ return count;
30
+ };
31
+
32
+ /**
33
+ * Regular expression source to match a whitespace, punctuation or symbol character, which can
34
+ * flank a delimiter run as opposed to a word character. It needs the `u` flag.
35
+ * @see https://spec.commonmark.org/0.31.2/#left-flanking-delimiter-run
36
+ */
37
+ export const WHITESPACE_OR_PUNCTUATION = String.raw`[\s\p{P}\p{S}]`;
38
+
39
+ /**
40
+ * Regular expression to match a {@link WHITESPACE_OR_PUNCTUATION whitespace, punctuation or symbol
41
+ * character}.
42
+ */
43
+ export const WHITESPACE_OR_PUNCTUATION_REGEX = new RegExp(WHITESPACE_OR_PUNCTUATION, 'u');
44
+
45
+ /**
46
+ * Check if the given character is a word character, which is neither whitespace nor punctuation
47
+ * (or a symbol). An underscore next to one on both sides can’t open or close emphasis.
48
+ * @param {string | undefined} char Character.
49
+ * @returns {boolean} Result.
50
+ * @see https://spec.commonmark.org/0.31.2/#left-flanking-delimiter-run
51
+ */
52
+ export const isWordChar = (char) => !!char && !WHITESPACE_OR_PUNCTUATION_REGEX.test(char);
53
+
54
+ /**
55
+ * Regular expression source to match a thematic break after its indentation, like `***` or
56
+ * `- - -`, up to the end of the line. Each character is spelled out rather than matched with a
57
+ * backreference, so the source can be combined with other capturing groups.
58
+ * @see https://spec.commonmark.org/0.31.2/#thematic-breaks
59
+ */
60
+ export const THEMATIC_BREAK = String.raw`(?:${[
61
+ String.raw`-(?:[ \t]*-){2,}`,
62
+ String.raw`\*(?:[ \t]*\*){2,}`,
63
+ String.raw`_(?:[ \t]*_){2,}`,
64
+ ].join('|')})[ \t]*$`;
65
+ /**
66
+ * Regular expression source to match a setext heading underline after its indentation, like `===`
67
+ * or `---`, up to the end of the line. A single `-` is also a bullet list item, so where both are
68
+ * matched as alternatives, the list item comes first.
69
+ * @see https://spec.commonmark.org/0.31.2/#setext-headings
70
+ */
71
+ export const SETEXT_UNDERLINE = String.raw`(?:=+|-+)[ \t]*$`;
72
+ /**
73
+ * Regular expression source to match the opening sequence of an ATX heading, like `##`, which has
74
+ * to be followed by {@link MARKER_END}.
75
+ * @see https://spec.commonmark.org/0.31.2/#atx-headings
76
+ */
77
+ export const ATX_HEADING_MARKER = '#{1,6}';
78
+ /**
79
+ * Regular expression source to match a bullet list marker, which has to be followed by
80
+ * {@link MARKER_END}.
81
+ * @see https://spec.commonmark.org/0.31.2/#list-items
82
+ */
83
+ export const BULLET_LIST_MARKER = '[-+*]';
84
+ /**
85
+ * Regular expression source to match the number of an ordered list marker.
86
+ * @see https://spec.commonmark.org/0.31.2/#list-items
87
+ */
88
+ export const ORDERED_LIST_NUMBER = String.raw`\d{1,9}`;
89
+ /**
90
+ * Regular expression source to match the delimiter after the number of an ordered list marker.
91
+ */
92
+ export const ORDERED_LIST_DELIMITER = '[.)]';
93
+
94
+ /**
95
+ * Regular expression source to match an ordered list marker, like `1.` or `1)`.
96
+ */
97
+ const ORDERED_LIST_MARKER = `${ORDERED_LIST_NUMBER}${ORDERED_LIST_DELIMITER}`;
98
+
99
+ /**
100
+ * Regular expression source to match a bullet or ordered list marker, which has to be followed by
101
+ * {@link MARKER_END}.
102
+ */
103
+ export const LIST_MARKER = `(?:${BULLET_LIST_MARKER}|${ORDERED_LIST_MARKER})`;
104
+ /**
105
+ * Regular expression source to match the place after an ATX heading or list marker: whitespace or
106
+ * the end of the line.
107
+ */
108
+ export const MARKER_END = String.raw`(?=[ \t]|$)`;
109
+ /**
110
+ * Regular expression source to match a code fence, made of three or more backticks or tildes.
111
+ * @see https://spec.commonmark.org/0.31.2/#fenced-code-blocks
112
+ */
113
+ export const CODE_FENCE = '(?:`{3,}|~{3,})';
114
+
115
+ /**
116
+ * Whitespace within an HTML tag, including the placeholder of a tab; see `addImportPlaceholders()`.
117
+ */
118
+ const TAG_SPACE = `[ \\t${CODE_TAB_PLACEHOLDER}]`;
119
+
120
+ /**
121
+ * Regular expression source to match an HTML open tag or closing tag.
122
+ * @see https://spec.commonmark.org/0.31.2/#raw-html
123
+ */
124
+ export const HTML_TAG_SOURCE =
125
+ `<[A-Za-z][A-Za-z0-9-]*(?:${TAG_SPACE}+[A-Za-z_:][\\w.:-]*` +
126
+ `(?:${TAG_SPACE}*=${TAG_SPACE}*` +
127
+ `(?:[^\\s"'=<>\`${CODE_TAB_PLACEHOLDER}]+|'[^'\\n]*'|"[^"\\n]*"))?)*` +
128
+ `${TAG_SPACE}*/?>|</[A-Za-z][A-Za-z0-9-]*${TAG_SPACE}*>`;
129
+
130
+ /**
131
+ * Regular expression source to match the place before a `<` that isn’t escaped. The lookahead comes
132
+ * first, so the lookbehind is only tried before a `<`.
133
+ */
134
+ const UNESCAPED_LT_SOURCE = `(?=<)${UNESCAPED_LOOKBEHIND}`;
135
+
136
+ /**
137
+ * Regular expression to match inline raw HTML on a line: an open tag, a closing tag, a comment, a
138
+ * processing instruction, a declaration or a CDATA section, which isn’t escaped.
139
+ * @see https://spec.commonmark.org/0.31.2/#raw-html
140
+ */
141
+ export const INLINE_HTML_REGEX = new RegExp(
142
+ [
143
+ UNESCAPED_LT_SOURCE,
144
+ '(?:',
145
+ [
146
+ HTML_TAG_SOURCE,
147
+ // Comment
148
+ String.raw`<!-->|<!--->|<!--.*?-->`,
149
+ // Processing instruction
150
+ String.raw`<\?.*?\?>`,
151
+ // Declaration
152
+ String.raw`<![A-Za-z][^>]*>`,
153
+ // CDATA section
154
+ String.raw`<!\[CDATA\[.*?\]\]>`,
155
+ ].join('|'),
156
+ ')',
157
+ ].join(''),
158
+ );
159
+
160
+ /**
161
+ * Regular expression source to match a URI scheme that runs a script or embeds content, in any
162
+ * case, as a scheme is case-insensitive.
163
+ */
164
+ const UNSAFE_SCHEME_SOURCE = `(?:${['javascript', 'vbscript', 'data']
165
+ .map((scheme) => scheme.replace(/[a-z]/g, (char) => `[${char}${char.toUpperCase()}]`))
166
+ .join('|')})`;
167
+
168
+ /**
169
+ * Regular expression to match an autolink, like `<https://example.com>` or `<foo@example.com>`,
170
+ * which isn’t escaped.
171
+ * @see https://spec.commonmark.org/0.31.2/#autolinks
172
+ */
173
+ export const AUTOLINK_REGEX = new RegExp(
174
+ [
175
+ UNESCAPED_LT_SOURCE,
176
+ '(?:',
177
+ [
178
+ // URI, other than one with a scheme that runs a script or embeds content, which is left to
179
+ // be escaped as text
180
+ String.raw`<(?!${UNSAFE_SCHEME_SOURCE}:)[A-Za-z][A-Za-z0-9+.-]{1,31}:[^\s<>]*>`,
181
+ // Email address
182
+ String.raw`<[\w.!#$%&'*+/=?^\x60{|}~-]+@[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?` +
183
+ String.raw`(?:\.[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?)*>`,
184
+ ].join('|'),
185
+ ')',
186
+ ].join(''),
187
+ );
188
+
189
+ /**
190
+ * Regular expression to match a footnote reference, like `[^1]`, which isn’t escaped. Footnotes
191
+ * aren’t supported, but they’re read by GitHub and many other renderers.
192
+ * @see https://github.github.com/gfm/
193
+ */
194
+ export const FOOTNOTE_REFERENCE_REGEX = new RegExp(
195
+ String.raw`${UNESCAPED_LOOKBEHIND}\[\^[^\s[\]]+\]`,
196
+ );
197
+ /**
198
+ * Regular expression to match a named character reference, like `&copy;`, which isn’t escaped.
199
+ * Lexical imports it as text, the same as the escaped `\&copy;`, which is exported escaped; see
200
+ * `escapeNamedCharacterReferences()`. The lookahead comes first, so the lookbehind is only tried
201
+ * before a `&`.
202
+ * @see https://spec.commonmark.org/0.31.2/#entity-and-numeric-character-references
203
+ */
204
+ export const NAMED_CHARACTER_REFERENCE_REGEX = new RegExp(
205
+ `(?=&)${UNESCAPED_LOOKBEHIND}&[A-Za-z][A-Za-z\\d]*;`,
206
+ );
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Placeholder characters used while converting Markdown, from the Unicode Private Use Area, which
3
+ * a document is unlikely to contain. Each one has its own code point, so a new placeholder takes
4
+ * the next one that is free.
5
+ */
6
+ /**
7
+ * Placeholder for the text of a raw syntax node, which Lexical doesn’t escape.
8
+ */
9
+ export const RAW_TEXT_PLACEHOLDER: "\uE000";
10
+ /**
11
+ * Placeholder for a backtick in the info string of a code block fenced with tildes, which is
12
+ * converted to one fenced with backticks before the Markdown is imported; see
13
+ * `convertTildeFences()`. Unlike that of a tilde fence, the info string of a backtick fence can’t
14
+ * contain a backtick.
15
+ */
16
+ export const INFO_BACKTICK: "\uE001";
17
+ /**
18
+ * Placeholder put after an escaped backslash at the end of a line; see `addImportPlaceholders()`.
19
+ */
20
+ export const ESCAPED_BACKSLASH_PLACEHOLDER: "\uE002";
21
+ /**
22
+ * Placeholder put with a period between a backslash and a formatting marker; see
23
+ * `addImportPlaceholders()`.
24
+ */
25
+ export const PUNCTUATION_PLACEHOLDER: "\uE003";
26
+ /**
27
+ * Placeholder given as the text of inline code made only of whitespace when it’s exported, so
28
+ * Lexical exports its formats; see `getFormatExportNode()`.
29
+ */
30
+ export const WHITESPACE_CODE_PLACEHOLDER: "\uE004";
31
+ /**
32
+ * Placeholder put in place of a tab in a code span; see `addImportPlaceholders()`.
33
+ */
34
+ export const CODE_TAB_PLACEHOLDER: "\uE005";
35
+ /**
36
+ * Placeholder put in place of a space in a code span made only of spaces; see
37
+ * `addImportPlaceholders()`.
38
+ */
39
+ export const CODE_SPACE_PLACEHOLDER: "\uE006";
40
+ /**
41
+ * Placeholder put at the start of a line of an HTML block; see `addImportPlaceholders()`.
42
+ */
43
+ export const HTML_BLOCK_PLACEHOLDER: "\uE007";
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Placeholder characters used while converting Markdown, from the Unicode Private Use Area, which
3
+ * a document is unlikely to contain. Each one has its own code point, so a new placeholder takes
4
+ * the next one that is free.
5
+ */
6
+
7
+ /**
8
+ * Placeholder for the text of a raw syntax node, which Lexical doesn’t escape.
9
+ */
10
+ export const RAW_TEXT_PLACEHOLDER = '';
11
+
12
+ /**
13
+ * Placeholder for a backtick in the info string of a code block fenced with tildes, which is
14
+ * converted to one fenced with backticks before the Markdown is imported; see
15
+ * `convertTildeFences()`. Unlike that of a tilde fence, the info string of a backtick fence can’t
16
+ * contain a backtick.
17
+ */
18
+ export const INFO_BACKTICK = '';
19
+
20
+ /**
21
+ * Placeholder put after an escaped backslash at the end of a line; see `addImportPlaceholders()`.
22
+ */
23
+ export const ESCAPED_BACKSLASH_PLACEHOLDER = '';
24
+
25
+ /**
26
+ * Placeholder put with a period between a backslash and a formatting marker; see
27
+ * `addImportPlaceholders()`.
28
+ */
29
+ export const PUNCTUATION_PLACEHOLDER = '';
30
+
31
+ /**
32
+ * Placeholder given as the text of inline code made only of whitespace when it’s exported, so
33
+ * Lexical exports its formats; see `getFormatExportNode()`.
34
+ */
35
+ export const WHITESPACE_CODE_PLACEHOLDER = '';
36
+
37
+ /**
38
+ * Placeholder put in place of a tab in a code span; see `addImportPlaceholders()`.
39
+ */
40
+ export const CODE_TAB_PLACEHOLDER = '';
41
+
42
+ /**
43
+ * Placeholder put in place of a space in a code span made only of spaces; see
44
+ * `addImportPlaceholders()`.
45
+ */
46
+ export const CODE_SPACE_PLACEHOLDER = '';
47
+
48
+ /**
49
+ * Placeholder put at the start of a line of an HTML block; see `addImportPlaceholders()`.
50
+ */
51
+ export const HTML_BLOCK_PLACEHOLDER = '';
@@ -4,6 +4,7 @@ export function unescapeCharacterReferences(markdown: string, { isInLink, isAtLi
4
4
  isInLink: boolean;
5
5
  isAtLineEnd: boolean;
6
6
  }): string;
7
+ export function escapeNamedCharacterReferences(markdown: string): string;
7
8
  /**
8
9
  * Export-only transformer that tidies up the Markdown of a text node that isn’t inline code, which
9
10
  * Lexical exports verbatim. It removes the unnecessary escapes Lexical adds; see `unescapeText()`.