From f6692582c26fd8d8f01df997e8f3f8a60ed2e6a7 Mon Sep 17 00:00:00 2001 From: KristofferC Date: Fri, 26 Mar 2021 09:27:48 +0100 Subject: [PATCH] fix markdown list rendering --- .../Markdown/src/render/terminal/formatting.jl | 18 ++++++++---------- stdlib/Markdown/test/runtests.jl | 8 ++++++++ 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/stdlib/Markdown/src/render/terminal/formatting.jl b/stdlib/Markdown/src/render/terminal/formatting.jl index bacd82f7ed021..87022124b9c8a 100644 --- a/stdlib/Markdown/src/render/terminal/formatting.jl +++ b/stdlib/Markdown/src/render/terminal/formatting.jl @@ -9,8 +9,9 @@ end words(s) = split(s, " ") lines(s) = split(s, "\n") -function wrapped_lines!(lines, io::IO, s::AbstractString, width, i) +function wrapped_line(io::IO, s::AbstractString, width, i) ws = words(s) + lines = String[] for word in ws word_length = ansi_length(word) word_length == 0 && continue @@ -22,19 +23,16 @@ function wrapped_lines!(lines, io::IO, s::AbstractString, width, i) lines[end] *= " " * word # this could be more efficient end end - return i + return i, lines end function wrapped_lines(io::IO, s::AbstractString; width = 80, i = 0) - lines = AbstractString[] - if occursin(r"\n", s) - for ss in split(s, "\n") - i = wrapped_lines!(lines, io, ss, width, i) - end - else - wrapped_lines!(lines, io, s, width, i) + ls = String[] + for ss in lines(s) + i, line = wrapped_line(io, ss, width, i) + append!(ls, line) end - return lines + return ls end wrapped_lines(io::IO, f::Function, args...; width = 80, i = 0) = diff --git a/stdlib/Markdown/test/runtests.jl b/stdlib/Markdown/test/runtests.jl index f9983d10089f9..f90eefb85310e 100644 --- a/stdlib/Markdown/test/runtests.jl +++ b/stdlib/Markdown/test/runtests.jl @@ -1222,3 +1222,11 @@ end """) end +@testset "issue #37232: linebreaks" begin + s = @md_str """ + Misc:\\ + - line\\ + """ + @test sprint(show, MIME("text/plain"), s) == " Misc:\n - line" +end +