const CODE: TextMatchTransformer = { dependencies: [CodeNode], export: (node: LexicalNode) => { if (!$isCodeNode(node)) { return null; } const textContent = node.getTextContent(); return '```' + (node.getLanguage() ?? '') + (textContent ? '\n' + textContent : '') + '\n' + '```'; }, importRegExp: /```$/, regExp: /```$/, trigger: '`', replace: (textNode) => { const codeNode = $createCodeNode(); const textNodeClone = $createTextNode(textNode.getTextContent().replace(/```$/, '')); const textNodeParent = textNode.getParent(); const selection = $getSelection(); if (textNodeParent) { const siblings = textNodeParent.getChildren(); if (siblings.length > 2 || (siblings.length > 1 && textNode === siblings.at(-1))) { selection?.insertNodes([codeNode]); } else { if ($isRangeSelection(selection)) { codeNode.append(textNode); $setBlocksType(selection, () => codeNode); } } textNode.replace(textNodeClone); } codeNode.select(0, 0); }, type: 'text-match', };