Defect #43446 ยป 0001-Fix-performance-issue.patch
| lib/redmine/wiki_formatting/common_mark/alerts_icons_scrubber.rb | ||
|---|---|---|
| 31 | 31 |
}.freeze |
| 32 | 32 | |
| 33 | 33 |
class AlertsIconsScrubber < Loofah::Scrubber |
| 34 |
def scrub(doc)
|
|
| 35 |
doc.search("p.markdown-alert-title").each do |node|
|
|
| 34 |
def scrub(node)
|
|
| 35 |
if node.name == 'p' && node['class'] == 'markdown-alert-title'
|
|
| 36 | 36 |
parent_node = node.parent |
| 37 | 37 |
parent_class_attr = parent_node['class'] # e.g., "markdown-alert markdown-alert-note" |
| 38 |
next unless parent_class_attr
|
|
| 38 |
return unless parent_class_attr
|
|
| 39 | 39 | |
| 40 | 40 |
# Extract the specific alert type (e.g., "note", "tip", "warning") |
| 41 | 41 |
# from the parent div's classes. |
| 42 | 42 |
match_data = parent_class_attr.match(/markdown-alert-(\w+)/) |
| 43 |
next unless match_data && match_data[1] # Ensure a type is found
|
|
| 43 |
return unless match_data && match_data[1] # Ensure a type is found
|
|
| 44 | 44 | |
| 45 | 45 |
alert_type = match_data[1] |
| 46 | 46 | |
| 47 | 47 |
# Get the corresponding icon name from our map. |
| 48 | 48 |
icon_name = ALERT_TYPE_TO_ICON_NAME[alert_type] |
| 49 |
next unless icon_name # Skip if no specific icon is defined for this alert type
|
|
| 49 |
return unless icon_name # Skip if no specific icon is defined for this alert type
|
|
| 50 | 50 | |
| 51 | 51 |
# Translate the alert title only if it matches a known alert type |
| 52 | 52 |
# (i.e., the title has not been overridden) |
| ... | ... | |
| 61 | 61 |
node.children.first.replace(icon_html) |
| 62 | 62 |
end |
| 63 | 63 |
end |
| 64 |
doc |
|
| 65 | 64 |
end |
| 66 | 65 |
end |
| 67 | 66 |
end |
| lib/redmine/wiki_formatting/common_mark/syntax_highlight_scrubber.rb | ||
|---|---|---|
| 24 | 24 |
# blocks as generated by commonmarker |
| 25 | 25 |
class SyntaxHighlightScrubber < Loofah::Scrubber |
| 26 | 26 |
def scrub(node) |
| 27 |
if node.matches?("pre > code")
|
|
| 28 |
return unless lang = node["class"].presence |
|
| 29 |
return unless lang =~ /\Alanguage-(\S+)\z/ |
|
| 27 |
# Equivalent to the CSS selector "pre > code". Implemented for performance |
|
| 28 |
return unless node.name == 'code' && node.parent.name == 'pre' |
|
| 30 | 29 | |
| 31 |
lang = $1
|
|
| 32 |
text = node.inner_text
|
|
| 30 |
return unless lang = node["class"].presence
|
|
| 31 |
return unless lang =~ /\Alanguage-(\S+)\z/
|
|
| 33 | 32 | |
| 34 |
# original language for extension development
|
|
| 35 |
node["data-language"] = lang unless node["data-language"]
|
|
| 33 |
lang = $1
|
|
| 34 |
text = node.inner_text
|
|
| 36 | 35 | |
| 37 |
if Redmine::SyntaxHighlighting.language_supported?(lang) |
|
| 38 |
html = Redmine::SyntaxHighlighting.highlight_by_language(text, lang) |
|
| 39 |
return if html.nil? |
|
| 36 |
# original language for extension development |
|
| 37 |
node["data-language"] = lang unless node["data-language"] |
|
| 40 | 38 | |
| 41 |
node.inner_html = html |
|
| 42 |
node["class"] = "#{lang} syntaxhl"
|
|
| 43 |
else |
|
| 44 |
# unsupported language, remove the class attribute |
|
| 45 |
node.remove_attribute("class")
|
|
| 46 |
end |
|
| 39 |
if Redmine::SyntaxHighlighting.language_supported?(lang) |
|
| 40 |
html = Redmine::SyntaxHighlighting.highlight_by_language(text, lang) |
|
| 41 |
return if html.nil? |
|
| 42 | ||
| 43 |
node.inner_html = html |
|
| 44 |
node["class"] = "#{lang} syntaxhl"
|
|
| 45 |
else |
|
| 46 |
# unsupported language, remove the class attribute |
|
| 47 |
node.remove_attribute("class")
|
|
| 47 | 48 |
end |
| 48 | 49 |
end |
| 49 | 50 |
end |