-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Expand file tree
/
Copy pathindex.ts
More file actions
116 lines (111 loc) · 2.95 KB
/
Copy pathindex.ts
File metadata and controls
116 lines (111 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
import type {
ElementTransformer,
MultilineElementTransformer,
TextFormatTransformer,
TextMatchTransformer,
Transformer,
} from './MarkdownTransformers';
import type {ElementNode} from 'lexical';
import {createMarkdownExport} from './MarkdownExport';
import {createMarkdownImport} from './MarkdownImport';
import {registerMarkdownShortcuts} from './MarkdownShortcuts';
import {
BOLD_ITALIC_STAR,
BOLD_ITALIC_UNDERSCORE,
BOLD_STAR,
BOLD_UNDERSCORE,
CHECK_LIST,
CODE,
ELEMENT_TRANSFORMERS,
HEADING,
HIGHLIGHT,
INLINE_CODE,
ITALIC_STAR,
ITALIC_UNDERSCORE,
LINK,
MULTILINE_ELEMENT_TRANSFORMERS,
nestHeadingInBlockquote,
normalizeMarkdown,
ORDERED_LIST,
QUOTE,
STRIKETHROUGH,
TEXT_FORMAT_TRANSFORMERS,
TEXT_MATCH_TRANSFORMERS,
TRANSFORMERS,
UNORDERED_LIST,
} from './MarkdownTransformers';
/**
* Renders markdown from a string. The selection is moved to the start after the operation.
*
* @param {boolean} [shouldPreserveNewLines] By setting this to true, new lines will be preserved between conversions
* @param {boolean} [shouldMergeAdjacentLines] By setting this to true, adjacent non empty lines will be merged according to commonmark spec: https://spec.commonmark.org/0.24/#example-177. Not applicable if shouldPreserveNewLines = true.
*/
function $convertFromMarkdownString(
markdown: string,
transformers: Array<Transformer> = TRANSFORMERS,
node?: ElementNode,
shouldPreserveNewLines = false,
shouldMergeAdjacentLines = false,
): void {
const sanitizedMarkdown = shouldPreserveNewLines
? markdown
: normalizeMarkdown(markdown, shouldMergeAdjacentLines);
const importMarkdown = createMarkdownImport(
transformers,
shouldPreserveNewLines,
);
return importMarkdown(sanitizedMarkdown, node);
}
/**
* Renders string from markdown. The selection is moved to the start after the operation.
*/
function $convertToMarkdownString(
transformers: Array<Transformer> = TRANSFORMERS,
node?: ElementNode,
shouldPreserveNewLines: boolean = false,
): string {
const exportMarkdown = createMarkdownExport(
transformers,
shouldPreserveNewLines,
);
return exportMarkdown(node);
}
export {
$convertFromMarkdownString,
$convertToMarkdownString,
BOLD_ITALIC_STAR,
BOLD_ITALIC_UNDERSCORE,
BOLD_STAR,
BOLD_UNDERSCORE,
CHECK_LIST,
CODE,
ELEMENT_TRANSFORMERS,
type ElementTransformer,
HEADING,
HIGHLIGHT,
INLINE_CODE,
ITALIC_STAR,
ITALIC_UNDERSCORE,
LINK,
MULTILINE_ELEMENT_TRANSFORMERS,
type MultilineElementTransformer,
nestHeadingInBlockquote,
ORDERED_LIST,
QUOTE,
registerMarkdownShortcuts,
STRIKETHROUGH,
TEXT_FORMAT_TRANSFORMERS,
TEXT_MATCH_TRANSFORMERS,
type TextFormatTransformer,
type TextMatchTransformer,
type Transformer,
TRANSFORMERS,
UNORDERED_LIST,
};