Sha256: 1c0e8e2b8d164f7a7f92f6584a29bae9939f5fa7fbe466664b22262d10d7535d

Contents?: true

Size: 1.32 KB

Versions: 3

Compression:

Stored size: 1.32 KB

Contents

module Infoboxer
  class Parser
    module HTML
      include Tree

      def html
        case
        when @context.check(%r{/[a-z]+>})
          html_closing_tag
        when @context.check(/br\s*>/)
          html_br
        when @context.check(%r{[a-z]+[^/>]*/>})
          html_auto_closing_tag
        when @context.check(%r{[a-z]+[^>/]*>})
          html_opening_tag
        else
          # not an HTML tag at all!
          nil
        end
      end

      def html_closing_tag
        @context.skip(%r{/})
        tag = @context.scan(/[a-z]+/)
        @context.skip(/>/)
        HTMLClosingTag.new(tag)
      end

      def html_br
        @context.skip(/br\s*>/)
        HTMLTag.new('br', {})
      end

      def html_auto_closing_tag
        tag = @context.scan(/[a-z]+/)
        attrs = @context.scan(%r{[^/>]*})
        @context.skip(%r{/>})
        HTMLTag.new(tag, parse_params(attrs))
      end

      def html_opening_tag
        tag = @context.scan(/[a-z]+/)
        attrs = @context.scan(/[^>]+/)
        @context.skip(/>/)
        contents = short_inline(%r{</#{tag}>})
        if @context.matched =~ %r{</#{tag}>}
          HTMLTag.new(tag, parse_params(attrs), contents)
        else
          [
            HTMLOpeningTag.new(tag, parse_params(attrs)),
            *contents
          ]
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

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