mirror of
https://github.com/philomena-dev/philomena.git
synced 2025-01-19 22:27:59 +01:00
change rules for bracketed links
This commit is contained in:
parent
4976ddb743
commit
689ce5cd5a
3 changed files with 11 additions and 6 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
_ ->
|
||||
|
|
Loading…
Reference in a new issue