diff options
author | Rémy Coutable <remy@rymai.me> | 2016-08-09 22:47:29 +0200 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2016-08-13 00:06:12 +0200 |
commit | e021604454f1093b7d762b28eae36e30083f0053 (patch) | |
tree | 6f6377cb9d7a92838dae62a7e59e87b9699c2c98 /lib | |
parent | 39f7f63fe951ff861ad151125188e6cdd598b6ff (diff) | |
download | gitlab-ce-e021604454f1093b7d762b28eae36e30083f0053.tar.gz |
Don't extract slash commands inside blockcode, blockquote or HTML tags
Improve slash command descriptions, support /due tomorrow
Signed-off-by: Rémy Coutable <remy@rymai.me>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/slash_commands/extractor.rb | 51 |
1 files changed, 48 insertions, 3 deletions
diff --git a/lib/gitlab/slash_commands/extractor.rb b/lib/gitlab/slash_commands/extractor.rb index 1a854b81aca..ce0a2eba535 100644 --- a/lib/gitlab/slash_commands/extractor.rb +++ b/lib/gitlab/slash_commands/extractor.rb @@ -34,9 +34,14 @@ module Gitlab commands = [] + content.delete!("\r") content.gsub!(commands_regex) do - commands << [$1, $2].flatten.reject(&:blank?) - '' + if $~[:cmd] + commands << [$~[:cmd], $~[:args]].reject(&:blank?) + '' + else + $~[0] + end end commands @@ -52,7 +57,47 @@ module Gitlab # # /^\/(?<cmd>close|reopen|...)(?:( |$))(?<args>[^\/\n]*)(?:\n|$)/ def commands_regex - /^\/(?<cmd>#{command_names.join('|')})(?:( |$))(?<args>[^\/\n]*)(?:\n|$)/ + @commands_regex ||= %r{ + (?<code> + # Code blocks: + # ``` + # Anything, including `/cmd args` which are ignored by this filter + # ``` + + ^``` + .+? + \n```$ + ) + | + (?<html> + # HTML block: + # <tag> + # Anything, including `/cmd args` which are ignored by this filter + # </tag> + + ^<[^>]+?>\n + .+? + \n<\/[^>]+?>$ + ) + | + (?<html> + # Quote block: + # >>> + # Anything, including `/cmd args` which are ignored by this filter + # >>> + + ^>>> + .+? + \n>>>$ + ) + | + (?: + # Command not in a blockquote, blockcode, or HTML tag: + # /close + + ^\/(?<cmd>#{command_names.join('|')})(?:(\ |$))(?<args>[^\/\n]*)(?:\n|$) + ) + }mx end end end |