Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRémy Coutable <remy@rymai.me>2016-08-09 23:47:29 +0300
committerRémy Coutable <remy@rymai.me>2016-08-13 01:06:12 +0300
commite021604454f1093b7d762b28eae36e30083f0053 (patch)
tree6f6377cb9d7a92838dae62a7e59e87b9699c2c98 /lib/gitlab/slash_commands
parent39f7f63fe951ff861ad151125188e6cdd598b6ff (diff)
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/gitlab/slash_commands')
-rw-r--r--lib/gitlab/slash_commands/extractor.rb51
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