summaryrefslogtreecommitdiff
path: root/docutils
diff options
context:
space:
mode:
authorwiemann <wiemann@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2007-08-17 03:41:58 +0000
committerwiemann <wiemann@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2007-08-17 03:41:58 +0000
commit046735bdbc915c6605466a4de5c5324ac08b443d (patch)
treed04e962231bde9ea58ba927f66f0925ed08e31a0 /docutils
parent932928db3565e81928df3934d26b6babf2f7328a (diff)
downloaddocutils-046735bdbc915c6605466a4de5c5324ac08b443d.tar.gz
avoid creation of duplicate ID's in sub-documents
git-svn-id: http://svn.code.sf.net/p/docutils/code/branches/subdocs@5405 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
Diffstat (limited to 'docutils')
-rw-r--r--docutils/nodes.py17
-rw-r--r--docutils/parsers/rst/directives/parts.py7
-rw-r--r--docutils/readers/standalone.py10
3 files changed, 24 insertions, 10 deletions
diff --git a/docutils/nodes.py b/docutils/nodes.py
index 59b6db3f1..33c6e6cd9 100644
--- a/docutils/nodes.py
+++ b/docutils/nodes.py
@@ -858,7 +858,7 @@ class document(Root, Structural, Element):
self.nametypes = {}
"""Mapping of names to hyperlink type (boolean: True => explicit,
- False => implicit."""
+ False => implicit)."""
self.ids = {}
"""Mapping of ids to nodes."""
@@ -923,6 +923,9 @@ class document(Root, Structural, Element):
self.decoration = None
"""Document's `decoration` node."""
+ self.reserved_ids = []
+ """ID's not to be used."""
+
self.document = self
def __getstate__(self):
@@ -944,18 +947,22 @@ class document(Root, Structural, Element):
def set_id(self, node, msgnode=None):
for id in node['ids']:
- if self.ids.has_key(id) and self.ids[id] is not node:
- msg = self.reporter.severe('Duplicate ID: "%s".' % id)
+ if (self.ids.has_key(id) and self.ids[id] is not node
+ or id in self.reserved_ids):
+ msg = self.reporter.severe(
+ 'Duplicate or reserved ID: "%s".' % id)
if msgnode != None:
msgnode += msg
if not node['ids']:
for name in node['names']:
id = self.settings.id_prefix + make_id(name)
- if id and not self.ids.has_key(id):
+ if id and not (self.ids.has_key(id)
+ or id in self.reserved_ids):
break
else:
id = ''
- while not id or self.ids.has_key(id):
+ while not id or (self.ids.has_key(id) or \
+ id in self.reserved_ids):
id = (self.settings.id_prefix +
self.settings.auto_id_prefix + str(self.id_start))
self.id_start += 1
diff --git a/docutils/parsers/rst/directives/parts.py b/docutils/parsers/rst/directives/parts.py
index 5a1aae653..60c041fb1 100644
--- a/docutils/parsers/rst/directives/parts.py
+++ b/docutils/parsers/rst/directives/parts.py
@@ -190,7 +190,8 @@ class Subdocuments(Directive):
# Perhaps this should be moved into the reader.
document = self.state_machine.document
subdoc_reader = standalone.Reader(
- parser_name='rst', docset_root=document.get('docset_root'))
+ parser_name='rst', docset_root=document.get('docset_root'),
+ reserved_ids=(document.ids.keys() + document.reserved_ids))
if not os.path.isabs(file_name):
if not document.hasattr('docset_root'):
raise self.error('a doc-set root must be declared using the '
@@ -226,6 +227,10 @@ class Subdocuments(Directive):
subdocument = subdoc_reader.read(
source=source, parser=Parser(subdoc_reader),
settings=subdoc_settings)
+ # Get ID's used by sub-document back into current document.
+ for id in subdocument.ids:
+ if subdocument.ids[id] is not None:
+ self.state_machine.document.ids[id] = subdocument.ids[id]
if len(subdocument) >= 1 and isinstance(subdocument[0], nodes.title):
# Single document title.
attributes = {}
diff --git a/docutils/readers/standalone.py b/docutils/readers/standalone.py
index 8b841ec98..ca3342c99 100644
--- a/docutils/readers/standalone.py
+++ b/docutils/readers/standalone.py
@@ -65,14 +65,16 @@ class Reader(readers.Reader):
misc.Transitions,
]
- def __init__(self, *args, **kwargs):
- self.docset_root = kwargs.setdefault('docset_root')
- del kwargs['docset_root']
- readers.Reader.__init__(self, *args, **kwargs)
+ def __init__(self, parser=None, parser_name=None,
+ docset_root=None, reserved_ids=[]):
+ self.docset_root = docset_root
+ self.reserved_ids = reserved_ids
+ readers.Reader.__init__(self, parser=parser, parser_name=parser_name)
def new_document(self):
"""Create and return a new empty document tree (root node)."""
document = utils.new_document(self.source.source_path, self.settings)
if self.docset_root is not None:
document['docset_root'] = self.docset_root
+ document.reserved_ids = self.reserved_ids
return document