philomena/lib/textile/url_lexer.ex

25 lines
582 B
Elixir
Raw Normal View History

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
|> repeat(utf8_char([]) |> lookahead_not(ending_sequence))
2019-11-04 00:58:11 +01:00
|> reduce({List, :to_string, []})
end
end