diff options
author | Surinna Curtis <ekiru.0@gmail.com> | 2017-11-16 01:38:26 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-11-16 01:38:26 -0600 |
commit | ee560abdbe7a2caf0f7ac6137faf248bbaff9a93 (patch) | |
tree | fcd9bdb5ba49ab7a6a79590c74db858ae77b4239 /app/lib | |
parent | 88627fd7aa2493a6890d60a5965459e4c7fe6fe9 (diff) | |
parent | 35fbdc36f92b610e8a73e2acb220e87cf5fc83b0 (diff) |
Merge pull request #216 from glitch-soc/merge-upstream-3023725
Merge upstream at commit 3023725
Diffstat (limited to 'app/lib')
-rw-r--r-- | app/lib/formatter.rb | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/app/lib/formatter.rb b/app/lib/formatter.rb index 57f105da7..733a1c4b7 100644 --- a/app/lib/formatter.rb +++ b/app/lib/formatter.rb @@ -89,20 +89,28 @@ class Formatter end end + def count_tag_nesting(tag) + if tag[1] == '/' then -1 + elsif tag[-2] == '/' then 0 + else 1 + end + end + def encode_custom_emojis(html, emojis) return html if emojis.empty? emoji_map = emojis.map { |e| [e.shortcode, full_asset_url(e.image.url(:static))] }.to_h i = -1 - inside_tag = false + tag_open_index = nil inside_shortname = false shortname_start_index = -1 + invisible_depth = 0 while i + 1 < html.size i += 1 - if inside_shortname && html[i] == ':' + if invisible_depth.zero? && inside_shortname && html[i] == ':' shortcode = html[shortname_start_index + 1..i - 1] emoji = emoji_map[shortcode] @@ -116,12 +124,18 @@ class Formatter end inside_shortname = false - elsif inside_tag && html[i] == '>' - inside_tag = false + elsif tag_open_index && html[i] == '>' + tag = html[tag_open_index..i] + tag_open_index = nil + if invisible_depth.positive? + invisible_depth += count_tag_nesting(tag) + elsif tag == '<span class="invisible">' + invisible_depth = 1 + end elsif html[i] == '<' - inside_tag = true + tag_open_index = i inside_shortname = false - elsif !inside_tag && html[i] == ':' + elsif !tag_open_index && html[i] == ':' inside_shortname = true shortname_start_index = i end |