Class: Banzai::Filter::InlineDiffFilter
- Inherits:
-
HTML::Pipeline::Filter
- Object
- HTML::Pipeline::Filter
- Banzai::Filter::InlineDiffFilter
- Defined in:
- lib/banzai/filter/inline_diff_filter.rb
Constant Summary collapse
- IGNORED_ANCESTOR_TAGS =
%w(pre code tt).to_set
Instance Method Summary collapse
Instance Method Details
#call ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/banzai/filter/inline_diff_filter.rb', line 9 def call doc.xpath('descendant-or-self::text()').each do |node| next if has_ancestor?(node, IGNORED_ANCESTOR_TAGS) content = node.to_html html_content = inline_diff_filter(content) next if content == html_content node.replace(html_content) end doc end |
#inline_diff_filter(text) ⇒ Object
23 24 25 26 |
# File 'lib/banzai/filter/inline_diff_filter.rb', line 23 def inline_diff_filter(text) html_content = text.gsub(/(?:\[\-(.*?)\-\]|\{\-(.*?)\-\})/, '<span class="idiff left right deletion">\1\2</span>') html_content.gsub(/(?:\[\+(.*?)\+\]|\{\+(.*?)\+\})/, '<span class="idiff left right addition">\1\2</span>') end |