Class: Slamdown::Parsing::Html
- Inherits:
-
Kramdown::Parser::Html
- Object
- Kramdown::Parser::Html
- Slamdown::Parsing::Html
- Defined in:
- lib/slamdown/parsing/html.rb
Overview
Parses HTML with Kramdown while retaining the explicit name of every source element that survives Kramdown's native conversion.
Defined Under Namespace
Classes: SourceAwareElementConverter
Instance Method Summary collapse
-
#parse ⇒ Object
Reproduces Kramdown::Parser::Html#parse's orchestration so the existing scanner can feed Slamdown's converter without global mutation.
Instance Method Details
#parse ⇒ Object
Reproduces Kramdown::Parser::Html#parse's orchestration so the existing scanner can feed Slamdown's converter without global mutation.
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/slamdown/parsing/html.rb', line 157 def parse @stack, @tree = [], @root @src = ::Kramdown::Utils::StringScanner.new(adapt_source(repair_unclosed_table_rows(source))) while true if (result = @src.scan(/\s*#{HTML_INSTRUCTION_RE}/o)) @tree.children << ::Kramdown::Element.new(:xml_pi, result.strip, nil, :category => :block) elsif @src.scan(/\s*#{HTML_DOCTYPE_RE}/o) # Kramdown deliberately discards the document type. elsif (result = @src.scan(/\s*#{HTML_COMMENT_RE}/o)) @tree.children << ::Kramdown::Element.new(:xml_comment, result.strip, nil, :category => :block) else break end end tag_handler = lambda do |child, closed, handle_body| parse_raw_html(child, &tag_handler) if !closed && handle_body end parse_raw_html(@tree, &tag_handler) SourceAwareElementConverter.convert(@tree) end |