about summary refs log tree commit diff
path: root/app/lib
diff options
context:
space:
mode:
authorFire Demon <firedemon@creature.cafe>2020-07-30 13:39:06 -0500
committerFire Demon <firedemon@creature.cafe>2020-08-30 05:45:16 -0500
commita38edbfcec7f2db247c6328ec84c9b81a29617e4 (patch)
tree050f60e0001459633952e3d1b5e05e18b31d64c5 /app/lib
parent369b9062dee5f21cd6d833f2c4687bb371889682 (diff)
[Command Tags] Use return template with code command
Diffstat (limited to 'app/lib')
-rw-r--r--app/lib/command_tag/commands/text_tools.rb17
1 files changed, 16 insertions, 1 deletions
diff --git a/app/lib/command_tag/commands/text_tools.rb b/app/lib/command_tag/commands/text_tools.rb
index 19f4b4f57..e004c7bec 100644
--- a/app/lib/command_tag/commands/text_tools.rb
+++ b/app/lib/command_tag/commands/text_tools.rb
@@ -2,8 +2,9 @@
 
 module CommandTag::Commands::TextTools
   def handle_code_at_start(args)
-    name = args.count > 1 ? args[0] : 'code'
+    return if args.count < 2
 
+    name = normalize(args[0])
     value = args.last.presence || ''
     @vars[name] = case @status.content_type
                   when 'text/markdown'
@@ -15,6 +16,20 @@ module CommandTag::Commands::TextTools
                   end
   end
 
+  def handle_code_with_return(args)
+    return if args.count > 1
+
+    value = args.last.presence || ''
+    case @status.content_type
+    when 'text/markdown'
+      ["```\n#{value}\n```"]
+    when 'text/html'
+      ["<pre><code>#{html_encode(value).gsub("\n", '<br/>')}</code></pre>"]
+    else
+      ["----------\n#{value}\n----------"]
+    end
+  end
+
   def handle_prepend_before_save(args)
     args.each { |arg| @text = "#{arg}\n#{text}" }
   end