Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix markdown list rendering #40203

Merged
merged 1 commit into from
Mar 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions stdlib/Markdown/src/render/terminal/formatting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) =
Expand Down
8 changes: 8 additions & 0 deletions stdlib/Markdown/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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