mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-30 23:08:00 +01:00
34 lines
No EOL
757 B
Elixir
34 lines
No EOL
757 B
Elixir
defmodule Textile.UrlLexer do
|
|
import NimbleParsec
|
|
|
|
def url_ending_in(ending_sequence) do
|
|
domain_character =
|
|
choice([
|
|
ascii_char([?a..?z]),
|
|
ascii_char([?A..?Z]),
|
|
ascii_char([?0..?9]),
|
|
string("-")
|
|
])
|
|
|
|
domain =
|
|
repeat(
|
|
choice([
|
|
domain_character |> string(".") |> concat(domain_character),
|
|
domain_character
|
|
])
|
|
)
|
|
|
|
scheme_and_domain =
|
|
choice([
|
|
string("#"),
|
|
string("/"),
|
|
string("data:image/"),
|
|
string("https://") |> concat(domain),
|
|
string("http://") |> concat(domain)
|
|
])
|
|
|
|
scheme_and_domain
|
|
|> repeat(lookahead_not(ending_sequence) |> utf8_char([]))
|
|
|> reduce({List, :to_string, []})
|
|
end
|
|
end |