lib/asciidoctor/parser.rb in asciidoctor-1.5.1 vs lib/asciidoctor/parser.rb in asciidoctor-1.5.2

- old
+ new

@@ -1,5 +1,6 @@ +# encoding: UTF-8 module Asciidoctor # Public: Methods to parse lines of AsciiDoc into an object hierarchy # representing the structure of the document. All methods are class methods and # should be invoked from the Parser class. The main entry point is ::next_block. # No Parser instances shall be discovered running around. (Any attempt to @@ -50,23 +51,10 @@ unless options[:header_only] while reader.has_more_lines? new_section, block_attributes = next_section(reader, document, block_attributes) document << new_section if new_section end - # NOTE we could try to avoid creating a preamble in the first place, though - # that would require reworking assumptions in next_section since the preamble - # is treated like an untitled section - # NOTE logic relocated to end of next_section - #if Compliance.unwrap_standalone_preamble && - # document.blocks.size == 1 && (first_block = document.blocks[0]).context == :preamble && - # first_block.blocks? && (document.doctype != 'book' || first_block.blocks[0].style != 'abstract') - # preamble = document.blocks.shift - # while (child_block = preamble.blocks.shift) - # child_block.parent = document - # document << child_block - # end - #end end document end @@ -228,10 +216,13 @@ if parent.context == :document && parent.blocks.empty? && ((has_header = parent.has_header?) || attributes.delete('invalid-header') || !is_next_line_section?(reader, attributes)) doctype = parent.doctype if has_header || (doctype == 'book' && attributes[1] != 'abstract') preamble = intro = Block.new(parent, :preamble, :content_model => :compound) + if doctype == 'book' && (parent.attr? 'preface-title') + preamble.title = parent.attr 'preface-title' + end parent << preamble end section = parent current_level = 0 @@ -945,11 +936,11 @@ # end #end if block.sub? :callouts unless (catalog_callouts block.source, document) - # No need to look for callouts if they aren't there + # No need to sub callouts if they aren't there block.remove_sub :callouts end end end @@ -1142,11 +1133,10 @@ if parent.context == list_type list_block.level = parent.level + 1 else list_block.level = 1 end - #Debug.debug { "Created #{list_type} block: #{list_block}" } while reader.has_more_lines? && (match = ListRxMap[list_type].match(reader.peek_line)) marker = resolve_list_marker(list_type, match[1]) # if we are moving to the next item, and the marker is different @@ -2119,10 +2109,12 @@ end accessible = value ? doc.set_attribute(name, value) : doc.delete_attribute(name) end if accessible && attrs + # NOTE lookup resolved value (resolution occurs inside set_attribute) + value = doc.attributes[name] if value Document::AttributeEntry.new(name, value).save_to(attrs) end [name, value] end @@ -2322,11 +2314,15 @@ parser_ctx.buffer = %(#{parser_ctx.buffer}#{cell_text}) else parser_ctx.buffer = %(#{parser_ctx.buffer}#{m.pre_match}) end - line = m.post_match + if (line = m.post_match) == '' + # hack to prevent dropping empty cell found at end of line (see issue #1106) + seen = false + end + parser_ctx.close_cell else # no other delimiters to see here # suck up this line into the buffer and move on parser_ctx.buffer = %(#{parser_ctx.buffer}#{line}#{EOL}) @@ -2344,11 +2340,12 @@ end end skipped = table_reader.skip_blank_lines unless parser_ctx.cell_open? - if !table_reader.has_more_lines? - parser_ctx.close_cell true + unless table_reader.has_more_lines? + # NOTE may have already closed cell in csv or dsv table (see previous call to parser_ctx.close_cell(true)) + parser_ctx.close_cell true if parser_ctx.cell_open? end end table.attributes['colcount'] ||= parser_ctx.col_count