2019-11-04 00:58:11 +01:00
|
|
|
defmodule Textile.UrlLexer do
|
|
|
|
import NimbleParsec
|
|
|
|
|
|
|
|
def url_ending_in(ending_sequence) do
|
2019-11-27 22:27:31 +01:00
|
|
|
domain =
|
|
|
|
repeat(
|
|
|
|
choice([
|
|
|
|
ascii_char([?a..?z]) |> string(".") |> ascii_char([?a..?z]),
|
|
|
|
ascii_char([?a..?z])
|
|
|
|
])
|
|
|
|
)
|
|
|
|
|
|
|
|
scheme_and_domain =
|
2019-11-04 00:58:11 +01:00
|
|
|
choice([
|
2019-11-27 22:27:31 +01:00
|
|
|
string("/"),
|
|
|
|
string("data:image/"),
|
|
|
|
string("https://") |> concat(domain),
|
|
|
|
string("http://") |> concat(domain)
|
2019-11-04 00:58:11 +01:00
|
|
|
])
|
|
|
|
|
2019-11-27 22:27:31 +01:00
|
|
|
scheme_and_domain
|
2019-11-27 22:38:53 +01:00
|
|
|
|> repeat(lookahead_not(ending_sequence) |> utf8_char([]))
|
2019-11-04 00:58:11 +01:00
|
|
|
|> reduce({List, :to_string, []})
|
|
|
|
end
|
|
|
|
end
|