Skip to content

Commit

Permalink
Hide multiple spaces when rendering markdown.
Browse files Browse the repository at this point in the history
This mirrors html rendering.

Test markdown's terminal output.
  • Loading branch information
hayd committed Oct 31, 2015
1 parent d0f9e12 commit 4e3aa06
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
5 changes: 2 additions & 3 deletions base/markdown/render/terminal/render.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ function term(io::IO, md::BlockQuote, columns)
for line in split(rstrip(s), "\n")
println(io, " "^margin, "|", line)
end
println(io)
end

function term(io::IO, md::List, columns)
Expand Down Expand Up @@ -93,7 +92,7 @@ function terminline(io::IO, content::Vector)
end

function terminline(io::IO, md::AbstractString)
print(io, md)
print(io, replace(md, r"[\s\t\n]+", " "))
end

function terminline(io::IO, md::Bold)
Expand All @@ -109,7 +108,7 @@ function terminline(io::IO, md::LineBreak)
end

function terminline(io::IO, md::Image)
print(io, "(Image: $(md.alt))")
terminline(io, "(Image: $(md.alt))")
end

function terminline(io::IO, md::Link)
Expand Down
14 changes: 14 additions & 0 deletions test/markdown.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,20 @@ World""" |> plain == "Hello\n\n–––\n\nWorld\n"
> baz
> ```""" |> plain == """> foo\n>\n> * bar\n>\n> ```\n> baz\n> ```\n\n"""

# Terminal (markdown) output

# multiple whitespace is ignored
@test sprint(term, md"a b") == " a b\n"
@test sprint(term, md"- a
not code") == " • a not code\n"
@test sprint(term, md"[x](https://julialang.org)") == " x\n"
@test sprint(term, md"![x](https://julialang.org)") == " (Image: x)\n"

# enumeration is normalized
@test sprint(term, md"""
1. a
3. b""") == " 1. a\n 2. b\n"

# HTML output

@test md"foo *bar* baz" |> html == "<p>foo <em>bar</em> baz</p>\n"
Expand Down

0 comments on commit 4e3aa06

Please sign in to comment.