Merge branch 'mentions-and-apostrophes' into 'master'
Mentions and apostrophes See merge request pleroma/elixir-libraries/linkify!41
This commit is contained in:
commit
c1aea9357d
3 changed files with 24 additions and 2 deletions
|
@ -5,6 +5,7 @@
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
- Incorrect detection of IPv4 addresses causing random numbers (e.g., $123.45) to get linked
|
- Incorrect detection of IPv4 addresses causing random numbers (e.g., $123.45) to get linked
|
||||||
|
- Inability to link mentions with a trailing apostrophe. e.g., @user@example's
|
||||||
|
|
||||||
## 0.4.0 - 2020-11-24
|
## 0.4.0 - 2020-11-24
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,13 @@ defmodule Linkify.Parser do
|
||||||
|
|
||||||
@delimiters ~r/[,.;:>?!]*$/
|
@delimiters ~r/[,.;:>?!]*$/
|
||||||
|
|
||||||
|
@en_apostrophes [
|
||||||
|
"'",
|
||||||
|
"'s",
|
||||||
|
"'ll",
|
||||||
|
"'d"
|
||||||
|
]
|
||||||
|
|
||||||
@prefix_extra [
|
@prefix_extra [
|
||||||
"magnet:?",
|
"magnet:?",
|
||||||
"dweb://",
|
"dweb://",
|
||||||
|
@ -209,6 +216,12 @@ defmodule Linkify.Parser do
|
||||||
|
|
||||||
defp strip_punctuation(buffer), do: String.replace(buffer, @delimiters, "")
|
defp strip_punctuation(buffer), do: String.replace(buffer, @delimiters, "")
|
||||||
|
|
||||||
|
defp strip_en_apostrophes(buffer) do
|
||||||
|
Enum.reduce(@en_apostrophes, buffer, fn abbrev, buf ->
|
||||||
|
String.replace_suffix(buf, abbrev, "")
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
def url?(buffer, opts) do
|
def url?(buffer, opts) do
|
||||||
valid_url?(buffer) && Regex.match?(@match_url, buffer) && valid_tld?(buffer, opts)
|
valid_url?(buffer) && Regex.match?(@match_url, buffer) && valid_tld?(buffer, opts)
|
||||||
end
|
end
|
||||||
|
@ -367,6 +380,7 @@ defmodule Linkify.Parser do
|
||||||
buffer
|
buffer
|
||||||
|> String.split("<")
|
|> String.split("<")
|
||||||
|> List.first()
|
|> List.first()
|
||||||
|
|> strip_en_apostrophes()
|
||||||
|> strip_punctuation()
|
|> strip_punctuation()
|
||||||
|> strip_parens()
|
|> strip_parens()
|
||||||
|
|
||||||
|
|
|
@ -383,10 +383,17 @@ defmodule LinkifyTest do
|
||||||
new_window: true
|
new_window: true
|
||||||
) == expected
|
) == expected
|
||||||
|
|
||||||
|
expected =
|
||||||
|
"That's <a href=\"https://example.com/user/user@example.com\" target=\"_blank\">@user@example.com</a>'s server"
|
||||||
|
|
||||||
text = "That's @user@example.com's server"
|
text = "That's @user@example.com's server"
|
||||||
|
|
||||||
assert Linkify.link(text, mention: true, mention_prefix: "https://example.com/user/") ==
|
assert Linkify.link(text,
|
||||||
text
|
mention: true,
|
||||||
|
mention_prefix: "https://example.com/user/",
|
||||||
|
new_window: true
|
||||||
|
) ==
|
||||||
|
expected
|
||||||
end
|
end
|
||||||
|
|
||||||
test "mentions with no word-separation before them" do
|
test "mentions with no word-separation before them" do
|
||||||
|
|
Reference in a new issue