diff --git a/doc/sphinxext/directive_formatting.py b/doc/sphinxext/directive_formatting.py index ffe0724c5c3..910f62a7114 100644 --- a/doc/sphinxext/directive_formatting.py +++ b/doc/sphinxext/directive_formatting.py @@ -6,6 +6,57 @@ from mne_doc_utils import sphinx_logger +DIRECTIVE_NAMES = [ + # Table of contents + "toctree", + # Admonitions, messages, warnings + "attention", + "caution", + "danger", + "error", + "hint", + "important", + "note", + "tip", + "warning", + "admonition", + "seealso", + # Changes between versions + "version-added", + "versionadded", + "versionchanged", + "version-changed", + "version-deprecated", + "deprecated", + "version-removed", + "versionremoved", + # Presentational + "rubric", + "centered", + "hlist", + # Code examples + "highlight", + "code-block", + "sourcecode", + "code", + "literalinclude", + # Glossary + "glossary", + # Meta-information + "sectionauthor", + "codeauthor", + # Index-generating markup + "index", + # Including content + "only", + # Tables + "tabularcolumns", + # Math + "math", + # Grammar production + "productionlist", +] + def setup(app): app.connect("source-read", check_directive_formatting) @@ -19,7 +70,7 @@ def setup_module(): def check_directive_formatting(*args): - """Check that directives are not missing a space. + """Check that directives are not malformed. For args, see Sphinx events 'source-read' and 'autodoc-process-docstring'. """ @@ -37,8 +88,8 @@ def check_directive_formatting(*args): else: raise RuntimeError("Unexpected number of arguments from Sphinx event") - # Check if any directives are present - if re.search(r"\.\.\s*[a-zA-Z]+::", source_concat) is None: + # Check if text resembling directives are present + if re.search(r"\.\.\s*[a-zA-Z\-]+\s*:", source_concat) is None: return # Separate content into lines (docstrings already are) @@ -48,7 +99,7 @@ def check_directive_formatting(*args): # Check for bad formatting for idx, line in enumerate(source): # Check for missing space after '..' - missing = re.search(r"\.\.[a-zA-Z]+::", line) + missing = re.search(r"\.\.[a-zA-Z\-]+\s*:", line) if missing is not None: sphinx_logger.warning( f"{source_type} '{name}' is missing a space after '..' in the " @@ -56,12 +107,26 @@ def check_directive_formatting(*args): ) # Extra spaces after '..' don't affect formatting + # Check for bad number of final colons (should be exactly 2) + bad_colons = re.search(r"\.\.\s*[a-zA-Z\-]+\s*(?