mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-24 04:27:59 +01:00
fix link parsing
This commit is contained in:
parent
5b77e2a060
commit
fa6be88874
3 changed files with 32 additions and 19 deletions
|
@ -123,8 +123,8 @@ defmodule Textile.Lexer do
|
||||||
{link_markup_start, link_markup_element} = markup_ending_in(string("\""))
|
{link_markup_start, link_markup_element} = markup_ending_in(string("\""))
|
||||||
|
|
||||||
link_stop =
|
link_stop =
|
||||||
|
repeat(
|
||||||
choice([
|
choice([
|
||||||
space(),
|
|
||||||
string("*"),
|
string("*"),
|
||||||
string("_"),
|
string("_"),
|
||||||
string("@"),
|
string("@"),
|
||||||
|
@ -135,8 +135,10 @@ defmodule Textile.Lexer do
|
||||||
string("."),
|
string("."),
|
||||||
string("?"),
|
string("?"),
|
||||||
string("!"),
|
string("!"),
|
||||||
string(",")
|
string(","),
|
||||||
])
|
])
|
||||||
|
)
|
||||||
|
|> choice([space(), eos()])
|
||||||
|
|
||||||
link_contents_start =
|
link_contents_start =
|
||||||
choice([
|
choice([
|
||||||
|
|
|
@ -179,7 +179,7 @@ defmodule Textile.Parser do
|
||||||
# link_start well_formed_including_paragraphs link_end link_url;
|
# link_start well_formed_including_paragraphs link_end link_url;
|
||||||
#
|
#
|
||||||
defp link(parser, [{:link_start, start} | r_tokens]) do
|
defp link(parser, [{:link_start, start} | r_tokens]) do
|
||||||
case well_formed_including_paragraphs(parser, nil, r_tokens) do
|
case well_formed_including_paragraphs(parser, :link_end, r_tokens) do
|
||||||
{:ok, tree, [{:link_end, _end}, {:link_url, url} | r2_tokens]} ->
|
{:ok, tree, [{:link_end, _end}, {:link_url, url} | r2_tokens]} ->
|
||||||
{:ok, [{:markup, ~s|<a href="#{escape_html(url)}">|}, tree, {:markup, ~s|</a>|}], r2_tokens}
|
{:ok, [{:markup, ~s|<a href="#{escape_html(url)}">|}, tree, {:markup, ~s|</a>|}], r2_tokens}
|
||||||
|
|
||||||
|
|
|
@ -2,13 +2,24 @@ defmodule Textile.UrlLexer do
|
||||||
import NimbleParsec
|
import NimbleParsec
|
||||||
|
|
||||||
def url_ending_in(ending_sequence) do
|
def url_ending_in(ending_sequence) do
|
||||||
protocol =
|
domain =
|
||||||
|
repeat(
|
||||||
choice([
|
choice([
|
||||||
string("/"), string("https://"), string("http://"), string("data:image/")
|
ascii_char([?a..?z]) |> string(".") |> ascii_char([?a..?z]),
|
||||||
|
ascii_char([?a..?z])
|
||||||
|
])
|
||||||
|
)
|
||||||
|
|
||||||
|
scheme_and_domain =
|
||||||
|
choice([
|
||||||
|
string("/"),
|
||||||
|
string("data:image/"),
|
||||||
|
string("https://") |> concat(domain),
|
||||||
|
string("http://") |> concat(domain)
|
||||||
])
|
])
|
||||||
|
|
||||||
protocol
|
scheme_and_domain
|
||||||
|> repeat(lookahead_not(ending_sequence) |> utf8_char([]))
|
|> repeat(utf8_char([]) |> lookahead_not(ending_sequence))
|
||||||
|> reduce({List, :to_string, []})
|
|> reduce({List, :to_string, []})
|
||||||
end
|
end
|
||||||
end
|
end
|
Loading…
Reference in a new issue