lib/asciidoctor/parser.rb in asciidoctor-2.0.0 vs lib/asciidoctor/parser.rb in asciidoctor-2.0.1
- old
+ new
@@ -600,13 +600,13 @@
attributes['alt'] ||= style || (attributes['default-alt'] = Helpers.basename(target, true).tr('_-', ' '))
unless (scaledwidth = attributes.delete 'scaledwidth').nil_or_empty?
# NOTE assume % units if not specified
attributes['scaledwidth'] = (TrailingDigitsRx.match? scaledwidth) ? %(#{scaledwidth}%) : scaledwidth
end
- if attributes.key? 'title'
- block.title = attributes.delete 'title'
- block.assign_caption((attributes.delete 'caption'), 'figure')
+ if attributes['title']
+ block.title = block_title = attributes.delete 'title'
+ block.assign_caption (attributes.delete 'caption'), 'figure'
end
end
attributes['target'] = target
break
@@ -630,16 +630,16 @@
return
else
target = expanded_target
end
end
- if extension.config[:content_model] == :attributes
- document.parse_attributes content, extension.config[:positional_attrs] || [], sub_input: true, into: attributes if content
+ if (ext_config = extension.config)[:content_model] == :attributes
+ document.parse_attributes content, ext_config[:positional_attrs] || ext_config[:pos_attrs] || [], sub_input: true, into: attributes if content
else
attributes['text'] = content || ''
end
- if (default_attrs = extension.config[:default_attrs])
+ if (default_attrs = ext_config[:default_attrs])
attributes.update(default_attrs) {|_, old_v| old_v }
end
if (block = extension.process_method[parent, target, attributes])
attributes.replace block.attributes
break
@@ -678,14 +678,14 @@
break
elsif (style == 'float' || style == 'discrete') && (Compliance.underline_style_section_titles ?
(is_section_title? this_line, reader.peek_line) : !indented && (atx_section_title? this_line))
reader.unshift_line this_line
- float_id, float_reftext, float_title, float_level = parse_section_title reader, document, attributes['id']
+ float_id, float_reftext, block_title, float_level = parse_section_title reader, document, attributes['id']
attributes['reftext'] = float_reftext if float_reftext
block = Block.new(parent, :floating_title, content_model: :empty)
- block.title = float_title
+ block.title = block_title
attributes.delete 'title'
block.id = float_id || ((doc_attrs.key? 'sectids') ? (Section.generate_id block.title, document) : nil)
block.level = float_level
break
@@ -869,15 +869,15 @@
build_block(block_context, :skip, terminator, parent, reader, attributes)
attributes.clear
return
else
if block_extensions && (extension = extensions.registered_for_block? block_context, cloaked_context)
- unless (content_model = extension.config[:content_model]) == :skip
- unless (positional_attrs = extension.config[:positional_attrs] || []).empty?
+ unless (content_model = (ext_config = extension.config)[:content_model]) == :skip
+ unless (positional_attrs = ext_config[:positional_attrs] || ext_config[:pos_attrs]).nil_or_empty?
AttributeList.rekey(attributes, [nil] + positional_attrs)
end
- if (default_attrs = extension.config[:default_attrs])
+ if (default_attrs = ext_config[:default_attrs])
default_attrs.each {|k, v| attributes[k] ||= v }
end
# QUESTION should we clone the extension for each cloaked context and set in config?
attributes['cloaked-context'] = cloaked_context
end
@@ -892,16 +892,23 @@
end
end
# FIXME we've got to clean this up, it's horrible!
block.source_location = reader.cursor_at_mark if document.sourcemap
- # FIXME title should be assigned when block is constructed
- block.title = attributes.delete 'title' if attributes.key? 'title'
+ # FIXME title and caption should be assigned when block is constructed (though we need to handle all cases)
+ if attributes['title']
+ block.title = block_title = attributes.delete 'title'
+ if CAPTIONABLE_BLOCKS[block_context = block.context] && document.attributes[%(#{block.context}-caption)]
+ block.assign_caption (attributes.delete 'caption'), block_context
+ end
+ end
# TODO eventually remove the style attribute from the attributes hash
#block.style = attributes.delete 'style'
block.style = attributes['style']
if (block_id = block.id || (block.id = attributes['id']))
+ # convert title to resolve attributes while in scope
+ block.title if block_title ? (block_title.include? ATTR_REF_HEAD) : block.title?
unless document.register :refs, [block_id, block]
logger.warn message_with_context %(id assigned to block already in use: #{block_id}), source_location: reader.cursor_at_mark
end
end
# FIXME remove the need for this update!
@@ -1042,17 +1049,10 @@
end
else
block = Block.new(parent, block_context, content_model: content_model, source: lines, attributes: attributes)
end
- # QUESTION should we have an explicit map or can we rely on check for *-caption attribute?
- if (attributes.key? 'title') && block.context != :admonition &&
- (parent.document.attributes.key? %(#{block.context}-caption))
- block.title = attributes.delete 'title'
- block.assign_caption(attributes.delete 'caption')
- end
-
# reader is confined within boundaries of a delimited block, so look for
# blocks until there are no more lines
parse_blocks block_reader, block if content_model == :compound
block
@@ -1519,11 +1519,11 @@
buffer << this_line
has_text = true
end
end
else
- has_text = true if !this_line.empty?
+ has_text = true unless this_line.empty?
if nested_list_type = (within_nested_list ? [:dlist] : NESTABLE_LIST_CONTEXTS).find {|ctx| ListRxMap[ctx] =~ this_line }
within_nested_list = true
if nested_list_type == :dlist && $3.nil_or_empty?
# get greedy again
has_text = false
@@ -1610,11 +1610,13 @@
elsif book && sect_level == 0 && document.attributes['partnums']
section.numbered = true
end
# generate an ID if one was not embedded or specified as anchor above section title
- if (id = section.id || (section.id = (document.attributes.key? 'sectids') ? (Section.generate_id section.title, document) : nil))
+ if (id = section.id || (section.id = (document.attributes.key? 'sectids') ? (generated_id = Section.generate_id section.title, document) : nil))
+ # convert title to resolve attributes while in scope
+ section.title if sect_title.include? ATTR_REF_HEAD unless generated_id
unless document.register :refs, [id, section]
logger.warn message_with_context %(id assigned to section already in use: #{id}), source_location: (reader.cursor_at_line reader.lineno - (sect_atx ? 1 : 2))
end
end
@@ -2266,13 +2268,9 @@
# attributes - attributes captured from above this Block
#
# returns an instance of Asciidoctor::Table parsed from the provided reader
def self.parse_table(table_reader, parent, attributes)
table = Table.new(parent, attributes)
- if attributes.key? 'title'
- table.title = attributes.delete 'title'
- table.assign_caption(attributes.delete 'caption')
- end
if (attributes.key? 'cols') && !(colspecs = parse_colspecs attributes['cols']).empty?
table.create_columns colspecs
explicit_colspecs = true
end