An open API service indexing awesome lists of open source software.

https://github.com/krepflap/ex_autolink

Elixir library for generating html hyperlinks from text
https://github.com/krepflap/ex_autolink

elixir

Last synced: 4 months ago
JSON representation

Elixir library for generating html hyperlinks from text

Awesome Lists containing this project

README

          

# ExAutolink

Basic conversion of http(s) links in text to html hyperlinks.

## Features

* Convert `http://` and `https://` links to html hyperlinks (`` 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](https://github.com/rrrene/html_sanitize_ex)
if you don't control the input

## Installation

The package can be installed by adding `ex_autolink` to your list of
dependencies in `mix.exs`:

```elixir
def deps do
[
{:ex_autolink, "~> 0.2.0"}
]
end
```

## Usage

```elixir
iex> ExAutolink.link("https://elixir-lang.org")
"
https://elixir-lang.org"

iex> ExAutolink.link("Go here: https://elixir-lang.org/.")
"Go here: https://elixir-lang.org/."

iex> ExAutolink.link("https://ja.wikipedia.org/wiki/Elixir_(プログラミング言語)")
"https://ja.wikipedia.org/wiki/Elixir_(プログラミング言語)"

iex> ExAutolink.link("https://elixir-lang.org!", args: %{class: "myclass active", rel: "nofollow noreferrer"})
"https://elixir-lang.org!"
```

## License

MIT.