Enable CommonMark alert extension (#42603).

Patch by Mizuki ISHIKAWA (user:ishikawa999).

git-svn-id: https://svn.redmine.org/redmine/trunk@23724 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Marius Balteanu
2025-04-29 21:13:55 +00:00
parent 0dc7337c7d
commit 8fa4c44581
5 changed files with 127 additions and 9 deletions

View File

@@ -34,6 +34,7 @@ module Redmine
header_ids: nil,
tasklist: true,
shortcodes: false,
alerts: true,
}.freeze,
# https://github.com/gjtorikian/commonmarker#parse-options

View File

@@ -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 node['class'] =~ /\Amarkdown-alert markdown-alert-[a-z]+\z/
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