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
585 def parse
586   @stack, @tree = [], @root
587   @src = Kramdown::Utils::StringScanner.new(adapt_source(source))
588 
589   while true
590     if (result = @src.scan(/\s*#{HTML_INSTRUCTION_RE}/o))
591       @tree.children << Element.new(:xml_pi, result.strip, nil, category: :block)
592     elsif (result = @src.scan(/\s*#{HTML_DOCTYPE_RE}/o))
593       # ignore the doctype
594     elsif (result = @src.scan(/\s*#{HTML_COMMENT_RE}/o))
595       @tree.children << Element.new(:xml_comment, result.strip, nil, category: :block)
596     else
597       break
598     end
599   end
600 
601   tag_handler = lambda do |c, closed, handle_body|
602     parse_raw_html(c, &tag_handler) if !closed && handle_body
603   end
604   parse_raw_html(@tree, &tag_handler)
605 
606   ElementConverter.convert(@tree)
607 end