From 1c0506342e6f3ced7770d285574fe09558cefa65 Mon Sep 17 00:00:00 2001 From: Tommy Hofmann Date: Fri, 21 Jun 2019 13:27:29 +0200 Subject: [PATCH] Add html rendering of Markdown tables --- src/WeaveMarkdown/html.jl | 16 +++++++++++++++- test/markdown_test.jl | 5 +++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/WeaveMarkdown/html.jl b/src/WeaveMarkdown/html.jl index 470ff7f..16a3011 100644 --- a/src/WeaveMarkdown/html.jl +++ b/src/WeaveMarkdown/html.jl @@ -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\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 diff --git a/test/markdown_test.jl b/test/markdown_test.jl index 5a05112..ce54618 100644 --- a/test/markdown_test.jl +++ b/test/markdown_test.jl @@ -39,6 +39,10 @@ x = 3 > Some important quote +head 1 | head 2 +-------|-------- +`code` | no code + """, flavor = WeaveMarkdown.weavemd)) ref_html = """

H1

@@ -70,6 +74,7 @@ more math

Some important quote

+
head 1head 2
codeno code
""" @test html == ref_html