Skip to content
Permalink
Browse files

add function try_add_config_value for sphinx

  • Loading branch information...
sdpython committed Jul 8, 2017
1 parent 0bfab61 commit 579b57ac6daabc4307b5c674dec36b61342aba90
@@ -20,6 +20,7 @@
from sphinx.util.nodes import set_source_info, process_index_entry
from sphinx import addnodes
from ..texthelper.texts_language import TITLES
from .sphinxext_helper import try_add_config_value


class todoext_node(nodes.admonition):
@@ -493,15 +494,18 @@ def depart_todoextlist_node(self, node):

def setup(app):
"""
setup for ``todoext`` (sphinx)
Setup for ``todoext`` (sphinx).
"""
if hasattr(app, "add_mapping"):
app.add_mapping('todoext', todoext_node)
app.add_mapping('todoextlist', todoextlist)

app.add_config_value('todoext_include_todosext', False, 'html')
app.add_config_value('todoext_link_only', False, 'html')
app.add_config_value('extlinks', {}, 'env')

# The following variable is shared with extension
# `todo <http://www.sphinx-doc.org/en/stable/ext/todo.html>`_.
try_add_config_value(app, 'extlinks', {}, 'env')

app.add_node(todoextlist,
html=(visit_todoextlist_node, depart_todoextlist_node),
@@ -0,0 +1,31 @@
"""
@file
@brief Helpers for sphinx extensions.
.. versionadded:: 1.5
"""


def try_add_config_value(app, name, default, rebuild, types_=()):
"""
Add a variables in the config file if it does not have it yet.
@param app Sphinx application
@param name name of the variable
@param default default value
@param rebuild see below
@param types_ expected types
@return True if added, False if already present.
Rebuild can be (source: `Sphinx <http://www.sphinx-doc.org/en/stable/extdev/appapi.html#sphinx.application.Sphinx.add_config_value>`_):
* 'env' if a change in the setting only takes effect when a document
is parsed - this means that the whole environment must be rebuilt.
* 'html' if a change in the setting needs a full rebuild of HTML documents.
* '' if a change in the setting will not need any special rebuild.
"""
if name in app.config:
return False
help(app.add_config_value)
app.add_config_value(name, default, rebuild, types_)
return True

0 comments on commit 579b57a

Please sign in to comment.
You can’t perform that action at this time.