replace ->,<- and <-> by the matching arrow characters in super notes

This commit is contained in:
mhermann 2024-01-03 18:16:32 +01:00
parent 3bb8ffbbe0
commit 2ed468a7dc

View file

@ -25,7 +25,7 @@ import {
$createHorizontalRuleNode,
$isHorizontalRuleNode,
} from '@lexical/react/LexicalHorizontalRuleNode'
import { $isParagraphNode, $isTextNode, LexicalNode } from 'lexical'
import { $isParagraphNode, $isTextNode, LexicalNode, $createTextNode } from 'lexical'
import {
$createRemoteImageNode,
$isRemoteImageNode,
@ -73,6 +73,42 @@ const IMAGE: TextMatchTransformer = {
type: 'text-match',
}
export const ARROW_DOUBLE: TextMatchTransformer = {
dependencies: [],
export: () => null,
importRegExp: /<-> /,
regExp: /<-> $/,
replace: (textNode) => {
textNode.replace($createTextNode('↔ '))
},
trigger: ' ',
type: 'text-match',
}
export const ARROW_RIGHT: TextMatchTransformer = {
dependencies: [],
export: () => null,
importRegExp: /-> /,
regExp: /-> $/,
replace: (textNode) => {
textNode.replace($createTextNode('→ '))
},
trigger: ' ',
type: 'text-match',
}
export const ARROW_LEFT: TextMatchTransformer = {
dependencies: [],
export: () => null,
importRegExp: /<- /,
regExp: /<- $/,
replace: (textNode) => {
textNode.replace($createTextNode('← '))
},
trigger: ' ',
type: 'text-match',
}
const INLINE_FILE: TextMatchTransformer = {
dependencies: [InlineFileNode],
export: (node) => {
@ -246,6 +282,9 @@ export const MarkdownTransformers = [
CHECK_LIST,
IMAGE,
INLINE_FILE,
ARROW_DOUBLE,
ARROW_RIGHT,
ARROW_LEFT,
...ELEMENT_TRANSFORMERS,
...TEXT_FORMAT_TRANSFORMERS,
...TEXT_MATCH_TRANSFORMERS,