logo

auto_linker

AutoLinker-shim, based on https://git.pleroma.social/pleroma/auto_linker git clone https://hacktivis.me/git/auto_linker.git
commit: 558a7e9f9a185fcdef5809740d12265ae91e8940
parent 6c7a0c13636d6d2125de30ea638e63cb4350abd0
Author: Egor Kislitsyn <egor@kislitsyn.com>
Date:   Mon, 18 Feb 2019 18:39:56 +0700

improve hashtags

Diffstat:

Mlib/auto_linker/builder.ex5++---
Mlib/auto_linker/parser.ex2+-
Mtest/auto_linker_test.exs2+-
3 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/lib/auto_linker/builder.ex b/lib/auto_linker/builder.ex @@ -125,16 +125,15 @@ defmodule AutoLinker.Builder do |> format_mention(name, opts) end - def create_hashtag_link(tag, _buffer, opts) do + def create_hashtag_link("#" <> tag, _buffer, opts) do hashtag_prefix = opts[:hashtag_prefix] url = hashtag_prefix <> tag - [] + [href: url] |> build_attrs(url, opts, :rel) |> build_attrs(url, opts, :target) |> build_attrs(url, opts, :class) - |> build_attrs(url, opts, :scheme) |> format_hashtag(tag, opts) end diff --git a/lib/auto_linker/parser.ex b/lib/auto_linker/parser.ex @@ -45,7 +45,7 @@ defmodule AutoLinker.Parser do # https://www.w3.org/TR/html5/forms.html#valid-e-mail-address @match_email ~r/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/u - @match_hashtag ~r/^\#(?<tag>\w+)/u + @match_hashtag ~r/^(?<tag>\#\w+)/u @prefix_extra [ "magnet:?", diff --git a/test/auto_linker_test.exs b/test/auto_linker_test.exs @@ -98,7 +98,7 @@ defmodule AutoLinkerTest do assert result_text == "<a href=\"https://example.com/user/hello\">#hello</a> <a href=\"https://example.com/user/world\">#world</a>" - assert MapSet.to_list(tags) == ["hello", "world"] + assert MapSet.to_list(tags) == ["#hello", "#world"] end end