diff --git a/lib/auto_linker/builder.ex b/lib/auto_linker/builder.ex index 185357f..be0ed26 100644 --- 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 index b00fc67..7374df0 100644 --- 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/^\#(?\w+)/u + @match_hashtag ~r/^(?\#\w+)/u @prefix_extra [ "magnet:?", diff --git a/test/auto_linker_test.exs b/test/auto_linker_test.exs index c906206..fc6f64d 100644 --- a/test/auto_linker_test.exs +++ b/test/auto_linker_test.exs @@ -98,7 +98,7 @@ defmodule AutoLinkerTest do assert result_text == "#hello #world" - assert MapSet.to_list(tags) == ["hello", "world"] + assert MapSet.to_list(tags) == ["#hello", "#world"] end end