Add html rendering of Markdown tables

pull/221/head
Tommy Hofmann 2019-06-21 13:27:29 +02:00
parent 9e462a480b
commit 1c0506342e
2 changed files with 20 additions and 1 deletions

View File

@ -1,6 +1,6 @@
#module Markdown2HTML
# Markdown to HTML writer, Modified from Julia Base.Markdown html writer
using Markdown: MD, Header, Code, Paragraph, BlockQuote, Footnote,
using Markdown: MD, Header, Code, Paragraph, BlockQuote, Footnote, Table,
Admonition, List, HorizontalRule, Bold, Italic, Image, Link, LineBreak,
LaTeX, isordered
@ -167,6 +167,20 @@ function html(io::IO, comment::Comment)
write(io, "\n<!-- $(comment.text) -->\n")
end
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
htmlinline(io, c)
end
end
end
end
end
end
html(io::IO, x) = tohtml(io, x)
# Inline elements

View File

@ -39,6 +39,10 @@ x = 3
> Some important quote
head 1 | head 2
-------|--------
`code` | no code
""", flavor = WeaveMarkdown.weavemd))
ref_html = """<h1>H1</h1>
@ -70,6 +74,7 @@ more math
<blockquote>
<p>Some important quote</p>
</blockquote>
<table><tr><th>head 1</th><th>head 2</th></tr><tr><td><code>code</code></td><td>no code</td></tr></table>
"""
@test html == ref_html