mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-24 04:27:59 +01:00
25 lines
No EOL
582 B
Elixir
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 |