summaryrefslogtreecommitdiffstats
path: root/lib/redmine
diff options
context:
space:
mode:
Diffstat (limited to 'lib/redmine')
-rw-r--r--lib/redmine/wiki_formatting/common_mark/formatter.rb1
-rw-r--r--lib/redmine/wiki_formatting/common_mark/sanitization_filter.rb22
2 files changed, 22 insertions, 1 deletions
diff --git a/lib/redmine/wiki_formatting/common_mark/formatter.rb b/lib/redmine/wiki_formatting/common_mark/formatter.rb
index b695fb854..f2b9bca04 100644
--- a/lib/redmine/wiki_formatting/common_mark/formatter.rb
+++ b/lib/redmine/wiki_formatting/common_mark/formatter.rb
@@ -34,6 +34,7 @@ module Redmine
header_ids: nil,
tasklist: true,
shortcodes: false,
+ alerts: true,
}.freeze,
# https://github.com/gjtorikian/commonmarker#parse-options
diff --git a/lib/redmine/wiki_formatting/common_mark/sanitization_filter.rb b/lib/redmine/wiki_formatting/common_mark/sanitization_filter.rb
index e603d9f7f..af72adc32 100644
--- a/lib/redmine/wiki_formatting/common_mark/sanitization_filter.rb
+++ b/lib/redmine/wiki_formatting/common_mark/sanitization_filter.rb
@@ -68,6 +68,26 @@ module Redmine
end
}
+ # Allow class on div and p tags only for alert blocks
+ # (must be exactly: "markdown-alert markdown-alert-*" for div, and "markdown-alert-title" for p)
+ (allowlist[:attributes]["div"] ||= []) << "class"
+ (allowlist[:attributes]["p"] ||= []) << "class"
+ allowlist[:transformers].push lambda{|env|
+ node = env[:node]
+ return unless node.element?
+
+ case node.name
+ when 'div'
+ unless /\Amarkdown-alert markdown-alert-[a-z]+\z/.match?(node['class'])
+ node.remove_attribute('class')
+ end
+ when 'p'
+ unless node['class'] == 'markdown-alert-title'
+ node.remove_attribute('class')
+ end
+ end
+ }
+
# Allow table cell alignment by style attribute
#
# Only necessary if we used the TABLE_PREFER_STYLE_ATTRIBUTES
@@ -85,7 +105,7 @@ module Redmine
node = env[:node]
return unless node.name == "a"
return unless node.has_attribute?("id")
- return if node.name == "a" && node["id"] =~ /\Afnref-\d+\z/
+ return if node.name == "a" && node["id"] =~ /\Afnref(-\d+){1,2}\z/
node.remove_attribute("id")
}