Sha256: 4ddc7f6c89d31890bf9dbc0692a2d49946cb1bd9c1efb83e8bbbe5b196c24a12

Contents?: true

Size: 1.57 KB

Versions: 69

Compression:

Stored size: 1.57 KB

Contents

# -*- coding: utf-8 -*-
#
#--
# Copyright (C) 2009-2016 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

69 entries across 66 versions & 16 rubygems

Version Path
logstash-output-scalyr-0.1.9 vendor/bundle/jruby/2.5.0/gems/kramdown-1.14.0/lib/kramdown/converter/remove_html_tags.rb
logstash-output-scalyr-0.1.8 vendor/bundle/jruby/2.5.0/gems/kramdown-1.14.0/lib/kramdown/converter/remove_html_tags.rb
logstash-output-scalyr-0.1.7 vendor/bundle/jruby/2.5.0/gems/kramdown-1.14.0/lib/kramdown/converter/remove_html_tags.rb
logstash-output-scalyr-0.1.6 vendor/bundle/jruby/2.5.0/gems/kramdown-1.14.0/lib/kramdown/converter/remove_html_tags.rb
logstash-output-newrelic-1.2.0 vendor/bundle/jruby/2.5.0/gems/kramdown-1.14.0/lib/kramdown/converter/remove_html_tags.rb
logstash-filter-csharp-0.2.1 vendor/bundle/jruby/2.3.0/gems/kramdown-1.13.2/lib/kramdown/converter/remove_html_tags.rb
logstash-filter-csharp-0.2.1 vendor/bundle/jruby/2.5.0/gems/kramdown-1.14.0/lib/kramdown/converter/remove_html_tags.rb
logstash-filter-csharp-0.2.0 vendor/bundle/jruby/2.3.0/gems/kramdown-1.13.2/lib/kramdown/converter/remove_html_tags.rb
logstash-filter-csharp-0.2.0 vendor/bundle/jruby/2.5.0/gems/kramdown-1.14.0/lib/kramdown/converter/remove_html_tags.rb
logstash-output-scalyr-0.1.5 vendor/bundle/jruby/2.5.0/gems/kramdown-1.14.0/lib/kramdown/converter/remove_html_tags.rb
logstash-output-scalyr-0.1.4 vendor/bundle/jruby/2.5.0/gems/kramdown-1.14.0/lib/kramdown/converter/remove_html_tags.rb
logstash-output-scalyr-0.1.3 vendor/bundle/jruby/2.5.0/gems/kramdown-1.14.0/lib/kramdown/converter/remove_html_tags.rb
logstash-output-scalyr-0.1.2 vendor/bundle/jruby/2.5.0/gems/kramdown-1.14.0/lib/kramdown/converter/remove_html_tags.rb
logstash-filter-device_detection-1.0.7-java vendor/bundle/jruby/1.9/gems/kramdown-1.14.0/lib/kramdown/converter/remove_html_tags.rb
mrcooper-logstash-output-azuresearch-0.2.2 vendor/jruby/2.5.0/gems/kramdown-1.14.0/lib/kramdown/converter/remove_html_tags.rb
logstash-output-icinga-1.1.0 vendor/jruby/1.9/gems/kramdown-1.13.2/lib/kramdown/converter/remove_html_tags.rb
logstash-output-icinga-1.1.0 vendor/jruby/2.3.0/gems/kramdown-1.13.2/lib/kramdown/converter/remove_html_tags.rb
kramdown-1.15.0 lib/kramdown/converter/remove_html_tags.rb
logstash-filter-cache-redis-0.3.1 vendor/bundle/jruby/1.9/gems/kramdown-1.14.0/lib/kramdown/converter/remove_html_tags.rb
logstash-filter-cache-redis-0.3.0 vendor/bundle/jruby/1.9/gems/kramdown-1.14.0/lib/kramdown/converter/remove_html_tags.rb