diff options
author | multiple creatures <dev@multiple-creature.party> | 2019-08-31 13:30:19 -0500 |
---|---|---|
committer | multiple creatures <dev@multiple-creature.party> | 2019-08-31 13:30:19 -0500 |
commit | 8c81626a56fb30151ad8bb32199161a414eab48d (patch) | |
tree | 525851d21a2ac46454bd812f96e8cfe151c701ea | |
parent | 867a13a74030ea1fc0b83208028de700aacc8177 (diff) |
add `strip` bangtag - removes leading/trailing whitespace from lines
-rw-r--r-- | app/lib/bangtags.rb | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/app/lib/bangtags.rb b/app/lib/bangtags.rb index 0e4b81560..31395740d 100644 --- a/app/lib/bangtags.rb +++ b/app/lib/bangtags.rb @@ -13,6 +13,7 @@ class Bangtags @crunch_newlines = false @once = false @sroff_open = false + @strip_lines = false @prefix_ns = { 'permalink' => ['link'], @@ -135,6 +136,9 @@ class Bangtags @vars[var] = new_value.join(':') end end + when 'strip' + chunk = nil + @strip_lines = cmd[1]&.downcase.in?(['y', 'yes', '', nil]) when 'tf' chunk = nil next if cmd[1].nil? @@ -916,12 +920,12 @@ class Bangtags text = @chunks.join text.gsub!(/\n\n+/, "\n") if @crunch_newlines + text.strip! + text = text.split("\n").map { |chunk| chunk.strip }.join("\n") if @strip_lines 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 |