Merge pull request #221 from thofma/master

Add html rendering of Markdown tables
pull/224/head
Sebastian Pfitzner 2019-06-26 12:10:46 +02:00 committed by GitHub
commit ed41be610a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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