improve hashtags

This commit is contained in:
Egor Kislitsyn 2019-02-18 18:39:56 +07:00
parent 6c7a0c1363
commit 558a7e9f9a
3 changed files with 4 additions and 5 deletions

View file

@ -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

View file

@ -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:?",

View file

@ -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