RobertDober / earmark_parser

The Markdown to AST part of Earmark.
Apache License 2.0
68 stars 26 forks source link

Parse HTML recursively #7

Open RobertDober opened 4 years ago

RobertDober commented 4 years ago

This would superseed Earmark#356 and is inspired by Earmark#353.

Basic idea

let the scanner be a little be more intelligent and scan the following line

<div> hello<br /> <span lang="greek">αλφα</span></div>

as

   [
     OpenTag{div, []}, Text{hello}, VoidTag{br}, 
     OpenTag{span, [{lang, greek}]} Text{αλφα} CloseTag{span}
     CloseTag{div}]
RobertDober commented 4 years ago

Also provide an option to put the HTML into metadata as discussed in #8.

This was discussed in https://github.com/pragdave/earmark/issues/356 as follows Do you mean

   {"div", [{"class", "elixir"}] [best code ever] %{verbatim: true}}

--->

   {"div", [{"class", "elixir"}] [best code ever] %{verbatim: true, html: ~s[<div class="elixir">best code ever</div>]}}

sure sounds like a sound idea to me.

Remains to be seen if the Option shall be capable of adding the verbatim content for other elements too, which might give

e.g.

     as_ast("<div....</div>**hello**", include_verabtims_for: :all) # :verbatim, :none (default) ?
   {:ok,
          [
               {"div", [{"class", "elixir"}] [best code ever] %{verbatim: true, verbatim_content: ~s[<div class="elixir">best code ever</div>]}
},           {"p", [], [{"strong", [], "hello", %{verbatim_content: "**hello**"}], %{verbatim_content: "**hello**"}], []

--->