From 0ad6679778e283399dacc881b503bfea5056a71c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Mon, 21 Feb 2022 10:59:10 +0100 Subject: [PATCH] Do not remove ial on blockquote inside triple quoted (#96) Closes #94. --- RELEASE.md | 10 ++++++ .../helpers/lookahead_helpers.ex | 4 --- lib/earmark_parser/line_scanner.ex | 4 +-- test/acceptance/ast/ial_test.exs | 36 ++++++++++++++++++- test/functional/scanner/line_type_test.exs | 8 ++--- 5 files changed, 51 insertions(+), 11 deletions(-) diff --git a/RELEASE.md b/RELEASE.md index cd85b87..b4e3d25 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -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 diff --git a/lib/earmark_parser/helpers/lookahead_helpers.ex b/lib/earmark_parser/helpers/lookahead_helpers.ex index 971de84..674b974 100644 --- a/lib/earmark_parser/helpers/lookahead_helpers.ex +++ b/lib/earmark_parser/helpers/lookahead_helpers.ex @@ -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}) diff --git a/lib/earmark_parser/line_scanner.ex b/lib/earmark_parser/line_scanner.ex index b307953..801ee11 100644 --- a/lib/earmark_parser/line_scanner.ex +++ b/lib/earmark_parser/line_scanner.ex @@ -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 diff --git a/test/acceptance/ast/ial_test.exs b/test/acceptance/ast/ial_test.exs index 2dd62e7..997c5d2 100644 --- a/test/acceptance/ast/ial_test.exs +++ b/test/acceptance/ast/ial_test.exs @@ -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 = "

some code

\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 = "

\"link\"

\n" @@ -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("
hello {: .example}
") + messages = [] + + assert as_ast(markdown) == {:ok, ast, messages} + end + + test "triple quoted with backquote and simple ial" do + markdown = """ + ``` + > ## hello {: .example} + ``` + """ + + ast = parse_html("
> ## hello {: .example}
") + messages = [] + + assert as_ast(markdown) == {:ok, ast, messages} + end + test "not attached" do markdown = "[link](url) {:lang=fr}" html = "

link

\n" @@ -47,7 +82,6 @@ defmodule Acceptance.Ast.IalTest do assert as_ast(markdown) == {:ok, ast, messages} end - end describe "IAL multiple values" do diff --git a/test/functional/scanner/line_type_test.exs b/test/functional/scanner/line_type_test.exs index b62392d..79f5c73 100644 --- a/test/functional/scanner/line_type_test.exs +++ b/test/functional/scanner/line_type_test.exs @@ -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) @@ -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)