Skip to content

Commit

Permalink
Revert Blockuotes to quote all lines for proper rendering on GitHub.
Browse files Browse the repository at this point in the history
  • Loading branch information
eneko committed Oct 9, 2017
1 parent af05202 commit a4d7c2f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
6 changes: 5 additions & 1 deletion Sources/MarkdownGenerator/MarkdownBlockquotes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,12 @@ extension MarkdownConvertible {
/// "## H2 Header".blockquoted // > ## H2 Header
///
public var blockquoted: MarkdownConvertible {
let input = markdown
if input.isEmpty {
return ""
}
let lines = markdown.components(separatedBy: String.newLine)
let quoted: [String] = lines.flatMap { $0.isEmpty ? "" : "> \($0)" }
let quoted = lines.map { "> \($0)".trimmingCharacters(in: .whitespaces) }
return quoted.joined(separator: String.newLine)
}
}
21 changes: 14 additions & 7 deletions Tests/MarkdownGeneratorTests/MarkdownBlockquotesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ class MarkdownBlockquotesTests: XCTestCase {

let output = """
> ## This is a header.
>
> 1. This is the first list item.
> 2. This is the second list item.
>
> Here's some example code:
>
> return shell_exec("echo $input | $markdown_script");
>
> > This is a quote.
"""

Expand All @@ -49,13 +49,20 @@ class MarkdownBlockquotesTests: XCTestCase {
}

func testMultipleInputs() {
XCTAssertEqual([input, input].blockquoted.markdown, [output, output].joined(separator: "\n\n"))
XCTAssertEqual([input, input].blockquoted.markdown, [output, output].joined(separator: "\n>\n"))
}

func testSingleLine() {
let input = """
Single line of text.
"""
XCTAssertEqual(input.blockquoted.markdown, "> Single line of text.")
}

func testWhitespaces() {
XCTAssertEqual("".blockquoted.markdown, "")
XCTAssertEqual("\n".blockquoted.markdown, "\n")
XCTAssertEqual("\t".blockquoted.markdown, "> \t")
XCTAssertEqual("\n".blockquoted.markdown, ">\n>")
XCTAssertEqual("\t".blockquoted.markdown, ">")
}

}

0 comments on commit a4d7c2f

Please sign in to comment.