Skip to content

Commit

Permalink
markdown: support formatting that extends to sibling nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
robfig committed Oct 22, 2023
1 parent e78ccdc commit 5aeee75
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 3 additions & 2 deletions packages/lexical-markdown/src/MarkdownExport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import type {
} from '@lexical/markdown';
import type {ElementNode, LexicalNode, TextFormatType, TextNode} from 'lexical';

import {$isLinkNode} from '@lexical/link';
import {
$getRoot,
$isDecoratorNode,
Expand Down Expand Up @@ -176,7 +177,7 @@ function getTextSibling(node: TextNode, backward: boolean): TextNode | null {
if (!sibling) {
const parent = node.getParentOrThrow();

if (parent.isInline()) {
if (parent.isInline() && !$isLinkNode(parent)) {
sibling = backward
? parent.getPreviousSibling()
: parent.getNextSibling();
Expand All @@ -185,7 +186,7 @@ function getTextSibling(node: TextNode, backward: boolean): TextNode | null {

while (sibling) {
if ($isElementNode(sibling)) {
if (!sibling.isInline()) {
if (!sibling.isInline() || $isLinkNode(sibling)) {
break;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ describe('Markdown', () => {
html: '<p><span style="white-space: pre-wrap;">Hello </span><a href="https://lexical.dev"><code spellcheck="false" style="white-space: pre-wrap;"><span>XXX</span></code></a><span style="white-space: pre-wrap;"> world</span></p>',
md: 'Hello [`XXX`](https://lexical.dev) world',
},
{
html: '<p><code spellcheck="false" style="white-space: pre-wrap;"><span>Hello</span></code><span style="white-space: pre-wrap;"> </span><a href="https://lexical.dev"><code spellcheck="false" style="white-space: pre-wrap;"><span>XXY</span></code></a></p>',
md: '`Hello` [`XXY`](https://lexical.dev)',
},
{
html: '<p><s><span style="white-space: pre-wrap;">Hello</span></s><span style="white-space: pre-wrap;"> world</span></p>',
md: '~~Hello~~ world',
Expand Down

0 comments on commit 5aeee75

Please sign in to comment.