nextjournal / markdown

A cross-platform clojure/script parser for Markdown

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Inline HTML possible?

jgrodziski opened this issue · comments

Hi,

I would like to allow the possibility of inlining HTML in Markdown. I understand you disable this for security reason I guess but can it be made configurable somehow?
I changed the code in nextjournal/markdown/parser.clj at line 415 with:

(defmethod apply-token "html_block" [doc {inlined-html :content}] (push-node doc {:type :text :text inlined-html}))

and it works great.
What do you think?
Thanks for that well-designed and very useful lib.
Jérémie.

Hi @jgrodziski,

glad you find it useful :-).

We didn't have the need for inline html so far. If needed for rendering purposes, I guess a user could add apply-token method implementations directly in their projects (as you do above) and add renderer functions in the hiccup conversion context under appropriate types, to be used as in

(nextjournal.markdown.transform/->hiccup 
 (assoc nextjournal.markdown.transform/default-hiccup-renderers :html your-fn)
 markdown-data)

My usecase is for a static site generator. I've recently changed my blogs to use nextjournal.markdown instead of markdown-clj (rationale in this Mastodon thread) and it's working great... except it broke most images on my blog, because they appeared as <img> tags (rather than the native Markdown syntax for images) in the Markdown sources of the existing posts.

I'd say the current behaviour makes nextjournal.markdown violate the CommonMark spec. If security is the reason, I'd still make the parser emit HTML nodes by default, but have them ignored in the ast->hiccup transformer.

BTW, thank you for the fantastic library! :)

Hi @nathell

I'd still make the parser emit HTML nodes

Right, that shouldn't harm.