Using Earmark, I’m trying to parse HTML inside markdown code blocks so that they can be syntax-highlighted. I’m having a bit of a rough time with it and, admittedly, I could probably stand to spend a bit more time trying to figure it out myself but I feel I’m maybe on the wrong path as it stands so I thought it couldn’t hurt to ask—also, whenever I do ask for help, I usually figure it out minutes later
So, I think understand that the following doesn’t work—the 3rd (content) element of the 4-tuple is usually ignored:
def parse() do
"""
```sql
<span class="k">SELECT</span> * <span class="k">FROM</span> table
```
"""
|> Earmark.as_ast!()
|> Earmark.map_ast(&parse_html/1)
|> Earmark.transform()
end
defp parse_html({"code", [{"class", "sql"}], [html], meta} = node, true) do
{:ok, html} = Floki.parse_fragment(html)
{:replace, {"code", [{"class", "sql"}], [html], meta}}
end
I say usually since the documentation doesn’t explicitly mention that the content node is ignored when using {:replace, node}
yet that seems to be the case (I’m actually not sure .
I there a way to simply replace the content node?
Is there just a better way of doing this (without using highlightjs)?
I’m looking at pre- and post-processors but currently not having much luck.
Thanks for reading!