Skip to content

Commit dd750f3

Browse files
committed
Fix Blockquote for empty lines
1 parent 65c2df3 commit dd750f3

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

Sources/MarkdownGenerator/MarkdownBlockquotes.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ extension MarkdownConvertible {
4242
/// "## H2 Header".blockquoted // > ## H2 Header
4343
///
4444
public var blockquoted: MarkdownConvertible {
45-
return markdown.components(separatedBy: String.newLine).map { "> \($0)".trimmingCharacters(in: .whitespaces) }.joined(separator: String.newLine)
45+
let lines = markdown.components(separatedBy: String.newLine)
46+
let quoted: [String] = lines.flatMap { $0.isEmpty ? "" : "> \($0)" }
47+
return quoted.joined(separator: String.newLine)
4648
}
4749
}

Tests/MarkdownGeneratorTests/MarkdownBlockquotesTests.swift

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ class MarkdownBlockquotesTests: XCTestCase {
2525

2626
let output = """
2727
> ## This is a header.
28-
>
28+
2929
> 1. This is the first list item.
3030
> 2. This is the second list item.
31-
>
31+
3232
> Here's some example code:
33-
>
33+
3434
> return shell_exec("echo $input | $markdown_script");
35-
>
35+
3636
> > This is a quote.
3737
"""
3838

@@ -49,7 +49,13 @@ class MarkdownBlockquotesTests: XCTestCase {
4949
}
5050

5151
func testMultipleInputs() {
52-
XCTAssertEqual([input, input].blockquoted.markdown, [output, output].joined(separator: "\n>\n"))
52+
XCTAssertEqual([input, input].blockquoted.markdown, [output, output].joined(separator: "\n\n"))
53+
}
54+
55+
func testWhitespaces() {
56+
XCTAssertEqual("".blockquoted.markdown, "")
57+
XCTAssertEqual("\n".blockquoted.markdown, "\n")
58+
XCTAssertEqual("\t".blockquoted.markdown, "> \t")
5359
}
5460

5561
}

0 commit comments

Comments
 (0)