Skip to content

Commit cb12d93

Browse files
committed
Move Transformer Groups from index to MarkdownTransformers
Move transformer groups created in index.ts to MarkdownTransformers.ts, co-locating them with the member transformers and avoiding a cyclical dependency involving index.ts.
1 parent f92696d commit cb12d93

File tree

3 files changed

+37
-33
lines changed

3 files changed

+37
-33
lines changed

packages/lexical-markdown/src/MarkdownShortcuts.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
} from 'lexical';
2727
import invariant from 'shared/invariant';
2828

29-
import {TRANSFORMERS} from '.';
29+
import {TRANSFORMERS} from './MarkdownTransformers';
3030
import {indexBy, PUNCTUATION_OR_SPACE, transformersByType} from './utils';
3131

3232
function runElementTransformers(

packages/lexical-markdown/src/MarkdownTransformers.ts

+32
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,14 @@ export const ITALIC_UNDERSCORE: TextFormatTransformer = {
350350
type: 'text-format',
351351
};
352352

353+
export const ELEMENT_TRANSFORMERS: Array<ElementTransformer> = [
354+
HEADING,
355+
QUOTE,
356+
CODE,
357+
UNORDERED_LIST,
358+
ORDERED_LIST,
359+
];
360+
353361
// Order of text transformers matters:
354362
//
355363
// - code should go first as it prevents any transformations inside
@@ -388,3 +396,27 @@ export const LINK: TextMatchTransformer = {
388396
trigger: ')',
389397
type: 'text-match',
390398
};
399+
400+
// Order of text format transformers matters:
401+
//
402+
// - code should go first as it prevents any transformations inside
403+
// - then longer tags match (e.g. ** or __ should go before * or _)
404+
export const TEXT_FORMAT_TRANSFORMERS: Array<TextFormatTransformer> = [
405+
INLINE_CODE,
406+
BOLD_ITALIC_STAR,
407+
BOLD_ITALIC_UNDERSCORE,
408+
BOLD_STAR,
409+
BOLD_UNDERSCORE,
410+
HIGHLIGHT,
411+
ITALIC_STAR,
412+
ITALIC_UNDERSCORE,
413+
STRIKETHROUGH,
414+
];
415+
416+
export const TEXT_MATCH_TRANSFORMERS: Array<TextMatchTransformer> = [LINK];
417+
418+
export const TRANSFORMERS: Array<Transformer> = [
419+
...ELEMENT_TRANSFORMERS,
420+
...TEXT_FORMAT_TRANSFORMERS,
421+
...TEXT_MATCH_TRANSFORMERS,
422+
];

packages/lexical-markdown/src/index.ts

+4-32
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
CODE,
2727
HEADING,
2828
HIGHLIGHT,
29+
ELEMENT_TRANSFORMERS
2930
INLINE_CODE,
3031
ITALIC_STAR,
3132
ITALIC_UNDERSCORE,
@@ -34,40 +35,11 @@ import {
3435
QUOTE,
3536
STRIKETHROUGH,
3637
UNORDERED_LIST,
38+
TEXT_FORMAT_TRANSFORMERS,
39+
TEXT_MATCH_TRANSFORMERS,
40+
TRANSFORMERS,
3741
} from './MarkdownTransformers';
3842

39-
const ELEMENT_TRANSFORMERS: Array<ElementTransformer> = [
40-
HEADING,
41-
QUOTE,
42-
CODE,
43-
UNORDERED_LIST,
44-
ORDERED_LIST,
45-
];
46-
47-
// Order of text format transformers matters:
48-
//
49-
// - code should go first as it prevents any transformations inside
50-
// - then longer tags match (e.g. ** or __ should go before * or _)
51-
const TEXT_FORMAT_TRANSFORMERS: Array<TextFormatTransformer> = [
52-
INLINE_CODE,
53-
BOLD_ITALIC_STAR,
54-
BOLD_ITALIC_UNDERSCORE,
55-
BOLD_STAR,
56-
BOLD_UNDERSCORE,
57-
HIGHLIGHT,
58-
ITALIC_STAR,
59-
ITALIC_UNDERSCORE,
60-
STRIKETHROUGH,
61-
];
62-
63-
const TEXT_MATCH_TRANSFORMERS: Array<TextMatchTransformer> = [LINK];
64-
65-
const TRANSFORMERS: Array<Transformer> = [
66-
...ELEMENT_TRANSFORMERS,
67-
...TEXT_FORMAT_TRANSFORMERS,
68-
...TEXT_MATCH_TRANSFORMERS,
69-
];
70-
7143
/**
7244
* Renders markdown from a string. The selection is moved to the start after the operation.
7345
*/

0 commit comments

Comments
 (0)