* refactoring: metadata (docinfo) type normalization and add test.

This commit is contained in:
Takayuki Shimizukawa 2014-08-02 16:39:07 +09:00
parent 6630255a10
commit 24280fd90d
3 changed files with 16 additions and 5 deletions

View File

@ -850,6 +850,14 @@ class BuildEnvironment:
else:
name, body = node
md[name.astext()] = body.astext()
for name, value in md.items():
if name in ('tocdepth',):
try:
value = int(value)
except ValueError:
value = 0
md[name] = value
del doctree[0]
def process_refonly_bullet_lists(self, docname, doctree):
@ -968,11 +976,7 @@ class BuildEnvironment:
def build_toc_from(self, docname, document):
"""Build a TOC from the doctree and store it in the inventory."""
numentries = [0] # nonlocal again...
try:
maxdepth = int(self.metadata[docname].get('tocdepth', 0))
except ValueError:
maxdepth = 0
maxdepth = self.metadata[docname].get('tocdepth', 0)
def traverse_in_section(node, cls):
"""Like traverse(), but stay within the same section."""

View File

@ -32,6 +32,10 @@
language, containing examples of all basic reStructuredText
constructs and many advanced constructs.
:nocomments:
:orphan:
:tocdepth: 1
.. meta::
:keywords: reStructuredText, demonstration, demo, parser
:description lang=en: A demonstration of the reStructuredText

View File

@ -61,6 +61,9 @@ def test_docinfo():
'date': u'2006-05-21',
'organization': u'humankind',
'revision': u'4564',
'tocdepth': 1,
'orphan': u'',
'nocomments': u'',
}
# I like this way of comparing dicts - easier to see the error.
for key in exampledocinfo: