Class: Redmine::WikiFormatting::CommonMark::AlertsIconsFilter

Inherits:
HTML::Pipeline::Filter
  • Object
show all
Defined in:
lib/redmine/wiki_formatting/common_mark/alerts_icons_filter.rb

Instance Method Summary collapse

Instance Method Details

#callObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/redmine/wiki_formatting/common_mark/alerts_icons_filter.rb', line 34

def call
  doc.search("p.markdown-alert-title").each do |node|
    parent_node = node.parent
    parent_class_attr = parent_node['class'] # e.g., "markdown-alert markdown-alert-note"
    next unless parent_class_attr

    # Extract the specific alert type (e.g., "note", "tip", "warning")
    # from the parent div's classes.
    match_data = parent_class_attr.match(/markdown-alert-(\w+)/)
    next unless match_data && match_data[1] # Ensure a type is found

    alert_type = match_data[1]

    # Get the corresponding icon name from our map.
    icon_name = ALERT_TYPE_TO_ICON_NAME[alert_type]
    next unless icon_name # Skip if no specific icon is defined for this alert type

    icon_html = ApplicationController.helpers.sprite_icon(icon_name, node.text)

    if icon_html
      # Replace the existing text node with the icon HTML and label (text).
      node.children.first.replace(icon_html)
    end
  end
  doc
end