Basic conversion of http(s) links in text to html hyperlinks.
- Convert
http://
andhttps://
links to html hyperlinks (<a>
tags) - You can pass in entire blocks of text containing multiple links
- Pass in any extra custom attributes you want
- Respects punctuation in text so links don't break
Anti-features:
- Doesn't sanitize HTML in your text input. See html_sanitize_ex if you don't control the input
The package can be installed by adding ex_autolink
to your list of
dependencies in mix.exs
:
def deps do
[
{:ex_autolink, "~> 0.2.0"}
]
end
iex> ExAutolink.link("https://elixir-lang.org")
"<a href=\"https://elixir-lang.org\">https://elixir-lang.org</a>"
iex> ExAutolink.link("Go here: https://elixir-lang.org/.")
"Go here: <a href=\"https://elixir-lang.org/\">https://elixir-lang.org/</a>."
iex> ExAutolink.link("https://ja.wikipedia.org/wiki/Elixir_(プログラミング言語)")
"<a href=\"https://ja.wikipedia.org/wiki/Elixir_(プログラミング言語)\">https://ja.wikipedia.org/wiki/Elixir_(プログラミング言語)</a>"
iex> ExAutolink.link("https://elixir-lang.org!", args: %{class: "myclass active", rel: "nofollow noreferrer"})
"<a href=\"https://elixir-lang.org\" class=\"myclass active\" rel=\"nofollow noreferrer\">https://elixir-lang.org</a>!"
MIT.