nextjournal / markdown

A cross-platform clojure/script parser for Markdown
ISC License
38 stars 4 forks source link

Inline HTML possible? #7

Open jgrodziski opened 1 year ago

jgrodziski commented 1 year ago

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.

zampino commented 1 year ago

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)
nathell commented 11 months ago

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! :)

zampino commented 11 months ago

Hi @nathell

I'd still make the parser emit HTML nodes

Right, that shouldn't harm.