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,8 +123,8 @@ defmodule Textile.Lexer do
{link_markup_start, link_markup_element} = markup_ending_in(string("\""))
link_stop =
repeat(
choice([
space(),
string("*"),
string("_"),
string("@"),
@ -135,8 +135,10 @@ defmodule Textile.Lexer do
string("."),
string("?"),
string("!"),
string(",")
string(","),
])
)
|> choice([space(), eos()])
link_contents_start =
choice([

View file

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

View file

@ -2,13 +2,24 @@ defmodule Textile.UrlLexer do
import NimbleParsec
def url_ending_in(ending_sequence) do
protocol =
domain =
repeat(
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
|> repeat(lookahead_not(ending_sequence) |> utf8_char([]))
scheme_and_domain
|> repeat(utf8_char([]) |> lookahead_not(ending_sequence))
|> reduce({List, :to_string, []})
end
end