From 867a13a74030ea1fc0b83208028de700aacc8177 Mon Sep 17 00:00:00 2001 From: multiple creatures Date: Sat, 31 Aug 2019 13:00:37 -0500 Subject: add `nosr` & `sr` bangtags to mark sections of posts that should and should not be read by screenreaders --- app/lib/bangtags.rb | 13 +++++++++++++ app/lib/formatter.rb | 6 ++++++ 2 files changed, 19 insertions(+) (limited to 'app') 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, '') + end + def format_console(html) cursor = '' "
#{html.strip.sub(/<\/p>\Z/, cursor)}

" -- cgit