diff --git a/lib/fast_textile/lexer.ex b/lib/fast_textile/lexer.ex index 82b16f17..670f1d76 100644 --- a/lib/fast_textile/lexer.ex +++ b/lib/fast_textile/lexer.ex @@ -29,6 +29,9 @@ defmodule FastTextile.Lexer do link_ending_characters = utf8_char('#$%&(),./:;<=?\\`|\'') + bracket_link_ending_characters = + utf8_char('" []') + end_of_link = choice([ concat(link_ending_characters, extended_space), @@ -137,7 +140,7 @@ defmodule FastTextile.Lexer do bracketed_link_url = string("\":") |> concat(link_url_scheme) - |> repeat(utf8_char(not: ?])) + |> repeat(lookahead_not(bracket_link_ending_characters) |> utf8_char([])) |> ignore(string("]")) |> reduce({List, :to_string, []}) |> unwrap_and_tag(:bracketed_link_url) diff --git a/lib/fast_textile/parser.ex b/lib/fast_textile/parser.ex index d31b8744..1c2d3ede 100644 --- a/lib/fast_textile/parser.ex +++ b/lib/fast_textile/parser.ex @@ -362,14 +362,14 @@ defmodule FastTextile.Parser do defp simple_unbracketed_attr(_this_state, _delim_token, _open_attr, _close_attr, _callback, _parser, _tokens, _state), do: {:error, "Expected a simple unbracketed attribute"} - defp escape(text), do: HTML.html_escape(text) |> HTML.safe_to_string() - defp flatten(tree) do + def flatten(tree) do tree |> List.flatten() |> Enum.map(fn {_k, v} -> v end) |> Enum.join() end + defp escape(text), do: HTML.html_escape(text) |> HTML.safe_to_string() defp partial_flatten(tree) do List.flatten(tree) end diff --git a/lib/philomena_web/views/post_view.ex b/lib/philomena_web/views/post_view.ex index cc83324d..355dad7c 100644 --- a/lib/philomena_web/views/post_view.ex +++ b/lib/philomena_web/views/post_view.ex @@ -1,15 +1,17 @@ defmodule PhilomenaWeb.PostView do alias Philomena.Attribution - alias Textile.Parser + alias FastTextile.Parser use PhilomenaWeb, :view def textile_safe_author(object) do author_name = author_name(object) + at_author_name = "@" <> author_name - Parser.parse(%Parser{image_transform: & &1}, author_name) + Parser.parse(%{image_transform: & &1}, at_author_name) + |> Parser.flatten() |> case do - [{:text, ^author_name}] -> + ^at_author_name -> author_name _ ->