Skip to content

Commit

Permalink
Reproduced the error in Oneline Parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertDober committed Jun 24, 2020
1 parent ecc9b71 commit caa6fa9
Showing 1 changed file with 30 additions and 20 deletions.
50 changes: 30 additions & 20 deletions lib/earmark.ex
Original file line number Diff line number Diff line change
Expand Up @@ -147,17 +147,27 @@ defmodule Earmark do
#### HTML Blocks
Are only supported if the begin and end tag is in its own line, thusly
HTML is not parsed recursively or detected in all conditons right now, though GFM compliance
is a goal.
<div>
Hello
</div>
But for now the following holds:
will parse as HTML while
A HTML Block defined by a tag starting a line and the same tag starting a different line is parsed
as one HTML AST node, marked with %{verbatim: true}
<div>Hello</div>
E.g.
iex(3)> lines = [ "<div><span>", "some</span><text>", "</div>more text" ]
...(3)> Earmark.as_ast(lines)
{:ok, [{"div", [], ["<span>", "some</span><text>"], %{meta: %{verbatim: true}}}, "more text"], []}
And a line starting with an opening tag and ending with the corresponding closing tag is parsed in similar
fashion
iex(4)> Earmark.as_ast([~s{<span class="superspan">spaniel</span>}])
{:ok, [{"span"}, [{"class", "superspan"}], ["spaniel"], %{meta: %{verbatim: true}}], []}
is not supported and its result is undefined
### Adding HTML attributes with the IAL extension
Expand Down Expand Up @@ -186,26 +196,26 @@ defmodule Earmark do
It is possible to add IAL attributes to generated links or images in the following
format.
iex(3)> markdown = "[link](url) {: .classy}"
...(3)> Earmark.as_html(markdown)
iex(4)> markdown = "[link](url) {: .classy}"
...(4)> Earmark.as_html(markdown)
{ :ok, "<p>\\n <a class=\\"classy\\" href=\\"url\\">\\n link\\n </a>\\n</p>\\n", []}
For both cases, malformed attributes are ignored and warnings are issued.
iex(4)> [ "Some text", "{:hello}" ] |> Enum.join("\\n") |> Earmark.as_html()
iex(5)> [ "Some text", "{:hello}" ] |> Enum.join("\\n") |> Earmark.as_html()
{:error, "<p>\\n Some text\\n</p>\\n", [{:warning, 2,"Illegal attributes [\\"hello\\"] ignored in IAL"}]}
It is possible to escape the IAL in both forms if necessary
iex(5)> markdown = "[link](url)\\\\{: .classy}"
...(5)> Earmark.as_html(markdown)
iex(6)> markdown = "[link](url)\\\\{: .classy}"
...(6)> Earmark.as_html(markdown)
{:ok, "<p>\\n <a href=\\"url\\">\\n link\\n </a>\\n {: .classy}\\n</p>\\n", []}
This of course is not necessary in code blocks or text lines
containing an IAL-like string, as in the following example
iex(6)> markdown = "hello {:world}"
...(6)> Earmark.as_html!(markdown)
iex(7)> markdown = "hello {:world}"
...(7)> Earmark.as_html!(markdown)
"<p>\\n hello {:world}\\n</p>\\n"
## Limitations
Expand Down Expand Up @@ -369,17 +379,17 @@ defmodule Earmark do
end

@doc """
iex(7)> markdown = "My `code` is **best**"
...(7)> {:ok, ast, []} = Earmark.as_ast(markdown)
...(7)> ast
iex(8)> markdown = "My `code` is **best**"
...(8)> {:ok, ast, []} = Earmark.as_ast(markdown)
...(8)> ast
[{"p", [], ["My ", {"code", [{"class", "inline"}], ["code"]}, " is ", {"strong", [], ["best"]}]}]
Options are passes like to `as_html`, some do not have an effect though (e.g. `smartypants`) as formatting and escaping is not done
for the AST.
iex(8)> markdown = "```elixir\\nIO.puts 42\\n```"
...(8)> {:ok, ast, []} = Earmark.as_ast(markdown, code_class_prefix: "lang-")
...(8)> ast
iex(9)> markdown = "```elixir\\nIO.puts 42\\n```"
...(9)> {:ok, ast, []} = Earmark.as_ast(markdown, code_class_prefix: "lang-")
...(9)> ast
[{"pre", [], [{"code", [{"class", "elixir lang-elixir"}], ["IO.puts 42"]}]}]
**Rationale**:
Expand Down

0 comments on commit caa6fa9

Please sign in to comment.