Skip to content

Commit 79e864e

Browse files
Add subset of docutils + Sphinx directives to end at
1 parent 5f187f3 commit 79e864e

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

jupyterlite_sphinx/_try_examples.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,28 @@ def _process_literal_blocks(md_text):
303303
"Yields",
304304
)
305305

306+
# Sourced from docutils.parsers.rst.directives._directive_registry.keys()
307+
# and from https://docutils.sourceforge.io/docs/ref/rst/directives.html
308+
# We hardcode a subset of this list as there is no public API in docutils
309+
# or Sphinx to get this information directly.
310+
# See https://docutils.sourceforge.io/docs/ref/rst/directives.html
311+
#
312+
# This subset is only a list of sensible defaults and widely used directives
313+
# based on our discretion that can signify the start of a new section in a
314+
# docstring and is not meant to be exhaustive.
315+
_irrelevant_directives = [
316+
"class",
317+
"contents",
318+
"epigraph",
319+
"footer",
320+
"header",
321+
"highlights",
322+
"parsed-literal",
323+
"pull-quote",
324+
"seealso",
325+
"sidebar",
326+
"topic",
327+
]
306328

307329
_examples_start_pattern = re.compile(r".. (rubric|admonition):: Examples")
308330
_next_section_pattern = re.compile(
@@ -315,10 +337,10 @@ def _process_literal_blocks(md_text):
315337
+ [r"\!\! processed by numpydoc \!\!"]
316338
# Attributes section sometimes has no directive.
317339
+ [r":Attributes:"]
318-
# The See Also section shows up for old numpydoc versions such as that
319-
# of SymPy where it is accounted for as an admonition and not a rubric,
320-
# therefore we check for it as a special case for now.
321-
+ [r"\.\. seealso::"]
340+
# Directives that can start a new section in a docstring and are
341+
# not handled by numpydoc in terms of reordering. Noticed in SymPy
342+
# as it does not use modern numpydoc at the time of writing.
343+
+ [rf"\.\. ({directive})::" for directive in _irrelevant_directives]
322344
)
323345
)
324346

0 commit comments

Comments
 (0)