Class: SlackMarkdown::Filters::BoldFilter
- Inherits:
-
HTML::Pipeline::Filter
- Object
- HTML::Pipeline::Filter
- SlackMarkdown::Filters::BoldFilter
show all
- Includes:
- IgnorableAncestorTags
- Defined in:
- lib/slack_markdown/filters/bold_filter.rb
Constant Summary
collapse
- BOLD_PATTERN =
/(?<=^|\W)\*(.+)\*(?=\W|$)/.freeze
IgnorableAncestorTags::DEFAULT_IGNORED_ANCESTOR_TAGS
Instance Method Summary
collapse
#ignored_ancestor_tags
Instance Method Details
#bold_filter(text) ⇒ Object
25
26
27
28
29
|
# File 'lib/slack_markdown/filters/bold_filter.rb', line 25
def bold_filter(text)
text.gsub(BOLD_PATTERN) do
"<b>#{Regexp.last_match(1)}</b>"
end
end
|
#call ⇒ Object
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/slack_markdown/filters/bold_filter.rb', line 11
def call
doc.search('.//text()').each do |node|
content = node.to_html
next if has_ancestor?(node, ignored_ancestor_tags)
next unless content.include?('*')
html = bold_filter(content)
next if html == content
node.replace(html)
end
doc
end
|