philomena/lib/textile/url_lexer.ex
2019-11-27 16:27:31 -05:00

25 lines
No EOL
582 B
Elixir

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