|
@@ -145,9 +145,26 @@ export function splitMarkdownIntoBlocks(
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* Serialize an array of editor blocks back to markdown.
|
|
* Serialize an array of editor blocks back to markdown.
|
|
|
|
|
+ *
|
|
|
|
|
+ * Continuation lines (second and subsequent lines within a single block's
|
|
|
|
|
+ * content) are indented by `(depth + 1) * 2` spaces so the markdown stays
|
|
|
|
|
+ * structurally valid — continuation paragraphs remain inside the list item.
|
|
|
*/
|
|
*/
|
|
|
export function serializeBlocks(blocks: EditorBlock[]): string {
|
|
export function serializeBlocks(blocks: EditorBlock[]): string {
|
|
|
return blocks
|
|
return blocks
|
|
|
- .map((block) => `${" ".repeat(block.depth)}* ${block.content}`)
|
|
|
|
|
|
|
+ .map((block) => {
|
|
|
|
|
+ const indent = " ".repeat(block.depth)
|
|
|
|
|
+ const prefix = `${indent}* `
|
|
|
|
|
+ const lines = block.content.split("\n")
|
|
|
|
|
+ const continuationIndent = " ".repeat((block.depth + 1) * 2)
|
|
|
|
|
+ return lines
|
|
|
|
|
+ .map((line, i) => {
|
|
|
|
|
+ if (i === 0) return `${prefix}${line}`
|
|
|
|
|
+ if (!line.trim()) return line
|
|
|
|
|
+ const trimmed = line.trimStart()
|
|
|
|
|
+ return `${continuationIndent}${trimmed}`
|
|
|
|
|
+ })
|
|
|
|
|
+ .join("\n")
|
|
|
|
|
+ })
|
|
|
.join("\n")
|
|
.join("\n")
|
|
|
}
|
|
}
|