Skip to content

Commit

Permalink
Fix rendering bug of Markdown Code.
Browse files Browse the repository at this point in the history
When a code block included a ```, it would not be rendered correctly.

(cherry picked from commit 60eda14)
ref #14638
  • Loading branch information
hayd authored and tkelman committed Mar 7, 2016
1 parent 147d6d0 commit 397a781
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
7 changes: 5 additions & 2 deletions base/markdown/render/plain.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ function plain{l}(io::IO, header::Header{l})
end

function plain(io::IO, code::Code)
println(io, "```", code.language)
# If the code includes a fenced block this will break parsing,
# so it must be enclosed by a longer ````-sequence.
n = mapreduce(length, max, 2, matchall(r"^`+"m, code.code)) + 1
println(io, "`" ^ n, code.language)
println(io, code.code)
println(io, "```")
println(io, "`" ^ n)
end

function plain(io::IO, p::Paragraph)
Expand Down
8 changes: 8 additions & 0 deletions test/markdown.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ foo
@test md"``code```more code``" == MD(Any[Paragraph(Any[Code("","code```more code")])])
@test md"``code``````more code``" == MD(Any[Paragraph(Any[Code("","code``````more code")])])

code_in_code = md"""
````
```
````
"""
@test code_in_code == MD(Code("```"))
@test plain(code_in_code) == "````\n```\n````\n"

@test md"""
* one
* two
Expand Down

0 comments on commit 397a781

Please sign in to comment.