Skip to content

Commit b97efac

Browse files
committed
Merge pull request #14638 from hayd/fix_plain_code
Fix rendering bug of Markdown Code.
2 parents 95a01df + 60eda14 commit b97efac

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
@@ -47,6 +47,14 @@ foo
4747
```
4848
""" == MD(LaTeX("..."))
4949

50+
code_in_code = md"""
51+
````
52+
```
53+
````
54+
"""
55+
@test code_in_code == MD(Code("```"))
56+
@test plain(code_in_code) == "````\n```\n````\n"
57+
5058
@test md"A footnote [^foo]." == MD(Paragraph(["A footnote ", Footnote("foo", nothing), "."]))
5159

5260
@test md"[^foo]: footnote" == MD(Paragraph([Footnote("foo", Any[" footnote"])]))

0 commit comments

Comments
 (0)