@sveltia/ui 0.87.1 → 0.87.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.
@@ -20,6 +20,8 @@ import {
20
20
  import { HeadingNode, QuoteNode } from '@lexical/rich-text';
21
21
  import { createCommand } from 'lexical';
22
22
 
23
+ import { LEADING_INLINE_CODE } from './transformers/inline-code.js';
24
+
23
25
  /**
24
26
  * @import { EditorThemeClasses, LexicalCommand } from 'lexical';
25
27
  * @import { Transformer } from '@lexical/markdown';
@@ -219,7 +221,8 @@ export const TRANSFORMER_MAP = {
219
221
  // MULTILINE_ELEMENT_TRANSFORMERS
220
222
  'code-block': [CODE],
221
223
  // TEXT_FORMAT_TRANSFORMERS
222
- code: [INLINE_CODE],
224
+ // The second one keeps the backslashes in inline code at the start of a node
225
+ code: [INLINE_CODE, LEADING_INLINE_CODE],
223
226
  bold: [
224
227
  BOLD_STAR,
225
228
  // Disabled for Markdown output in `DISABLED_MARKDOWN_TAGS` below
@@ -96,7 +96,6 @@ import {
96
96
  import {
97
97
  convertSetextHeadings,
98
98
  convertTildeFences,
99
- increaseListIndentation,
100
99
  padBlankBlockquoteLines,
101
100
  splitMultilineFormatting,
102
101
  trimBlankBlockquoteLines,
@@ -1191,10 +1190,9 @@ export const convertMarkdownToLexical = async (editor, value, enabledTransformer
1191
1190
  */
1192
1191
  $import: () => {
1193
1192
  convertFromMarkdownString(
1194
- // Split multiline formatting into separate lines to prevent Markdown parsing issues, then
1195
- // increase list indentation levels to prevent Markdown parsing issues, and pad blank
1196
- // blockquote lines so they are not imported as literal `>` text
1197
- padBlankBlockquoteLines(increaseListIndentation(splitMultilineFormatting(normalizedValue))),
1193
+ // Split multiline formatting into separate lines to prevent Markdown parsing issues, and
1194
+ // pad blank blockquote lines so they are not imported as literal `>` text
1195
+ padBlankBlockquoteLines(splitMultilineFormatting(normalizedValue)),
1198
1196
  enabledTransformers,
1199
1197
  );
1200
1198
  },
@@ -1,7 +1,6 @@
1
1
  export function splitMultilineFormatting(value: string): string;
2
2
  export function convertTildeFences(value: string): string;
3
3
  export function convertSetextHeadings(value: string): string;
4
- export function increaseListIndentation(value: string): string;
5
4
  export function padBlankBlockquoteLines(value: string): string;
6
5
  export function trimBlankBlockquoteLines(value: string): string;
7
6
  export type CodeBlock = {
@@ -327,24 +327,6 @@ export const convertSetextHeadings = (value) => {
327
327
  });
328
328
  };
329
329
 
