@sveltia/ui 0.41.2 → 0.41.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.
|
@@ -52,6 +52,15 @@ export const NODE_MAP: Record<Exclude<TextEditorBlockType | "link", "paragraph">
|
|
|
52
52
|
* @type {Record<Exclude<TextEditorNodeType, 'paragraph'>, Transformer[]>}
|
|
53
53
|
*/
|
|
54
54
|
export const TRANSFORMER_MAP: Record<Exclude<TextEditorNodeType, "paragraph">, Transformer[]>;
|
|
55
|
+
/**
|
|
56
|
+
* List of Markdown tags that should be disabled in the editor when converting Lexical nodes to
|
|
57
|
+
* Markdown (but not when converting Markdown to Lexical nodes because we don’t want to lose any
|
|
58
|
+
* formatting). Use underscore for italic text in Markdown instead of asterisks, and use double
|
|
59
|
+
* asterisks for bold text in Markdown instead of underscores. Also, disable triple asterisks and
|
|
60
|
+
* triple underscores for bold+italic text in Markdown, which can be confusing and is not commonly
|
|
61
|
+
* used. This is to ensure that the Markdown output is more readable and consistent.
|
|
62
|
+
*/
|
|
63
|
+
export const DISABLED_MARKDOWN_TAGS: string[];
|
|
55
64
|
import type { EditorThemeClasses } from 'lexical';
|
|
56
65
|
import type { TextEditorFormatType } from '../../typedefs';
|
|
57
66
|
import type { TextEditorInlineType } from '../../typedefs';
|
|
@@ -5,9 +5,11 @@ import {
|
|
|
5
5
|
BOLD_ITALIC_STAR,
|
|
6
6
|
BOLD_ITALIC_UNDERSCORE,
|
|
7
7
|
BOLD_STAR,
|
|
8
|
+
BOLD_UNDERSCORE,
|
|
8
9
|
CODE,
|
|
9
10
|
HEADING,
|
|
10
11
|
INLINE_CODE,
|
|
12
|
+
ITALIC_STAR,
|
|
11
13
|
ITALIC_UNDERSCORE,
|
|
12
14
|
LINK,
|
|
13
15
|
ORDERED_LIST,
|
|
@@ -241,9 +243,31 @@ export const TRANSFORMER_MAP = {
|
|
|
241
243
|
'code-block': [CODE],
|
|
242
244
|
// TEXT_FORMAT_TRANSFORMERS
|
|
243
245
|
code: [INLINE_CODE],
|
|
244
|
-
bold: [
|
|
245
|
-
|
|
246
|
+
bold: [
|
|
247
|
+
BOLD_STAR,
|
|
248
|
+
// Disabled for Markdown output in `DISABLED_MARKDOWN_TAGS` below
|
|
249
|
+
BOLD_UNDERSCORE,
|
|
250
|
+
BOLD_ITALIC_STAR,
|
|
251
|
+
BOLD_ITALIC_UNDERSCORE,
|
|
252
|
+
],
|
|
253
|
+
italic: [
|
|
254
|
+
ITALIC_UNDERSCORE,
|
|
255
|
+
// Disabled for Markdown output in `DISABLED_MARKDOWN_TAGS` below
|
|
256
|
+
ITALIC_STAR,
|
|
257
|
+
BOLD_ITALIC_STAR,
|
|
258
|
+
BOLD_ITALIC_UNDERSCORE,
|
|
259
|
+
],
|
|
246
260
|
strikethrough: [STRIKETHROUGH],
|
|
247
261
|
// TEXT_MATCH_TRANSFORMERS
|
|
248
262
|
link: [LINK],
|
|
249
263
|
};
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* List of Markdown tags that should be disabled in the editor when converting Lexical nodes to
|
|
267
|
+
* Markdown (but not when converting Markdown to Lexical nodes because we don’t want to lose any
|
|
268
|
+
* formatting). Use underscore for italic text in Markdown instead of asterisks, and use double
|
|
269
|
+
* asterisks for bold text in Markdown instead of underscores. Also, disable triple asterisks and
|
|
270
|
+
* triple underscores for bold+italic text in Markdown, which can be confusing and is not commonly
|
|
271
|
+
* used. This is to ensure that the Markdown output is more readable and consistent.
|
|
272
|
+
*/
|
|
273
|
+
export const DISABLED_MARKDOWN_TAGS = ['*', '__', '***', '___'];
|
|
@@ -52,6 +52,7 @@ import {
|
|
|
52
52
|
import prismComponents from 'prismjs/components';
|
|
53
53
|
import {
|
|
54
54
|
BLOCK_BUTTON_TYPES,
|
|
55
|
+
DISABLED_MARKDOWN_TAGS,
|
|
55
56
|
EDITOR_THEME,
|
|
56
57
|
NODE_MAP,
|
|
57
58
|
PRISM_BASE_URL,
|
|
@@ -162,10 +163,14 @@ export const getSelectionTypes = () => {
|
|
|
162
163
|
* @param {Transformer[]} enabledTransformers Enabled Markdown transformers.
|
|
163
164
|
*/
|
|
164
165
|
export const onEditorUpdate = (editor, enabledTransformers) => {
|
|
166
|
+
const transformers = enabledTransformers.filter(
|
|
167
|
+
(/** @type {any} */ { tag }) => !DISABLED_MARKDOWN_TAGS.includes(tag),
|
|
168
|
+
);
|
|
169
|
+
|
|
165
170
|
editor.getRootElement()?.dispatchEvent(
|
|
166
171
|
new CustomEvent('Update', {
|
|
167
172
|
detail: {
|
|
168
|
-
value: convertToMarkdownString(
|
|
173
|
+
value: convertToMarkdownString(transformers)
|
|
169
174
|
// Remove unnecessary backslash for underscore and backslash characters
|
|
170
175
|
// @see https://github.com/sveltia/sveltia-cms/issues/430
|
|
171
176
|
// @see https://github.com/sveltia/sveltia-cms/issues/512
|