class Qiita::Markdown::Filters::Simplify

A filter for simplifying document structure by removing complex markups (mainly block elements) and complex contents.

The logic of this filter is similar to the ‘FinalSanitizer` filter, but this does not use the `sanitize` gem internally for the following reasons:

Constants

COMPLEX_CONTENT_ELEMENTS
SIMPLE_ELEMENTS

Public Instance Methods

call() click to toggle source
# File lib/qiita/markdown/filters/simplify.rb, line 22
def call
  remove_complex_contents
  clean_complex_markups
  doc
end

Private Instance Methods

clean_complex_markups() click to toggle source

Remove complex markups while keeping their contents.

# File lib/qiita/markdown/filters/simplify.rb, line 37
def clean_complex_markups
  doc.traverse do |node|
    next unless node.element?
    next if SIMPLE_ELEMENTS.include?(node.name)

    node.replace(node.children)
  end
end
remove_complex_contents() click to toggle source

Remove complex elements along with their contents entirely.

# File lib/qiita/markdown/filters/simplify.rb, line 31
def remove_complex_contents
  selector = COMPLEX_CONTENT_ELEMENTS.join(",")
  doc.search(selector).each(&:remove)
end