@sveltia/ui 0.75.1 → 0.75.3

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.
@@ -62,7 +62,12 @@ import {
62
62
  TEXT_FORMAT_BUTTON_TYPES,
63
63
  TRANSFORMER_MAP,
64
64
  } from './constants.js';
65
- import { increaseListIndentation, splitMultilineFormatting } from './markdown.js';
65
+ import {
66
+ increaseListIndentation,
67
+ padBlankBlockquoteLines,
68
+ splitMultilineFormatting,
69
+ trimBlankBlockquoteLines,
70
+ } from './markdown.js';
66
71
  import {
67
72
  isPlainLanguage,
68
73
  loadCodeLanguage,
@@ -182,16 +187,18 @@ export const onEditorUpdate = (editor, enabledTransformers) => {
182
187
  editor.getRootElement()?.dispatchEvent(
183
188
  new CustomEvent('Update', {
184
189
  detail: {
185
- value: convertToMarkdownString(transformers)
186
- // Remove unnecessary backslash for underscore and backslash characters
187
- // @see https://github.com/sveltia/sveltia-cms/issues/430
188
- // @see https://github.com/sveltia/sveltia-cms/issues/512
189
- .replace(/\\([_\\])/g, '$1')
190
- // Replace encoded spaces with regular spaces. The HTML entity can appear with a
191
- // combination of bold and italic text
192
- // @see https://github.com/sveltia/sveltia-cms/issues/511
193
- // @see https://github.com/sveltia/sveltia-cms/issues/534
194
- .replace(/ /g, ' '),
190
+ value: trimBlankBlockquoteLines(
191
+ convertToMarkdownString(transformers)
192
+ // Remove unnecessary backslash for underscore and backslash characters
193
+ // @see https://github.com/sveltia/sveltia-cms/issues/430
194
+ // @see https://github.com/sveltia/sveltia-cms/issues/512
195
+ .replace(/\\([_\\])/g, '$1')
196
+ // Replace encoded spaces with regular spaces. The HTML entity can appear with a
197
+ // combination of bold and italic text
198
+ // @see https://github.com/sveltia/sveltia-cms/issues/511
199
+ // @see https://github.com/sveltia/sveltia-cms/issues/534
200
+ .replace(/ /g, ' '),
201
+ ),
195
202
  selection: getSelectionTypes(),
196
203
  },
197
204
  }),
@@ -508,6 +515,9 @@ export const convertMarkdownToLexical = async (editor, value, enabledTransformer
508
515
  // Increase list indentation levels to prevent Markdown parsing issues
509
516
  value = increaseListIndentation(value);
510
517
 
518
+ // Pad blank blockquote lines so they are not imported as literal `>` text
519
+ value = padBlankBlockquoteLines(value);
520
+
511
521
  return new Promise((resolve, reject) => {
512
522
  editor.update(() => {
513
523
  try {
@@ -1,2 +1,4 @@
1
1
  export function splitMultilineFormatting(value: string): string;
2
2
  export function increaseListIndentation(value: string): string;
3
+ export function padBlankBlockquoteLines(value: string): string;
4
+ export function trimBlankBlockquoteLines(value: string): string;
@@ -12,24 +12,20 @@ export const splitMultilineFormatting = (value) =>
12
12
  .replace(/(\s+)`([^`\n]+?)\n([^`\n]+?)`(\s+)/gm, '$1`$2`\n`$3`$4');
13
13
 
14
14
  /**
15
- * Increase list indentation levels to prevent Markdown parsing issues.
16
- * Slate uses 2 spaces per indentation level, whereas Lexical uses 4 spaces.
17
- * This function doubles the indentation to match Lexical's expectations.
15
+ * Apply a function to each line of a Markdown string, leaving the lines inside fenced code blocks
16
+ * untouched.
18
17
  * @param {string} value Markdown string to process.
18
+ * @param {(line: string) => string} callback Function that returns a processed line.
19
19
  * @returns {string} Processed Markdown string.
20
- * @see https://github.com/sveltia/sveltia-cms/issues/549
21
20
  */
22
- export const increaseListIndentation = (value) => {
23
- if (!value.match(/^\s{2}(?:-|\+|\*|\d+\.)\s/m)) {
24
- return value;
25
- }
26
-
21
+ const mapLinesOutsideCodeBlocks = (value, callback) => {
27
22
  let inCodeBlock = false;
28
23
 
29
24
  return value
30
25
  .split('\n')
31
26
  .map((line) => {
32
- if (/^(`{3,}|~{3,})/.test(line)) {
27
+ // Like Lexical's `CODE_START_REGEX`, allow an indented fence
28
+ if (/^[ \t]*(`{3,}|~{3,})/.test(line)) {
33
29
  inCodeBlock = !inCodeBlock;
34
30
  return line;
35
31
  }
@@ -38,10 +34,56 @@ export const increaseListIndentation = (value) => {
38
34
  return line;
39
35
  }
40
36
 
41
- return line.replace(
42
- /^(\s+)(-|\+|\*|\d+\.)/,
43
- (_match, p1, p2) => `${' '.repeat(p1.length * 2)}${p2}`,
44
- );
37
+ return callback(line);
45
38
  })
46
39
  .join('\n');
47
40
  };
41
+
42
+ /**
43
+ * Increase list indentation levels to prevent Markdown parsing issues.
44
+ * Slate uses 2 spaces per indentation level, whereas Lexical uses 4 spaces.
45
+ * This function doubles the indentation to match Lexical's expectations.
46
+ * @param {string} value Markdown string to process.
47
+ * @returns {string} Processed Markdown string.
48
+ * @see https://github.com/sveltia/sveltia-cms/issues/549
49
+ */
50
+ export const increaseListIndentation = (value) => {
51
+ if (!value.match(/^\s{2}(?:-|\+|\*|\d+\.)\s/m)) {
52
+ return value;
53
+ }
54
+
55
+ return mapLinesOutsideCodeBlocks(value, (line) =>
56
+ line.replace(/^(\s+)(-|\+|\*|\d+\.)/, (_match, p1, p2) => `${' '.repeat(p1.length * 2)}${p2}`),
57
+ );
58
+ };
59
+
60
+ /**
61
+ * Add a trailing space to a blank blockquote line (`>`) so Lexical treats it as a blank line within
62
+ * the blockquote. Without the space, the line does not match Lexical's `/^>\s/` quote pattern and
63
+ * is imported as literal `>` text, which is then exported as `> >`, an empty nested blockquote.
64
+ * @param {string} value Markdown string to process.
65
+ * @returns {string} Processed Markdown string.
66
+ * @see https://github.com/sveltia/sveltia-cms/issues/995
67
+ */
68
+ export const padBlankBlockquoteLines = (value) => {
69
+ if (!/^>$/m.test(value)) {
70
+ return value;
71
+ }
72
+
73
+ return mapLinesOutsideCodeBlocks(value, (line) => (line === '>' ? '> ' : line));
74
+ };
75
+
76
+ /**
77
+ * Remove the trailing space Lexical outputs for a blank blockquote line (`> `) so the line
78
+ * round-trips as `>`, the canonical form.
79
+ * @param {string} value Markdown string to process.
80
+ * @returns {string} Processed Markdown string.
81
+ * @see https://github.com/sveltia/sveltia-cms/issues/995
82
+ */
83
+ export const trimBlankBlockquoteLines = (value) => {
84
+ if (!/^> $/m.test(value)) {
85
+ return value;
86
+ }
87
+
88
+ return mapLinesOutsideCodeBlocks(value, (line) => (line === '> ' ? '>' : line));
89
+ };
@@ -1,4 +1,4 @@
1
1
  /**
2
2
  * Version of this package, used to resolve the prebuilt Shiki engine chunk from a CDN.
3
3
  */
4
- export const UI_VERSION: "0.75.1";
4
+ export const UI_VERSION: "0.75.3";
@@ -3,4 +3,4 @@
3
3
  /**
4
4
  * Version of this package, used to resolve the prebuilt Shiki engine chunk from a CDN.
5
5
  */
6
- export const UI_VERSION = '0.75.1';
6
+ export const UI_VERSION = '0.75.3';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltia/ui",
3
- "version": "0.75.1",
3
+ "version": "0.75.3",
4
4
  "description": "A collection of Svelte components and utilities for building user interfaces.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -36,20 +36,20 @@
36
36
  "!dist/test-utils"
37
37
  ],
38
38
  "dependencies": {
39
- "@lexical/code-core": "^0.50.0",
40
- "@lexical/dragon": "^0.50.0",
41
- "@lexical/extension": "^0.50.0",
42
- "@lexical/history": "^0.50.0",
43
- "@lexical/link": "^0.50.0",
44
- "@lexical/list": "^0.50.0",
45
- "@lexical/markdown": "^0.50.0",
46
- "@lexical/rich-text": "^0.50.0",
47
- "@lexical/selection": "^0.50.0",
48
- "@lexical/table": "^0.50.0",
49
- "@lexical/utils": "^0.50.0",
39
+ "@lexical/code-core": "^0.51.0",
40
+ "@lexical/dragon": "^0.51.0",
41
+ "@lexical/extension": "^0.51.0",
42
+ "@lexical/history": "^0.51.0",
43
+ "@lexical/link": "^0.51.0",
44
+ "@lexical/list": "^0.51.0",
45
+ "@lexical/markdown": "^0.51.0",
46
+ "@lexical/rich-text": "^0.51.0",
47
+ "@lexical/selection": "^0.51.0",
48
+ "@lexical/table": "^0.51.0",
49
+ "@lexical/utils": "^0.51.0",
50
50
  "@sveltia/i18n": "^1.4.0",
51
51
  "@sveltia/utils": "^0.12.1",
52
- "lexical": "^0.50.0"
52
+ "lexical": "^0.51.0"
53
53
  },
54
54
  "devDependencies": {
55
55
  "@rollup/plugin-yaml": "^5.0.0",