Commit 2ab1d915 authored by lain's avatar lain
Browse files

Use unicode regex in mentions and links.

parent 7d34cec5
defmodule Pleroma.Formatter do defmodule Pleroma.Formatter do
alias Pleroma.User alias Pleroma.User
@link_regex ~r/https?:\/\/[\w\.\/?=\-#%&]+[\w]/ @link_regex ~r/https?:\/\/[\w\.\/?=\-#%&]+[\w]/u
def linkify(text) do def linkify(text) do
Regex.replace(@link_regex, text, "<a href='\\0'>\\0</a>") Regex.replace(@link_regex, text, "<a href='\\0'>\\0</a>")
end end
...@@ -14,7 +14,7 @@ def parse_tags(text) do ...@@ -14,7 +14,7 @@ def parse_tags(text) do
def parse_mentions(text) do def parse_mentions(text) do
# Modified from # Modified from
regex = ~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])?)*/ regex = ~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
Regex.scan(regex, text) Regex.scan(regex, text)
|> List.flatten |> List.flatten
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment