mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 21:47: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,20 +123,22 @@ defmodule Textile.Lexer do
|
|||
{link_markup_start, link_markup_element} = markup_ending_in(string("\""))
|
||||
|
||||
link_stop =
|
||||
choice([
|
||||
space(),
|
||||
string("*"),
|
||||
string("_"),
|
||||
string("@"),
|
||||
string("+"),
|
||||
string("^"),
|
||||
string("-"),
|
||||
string("~"),
|
||||
string("."),
|
||||
string("?"),
|
||||
string("!"),
|
||||
string(",")
|
||||
])
|
||||
repeat(
|
||||
choice([
|
||||
string("*"),
|
||||
string("_"),
|
||||
string("@"),
|
||||
string("+"),
|
||||
string("^"),
|
||||
string("-"),
|
||||
string("~"),
|
||||
string("."),
|
||||
string("?"),
|
||||
string("!"),
|
||||
string(","),
|
||||
])
|
||||
)
|
||||
|> choice([space(), eos()])
|
||||
|
||||
link_contents_start =
|
||||
choice([
|
||||
|
|
|
@ -179,7 +179,7 @@ defmodule Textile.Parser do
|
|||
# link_start well_formed_including_paragraphs link_end link_url;
|
||||
#
|
||||
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, [{:markup, ~s|<a href="#{escape_html(url)}">|}, tree, {:markup, ~s|</a>|}], r2_tokens}
|
||||
|
||||
|
|
|
@ -2,13 +2,24 @@ defmodule Textile.UrlLexer do
|
|||
import NimbleParsec
|
||||
|
||||
def url_ending_in(ending_sequence) do
|
||||
protocol =
|
||||
domain =
|
||||
repeat(
|
||||
choice([
|
||||
ascii_char([?a..?z]) |> string(".") |> ascii_char([?a..?z]),
|
||||
ascii_char([?a..?z])
|
||||
])
|
||||
)
|
||||
|
||||
scheme_and_domain =
|
||||
choice([
|
||||
string("/"), string("https://"), string("http://"), string("data:image/")
|
||||
string("/"),
|
||||
string("data:image/"),
|
||||
string("https://") |> concat(domain),
|
||||
string("http://") |> concat(domain)
|
||||
])
|
||||
|
||||
protocol
|
||||
|> repeat(lookahead_not(ending_sequence) |> utf8_char([]))
|
||||
scheme_and_domain
|
||||
|> repeat(utf8_char([]) |> lookahead_not(ending_sequence))
|
||||
|> reduce({List, :to_string, []})
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue