Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions jupyterlite_sphinx/_try_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,12 +391,14 @@ def insert_try_examples_directive(lines, **options):
lines[right_index]
):
right_index += 1
if "!! processed by numpydoc !!" in lines[right_index]:

# Check if we've reached the end of the docstring
if right_index < len(lines) and "!! processed by numpydoc !!" in lines[right_index]:
# Sometimes the .. appears on an earlier line than !! processed by numpydoc !!
if not re.search(
r"\.\.\s+\!\! processed by numpy doc \!\!", lines[right_index]
):
while lines[right_index].strip() != "..":
while right_index > 0 and lines[right_index].strip() != "..":
right_index -= 1

# Add the ".. try_examples::" directive and indent the content of the Examples section
Expand All @@ -407,7 +409,10 @@ def insert_try_examples_directive(lines, **options):
+ [""]
+ [" " + line for line in lines[left_index:right_index]]
+ [""]
+ lines[right_index:]
)

# Append the remainder of the docstring, if there is any
if right_index < len(lines):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make sure I understand correctly, this condition will be False in the case where the example section is last and there is no emptyline after it. The check keeps jupyterlite_sphinx from inserting an emptyline at the end in this case. If so, that sounds reasonable.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, you're right!

new_lines += lines[right_index:]

return new_lines
Loading