Skip to content

Commit

Permalink
Fix zero-length Markdown headers (#47725)
Browse files Browse the repository at this point in the history
* Fix zero-length Markdown headers

* Add test on empty header
  • Loading branch information
adrhill authored Dec 27, 2022
1 parent 4c2a431 commit a40e24e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
3 changes: 2 additions & 1 deletion stdlib/Markdown/src/render/terminal/render.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ function _term_header(io::IO, md, char, columns)
if line_no > 1
line_width = max(line_width, div(columns, 3))
end
char != ' ' && print(io, '\n', ' '^(margin), char^(line_width-margin))
header_width = max(0, line_width-margin)
char != ' ' && header_width > 0 && print(io, '\n', ' '^(margin), char^header_width)
end
end

Expand Down
1 change: 1 addition & 0 deletions stdlib/Markdown/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ table = md"""
let out =
@test sprint(show, "text/plain", book) ==
" Title\n ≡≡≡≡≡\n\n Some discussion\n\n │ A quote\n\n Section important\n =================\n\n Some bolded\n\n • list1\n\n • list2"
@test sprint(show, "text/plain", md"#") == " " # edge case of empty header
@test sprint(show, "text/markdown", book) ==
"""
# Title
Expand Down

0 comments on commit a40e24e

Please sign in to comment.