about summary refs log tree commit diff
diff options
context:
space:
mode:
authormultiple creatures <dev@multiple-creature.party>2019-07-20 11:51:25 -0500
committermultiple creatures <dev@multiple-creature.party>2019-07-20 11:51:25 -0500
commit1edc2f1aeb5d8ebe217d6909b7df975c6e1b024a (patch)
treed0c54041520e595c859afbfba823f5ac2fa57aeb
parentf0506110c4543f34629e9950e71d58d23e50c619 (diff)
fix display of `admin:eval` comments
-rw-r--r--app/lib/bangtags.rb12
1 files changed, 9 insertions, 3 deletions
diff --git a/app/lib/bangtags.rb b/app/lib/bangtags.rb
index f853a49a9..0e8b7c532 100644
--- a/app/lib/bangtags.rb
+++ b/app/lib/bangtags.rb
@@ -9,6 +9,8 @@ class Bangtags
     @account       = status.account
     @parent_status = Status.find(status.in_reply_to_id) if status.in_reply_to_id
 
+    @crunch_newlines = false
+
     @prefix_ns = {
       'permalink' => ['link'],
       'cloudroot' => ['link'],
@@ -557,7 +559,6 @@ class Bangtags
               @chunks << "<em>Unauthorized.</em>"
               next
             end
-            @chunks << "<strong>Input:</strong>"
             unless cmd[2].present? && cmd[2].downcase == 'last'
               @vars.delete("_admin:eval")
               @vore_stack.push("_admin:eval")
@@ -666,6 +667,8 @@ class Bangtags
     account.user.save
 
     text = @chunks.join
+    text.gsub!(/\n\n+/, "\n") if @crunch_newlines
+
     if text.blank?
       RemoveStatusService.new.call(@status)
     else
@@ -696,15 +699,18 @@ class Bangtags
         next if post_cmd[1].nil?
         case post_cmd[1]
         when 'eval'
+          @crunch_newlines = true
+          @vars["_admin:eval"].strip!
+          @chunks << "\n<strong>Input:</strong>"
           @chunks << "<pre><code>"
           @chunks << html_entities.encode(@vars["_admin:eval"]).gsub("\n", '<br/>')
-          @chunks << "</code></pre>\n"
-          @chunks << "<strong>Output:</strong>"
+          @chunks << "</code></pre>"
           begin
             result = eval(@vars["_admin:eval"])
           rescue Exception => e
             result = "\u274c #{e.message}"
           end
+          @chunks << "<strong>Output:</strong>"
           @chunks << "<pre><code>"
           @chunks << html_entities.encode(result).gsub("\n", '<br/>')
           @chunks << "</code></pre>"