Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions .changeset/block-blank-before.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@meowdown/markdown': minor
'@meowdown/core': minor
---

Keep blocks that the source writes without a blank line between them on adjacent lines.
16 changes: 11 additions & 5 deletions packages/core/src/converters/ast-to-pm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,30 @@ export function astToDoc(
nodes: TypedNodeBuilders = getNodeBuilders(),
): ProseMirrorNode {
const children = node.children?.map((child) => astToDoc(child, nodes)) || []
const blankBefore =
node.type === 'document' || node.type === 'tableRow' || node.type === 'tableCell'
? null
: (node.blankBefore ?? null)
switch (node.type) {
case 'document':
return nodes.doc(
{ frontmatter: node.frontmatter ?? null, frontmatterTight: !!node.frontmatterTight },
children,
)
case 'paragraph':
return nodes.paragraph(node.value)
return nodes.paragraph({ blankBefore }, node.value)
case 'heading':
return nodes.heading(
{
level: node.level,
setextUnderline: node.setextUnderline ?? null,
closingHashes: node.closingHashes ?? null,
blankBefore,
},
node.value,
)
case 'blockquote':
return nodes.blockquote(children)
return nodes.blockquote({ blankBefore }, children)
case 'listItem':
return nodes.list(
{
Expand All @@ -40,7 +45,7 @@ export function astToDoc(
marker: node.marker ?? null,
taskMarker: node.taskMarker,
markerGap: node.markerGap,
blankBefore: node.blankBefore ?? null,
blankBefore,
},
children,
)
Expand All @@ -50,13 +55,14 @@ export function astToDoc(
language: node.language,
fenceStyle: node.fenceStyle ?? null,
fenceLength: node.fenceLength ?? null,
blankBefore,
},
node.value,
)
case 'horizontalRule':
return nodes.horizontalRule({ marker: node.marker ?? null })
return nodes.horizontalRule({ marker: node.marker ?? null, blankBefore })
case 'htmlComment':
return nodes.htmlComment({ content: node.value })
return nodes.htmlComment({ content: node.value, blankBefore })
case 'table':
return nodes.table(children)
case 'tableRow':
Expand Down
Loading
Loading