Skip to content

Commit 8a4b9e2

Browse files
committed
fix markdown list rendering (#40203)
(cherry picked from commit 0f828a2)
1 parent fb4a489 commit 8a4b9e2

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

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

Lines changed: 8 additions & 10 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_line(io::IO, s::AbstractString, width, i)
1313
ws = words(s)
14+
lines = String[]
1415
for word in ws
1516
word_length = ansi_length(word)
1617
word_length == 0 && continue
@@ -22,19 +23,16 @@ function wrapped_lines!(lines, io::IO, s::AbstractString, width, i)
2223
lines[end] *= " " * word # this could be more efficient
2324
end
2425
end
25-
return i
26+
return i, lines
2627
end
2728

2829
function wrapped_lines(io::IO, s::AbstractString; width = 80, i = 0)
29-
lines = AbstractString[]
30-
if occursin(r"\n", s)
31-
for ss in split(s, "\n")
32-
i = wrapped_lines!(lines, io, ss, width, i)
33-
end
34-
else
35-
wrapped_lines!(lines, io, s, width, i)
30+
ls = String[]
31+
for ss in lines(s)
32+
i, line = wrapped_line(io, ss, width, i)
33+
append!(ls, line)
3634
end
37-
return lines
35+
return ls
3836
end
3937

4038
wrapped_lines(io::IO, f::Function, args...; width = 80, i = 0) =

stdlib/Markdown/test/runtests.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,3 +1222,11 @@ end
12221222
""")
12231223
end
12241224

1225+
@testset "issue #37232: linebreaks" begin
1226+
s = @md_str """
1227+
Misc:\\
1228+
- line\\
1229+
"""
1230+
@test sprint(show, MIME("text/plain"), s) == " Misc:\n - line"
1231+
end
1232+

0 commit comments

Comments
 (0)