Fix hashtag parsing at the end of lines
This commit is contained in:
parent
29d259cb0a
commit
94aeffd227
2 changed files with 34 additions and 2 deletions
|
@ -94,13 +94,19 @@ defmodule Linkify.Parser do
|
|||
) do
|
||||
{buffer, user_acc} = link(buffer, opts, user_acc)
|
||||
|
||||
case Regex.run(@match_skipped_tag, text, capture: [:tag]) do
|
||||
buffer =
|
||||
case buffer do
|
||||
[_, _, _] -> Enum.join(buffer)
|
||||
_ -> buffer
|
||||
end
|
||||
|
||||
case Regex.run(@match_skipped_tag, buffer, capture: [:tag]) do
|
||||
[tag] ->
|
||||
text = String.trim_leading(text, tag)
|
||||
do_parse({text, user_acc}, opts, {"", accumulate(acc, buffer, "<#{tag}"), :skip})
|
||||
|
||||
nil ->
|
||||
do_parse({text, user_acc}, opts, {"<", acc, {:open, 1}})
|
||||
do_parse({text, user_acc}, opts, {"<", accumulate(acc, buffer, ""), {:open, 1}})
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -179,6 +179,32 @@ defmodule LinkifyTest do
|
|||
|
||||
assert MapSet.to_list(tags) == ["#hello", "#world"]
|
||||
|
||||
text = "#justOne"
|
||||
|
||||
{result_text, %{tags: _tags}} =
|
||||
Linkify.link_map(text, %{tags: MapSet.new()},
|
||||
hashtag: true,
|
||||
hashtag_handler: handler,
|
||||
hashtag_prefix: "https://example.com/user/",
|
||||
rel: false
|
||||
)
|
||||
|
||||
assert result_text ==
|
||||
"<a href=\"https://example.com/user/justOne\">#justOne</a>"
|
||||
|
||||
text = "#justOne."
|
||||
|
||||
{result_text, %{tags: _tags}} =
|
||||
Linkify.link_map(text, %{tags: MapSet.new()},
|
||||
hashtag: true,
|
||||
hashtag_handler: handler,
|
||||
hashtag_prefix: "https://example.com/user/",
|
||||
rel: false
|
||||
)
|
||||
|
||||
assert result_text ==
|
||||
"<a href=\"https://example.com/user/justOne\">#justOne</a>."
|
||||
|
||||
text = "#cofe <br><a href=\"https://pleroma.social/\">Source</a>"
|
||||
|
||||
{_result_text, %{tags: tags}} =
|
||||
|
|
Loading…
Reference in a new issue