From 93a93707906478e1387e2f325e9e5ca34e712baf Mon Sep 17 00:00:00 2001 From: Laurens Valk Date: Fri, 1 Apr 2022 09:31:28 +0200 Subject: [PATCH] doc/common/extensions: Hide version directives in IDE build. Version tags can be useful to keep track of new or updated features. This lets us hide such details in the documentation that ships with the IDE to keep it concise. --- doc/common/conf.py | 2 ++ doc/common/extensions/versionchanged.py | 28 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 doc/common/extensions/versionchanged.py diff --git a/doc/common/conf.py b/doc/common/conf.py index 6198f8d..331b0a8 100644 --- a/doc/common/conf.py +++ b/doc/common/conf.py @@ -53,10 +53,12 @@ extensions = [ 'sphinx.ext.napoleon', 'sphinx.ext.todo', 'sphinx.ext.mathjax', + # Custom Pybricks extensions 'color', 'classlink', 'requirements', 'requirements-static', + 'versionchanged', ] # Add any paths that contain templates here, relative to this directory. diff --git a/doc/common/extensions/versionchanged.py b/doc/common/extensions/versionchanged.py new file mode 100644 index 0000000..513829b --- /dev/null +++ b/doc/common/extensions/versionchanged.py @@ -0,0 +1,28 @@ +"""This directive hides the builtin directives + * versionchanged + * versionadded + * deprecated +when building documentation with the 'ide' tag. +""" +from docutils import nodes +from docutils.parsers.rst import Directive + + +class PybricksVersionDirective(Directive): + + has_content = True + + def run(self): + html = "" + node = nodes.raw('', html, format="html") + return [node] + + +def setup(app): + if 'ide' in app.tags.tags: + app.add_directive_to_domain('py', 'deprecated', + PybricksVersionDirective, override=True) + app.add_directive_to_domain('py', 'versionadded', + PybricksVersionDirective, override=True) + app.add_directive_to_domain('py', 'versionchanged', + PybricksVersionDirective, override=True)