Skip to content
Snippets Groups Projects
Commit 558a7e9f authored by minibikini's avatar minibikini
Browse files

improve hashtags

parent 6c7a0c13
No related branches found
No related tags found
7 merge requests!10Improve Parser,!9Improve detection of URLs and Asian scripts,!8Improve CI,!6Fix link text,!5Improve hashtags and `rel` attribute,!3fix carriage return,!2Small fixes and improvements
...@@ -125,16 +125,15 @@ defmodule AutoLinker.Builder do ...@@ -125,16 +125,15 @@ defmodule AutoLinker.Builder do
|> format_mention(name, opts) |> format_mention(name, opts)
end end
def create_hashtag_link(tag, _buffer, opts) do def create_hashtag_link("#" <> tag, _buffer, opts) do
hashtag_prefix = opts[:hashtag_prefix] hashtag_prefix = opts[:hashtag_prefix]
url = hashtag_prefix <> tag url = hashtag_prefix <> tag
[] [href: url]
|> build_attrs(url, opts, :rel) |> build_attrs(url, opts, :rel)
|> build_attrs(url, opts, :target) |> build_attrs(url, opts, :target)
|> build_attrs(url, opts, :class) |> build_attrs(url, opts, :class)
|> build_attrs(url, opts, :scheme)
|> format_hashtag(tag, opts) |> format_hashtag(tag, opts)
end end
......
...@@ -45,7 +45,7 @@ defmodule AutoLinker.Parser do ...@@ -45,7 +45,7 @@ defmodule AutoLinker.Parser do
# https://www.w3.org/TR/html5/forms.html#valid-e-mail-address # 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_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 [ @prefix_extra [
"magnet:?", "magnet:?",
......
...@@ -98,7 +98,7 @@ defmodule AutoLinkerTest do ...@@ -98,7 +98,7 @@ defmodule AutoLinkerTest do
assert result_text == assert result_text ==
"<a href=\"https://example.com/user/hello\">#hello</a> <a href=\"https://example.com/user/world\">#world</a>" "<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
end end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment