Skip to content

Commit 006a478

Browse files
CopilotDongyuZhao
andcommitted
Fix soft line break issue in blockquote test case and paragraph processing
Co-authored-by: DongyuZhao <8455725+DongyuZhao@users.noreply.github.com>
1 parent 4ed6172 commit 006a478

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

Sources/CodeParserCollection/Markdown/Nodes/MarkdownParagraphBuilder.swift

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,22 @@ public class MarkdownParagraphBuilder: MarkdownBlockBuilderProtocol {
8181
}
8282
}
8383

84-
// Only add separators if there's actual content and this line has content
85-
if !paragraph.children.isEmpty && !contentTokens.isEmpty && endsWithHardBreak {
86-
// Only add hard line breaks - soft line breaks are implicit in AST
87-
let lineBreakToken = createLineBreakToken("__HARD_LINE_BREAK__")
88-
let lineBreakNodes = inlineProcessor.processInlineTokens([lineBreakToken])
89-
for node in lineBreakNodes {
90-
paragraph.children.append(node)
84+
// Add line breaks for continuation lines if there's existing content and this line has content
85+
if !paragraph.children.isEmpty && !contentTokens.isEmpty {
86+
if endsWithHardBreak {
87+
// Add hard line break for lines ending with two spaces or backslash
88+
let lineBreakToken = createLineBreakToken("__HARD_LINE_BREAK__")
89+
let lineBreakNodes = inlineProcessor.processInlineTokens([lineBreakToken])
90+
for node in lineBreakNodes {
91+
paragraph.children.append(node)
92+
}
93+
} else {
94+
// Add soft line break for regular continuation lines
95+
let lineBreakToken = createLineBreakToken("__SOFT_LINE_BREAK__")
96+
let lineBreakNodes = inlineProcessor.processInlineTokens([lineBreakToken])
97+
for node in lineBreakNodes {
98+
paragraph.children.append(node)
99+
}
91100
}
92101
}
93102

Tests/CodeParserCollectionTests/Markdown/Nodes/MarkdownBlockQuotesTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ struct MarkdownBlockQuotesTests {
217217
"""
218218
let result = parser.parse(input, language: language)
219219

220-
let expectedSig = "document[blockquote[paragraph[text(\"foo\"),text(\"bar\")]]]"
220+
let expectedSig = "document[blockquote[paragraph[text(\"foo\"),line_break(soft),text(\"bar\")]]]"
221221
#expect(sig(result.root) == expectedSig)
222222
}
223223

0 commit comments

Comments
 (0)