mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
* refactoring: metadata (docinfo) type normalization and add test.
This commit is contained in:
parent
6630255a10
commit
24280fd90d
@ -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."""
|
||||
|
@ -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
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user