Including raw HTML in Julia Markdown

Hi,
I am trying to create a report in Julia markdown using the Weave.jl Package. However, I got stuck when using raw HTML or JavaScript in the document as it does not get rendered correctly. Using pandoc to convert the markdown to HTML works fine when using pandoc markdown. My questions are:

  1. Is raw HTML and JavaScript allowed in Julia markdown?
  2. Is there anyway to add this functionality in Julia Markdown (Some resources would be helpful) or using pandoc is the only way for such reports for now?

There was one other topic similar to this last year which did not get answered, so I was wondering if something changed in this time.

Preserving HTML when processing Markdown

Thanks for your time.

2 Likes

How about using @raw html block in Documenter?

1 Like

Thank You @tkf . I guess this is the way I need to proceed even though it may be slightly cumbersome to include Documenter.jl markdown parsing into Weave.jl.

Is it too crazy to just use Documenter.jl instead of Weave.jl? You can use @example and @eval to execute Julia code. Isn’t it the main feature of Weave.jl? I’ve never used Weave.jl (as I use Literate.jl + Documenter.jl for literate programming) so I may be missing something, though.

1 Like

I asked the question here : plain html in julia markdown - Stack Overflow for builtin Julia Markdown. Did you get an answer that could fit?

Raw HTML in Markdown is at best a workaround, and it should not be encouraged — that Markdown may need to be rendered as something other than HTML.

What is the problem that you are trying to solve? Can’t you achieve it with CSS?

2 Likes

I’m used to include basic html in my markdown files, let’s say to add a class to an image or to use features not covered by markdown. That’s why I was surprised Base.Markdown escaping all html. But I can escape myself what needs to be escaped and silence the existing escape function. This is an other workaround.

There are CSS-based techniques for that, eg see the “Use CSS And Special URL Parameters” section here.

Originally Markdown was indeed developed for mixing in HTML entities. Then people started to utilize it as a general markup language for rendering to various other formats, which is pretty much the way Julia uses it. This use case does not mix well with HTML entities.

1 Like

I did not know these CSS selectors. They require a separate stylesheet because for the same reason I can not include a <style> tag. I’m going to think about it…

An alternative is to use an auxiliary function fd2html exported by Franklin.jl which supports inclusion of HTML blocks. I’m not sure of your use case but assuming you want to write in Markdown and get some resulting HTML then that would do the job:

julia> using Franklin
julia> s = """
    Some **Markdown** with _emphasis_ and `inline` code and then
    ~~~
    <div class="blah">Hello</div>
    ~~~
    Then more [markdown](https://daringfireball.net/projects/markdown/).
    """
julia> println(s |> fd2html)
<p>Some <strong>Markdown</strong> with <em>emphasis</em> and <code>inline</code> code and then 
<div class="blah">Hello</div>
 Then more <a href="https://daringfireball.net/projects/markdown/">markdown</a>.</p>
2 Likes

Did not know Franklin before, it’s worth knowing it! The solution for html is interesting.
Btw, there are missing images here.

1 Like

Also take a look at GithubMarkdown.jl, which allows you to render gfm to HTML.

4 Likes

thanks for that, now saved by rick and morty

1 Like