mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-12-05 00:57:59 +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 |