diff --git a/stdlib/Markdown/src/render/terminal/formatting.jl b/stdlib/Markdown/src/render/terminal/formatting.jl index 4fd1cccedf7fb..bacd82f7ed021 100644 --- a/stdlib/Markdown/src/render/terminal/formatting.jl +++ b/stdlib/Markdown/src/render/terminal/formatting.jl @@ -42,6 +42,7 @@ wrapped_lines(io::IO, f::Function, args...; width = 80, i = 0) = function print_wrapped(io::IO, s...; width = 80, pre = "", i = 0) lines = wrapped_lines(io, s..., width = width, i = i) + isempty(lines) && return 0, 0 print(io, lines[1]) for line in lines[2:end] print(io, '\n', pre, line) diff --git a/stdlib/Markdown/test/runtests.jl b/stdlib/Markdown/test/runtests.jl index 286004707b8bd..f9983d10089f9 100644 --- a/stdlib/Markdown/test/runtests.jl +++ b/stdlib/Markdown/test/runtests.jl @@ -1213,3 +1213,12 @@ end | $x | """) end + +@testset "issue 40080: empty list item breaks display()" begin + d = TextDisplay(devnull) + display(d, md""" + 1. hello + 2. + """) +end +