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