Skip to content

Commit 3bb9b8c

Browse files
author
ComputelessComputer
committed
fix empty lines lost on reload
1 parent fa04f5a commit 3bb9b8c

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

src/components/editor/extensions/paragraph/ParagraphExtension.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,32 @@
11
import { Paragraph, } from "@tiptap/extension-paragraph";
22

3+
const EMPTY_MARKER = "\u200B";
4+
35
export const CustomParagraph = Paragraph.extend({
6+
parseMarkdown: (token, helpers,) => {
7+
const tokens = token.tokens || [];
8+
9+
if (tokens.length === 1 && tokens[0].type === "image") {
10+
return helpers.parseChildren([tokens[0],],);
11+
}
12+
13+
const content = helpers.parseInline(tokens,);
14+
15+
if (
16+
content.length === 1
17+
&& content[0].type === "text"
18+
&& (content[0].text === EMPTY_MARKER || content[0].text === " " || content[0].text === "\u00A0")
19+
) {
20+
return helpers.createNode("paragraph", undefined, [],);
21+
}
22+
23+
return helpers.createNode("paragraph", undefined, content,);
24+
},
25+
426
renderMarkdown: (node, helpers,) => {
527
const content = helpers.renderChildren(node.content || [],);
628
if (content === "") {
7-
return "\u200B\n\n";
29+
return `${EMPTY_MARKER}\n\n`;
830
}
931
return `${content}\n\n`;
1032
},

0 commit comments

Comments
 (0)