diff options
author | Maksim Pechnikov <parallel588@gmail.com> | 2018-12-14 12:41:55 +0300 |
---|---|---|
committer | Maksim Pechnikov <parallel588@gmail.com> | 2018-12-14 16:03:58 +0300 |
commit | baead4ea4b84ab1190b87a2dc73cdc4afaa6ebc6 (patch) | |
tree | 9f602b5abff3daafedb34bf50c4967a6503e4511 /lib/pleroma/formatter.ex | |
parent | 91236c60c7aa266c1e874ebdd2aa44becfc6709b (diff) | |
download | pleroma-baead4ea4b84ab1190b87a2dc73cdc4afaa6ebc6.tar.gz |
fix markdown formatting
Diffstat (limited to 'lib/pleroma/formatter.ex')
-rw-r--r-- | lib/pleroma/formatter.ex | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/pleroma/formatter.ex b/lib/pleroma/formatter.ex index 133683794..b6079551c 100644 --- a/lib/pleroma/formatter.ex +++ b/lib/pleroma/formatter.ex @@ -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 = |