Skip to content

Commit f5f9eef

Browse files
committed
Add processing of literal blocks in RST
1 parent 2582889 commit f5f9eef

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

jupyterlite_sphinx/_try_examples.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def _append_code_cell_and_clear_lines(code_lines, output_lines, notebook):
133133
def _append_markdown_cell_and_clear_lines(markdown_lines, notebook):
134134
"""Append new markdown cell to notebook, clearing lines."""
135135
markdown_text = "\n".join(markdown_lines)
136-
# Convert blocks of LaTeX equations
136+
markdown_text = _process_literal_blocks(markdown_text)
137137
markdown_text = _process_latex(markdown_text)
138138
markdown_text = _strip_ref_identifiers(markdown_text)
139139
markdown_text = _convert_links(markdown_text)
@@ -216,6 +216,33 @@ def _process_latex(md_text):
216216
return "\n".join(wrapped_lines)
217217

218218

219+
def _process_literal_blocks(md_text):
220+
md_lines = md_text.split("\n")
221+
new_lines = []
222+
in_literal_block = False
223+
literal_block_accumulator = []
224+
225+
for line in md_lines:
226+
indent_level = len(line) - len(line.lstrip())
227+
228+
if in_literal_block and (indent_level > 0 or line.strip() == ""):
229+
literal_block_accumulator.append(line)
230+
elif in_literal_block:
231+
new_lines.extend(["```"] + literal_block_accumulator + ["```", line])
232+
literal_block_accumulator = []
233+
in_literal_block = False
234+
elif line.endswith("::"):
235+
in_literal_block = True
236+
new_lines.append(line[:-2])
237+
else:
238+
new_lines.append(line)
239+
240+
if literal_block_accumulator:
241+
new_lines.extend(["```"] + literal_block_accumulator + ["```"])
242+
243+
return "\n".join(new_lines)
244+
245+
219246
# https://www.sphinx-doc.org/en/master/usage/extensions/napoleon.html#docstring-sections
220247
_non_example_docstring_section_headers = (
221248
"Args",

0 commit comments

Comments
 (0)