Skip to content

Commit 397a781

Browse files
haydtkelman
authored andcommitted
Fix rendering bug of Markdown Code.
When a code block included a ```, it would not be rendered correctly. (cherry picked from commit 60eda14) ref #14638
1 parent 147d6d0 commit 397a781

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

base/markdown/render/plain.jl

+5-2
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@ function plain{l}(io::IO, header::Header{l})
2020
end
2121

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

2831
function plain(io::IO, p::Paragraph)

test/markdown.jl

+8
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ foo
4141
@test md"``code```more code``" == MD(Any[Paragraph(Any[Code("","code```more code")])])
4242
@test md"``code``````more code``" == MD(Any[Paragraph(Any[Code("","code``````more code")])])
4343

44+
code_in_code = md"""
45+
````
46+
```
47+
````
48+
"""
49+
@test code_in_code == MD(Code("```"))
50+
@test plain(code_in_code) == "````\n```\n````\n"
51+
4452
@test md"""
4553
* one
4654
* two

0 commit comments

Comments
 (0)