Skip to content
This repository has been archived by the owner on Jan 13, 2024. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
add function try_add_config_value for sphinx
  • Loading branch information
sdpython committed Jul 8, 2017
1 parent 0bfab61 commit 579b57a
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/pyquickhelper/sphinxext/sphinx_todoext_extension.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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),
Expand Down
31 changes: 31 additions & 0 deletions src/pyquickhelper/sphinxext/sphinxext_helper.py
@@ -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.