about summary refs log tree commit diff
path: root/app/lib
diff options
context:
space:
mode:
Diffstat (limited to 'app/lib')
-rw-r--r--app/lib/bangtags.rb13
-rw-r--r--app/lib/formatter.rb6
2 files changed, 19 insertions, 0 deletions
diff --git a/app/lib/bangtags.rb b/app/lib/bangtags.rb
index 10076f074..0e4b81560 100644
--- a/app/lib/bangtags.rb
+++ b/app/lib/bangtags.rb
@@ -12,6 +12,7 @@ class Bangtags
 
     @crunch_newlines = false
     @once = false
+    @sroff_open = false
 
     @prefix_ns = {
       'permalink' => ['link'],
@@ -687,6 +688,14 @@ class Bangtags
             keyboard[(keyboard.size * (rand ** 3)).floor].split('').sample
           end
           chunk = chunk.join
+        when 'nosr', 'sroff', 'srskip'
+          next if @sroff_open
+          @sroff_open = true
+          chunk = "\uf333"
+        when 'sr', 'sron', 'srcont'
+          next unless @sroff_open
+          @sroff_open = false
+          chunk = "\uf334"
         when 'admin'
           chunk = nil
           next unless @user.admin?
@@ -911,6 +920,8 @@ class Bangtags
     if text.blank?
       RemoveStatusService.new.call(@status)
     else
+      text.gsub!(/^\uf333\n/m, "\uf333")
+      text.gsub!(/\n\uf334$/m, "\uf334")
       status.text = text
       status.save
       postprocess_after_save
@@ -987,6 +998,8 @@ class Bangtags
         end
       end
     end
+
+    @chunks << "\uf334" if @sroff_open
   end
 
   def postprocess_after_save
diff --git a/app/lib/formatter.rb b/app/lib/formatter.rb
index 499bf90a9..272dc7222 100644
--- a/app/lib/formatter.rb
+++ b/app/lib/formatter.rb
@@ -221,6 +221,8 @@ class Formatter
       html = format_bbdown(html)
     end
 
+    html = format_screenreader(html)
+
     html = encode_and_link_urls(html, linkable_accounts, keep_html: %w(text/markdown text/x-bbcode text/x-bbcode+markdown text/html).include?(status.content_type))
     html = encode_custom_emojis(html, status.emojis, options[:autoplay]) if options[:custom_emojify]
 
@@ -248,6 +250,10 @@ class Formatter
     html.html_safe # rubocop:disable Rails/OutputSafety
   end
 
+  def format_screenreader(html)
+    html.gsub(/\uf333(.*)\uf334/m, '<span aria-hidden="true">\1</span>')
+  end
+
   def format_console(html)
     cursor = '<span class="cursor"></span>'
     "<pre><code>#{html.strip.sub(/<\/p>\Z/, cursor)}</p></code></pre>"