diff --git a/lib/earmark_parser/ast/inline.ex b/lib/earmark_parser/ast/inline.ex index da4c6e1..87a8fac 100644 --- a/lib/earmark_parser/ast/inline.ex +++ b/lib/earmark_parser/ast/inline.ex @@ -136,7 +136,7 @@ defmodule EarmarkParser.Ast.Inline do end end - @link_text ~S{(?:\[[^]]*\]|[^][]|\])*} + @link_text ~S{(?:\[[^]]*\]|[^][])*} def converter_for_reflink({src, lnb, context, use_linky?}) do if use_linky? do diff --git a/test/acceptance/ast/reflink_test.exs b/test/acceptance/ast/reflink_test.exs index cc99d93..0bd1eff 100644 --- a/test/acceptance/ast/reflink_test.exs +++ b/test/acceptance/ast/reflink_test.exs @@ -76,7 +76,7 @@ defmodule Acceptance.Ast.ReflinkTest do test "not so simple case" do markdown = "[[]]]text] [reference]\n[reference]: some_url" - html = "
\n" + html = "[[]]]text] reference
\n" ast = parse_html(html) messages = [] diff --git a/test/acceptance/bug_test/linked_images_test.exs b/test/acceptance/bug_test/linked_images_test.exs new file mode 100644 index 0000000..01c7558 --- /dev/null +++ b/test/acceptance/bug_test/linked_images_test.exs @@ -0,0 +1,68 @@ +defmodule Acceptance.BugTest.LinkedImagesTest do + use ExUnit.Case, async: true + import Support.Helpers, only: [as_ast: 1] + import EarmarkAstDsl, only: [p: 1, tag: 3] + + test "consecutive reference-style linked images" do + markdown = """ + [![Badge 1][img1]][url1] [![Badge 2][img2]][url2] + + [img1]: https://google.com/logo.png + [img2]: https://yahoo.com/logo.png + [url1]: https://google.com + [url2]: https://yahoo.com + """ + + expected_ast = [ + p([ + tag("a", [tag("img", [], src: "https://google.com/logo.png", alt: "Badge 1", title: "")], + href: "https://google.com", + title: "" + ), + " ", + tag("a", [tag("img", [], src: "https://yahoo.com/logo.png", alt: "Badge 2", title: "")], + href: "https://yahoo.com", + title: "" + ) + ]) + ] + + assert as_ast(markdown) == {:ok, expected_ast, []} + end + + test "single reference-style linked image" do + markdown = """ + [![Badge 1][img1]][url1] + + [img1]: https://google.com/logo.png + [url1]: https://google.com + """ + + expected_ast = [ + p([ + tag("a", [tag("img", [], src: "https://google.com/logo.png", alt: "Badge 1", title: "")], + href: "https://google.com", + title: "" + ) + ]) + ] + + assert as_ast(markdown) == {:ok, expected_ast, []} + end + + test "normal multiple images" do + markdown = """ + [](https://google.com) [](https://yahoo.com) + """ + + expected_ast = [ + p([ + tag("a", [tag("img", [], src: "https://google.com/logo.png", alt: "Badge 1")], href: "https://google.com"), + " ", + tag("a", [tag("img", [], src: "https://yahoo.com/logo.png", alt: "Badge 2")], href: "https://yahoo.com") + ]) + ] + + assert as_ast(markdown) == {:ok, expected_ast, []} + end +end