Skip to content

Commit a4d7c2f

Browse files
committed
Revert Blockuotes to quote all lines for proper rendering on GitHub.
1 parent af05202 commit a4d7c2f

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

Sources/MarkdownGenerator/MarkdownBlockquotes.swift

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

Tests/MarkdownGeneratorTests/MarkdownBlockquotesTests.swift

Lines changed: 14 additions & 7 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,13 +49,20 @@ 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 testSingleLine() {
56+
let input = """
57+
Single line of text.
58+
"""
59+
XCTAssertEqual(input.blockquoted.markdown, "> Single line of text.")
5360
}
5461

5562
func testWhitespaces() {
5663
XCTAssertEqual("".blockquoted.markdown, "")
57-
XCTAssertEqual("\n".blockquoted.markdown, "\n")
58-
XCTAssertEqual("\t".blockquoted.markdown, "> \t")
64+
XCTAssertEqual("\n".blockquoted.markdown, ">\n>")
65+
XCTAssertEqual("\t".blockquoted.markdown, ">")
5966
}
6067

6168
}

0 commit comments

Comments
 (0)