Skip to content

Commit

Permalink
resolves asciidoctor#2244 warn if duplicate ID is detected
Browse files Browse the repository at this point in the history
  • Loading branch information
mojavelinux committed Jul 10, 2017
1 parent 8e80317 commit 5abedeb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
4 changes: 3 additions & 1 deletion lib/asciidoctor/document.rb
Expand Up @@ -566,7 +566,9 @@ def register type, value
@catalog[:ids][id] ||= reftext || ('[' + id + ']')
when :refs
id, ref, reftext = value
unless (refs = @catalog[:refs]).key? id
if (refs = @catalog[:refs]).key? id
nil
else
refs[id] = ref
@catalog[:ids][id] = reftext || ('[' + id + ']')
end
Expand Down
16 changes: 12 additions & 4 deletions lib/asciidoctor/parser.rb
Expand Up @@ -913,7 +913,9 @@ def self.next_block(reader, parent, attributes = {}, options = {})
#block.style = attributes.delete 'style'
block.style = attributes['style']
if (block_id = (block.id ||= attributes['id']))
document.register :refs, [block_id, block, attributes['reftext'] || (block.title? ? block.title : nil)]
unless document.register :refs, [block_id, block, attributes['reftext'] || (block.title? ? block.title : nil)]
warn %(asciidoctor: WARNING: #{reader.path}: block with duplicate ID detected: #{block_id})
end
end
# FIXME remove the need for this update!
block.attributes.update(attributes) unless attributes.empty?
Expand Down Expand Up @@ -1212,7 +1214,9 @@ def self.catalog_inline_anchors text, block, document
next if (reftext.include? '{') && (reftext = document.sub_attributes reftext).empty?
end
end
document.register :refs, [id, (Inline.new block, :anchor, reftext, :type => :ref, :target => id), reftext]
unless document.register :refs, [id, (Inline.new block, :anchor, reftext, :type => :ref, :target => id), reftext]
warn %(asciidoctor: WARNING: #{document.reader.path}: anchor with duplicate ID detected: #{id})
end
end if (text.include? '[[') || (text.include? 'or:')
nil
end
Expand All @@ -1227,7 +1231,9 @@ def self.catalog_inline_anchors text, block, document
def self.catalog_inline_biblio_anchor text, block, document
if InlineBiblioAnchorRx =~ text
# QUESTION should we sub attributes in reftext (like with regular anchors)?
document.register :refs, [(id = $1), (Inline.new block, :anchor, (reftext = %([#{$2 || id}])), :type => :bibref, :target => id), reftext]
unless document.register :refs, [(id = $1), (Inline.new block, :anchor, (reftext = %([#{$2 || id}])), :type => :bibref, :target => id), reftext]
warn %(asciidoctor: WARNING: #{document.reader.path}: bibliography anchor with duplicate ID detected: #{id})
end
end
nil
end
Expand Down Expand Up @@ -1610,7 +1616,9 @@ def self.initialize_section reader, parent, attributes = {}
# generate an ID if one was not embedded or specified as anchor above section title
if (id = section.id ||= (attributes['id'] ||
((document.attributes.key? 'sectids') ? (Section.generate_id section.title, document) : nil)))
document.register :refs, [id, section, sect_reftext || section.title]
unless document.register :refs, [id, section, sect_reftext || section.title]
warn %(asciidoctor: WARNING: #{reader.path}: section with duplicate ID detected: #{id})
end
end

section.update_attributes(attributes)
Expand Down

0 comments on commit 5abedeb

Please sign in to comment.