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 =
|
link_ending_characters =
|
||||||
utf8_char('#$%&(),./:;<=?\\`|\'')
|
utf8_char('#$%&(),./:;<=?\\`|\'')
|
||||||
|
|
||||||
|
bracket_link_ending_characters =
|
||||||
|
utf8_char('" []')
|
||||||
|
|
||||||
end_of_link =
|
end_of_link =
|
||||||
choice([
|
choice([
|
||||||
concat(link_ending_characters, extended_space),
|
concat(link_ending_characters, extended_space),
|
||||||
|
@ -137,7 +140,7 @@ defmodule FastTextile.Lexer do
|
||||||
bracketed_link_url =
|
bracketed_link_url =
|
||||||
string("\":")
|
string("\":")
|
||||||
|> concat(link_url_scheme)
|
|> concat(link_url_scheme)
|
||||||
|> repeat(utf8_char(not: ?]))
|
|> repeat(lookahead_not(bracket_link_ending_characters) |> utf8_char([]))
|
||||||
|> ignore(string("]"))
|
|> ignore(string("]"))
|
||||||
|> reduce({List, :to_string, []})
|
|> reduce({List, :to_string, []})
|
||||||
|> unwrap_and_tag(:bracketed_link_url)
|
|> 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),
|
defp simple_unbracketed_attr(_this_state, _delim_token, _open_attr, _close_attr, _callback, _parser, _tokens, _state),
|
||||||
do: {:error, "Expected a simple unbracketed attribute"}
|
do: {:error, "Expected a simple unbracketed attribute"}
|
||||||
|
|
||||||
defp escape(text), do: HTML.html_escape(text) |> HTML.safe_to_string()
|
def flatten(tree) do
|
||||||
defp flatten(tree) do
|
|
||||||
tree
|
tree
|
||||||
|> List.flatten()
|
|> List.flatten()
|
||||||
|> Enum.map(fn {_k, v} -> v end)
|
|> Enum.map(fn {_k, v} -> v end)
|
||||||
|> Enum.join()
|
|> Enum.join()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp escape(text), do: HTML.html_escape(text) |> HTML.safe_to_string()
|
||||||
defp partial_flatten(tree) do
|
defp partial_flatten(tree) do
|
||||||
List.flatten(tree)
|
List.flatten(tree)
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,15 +1,17 @@
|
||||||
defmodule PhilomenaWeb.PostView do
|
defmodule PhilomenaWeb.PostView do
|
||||||
alias Philomena.Attribution
|
alias Philomena.Attribution
|
||||||
alias Textile.Parser
|
alias FastTextile.Parser
|
||||||
|
|
||||||
use PhilomenaWeb, :view
|
use PhilomenaWeb, :view
|
||||||
|
|
||||||
def textile_safe_author(object) do
|
def textile_safe_author(object) do
|
||||||
author_name = author_name(object)
|
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
|
|> case do
|
||||||
[{:text, ^author_name}] ->
|
^at_author_name ->
|
||||||
author_name
|
author_name
|
||||||
|
|
||||||
_ ->
|
_ ->
|
||||||
|
|
Loading…
Reference in a new issue