diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2018-12-01 18:46:22 +0900 |
---|---|---|
committer | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2018-12-01 18:46:22 +0900 |
commit | e294b8e036ffbc5cc0147173fe555780e68cfbbc (patch) | |
tree | c83fe851d439aad16d6ad5b6ea50e86326a59b2d /sphinx/util/docutils.py | |
parent | 48bc80209da4404285863bd27e611887929426b7 (diff) | |
download | sphinx-git-e294b8e036ffbc5cc0147173fe555780e68cfbbc.tar.gz |
Add role manipulator functions to sphinx.util.docutils
Diffstat (limited to 'sphinx/util/docutils.py')
-rw-r--r-- | sphinx/util/docutils.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/sphinx/util/docutils.py b/sphinx/util/docutils.py index 820c9c620..07be9f092 100644 --- a/sphinx/util/docutils.py +++ b/sphinx/util/docutils.py @@ -67,6 +67,28 @@ def docutils_namespace(): additional_nodes.discard(node) +def is_role_registered(name): + # type: (unicode) -> bool + """Check the *name* role is already registered.""" + return name in roles._roles + + +def register_role(name, role): + # type: (unicode, RoleFunction) -> None + """Register a role to docutils. + + This modifies global state of docutils. So it is better to use this + inside ``docutils_namespace()`` to prevent side-effects. + """ + roles.register_local_role(name, role) + + +def unregister_role(name): + # type: (unicode) -> None + """Unregister a role from docutils.""" + roles._roles.pop(name, None) + + def is_node_registered(node): # type: (Type[nodes.Element]) -> bool """Check the *node* is already registered.""" |