Sha256: ec10b4d4ea0afdfde8b6f980f04e9abd5d3ef68cbcc9f523ffbd061c97bbf5a4

Contents?: true

Size: 1.65 KB

Versions: 3

Compression:

Stored size: 1.65 KB

Contents

module Infoboxer
  module Tree
    module HTMLTagCommons
      BLOCK_TAGS = %w[div p br].freeze # FIXME: are some other used in WP?

      def text
        super + (BLOCK_TAGS.include?(tag) ? "\n" : '')
      end
    end

    # Represents HTML tag, surrounding some contents.
    class HTMLTag < Compound
      def initialize(tag, attrs, children = Nodes.new)
        super(children, attrs)
        @tag = tag
      end

      attr_reader :tag
      alias_method :attrs, :params

      include HTMLTagCommons

      # @private
      # Internal, used by {Parser}.
      def empty?
        # even empty tag, for ex., <br>, should not be dropped!
        false
      end

      private

      def descr
        "#{clean_class}:#{tag}(#{show_params})"
      end
    end

    # Represents orphan opening HTML tag.
    #
    # NB: Infoboxer not tries to parse entire structure of HTML-heavy
    # MediaWiki articles. So, if you have `<div>` at line 150 and closing
    # `</div>` at line 875, there would be orphane `HTMLOpeningTag` and
    # {HTMLClosingTag}. It is not always convenient, but reasonable enough.
    #
    class HTMLOpeningTag < Node
      def initialize(tag, attrs)
        super(attrs)
        @tag = tag
      end

      attr_reader :tag
      alias_method :attrs, :params

      include HTMLTagCommons

      private

      def descr
        "#{clean_class}:#{tag}(#{show_params})"
      end
    end

    # Represents orphan closing HTML tag. See {HTMLOpeningTag} for
    # explanation.
    class HTMLClosingTag < Node
      def initialize(tag)
        @tag = tag
      end

      attr_reader :tag

      def descr
        "#{clean_class}:#{tag}"
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
infoboxer-0.3.3 lib/infoboxer/tree/html.rb
infoboxer-0.3.2 lib/infoboxer/tree/html.rb
infoboxer-0.3.1 lib/infoboxer/tree/html.rb