lib/asciidoctor/extensions.rb in asciidoctor-2.0.0.rc.3 vs lib/asciidoctor/extensions.rb in asciidoctor-2.0.0

- old
+ new

@@ -141,11 +141,13 @@ sect.numbered = sect.special ? parent.numbered && true : true end else sect.numbered = true if opts.fetch :numbered, (book && (doc.attr? 'partnums')) end - unless (id = attrs.delete 'id') == false + if (id = attrs['id']) == false + attrs.delete 'id' + else sect.id = attrs['id'] = id || ((doc.attr? 'sectids') ? (Section.generate_id sect.title, doc) : nil) end sect.update_attributes attrs sect end @@ -209,16 +211,29 @@ # Returns The parent node into which the blocks are parsed. #-- # QUESTION is parse_content the right method name? should we wrap in open block automatically? def parse_content parent, content, attributes = nil reader = Reader === content ? content : (Reader.new content) - while ((block = Parser.next_block reader, parent, (attributes ? attributes.merge : {})) && parent << block) || - reader.has_more_lines? - end + Parser.parse_blocks reader, parent, attributes parent end + # Public: Parses the attrlist String into a Hash of attributes + # + # block - the current AbstractBlock or the parent AbstractBlock if there is no current block (used for applying subs) + # attrlist - the list of attributes as a String + # opts - an optional Hash of options to control processing: + # :positional_attributes - an Array of attribute names to map positional arguments to (optional, default: false) + # :sub_attributes - enables attribute substitution on the attrlist argument (optional, default: false) + # + # Returns a Hash of parsed attributes + def parse_attributes block, attrlist, opts = {} + return {} if attrlist ? attrlist.empty? : true + attrlist = block.sub_attributes attrlist if opts[:sub_attributes] && (attrlist.include? ATTR_REF_HEAD) + (AttributeList.new attrlist).parse (opts[:positional_attributes] || []) + end + # TODO fill out remaining methods [ [:create_paragraph, :create_block, :paragraph], [:create_open_block, :create_block, :open], [:create_example_block, :create_block, :example], @@ -292,29 +307,30 @@ option :content_model, value end alias parse_content_as content_model def positional_attributes *value - option :pos_attrs, value.flatten + option :positional_attrs, value.flatten end alias name_positional_attributes positional_attributes # NOTE positional_attrs alias is deprecated alias positional_attrs positional_attributes - def default_attrs value + def default_attributes value option :default_attrs, value end - alias default_attributes default_attrs + # NOTE default_attrs alias is deprecated + alias default_attr default_attributes def resolve_attributes *args # NOTE assume true as default value; rewrap single-argument string or symbol if (args = args.fetch 0, true).respond_to? :to_sym args = [args] end unless args.size > 1 case args when true - option :pos_attrs, [] + option :positional_attrs, [] option :default_attrs, {} when ::Array names, defaults = [], {} args.each do |arg| if (arg = arg.to_s).include? '=' @@ -331,11 +347,11 @@ names[idx] = name else names << arg end end - option :pos_attrs, names.compact + option :positional_attrs, names.compact option :default_attrs, defaults when ::Hash names, defaults = [], {} args.each do |key, val| if (name = key.to_s).include? ':' @@ -343,11 +359,11 @@ idx = idx == '@' ? names.size : idx.to_i names[idx] = name end defaults[name] = val if val end - option :pos_attrs, names.compact + option :positional_attrs, names.compact option :default_attrs, defaults else raise ::ArgumentError, %(unsupported attributes specification for macro: #{args.inspect}) end end @@ -505,10 +521,10 @@ # Recognized options: # # * :named - The name of the block (required: true) # * :contexts - The blocks contexts on which this style can be used (default: [:paragraph, :open] # * :content_model - The structure of the content supported in this block (default: :compound) - # * :pos_attrs - A list of attribute names used to map positional attributes (default: nil) + # * :positional_attrs - A list of attribute names used to map positional attributes (default: nil) # * :default_attrs - A hash of attribute names and values used to seed the attributes hash (default: nil) # * ... # # BlockProcessor implementations must extend BlockProcessor. class BlockProcessor < Processor