Sha256: 1d615d2eb8bbf1c3880a3697264f7602e50ae1dc9ce77c869aba596e11856f2d

Contents?: true

Size: 1.67 KB

Versions: 15

Compression:

Stored size: 1.67 KB

Contents

# -*- coding: utf-8; frozen_string_literal: true -*-
#
#--
# Copyright (C) 2009-2019 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)
        real_el, el = el, el.value if el.type == :footnote

        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
        real_el || el
      end

    end

  end
end

Version data entries

15 entries across 15 versions & 4 rubygems

Version Path
getargv-0.3.3-universal-darwin vendor/bundle/ruby/3.3.0/gems/kramdown-2.4.0/lib/kramdown/converter/remove_html_tags.rb
kramdown-2.4.0 lib/kramdown/converter/remove_html_tags.rb
kramdown-2.3.2 lib/kramdown/converter/remove_html_tags.rb
kramdown-2.3.1 lib/kramdown/converter/remove_html_tags.rb
daqing_kramdown-2.3.2 lib/kramdown/converter/remove_html_tags.rb
daqing_kramdown-2.3.1 lib/kramdown/converter/remove_html_tags.rb
zine_brewer-1.5.0 vendor/bundle/ruby/2.7.0/gems/kramdown-2.3.0/lib/kramdown/converter/remove_html_tags.rb
zine_brewer-1.3.0 vendor/bundle/ruby/2.7.0/gems/kramdown-2.3.0/lib/kramdown/converter/remove_html_tags.rb
kramdown-2.3.0 lib/kramdown/converter/remove_html_tags.rb
kramdown-2.2.1 lib/kramdown/converter/remove_html_tags.rb
kramdown-2.2.0 lib/kramdown/converter/remove_html_tags.rb
kramdown-2.1.0 lib/kramdown/converter/remove_html_tags.rb
kramdown-2.0.0 lib/kramdown/converter/remove_html_tags.rb
kramdown-2.0.0.beta2 lib/kramdown/converter/remove_html_tags.rb
kramdown-2.0.0.beta1 lib/kramdown/converter/remove_html_tags.rb