Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/lexical-markdown/src/MarkdownTransformers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
$createTextNode,
$findMatchingParent,
$getState,
$isParagraphNode,
$setState,
createState,
ElementNode,
Expand Down Expand Up @@ -241,7 +242,12 @@ const createBlockNode = (
return (parentNode, children, match, isImport) => {
const node = createNode(match);
node.append(...children);
parentNode.replace(node);
if (!isImport && !$isParagraphNode(parentNode)) {
parentNode.clear();
parentNode.append(node);
} else {
Comment thread
achaljhawar marked this conversation as resolved.
Outdated
parentNode.replace(node);
}
if (!isImport) {
node.select(0, 0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import {buildEditorFromExtensions} from '@lexical/extension';
import {$createLinkNode, $isLinkNode, LinkExtension} from '@lexical/link';
import {ListExtension} from '@lexical/list';
import {registerMarkdownShortcuts} from '@lexical/markdown';
import {RichTextExtension} from '@lexical/rich-text';
import {
$isHeadingNode,
$isQuoteNode,
RichTextExtension,
} from '@lexical/rich-text';
import {
$createParagraphNode,
$createTextNode,
Expand Down Expand Up @@ -156,3 +160,19 @@ describe('LINK', () => {
});
});
});

describe('BLOCK QUOTE + HEADING', () => {
test('typing "> # SOME HEADER" creates a heading inside a quote (issue #7407)', () => {
Comment thread
achaljhawar marked this conversation as resolved.
Outdated
const editor = buildEditorFromExtensions([MarkdownShortcutTestExtension]);
typeMarkdown(editor, '> # SOME HEADER');
editor.read(() => {
const root = $getRoot();
const firstChild = root.getFirstChildOrThrow();
assert($isQuoteNode(firstChild), 'Root child must be a QuoteNode');
const quoteChild = firstChild.getFirstChildOrThrow();
assert($isHeadingNode(quoteChild), 'Quote child must be a HeadingNode');
expect(quoteChild.getTag()).toBe('h1');
expect(quoteChild.getTextContent()).toBe('SOME HEADER');
});
});
});
Loading