Skip to content

Commit

Permalink
Do not remove ial on blockquote inside triple quoted (#96)
Browse files Browse the repository at this point in the history
Closes #94.
  • Loading branch information
josevalim authored and RobertDober committed Feb 21, 2022
1 parent 3a38b40 commit 0ad6679
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 11 deletions.
10 changes: 10 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@

## 1.4.20 2022-02-21

- [Preserve newlines inside HTML code](https://github.com/RobertDober/earmark_parser/pull/97)

Kudos to [José Valim](https://github.com/josevalim)

- [Do not remove ial on blockquote inside triple quoted](https://github.com/RobertDober/earmark_parser/pull/96)

Kudos to [José Valim](https://github.com/josevalim)

- Removed support for Elixir 1.10 (following `ex_doc`'s lead)


## 1.4.19 2022-01-07

Expand Down
4 changes: 0 additions & 4 deletions lib/earmark_parser/helpers/lookahead_helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@ defmodule EarmarkParser.Helpers.LookaheadHelpers do
defp has_still_opening_backtix([{:other, _} | rest], nil),
do: has_still_opening_backtix(rest, nil)

# Mystery fix, in Earmark the lexer behaves differently
defp has_still_opening_backtix([{:verbatim, _} | rest], nil),
do: has_still_opening_backtix(rest, nil)

defp has_still_opening_backtix([{:backtix, btx} | rest], nil),
do: has_still_opening_backtix(rest, {:new, btx})

Expand Down
4 changes: 2 additions & 2 deletions lib/earmark_parser/line_scanner.ex
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,12 @@ defmodule EarmarkParser.LineScanner do
content: String.trim(heading),
indent: 0,
ial: ial,
line: stripped_line
line: line
}

match = lt_four? && Regex.run(~r/\A>\s?(.*)/, content) ->
[_, quote] = match
%Line.BlockQuote{content: quote, indent: indent, ial: ial, line: stripped_line}
%Line.BlockQuote{content: quote, indent: indent, ial: ial, line: line}

match = Regex.run(@indent_re, line) ->
[_, spaces, more_spaces, rest] = match
Expand Down
36 changes: 35 additions & 1 deletion test/acceptance/ast/ial_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ defmodule Acceptance.Ast.IalTest do
assert as_ast(markdown) == {:ok, ast, messages}
end

test "blockquote and headers with simple ial" do
markdown = "> ### some code {: .classy}"
html = "<blockquote><h3 class=\"classy\">some code</h3></blockquote>\n"
ast = parse_html(html)
messages = []

assert as_ast(markdown) == {:ok, ast, messages}
end

test "img with simple ial" do
markdown = "![link](url){:#thatsme}"
html = "<p><img alt=\"link\" id=\"thatsme\" src=\"url\" /></p>\n"
Expand All @@ -31,6 +40,32 @@ defmodule Acceptance.Ast.IalTest do
assert as_ast(markdown) == {:ok, ast, messages}
end

test "triple quoted with simple ial" do
markdown = """
```
hello {: .example}
```
"""

ast = parse_html("<pre><code>hello {: .example}</code></pre>")
messages = []

assert as_ast(markdown) == {:ok, ast, messages}
end

test "triple quoted with backquote and simple ial" do
markdown = """
```
> ## hello {: .example}
```
"""

ast = parse_html("<pre><code>> ## hello {: .example}</code></pre>")
messages = []

assert as_ast(markdown) == {:ok, ast, messages}
end

test "not attached" do
markdown = "[link](url) {:lang=fr}"
html = "<p><a href=\"url\" lang=\"fr\">link</a></p>\n"
Expand All @@ -47,7 +82,6 @@ defmodule Acceptance.Ast.IalTest do

assert as_ast(markdown) == {:ok, ast, messages}
end

end

describe "IAL multiple values" do
Expand Down
8 changes: 4 additions & 4 deletions test/functional/scanner/line_type_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,9 @@ defmodule Functional.Scanner.LineTypeTest do
|> Enum.map(fn {{input, token, _nil}, test_nb} ->
tag = "ial_#{test_nb}" |> String.to_atom()
name = "test: #{test_nb} (#{input})"
input_ = "#{input}#{@ial}"
input = "#{input}#{@ial}"
result =
EarmarkParser.LineScanner.type_of({input_, 1774}, false)
EarmarkParser.LineScanner.type_of({input, 1774}, false)
indent = input |> String.replace(@all_but_leading_ws, "") |> String.length()
expected = struct(token, ial: ".ial_class", line: input, indent: indent, lnb: 1774)

Expand All @@ -343,9 +343,9 @@ defmodule Functional.Scanner.LineTypeTest do
|> Enum.map(fn {{input, token}, test_nb} ->
tag = "block_ial_#{test_nb}" |> String.to_atom()
name = "test: #{test_nb} (#{input})"
input_ = "#{input}#{@ial}"
input = "#{input}#{@ial}"
result =
EarmarkParser.LineScanner.type_of({input_, 1774}, false)
EarmarkParser.LineScanner.type_of({input, 1774}, false)
indent = input |> String.replace(@all_but_leading_ws, "") |> String.length()
expected = struct(token, content: token.content <> @ial, ial: ".ial_class", line: input, indent: indent, lnb: 1774)

Expand Down

0 comments on commit 0ad6679

Please sign in to comment.