Browse Source

improve hashtags

merge-requests/2/head
Egor Kislitsyn 5 years ago
parent
commit
558a7e9f9a
3 changed files with 4 additions and 5 deletions
  1. +2
    -3
      lib/auto_linker/builder.ex
  2. +1
    -1
      lib/auto_linker/parser.ex
  3. +1
    -1
      test/auto_linker_test.exs

+ 2
- 3
lib/auto_linker/builder.ex 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


+ 1
- 1
lib/auto_linker/parser.ex 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:?",


+ 1
- 1
test/auto_linker_test.exs 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


Loading…
Cancel
Save