fix markdown formatting

This commit is contained in:
Maksim Pechnikov 2018-12-14 12:41:55 +03:00
commit baead4ea4b
7 changed files with 49 additions and 11 deletions

View file

@ -5,6 +5,8 @@ defmodule Pleroma.Formatter do
alias Pleroma.Emoji
@tag_regex ~r/\#\w+/u
@mardown_characters_regex ~r/(`|\*|_|{|}|[|]|\(|\)|#|\+|-|\.|!)/
def parse_tags(text, data \\ %{}) do
Regex.scan(@tag_regex, text)
|> Enum.map(fn ["#" <> tag = full_tag] -> {full_tag, String.downcase(tag)} end)
@ -76,6 +78,18 @@ defmodule Pleroma.Formatter do
|> Enum.join("")
end
@doc """
Escapes a special characters in mention names.
"""
@spec mentions_escape(String.t(), list({String.t(), any()})) :: String.t()
def mentions_escape(text, mentions) do
mentions
|> Enum.reduce(text, fn {name, _}, acc ->
escape_name = String.replace(name, @mardown_characters_regex, "\\\\\\1")
String.replace(acc, name, escape_name)
end)
end
@doc "changes scheme:... urls to html links"
def add_links({subs, text}) do
links =