fix: Remove slashes and literal newlines from markdown, closes #7691

This commit is contained in:
Tom Moor committed 2024-10-07 23:01:07 -04:00
1 parent a0e363799c
commit ba5eb60825
4 files changed
+9 -4

No files matched your search

+3 -1
View File
@@ -643,7 +643,9 @@ export default class Document extends ArchivableModel {
nodes: extensionManager.nodes,
marks: extensionManager.marks,
});
const markdown = serializer.serialize(Node.fromJSON(schema, this.data));
const markdown = serializer.serialize(Node.fromJSON(schema, this.data), {
softBreak: true,
});
return markdown;
};
+4 -1
View File
@@ -3,6 +3,8 @@
// https://raw.githubusercontent.com/ProseMirror/prosemirror-markdown/master/src/to_markdown.js
// forked for table support
type Options = { tightLists?: boolean; softBreak?: boolean };
// ::- A specification for serializing a ProseMirror document as
// Markdown/CommonMark text.
export class MarkdownSerializer {
@@ -50,7 +52,7 @@ export class MarkdownSerializer {
// :: (Node, ?Object) → string
// Serialize the content of the given node to
// [CommonMark](http://commonmark.org/).
serialize(content, options?: { tightLists?: boolean }): string {
serialize(content, options?: Options): string {
const state = new MarkdownSerializerState(this.nodes, this.marks, options);
state.renderContent(content);
return state.out;
@@ -66,6 +68,7 @@ export class MarkdownSerializerState {
inTightList = false;
closed = false;
delim = "";
options: Options;
constructor(nodes, marks, options) {
this.nodes = nodes;
+1 -1
View File
@@ -55,7 +55,7 @@ export default class HardBreak extends Node {
}
toMarkdown(state: MarkdownSerializerState) {
state.write("\\n");
state.write(state.options.softBreak ? "\n" : "\\n");
}
parseMarkdown() {
+1 -1
View File
@@ -37,7 +37,7 @@ export default class Paragraph extends Node {
node.childCount === 0 &&
!state.inTable
) {
state.write("\\\n");
state.write(state.options.softBreak ? "\n" : "\\\n");
} else {
state.renderInline(node);
state.closeBlock(node);