Sha256: 5fe8bd26547d822facaa043d88f87cc849131b6a640e829ca5852b1f091bb0c8

Contents?: true

Size: 1.57 KB

Versions: 14

Compression:

Stored size: 1.57 KB

Contents

# -*- coding: utf-8 -*-
#
#--
# Copyright (C) 2009-2015 Thomas Leitner <t_leitner@gmx.at>
#
# This file is part of kramdown which is licensed under the MIT.
#++
#

require 'kramdown/converter'

module Kramdown

  module Converter

    # 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.
    class RemoveHtmlTags < Base

      def initialize(root, options)
        super
        @options[:template] = ''
      end

      def convert(el)
        children = el.children.dup
        index = 0
        while index < children.length
          if [:xml_pi].include?(children[index].type) ||
              (children[index].type == :html_element && %w[style script].include?(children[index].value))
            children[index..index] = []
          elsif children[index].type == :html_element &&
            ((@options[:remove_block_html_tags] && children[index].options[:category] == :block) ||
             (@options[:remove_span_html_tags] && children[index].options[:category] == :span))
            children[index..index] = children[index].children
          else
            convert(children[index])
            index += 1
          end
        end
        el.children = children
        el
      end

    end

  end
end

Version data entries

14 entries across 13 versions & 5 rubygems

Version Path
able-neo4j-1.0.0 vendor/bundle/jruby/1.9/gems/kramdown-1.8.0/lib/kramdown/converter/remove_html_tags.rb
kramdown-1.10.0 lib/kramdown/converter/remove_html_tags.rb
angular-rails4-templates-0.4.1 vendor/ruby/2.1.0/gems/kramdown-1.8.0/lib/kramdown/converter/remove_html_tags.rb
angular-rails4-templates-0.4.0 vendor/ruby/2.1.0/gems/kramdown-1.8.0/lib/kramdown/converter/remove_html_tags.rb
angular-rails4-templates-0.3.0 vendor/ruby/2.1.0/gems/kramdown-1.8.0/lib/kramdown/converter/remove_html_tags.rb
logstash-input-beats-2.0.2 vendor/jruby/1.9/gems/kramdown-1.9.0/lib/kramdown/converter/remove_html_tags.rb
logstash-input-beats-2.0.2 vendor/jruby/1.9/gems/logstash-codec-json-2.0.3/vendor/gems/kramdown-1.9.0/lib/kramdown/converter/remove_html_tags.rb
logstash-codec-json-2.0.3 vendor/gems/kramdown-1.9.0/lib/kramdown/converter/remove_html_tags.rb
logstash-input-beats-0.9.2 vendor/jruby/1.9/gems/kramdown-1.9.0/lib/kramdown/converter/remove_html_tags.rb
logstash-input-beats-0.9.1 vendor/jruby/1.9/gems/kramdown-1.9.0/lib/kramdown/converter/remove_html_tags.rb
kramdown-1.9.0 lib/kramdown/converter/remove_html_tags.rb
kramdown-1.8.0 lib/kramdown/converter/remove_html_tags.rb
kramdown-1.7.0 lib/kramdown/converter/remove_html_tags.rb
kramdown-1.6.0 lib/kramdown/converter/remove_html_tags.rb