Skip to content

Commit 36505aa

Browse files
authored
fix markdown rendering (#37235)
1 parent c10c451 commit 36505aa

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

stdlib/Markdown/src/render/terminal/formatting.jl

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ end
99
words(s) = split(s, " ")
1010
lines(s) = split(s, "\n")
1111

12-
function wrapped_lines!(lines, io::IO, s::AbstractString, width, i)
12+
function _wrapped_lines(s::AbstractString, width, i)
1313
ws = words(s)
14+
lines = String[]
1415
for word in ws
1516
word_length = ansi_length(word)
1617
if i + word_length + 1 > width
@@ -25,17 +26,14 @@ function wrapped_lines!(lines, io::IO, s::AbstractString, width, i)
2526
end
2627
end
2728
end
28-
return i
29+
return i, lines
2930
end
3031

3132
function wrapped_lines(io::IO, s::AbstractString; width = 80, i = 0)
32-
lines = AbstractString[]
33-
if occursin(r"\n", s)
34-
for ss in split(s, "\n")
35-
i = wrapped_lines!(lines, io, ss, width, i)
36-
end
37-
else
38-
wrapped_lines!(lines, io, s, width, i)
33+
lines = String[]
34+
for ss in split(s, "\n")
35+
i, line = _wrapped_lines(ss, width, i)
36+
append!(lines, line)
3937
end
4038
return lines
4139
end

stdlib/Markdown/test/runtests.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,3 +1158,11 @@ end
11581158
| $x |
11591159
""")
11601160
end
1161+
1162+
@testset "issue #37232: linebreaks" begin
1163+
s = @md_str """
1164+
Misc:\\
1165+
- line\\
1166+
"""
1167+
@test sprint(show, MIME("text/plain"), s) == " Misc:\n - line\n "
1168+
end

0 commit comments

Comments
 (0)