Commit 2690f2b6 authored by minibikini's avatar minibikini

Rename to Linkify

parent 093d2344
# AutoLinker
# Linkify
[![Build Status](https://travis-ci.org/smpallen99/auto_linker.png?branch=master)](https://travis-ci.org/smpallen99/auto_linker) [![Hex Version][hex-img]][hex] [![License][license-img]][license]
[hex-img]: https://img.shields.io/hexpm/v/auto_linker.svg
[hex]: https://hex.pm/packages/auto_linker
[license-img]: http://img.shields.io/badge/license-MIT-brightgreen.svg
[license]: http://opensource.org/licenses/MIT
AutoLinker is a basic package for turning website names, and phone numbers into links.
Linkify is a basic package for turning website names, and phone numbers into links.
Use this package in your web view to convert web references into click-able links.
......@@ -15,11 +8,11 @@ This is a very early version. Some of the described options are not yet function
## Installation
The package can be installed by adding `auto_linker` to your list of dependencies in `mix.exs`:
The package can be installed by adding `linkify` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[{:auto_linker, "~> 0.2"}]
[{:linkify, "~> 0.1"}]
end
```
......@@ -28,26 +21,26 @@ end
The following examples illustrate some examples on how to use the auto linker.
```iex
iex> AutoLinker.link("google.com")
"<a href='http://google.com' class='auto-linker' target='_blank' rel='noopener noreferrer'>google.com</a>"
iex> Linkify.link("google.com")
"<a href='http://google.com' class='linkified' target='_blank' rel='noopener noreferrer'>google.com</a>"
iex> AutoLinker.link("google.com", new_window: false, rel: false)
"<a href='http://google.com' class='auto-linker'>google.com</a>"
iex> Linkify.link("google.com", new_window: false, rel: false)
"<a href='http://google.com' class='linkified'>google.com</a>"
iex> AutoLinker.link("google.com", new_window: false, rel: false, class: false)
iex> Linkify.link("google.com", new_window: false, rel: false, class: false)
"<a href='http://google.com'>google.com</a>"
iex> AutoLinker.link("call me at x9999", phone: true)
iex> Linkify.link("call me at x9999", phone: true)
"call me at <a href=\"#\" class=\"phone-number\" data-phone=\"9999\">x9999</a>"
iex> AutoLinker.link("or at home on 555.555.5555", phone: true)
iex> Linkify.link("or at home on 555.555.5555", phone: true)
"or at home on <a href=\"#\" class=\"phone-number\" data-phone=\"5555555555\">555.555.5555</a>"
iex> AutoLinker.link(", work (555) 555-5555", phone: true)
iex> Linkify.link(", work (555) 555-5555", phone: true)
", work <a href=\"#\" class=\"phone-number\" data-phone=\"5555555555\">(555) 555-5555</a>"
```
See the [Docs](https://hexdocs.pm/auto_linker/) for more examples
See the [Docs](https://hexdocs.pm/linkify/) for more examples
## Configuration
......@@ -55,7 +48,7 @@ By default, link parsing is enabled and phone parsing is disabled.
```elixir
# enable phone parsing, and disable link parsing
config :auto_linker, opts: [phone: true, url: false]
config :linkify, opts: [phone: true, url: false]
```
......
defmodule AutoLinker do
defmodule Linkify do
@moduledoc """
Create url links from text containing urls.
......@@ -7,24 +7,24 @@ defmodule AutoLinker do
## Examples
iex> AutoLinker.link("google.com")
~s(<a href="http://google.com" class="auto-linker" target="_blank" rel="noopener noreferrer">google.com</a>)
iex> Linkify.link("google.com")
~s(<a href="http://google.com" class="linkified" target="_blank" rel="noopener noreferrer">google.com</a>)
iex> AutoLinker.link("google.com", new_window: false, rel: false)
~s(<a href="http://google.com" class="auto-linker">google.com</a>)
iex> Linkify.link("google.com", new_window: false, rel: false)
~s(<a href="http://google.com" class="linkified">google.com</a>)
iex> AutoLinker.link("google.com", new_window: false, rel: false, class: false)
iex> Linkify.link("google.com", new_window: false, rel: false, class: false)
~s(<a href="http://google.com">google.com</a>)
"""
import AutoLinker.Parser
import Linkify.Parser
@doc """
Auto link a string.
Options:
* `class: "auto-linker"` - specify the class to be added to the generated link. false to clear
* `class: "linkified"` - specify the class to be added to the generated link. false to clear
* `rel: "noopener noreferrer"` - override the rel attribute. false to clear
* `new_window: true` - set to false to remove `target='_blank'` attribute
* `truncate: false` - Set to a number to truncate urls longer then the number. Truncated urls will end in `..`
......@@ -42,9 +42,9 @@ defmodule AutoLinker do
* `validate_tld: true` - Set to false to disable TLD validation for urls/emails, also can be set to :no_scheme to validate TLDs only for urls without a scheme (e.g `example.com` will be validated, but `http://example.loki` won't)
Each of the above options can be specified when calling `link(text, opts)`
or can be set in the `:auto_linker`'s configuration. For example:
or can be set in the `:linkify`'s configuration. For example:
config :auto_linker,
config :linkify,
class: false,
new_window: false
......
defmodule AutoLinker.Builder do
defmodule Linkify.Builder do
@moduledoc """
Module for building the auto generated link.
"""
......@@ -36,7 +36,7 @@ defmodule AutoLinker.Builder do
end
defp build_attrs(attrs, _, opts, :class) do
case Map.get(opts, :class, "auto-linker") do
case Map.get(opts, :class, "linkified") do
cls when is_binary(cls) -> [{:class, cls} | attrs]
_ -> attrs
end
......
defmodule AutoLinker.Parser do
defmodule Linkify.Parser do
@moduledoc """
Module to handle parsing the the input string.
"""
alias AutoLinker.Builder
alias Linkify.Builder
@invalid_url ~r/(\.\.+)|(^(\d+\.){1,2}\d+$)/
......@@ -50,8 +50,8 @@ defmodule AutoLinker.Parser do
## Examples
iex> AutoLinker.Parser.parse("Check out google.com")
~s{Check out <a href="http://google.com" class="auto-linker" target="_blank" rel="noopener noreferrer">google.com</a>}
iex> Linkify.Parser.parse("Check out google.com")
~s{Check out <a href="http://google.com" class="linkified" target="_blank" rel="noopener noreferrer">google.com</a>}
"""
@types [:url, :email, :hashtag, :mention, :extra]
......@@ -214,8 +214,6 @@ defmodule AutoLinker.Parser do
defp strip_parens(buffer), do: buffer
# @doc false
def url?(buffer, opts) do
valid_url?(buffer) && Regex.match?(@match_url, buffer) && valid_tld?(buffer, opts)
end
......
defmodule AutoLinker.Mixfile do
defmodule Linkify.Mixfile do
use Mix.Project
@version "0.2.2"
@version "0.1.0"
def project do
[
app: :auto_linker,
app: :linkify,
version: @version,
elixir: "~> 1.4",
elixir: "~> 1.7",
build_embedded: Mix.env() == :prod,
start_permanent: Mix.env() == :prod,
deps: deps(),
docs: [extras: ["README.md"]],
package: package(),
name: "AutoLinker",
name: "Linkify",
description: """
AutoLinker is a basic package for turning website names into links.
Linkify is a basic package for turning website names into links.
"""
]
end
......@@ -37,10 +37,9 @@ defmodule AutoLinker.Mixfile do
defp package do
[
maintainers: ["Stephen Pallen"],
licenses: ["MIT"],
links: %{"Github" => "https://github.com/smpallen99/auto_linker"},
files: ~w(lib README.md mix.exs LICENSE)
links: %{"GitLab" => "https://git.pleroma.social/pleroma/linkify"},
files: ~w(lib priv README.md mix.exs LICENSE)
]
end
end
defmodule AutoLinker.BuilderTest do
defmodule Linkify.BuilderTest do
use ExUnit.Case, async: true
doctest AutoLinker.Builder
doctest Linkify.Builder
import AutoLinker.Builder
import Linkify.Builder
test "create_link/2" do
expected =
"<a href=\"http://text\" class=\"auto-linker\" target=\"_blank\" rel=\"noopener noreferrer\">text</a>"
"<a href=\"http://text\" class=\"linkified\" target=\"_blank\" rel=\"noopener noreferrer\">text</a>"
assert create_link("text", %{}) == expected
expected = "<a href=\"http://text\" class=\"auto-linker\" target=\"_blank\">text</a>"
expected = "<a href=\"http://text\" class=\"linkified\" target=\"_blank\">text</a>"
assert create_link("text", %{rel: nil}) == expected
expected =
"<a href=\"http://text\" class=\"auto-linker\" target=\"_blank\" rel=\"me\">text</a>"
expected = "<a href=\"http://text\" class=\"linkified\" target=\"_blank\" rel=\"me\">text</a>"
assert create_link("text", %{rel: "me"}) == expected
expected = "<a href=\"http://text\" class=\"auto-linker\" target=\"_blank\">t...</a>"
expected = "<a href=\"http://text\" class=\"linkified\" target=\"_blank\">t...</a>"
assert create_link("text", %{truncate: 3, rel: false}) == expected
expected = "<a href=\"http://text\" class=\"auto-linker\" target=\"_blank\">text</a>"
expected = "<a href=\"http://text\" class=\"linkified\" target=\"_blank\">text</a>"
assert create_link("text", %{truncate: 2, rel: false}) == expected
expected = "<a href=\"http://text\" class=\"auto-linker\" target=\"_blank\">http://text</a>"
expected = "<a href=\"http://text\" class=\"linkified\" target=\"_blank\">http://text</a>"
assert create_link("http://text", %{rel: false, strip_prefix: false}) == expected
end
......@@ -48,13 +47,13 @@ defmodule AutoLinker.BuilderTest do
test "create_mention_link/3" do
expected =
"<a href=\"/u/navi\" class=\"auto-linker\" target=\"_blank\" rel=\"noopener noreferrer\">@navi</a>"
"<a href=\"/u/navi\" class=\"linkified\" target=\"_blank\" rel=\"noopener noreferrer\">@navi</a>"
assert create_mention_link("@navi", "hello @navi", %{mention_prefix: "/u/"}) == expected
end
test "create_email_link/3" do
expected = "<a href=\"mailto:user@example.org\" class=\"auto-linker\">user@example.org</a>"
expected = "<a href=\"mailto:user@example.org\" class=\"linkified\">user@example.org</a>"
assert create_email_link("user@example.org", %{}) == expected
assert create_email_link("user@example.org", %{href: "mailto:user@example.org"}) == expected
end
......
defmodule AutoLinker.ParserTest do
defmodule Linkify.ParserTest do
use ExUnit.Case, async: true
doctest AutoLinker.Parser
doctest Linkify.Parser
import AutoLinker.Parser
import Linkify.Parser
describe "url?/2" do
test "valid scheme true" do
......@@ -111,7 +111,7 @@ defmodule AutoLinker.ParserTest do
text = "google.com\r\nssss"
expected =
"<a href=\"http://google.com\" class=\"auto-linker\" target=\"_blank\" rel=\"noopener noreferrer\">google.com</a>\r\nssss"
"<a href=\"http://google.com\" class=\"linkified\" target=\"_blank\" rel=\"noopener noreferrer\">google.com</a>\r\nssss"
assert parse(text) == expected
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment