@ekz/lexical-markdown 0.40.0

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.
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+ import type { TextFormatTransformersIndex } from './MarkdownImport';
9
+ import type { TextFormatTransformer } from './MarkdownTransformers';
10
+ import type { TextNode } from '@ekz/lexical';
11
+ export declare function findOutermostTextFormatTransformer(textNode: TextNode, textFormatTransformersIndex: TextFormatTransformersIndex): {
12
+ startIndex: number;
13
+ endIndex: number;
14
+ transformer: TextFormatTransformer;
15
+ match: RegExpMatchArray;
16
+ } | null;
17
+ export declare function importTextFormatTransformer(textNode: TextNode, startIndex: number, endIndex: number, transformer: TextFormatTransformer, match: RegExpMatchArray): {
18
+ transformedNode: TextNode;
19
+ nodeBefore: TextNode | undefined;
20
+ nodeAfter: TextNode | undefined;
21
+ };
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+ import type { TextMatchTransformer } from './MarkdownTransformers';
9
+ import { type TextNode } from '@ekz/lexical';
10
+ export declare function findOutermostTextMatchTransformer(textNode_: TextNode, textMatchTransformers: Array<TextMatchTransformer>): {
11
+ startIndex: number;
12
+ endIndex: number;
13
+ transformer: TextMatchTransformer;
14
+ match: RegExpMatchArray;
15
+ } | null;
16
+ export declare function importFoundTextMatchTransformer(textNode: TextNode, startIndex: number, endIndex: number, transformer: TextMatchTransformer, match: RegExpMatchArray): {
17
+ transformedNode?: TextNode;
18
+ nodeBefore: TextNode | undefined;
19
+ nodeAfter: TextNode | undefined;
20
+ } | null;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+ import type { TextFormatTransformersIndex } from './MarkdownImport';
9
+ import type { TextMatchTransformer } from './MarkdownTransformers';
10
+ import { type LexicalNode, type TextNode } from '@ekz/lexical';
11
+ /**
12
+ * Returns true if the node can contain transformable markdown.
13
+ * Code nodes cannot contain transformable markdown.
14
+ * For example, `code **bold**` should not be transformed to
15
+ * <code>code <strong>bold</strong></code>.
16
+ */
17
+ export declare function canContainTransformableMarkdown(node: LexicalNode | undefined): node is TextNode;
18
+ /**
19
+ * Handles applying both text format and text match transformers.
20
+ * It finds the outermost text format or text match and applies it,
21
+ * then recursively calls itself to apply the next outermost transformer,
22
+ * until there are no more transformers to apply.
23
+ */
24
+ export declare function importTextTransformers(textNode: TextNode, textFormatTransformersIndex: TextFormatTransformersIndex, textMatchTransformers: Array<TextMatchTransformer>): void;
package/index.d.ts ADDED
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+ import type { ElementTransformer, MultilineElementTransformer, TextFormatTransformer, TextMatchTransformer, Transformer } from './MarkdownTransformers';
9
+ import type { ElementNode } from '@ekz/lexical';
10
+ import { registerMarkdownShortcuts } from './MarkdownShortcuts';
11
+ 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, ORDERED_LIST, QUOTE, STRIKETHROUGH, TEXT_FORMAT_TRANSFORMERS, TEXT_MATCH_TRANSFORMERS, TRANSFORMERS, UNORDERED_LIST } from './MarkdownTransformers';
12
+ /**
13
+ * Renders markdown from a string. The selection is moved to the start after the operation.
14
+ *
15
+ * @param {boolean} [shouldPreserveNewLines] By setting this to true, new lines will be preserved between conversions
16
+ * @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.
17
+ */
18
+ declare function $convertFromMarkdownString(markdown: string, transformers?: Array<Transformer>, node?: ElementNode, shouldPreserveNewLines?: boolean, shouldMergeAdjacentLines?: boolean): void;
19
+ /**
20
+ * Renders string from markdown. The selection is moved to the start after the operation.
21
+ */
22
+ declare function $convertToMarkdownString(transformers?: Array<Transformer>, node?: ElementNode, shouldPreserveNewLines?: boolean): string;
23
+ 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, ORDERED_LIST, QUOTE, registerMarkdownShortcuts, STRIKETHROUGH, TEXT_FORMAT_TRANSFORMERS, TEXT_MATCH_TRANSFORMERS, type TextFormatTransformer, type TextMatchTransformer, type Transformer, TRANSFORMERS, UNORDERED_LIST, };
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@ekz/lexical-markdown",
3
+ "description": "This package contains Markdown helpers and functionality for Lexical.",
4
+ "keywords": [
5
+ "lexical",
6
+ "editor",
7
+ "rich-text",
8
+ "markdown"
9
+ ],
10
+ "license": "MIT",
11
+ "version": "0.40.0",
12
+ "main": "LexicalMarkdown.js",
13
+ "types": "index.d.ts",
14
+ "dependencies": {
15
+ "@ekz/lexical-code": "0.40.0",
16
+ "@ekz/lexical-link": "0.40.0",
17
+ "@ekz/lexical-list": "0.40.0",
18
+ "@ekz/lexical-rich-text": "0.40.0",
19
+ "@ekz/lexical-text": "0.40.0",
20
+ "@ekz/lexical-utils": "0.40.0",
21
+ "@ekz/lexical": "0.40.0"
22
+ },
23
+ "repository": {
24
+ "type": "git",
25
+ "url": "git+https://github.com/facebook/lexical.git",
26
+ "directory": "packages/lexical-markdown"
27
+ },
28
+ "module": "LexicalMarkdown.mjs",
29
+ "sideEffects": false,
30
+ "exports": {
31
+ ".": {
32
+ "import": {
33
+ "types": "./index.d.ts",
34
+ "development": "./LexicalMarkdown.dev.mjs",
35
+ "production": "./LexicalMarkdown.prod.mjs",
36
+ "node": "./LexicalMarkdown.node.mjs",
37
+ "default": "./LexicalMarkdown.mjs"
38
+ },
39
+ "require": {
40
+ "types": "./index.d.ts",
41
+ "development": "./LexicalMarkdown.dev.js",
42
+ "production": "./LexicalMarkdown.prod.js",
43
+ "default": "./LexicalMarkdown.js"
44
+ }
45
+ }
46
+ }
47
+ }
package/utils.d.ts ADDED
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ *
7
+ */
8
+ import { type ElementNode, type LexicalNode, type TextFormatType } from '@ekz/lexical';
9
+ import { ElementTransformer, MultilineElementTransformer, TextFormatTransformer, TextMatchTransformer, Transformer } from './MarkdownTransformers';
10
+ type MarkdownFormatKind = 'noTransformation' | 'paragraphH1' | 'paragraphH2' | 'paragraphH3' | 'paragraphH4' | 'paragraphH5' | 'paragraphH6' | 'paragraphBlockQuote' | 'paragraphUnorderedList' | 'paragraphOrderedList' | 'paragraphCodeBlock' | 'horizontalRule' | 'bold' | 'code' | 'italic' | 'underline' | 'strikethrough' | 'italic_bold' | 'strikethrough_italic' | 'strikethrough_bold' | 'strikethrough_italic_bold' | 'link';
11
+ type MarkdownCriteria = Readonly<{
12
+ export?: (node: LexicalNode, traverseChildren: (elementNode: ElementNode) => string) => string | null;
13
+ exportFormat?: TextFormatType;
14
+ exportTag?: string;
15
+ exportTagClose?: string;
16
+ markdownFormatKind: MarkdownFormatKind | null | undefined;
17
+ regEx: RegExp;
18
+ regExForAutoFormatting: RegExp;
19
+ requiresParagraphStart: boolean | null | undefined;
20
+ }>;
21
+ type MarkdownCriteriaArray = Array<MarkdownCriteria>;
22
+ export declare function getAllMarkdownCriteriaForParagraphs(): MarkdownCriteriaArray;
23
+ export declare function getAllMarkdownCriteriaForTextNodes(): MarkdownCriteriaArray;
24
+ export declare function indexBy<T>(list: Array<T>, callback: (arg0: T) => string | undefined): Readonly<Record<string, Array<T>>>;
25
+ export declare function transformersByType(transformers: Array<Transformer>): Readonly<{
26
+ element: Array<ElementTransformer>;
27
+ multilineElement: Array<MultilineElementTransformer>;
28
+ textFormat: Array<TextFormatTransformer>;
29
+ textMatch: Array<TextMatchTransformer>;
30
+ }>;
31
+ export declare const PUNCTUATION_OR_SPACE: RegExp;
32
+ export declare const WHITESPACE: RegExp;
33
+ export declare const PUNCTUATION: RegExp;
34
+ export declare function isEmptyParagraph(node: LexicalNode): boolean;
35
+ export {};