Skip to content

Commit

Permalink
table column alignment in html output (#33849)
Browse files Browse the repository at this point in the history
  • Loading branch information
pfitzseb authored and KristofferC committed Apr 11, 2020
1 parent fd44424 commit 780e178
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 4 additions & 2 deletions stdlib/Markdown/src/GitHub/table.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ function html(io::IO, md::Table)
withtag(io, :table) do
for (i, row) in enumerate(md.rows)
withtag(io, :tr) do
for c in md.rows[i]
withtag(io, i == 1 ? :th : :td) do
for (j, c) in enumerate(md.rows[i])
alignment = md.align[j]
alignment = alignment === :l ? "left" : alignment === :r ? "right" : "center"
withtag(io, i == 1 ? :th : :td, ("align", alignment)) do
htmlinline(io, c)
end
end
Expand Down
2 changes: 2 additions & 0 deletions stdlib/Markdown/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,7 @@ let text =
""",
table = Markdown.parse(text)
@test text == Markdown.plain(table)
@test Markdown.html(table) == """<table><tr><th align="left">Markdown</th><th align="center">Table</th><th align="right">Test</th></tr><tr><td align="left">foo</td><td align="center"><code>bar</code></td><td align="right"><em>baz</em></td></tr><tr><td align="left"><code>bar</code></td><td align="center">baz</td><td align="right"><em>foo</em></td></tr></table>\n"""
end
let text =
"""
Expand All @@ -519,6 +520,7 @@ let text =
""",
table = Markdown.parse(text)
@test text == Markdown.plain(table)
@test Markdown.html(table) == """<table><tr><th align="left">a</th><th align="right">b</th></tr><tr><td align="left"><code>x | y</code></td><td align="right">2</td></tr></table>\n"""
end

# LaTeX extension
Expand Down

0 comments on commit 780e178

Please sign in to comment.