summaryrefslogtreecommitdiff
path: root/_exts
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2019-09-18 18:49:53 +0200
committerFlorian Dold <florian.dold@gmail.com>2019-09-18 18:49:53 +0200
commite0ffb439998894f368f24fcea8fbdec4fad00a99 (patch)
tree4983fd3381170559454256d5f35f96c0ff2aa9f6 /_exts
parent47adf02f389d4b0a5a0c21323dd2b2f1ad9a393a (diff)
downloaddocs-e0ffb439998894f368f24fcea8fbdec4fad00a99.tar.gz
docs-e0ffb439998894f368f24fcea8fbdec4fad00a99.tar.bz2
docs-e0ffb439998894f368f24fcea8fbdec4fad00a99.zip
omit deep section names
Diffstat (limited to '_exts')
-rw-r--r--_exts/taler_sphinx_theme/__init__.py27
-rw-r--r--_exts/tsref.py5
2 files changed, 29 insertions, 3 deletions
diff --git a/_exts/taler_sphinx_theme/__init__.py b/_exts/taler_sphinx_theme/__init__.py
index 9ac8f38..2d3c61c 100644
--- a/_exts/taler_sphinx_theme/__init__.py
+++ b/_exts/taler_sphinx_theme/__init__.py
@@ -17,7 +17,8 @@ def setup(app):
"""Setup conntects events to the sitemap builder"""
app.connect('html-page-context', add_html_link)
app.connect('build-finished', create_sitemap)
- app.set_translator('html', HTMLTranslator)
+ app.set_translator('html', MyHTMLTranslator)
+ app.set_translator('html-linked', MyHTMLTranslator)
app.sitemap_links = []
app.add_html_theme('taler_sphinx_theme', path.abspath(path.dirname(__file__) + "/guzzle_sphinx_theme"))
@@ -53,7 +54,7 @@ def html_theme_path():
return [os.path.dirname(os.path.abspath(__file__))]
-class HTMLTranslator(SphinxHTMLTranslator):
+class MyHTMLTranslator(SphinxHTMLTranslator):
"""
Handle translating to bootstrap structure.
"""
@@ -141,3 +142,25 @@ class HTMLTranslator(SphinxHTMLTranslator):
def visit_container(self, node):
self.body.append(self.starttag(node, 'div', CLASS='docutils'))
+
+ def add_secnumber(self, node):
+ # type: (nodes.Element) -> None
+ if node.get('secnumber'):
+ numbers = list(map(str, node['secnumber']))
+ if len(numbers) <= 3:
+ self.body.append('.'.join(numbers) + self.secnumber_suffix)
+ elif isinstance(node.parent, nodes.section):
+ if self.builder.name == 'singlehtml':
+ docname = self.docnames[-1]
+ anchorname = "%s/#%s" % (docname, node.parent['ids'][0])
+ if anchorname not in self.builder.secnumbers:
+ anchorname = "%s/" % docname # try first heading which has no anchor
+ else:
+ anchorname = '#' + node.parent['ids'][0]
+ if anchorname not in self.builder.secnumbers:
+ anchorname = '' # try first heading which has no anchor
+ if self.builder.secnumbers.get(anchorname):
+ numbers = list(self.builder.secnumbers[anchorname])
+ if len(numbers) <= 3:
+ self.body.append('.'.join(map(str, numbers)) +
+ self.secnumber_suffix)
diff --git a/_exts/tsref.py b/_exts/tsref.py
index ae0e924..daeb08c 100644
--- a/_exts/tsref.py
+++ b/_exts/tsref.py
@@ -171,7 +171,10 @@ class LinkFilter(Filter):
defname = make_id('tsref-type-' + value);
t = copy_token(ttype)
if defname in id_to_doc:
- current_docname = self.app.builder._current_docname
+ if hasattr(self.app.builder, "_current_docname"):
+ current_docname = self.app.builder._current_docname
+ else:
+ current_docname = "(unknown-doc)"
docname = id_to_doc[defname]
uri = self.app.builder.get_relative_uri(current_docname, docname)
href = uri + "#" + defname