Is it possible to extract all the raw text nodes from Markdown files using Earmark?
I’ve been using the built-in map_ast_with function and not having much luck, I seem to miss a lot of text.
defp markdown_to_text(markdown) do
{:ok, ast, _} = Earmark.as_ast(markdown)
fun = fn node, acc ->
case node do
[content] when is_binary(content) ->
{ node, [acc | content] }
_ ->
{ node, acc }
end
end
{ ast, text } = Earmark.Transform.map_ast_with(ast, [], fun)
Enum.join(text)
end