class Kramdown::Parser::Html

Used for parsing an HTML document.

The parsing code is in the Parser module that can also be used by other parsers.

Public Instance Methods

parse() click to toggle source

Parse the source string provided on initialization as HTML document.

    # File lib/kramdown/parser/html.rb
578 def parse
579   @stack, @tree = [], @root
580   @src = Kramdown::Utils::StringScanner.new(adapt_source(source))
581 
582   while true
583     if (result = @src.scan(/\s*#{HTML_INSTRUCTION_RE}/o))
584       @tree.children << Element.new(:xml_pi, result.strip, nil, category: :block)
585     elsif (result = @src.scan(/\s*#{HTML_DOCTYPE_RE}/o))
586       # ignore the doctype
587     elsif (result = @src.scan(/\s*#{HTML_COMMENT_RE}/o))
588       @tree.children << Element.new(:xml_comment, result.strip, nil, category: :block)
589     else
590       break
591     end
592   end
593 
594   tag_handler = lambda do |c, closed, handle_body|
595     parse_raw_html(c, &tag_handler) if !closed && handle_body
596   end
597   parse_raw_html(@tree, &tag_handler)
598 
599   ElementConverter.convert(@tree)
600 end