class Kramdown::Converter::RemoveHtmlTags
Removes all block (and optionally span) level HTML tags from the element tree.
This converter can be used on parsed HTML documents to get an element tree that will only contain native kramdown elements.
Note that the returned element tree may not be fully conformant (i.e. the content models of *some elements may be violated)!
This converter modifies the given tree in-place and returns it.
Public Class Methods
new(root, options)
click to toggle source
Calls superclass method
Kramdown::Converter::Base::new
# File lib/kramdown/converter/remove_html_tags.rb 26 def initialize(root, options) 27 super 28 @options[:template] = '' 29 end
Public Instance Methods
convert(el)
click to toggle source
# File lib/kramdown/converter/remove_html_tags.rb 31 def convert(el) 32 real_el, el = el, el.value if el.type == :footnote 33 34 children = el.children.dup 35 index = 0 36 while index < children.length 37 if children[index].type == :xml_pi || 38 (children[index].type == :html_element && (children[index].value == 'style' || 39 children[index].value == 'script')) 40 children[index..index] = [] 41 elsif children[index].type == :html_element && 42 ((@options[:remove_block_html_tags] && children[index].options[:category] == :block) || 43 (@options[:remove_span_html_tags] && children[index].options[:category] == :span)) 44 children[index..index] = children[index].children 45 else 46 convert(children[index]) 47 index += 1 48 end 49 end 50 el.children = children 51 real_el || el 52 end