fix link parsing

This commit is contained in:
byte[] 2019-11-27 16:27:31 -05:00
parent 5b77e2a060
commit fa6be88874
3 changed files with 32 additions and 19 deletions

View file

@ -123,20 +123,22 @@ 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 =
choice([ repeat(
space(), choice([
string("*"), string("*"),
string("_"), string("_"),
string("@"), string("@"),
string("+"), string("+"),
string("^"), string("^"),
string("-"), string("-"),
string("~"), string("~"),
string("."), string("."),
string("?"), string("?"),
string("!"), string("!"),
string(",") string(","),
]) ])
)
|> choice([space(), eos()])
link_contents_start = link_contents_start =
choice([ choice([

View file

@ -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}

View file

@ -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([
ascii_char([?a..?z]) |> string(".") |> ascii_char([?a..?z]),
ascii_char([?a..?z])
])
)
scheme_and_domain =
choice([ choice([
string("/"), string("https://"), string("http://"), string("data:image/") 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