330
- /**
331
- * Increase list indentation levels to prevent Markdown parsing issues.
332
- * Slate uses 2 spaces per indentation level, whereas Lexical uses 4 spaces.
333
- * This function doubles the indentation to match Lexical's expectations.
334
- * @param {string} value Markdown string to process.
335
- * @returns {string} Processed Markdown string.
336
- * @see https://github.com/sveltia/sveltia-cms/issues/549
337
- */
338
- export const increaseListIndentation = (value) => {
339
- if (!value.match(/^\s{2}(?:-|\+|\*|\d+\.)\s/m)) {
340
- return value;
341
- }
342
-
343
- return mapLinesOutsideCodeBlocks(value, (line) =>
344
- line.replace(/^(\s+)(-|\+|\*|\d+\.)/, (_match, p1, p2) => `${' '.repeat(p1.length * 2)}${p2}`),
345
- );
346
- };
347
-
348
330
  /**
349
331
  * Add a trailing space to a blank blockquote line (`>`) so Lexical treats it as a blank line within
350
332
  * the blockquote. Without the space, the line does not match Lexical's `/^>\s/` quote pattern and
@@ -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.87.1";
4
+ export const UI_VERSION: "0.87.2";
@@ -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.87.1';
6
+ export const UI_VERSION = '0.87.2';
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @import { TextMatchTransformer } from '@lexical/markdown';
3
+ * @import { TextNode } from 'lexical';
4
+ */
5
+ /**
6
+ * Import-only transformer for a code span at the start of a node, such as a table cell, a
7
+ * paragraph or bold text starting with inline code. Lexical’s `INLINE_CODE` transformer then reuses
8
+ * the node for the code, and removes the backslash escapes from the node once the inline syntax has
9
+ * been imported, so `` `C:\$MFT` `` would become `C:$MFT`, though backslashes are literal in a code
10
+ * span. Backslashes in a code span split from the text before it are kept. A text match wrapping a
11
+ * code span takes priority over it, and this one replaces the node with a new one, leaving the old
12
+ * node, which is no longer in the document, to be unescaped.
13
+ * @type {TextMatchTransformer}
14
+ * @see https://github.com/sveltia/sveltia-cms/issues/1100
15
+ */
16
+ export const LEADING_INLINE_CODE: TextMatchTransformer;
17
+ import type { TextMatchTransformer } from '@lexical/markdown';
@@ -0,0 +1,52 @@
1
+ import { $createTextNode as createTextNode } from 'lexical';
2
+
3
+ /**
4
+ * @import { TextMatchTransformer } from '@lexical/markdown';
5
+ * @import { TextNode } from 'lexical';
6
+ */
7
+
8
+ /**
9
+ * Import-only transformer for a code span at the start of a node, such as a table cell, a
10
+ * paragraph or bold text starting with inline code. Lexical’s `INLINE_CODE` transformer then reuses
11
+ * the node for the code, and removes the backslash escapes from the node once the inline syntax has
12
+ * been imported, so `` `C:\$MFT` `` would become `C:$MFT`, though backslashes are literal in a code
13
+ * span. Backslashes in a code span split from the text before it are kept. A text match wrapping a
14
+ * code span takes priority over it, and this one replaces the node with a new one, leaving the old
15
+ * node, which is no longer in the document, to be unescaped.
16
+ * @type {TextMatchTransformer}
17
+ * @see https://github.com/sveltia/sveltia-cms/issues/1100
18
+ */
19
+ export const LEADING_INLINE_CODE = {
20
+ dependencies: [],
21
+ /**
22
+ * Never export Markdown; Lexical’s `INLINE_CODE` transformer exports the code.
23
+ * @returns {null} Nothing.
24
+ */
25
+ export: () => null,
26
+ // A code span as Lexical’s `INLINE_CODE` transformer reads it: from a backtick run to the next
27
+ // run of the same length
28
+ // @see https://spec.commonmark.org/0.31.2/#code-spans
29
+ importRegExp: /^(`+)(?!`)([^]*?[^`])\1(?!`)/,
30
+ regExp: /(?!)/,
31
+ /**
32
+ * Replace the given text node, which has been split at the end of the code span, with a new code
33
+ * node, keeping its formats and style.
34
+ * @param {TextNode} node Text node.
35
+ * @param {RegExpMatchArray} match Match of the code span.
36
+ * @returns {TextNode} New node.
37
+ */
38
+ replace: (node, [, , content]) => {
39
+ // One space is stripped from both ends of the content if it’s padded on both sides and has a
40
+ // non-space character
41
+ const codeNode = createTextNode(/^ .*[^ ].* $/s.test(content) ? content.slice(1, -1) : content)
42
+ .setFormat(node.getFormat())
43
+ .setStyle(node.getStyle())
44
+ // Lexical doesn’t import the inline syntax in a node that is already code
45
+ .toggleFormat('code');
46
+
47
+ node.replace(codeNode);
48
+
49
+ return codeNode;
50
+ },
51
+ type: 'text-match',
52
+ };
@@ -24,6 +24,7 @@ import {
24
24
  import { $isParagraphNode as isParagraphNode, $isTextNode as isTextNode } from 'lexical';
25
25
 
26
26
  import { BLOCK_SYNTAX_ESCAPE } from './block-escape.js';
27
+ import { LEADING_INLINE_CODE } from './inline-code.js';
27
28
 
28
29
  /**
29
30
  * @import { ElementTransformer, TextMatchTransformer, Transformer } from '@lexical/markdown';
@@ -90,7 +91,7 @@ export const mapToTableCells = (textContent, transformers) => {
90
91
  */
91
92
  export const createTableTransformer = (cellTransformers = []) => {
92
93
  /** @type {Transformer[]} */
93
- const transformers = [...cellTransformers, ...TRANSFORMERS];
94
+ const transformers = [...cellTransformers, ...TRANSFORMERS, LEADING_INLINE_CODE];
94
95
  /** @type {Transformer[]} */
95
96
  const exportTransformers = [...transformers, BLOCK_SYNTAX_ESCAPE];
96
97
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltia/ui",
3
- "version": "0.87.1",
3
+ "version": "0.87.2",
4
4
  "description": "A collection of Svelte components and utilities for building user interfaces.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -81,14 +81,14 @@
81
81
  "eslint-config-airbnb-extended": "^3.3.0",
82
82
  "eslint-config-prettier": "^10.1.8",
83
83
  "eslint-plugin-import": "^2.32.0",
84
- "eslint-plugin-jsdoc": "^65.3.12",
84
+ "eslint-plugin-jsdoc": "^65.3.15",
85
85
  "eslint-plugin-package-json": "^1.10.1",
86
86
  "eslint-plugin-svelte": "^3.23.1",
87
87
  "globals": "^17.13.0",
88
88
  "happy-dom": "^21.0.3",
89
89
  "oxlint": "^1.88.0",
90
90
  "playwright": "^1.64.1",
91
- "postcss": "^8.5.30",
91
+ "postcss": "^8.5.31",
92
92
  "postcss-html": "^2.0.0",
93
93
  "prettier": "^3.9.10",
94
94
  "prettier-plugin-svelte": "^4.1.1",