|
39 | 39 | # --------------------- |
40 | 40 |
|
41 | 41 | SAGE_LIVE_DOC = os.environ.get('SAGE_LIVE_DOC', 'no') |
42 | | -SAGE_PREPARSED_DOC = os.environ.get('SAGE_PREPARSED_DOC', 'yes') |
43 | 42 |
|
44 | 43 | # Add any Sphinx extension module names here, as strings. They can be extensions |
45 | 44 | # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. |
@@ -993,40 +992,40 @@ def apply(self): |
993 | 992 | if isinstance(prev_node, nodes.paragraph): |
994 | 993 | prev_node['classes'].append('with-sage-tab') |
995 | 994 |
|
996 | | - if SAGE_PREPARSED_DOC == 'yes': |
997 | | - # Tab for preparsed version |
998 | | - from sage.repl.preparse import preparse |
999 | | - container = TabContainer("", type="tab", new_set=False) |
1000 | | - textnodes = [Text('Python')] |
1001 | | - label = Label("", "", *textnodes) |
1002 | | - container += label |
1003 | | - content = Container("", is_div=True, classes=["tab-content"]) |
1004 | | - example_lines = [] |
1005 | | - preparsed_lines = ['>>> from sage.all import *'] |
1006 | | - for line in node.rawsource.splitlines() + ['']: # one extra to process last example |
1007 | | - newline = line.lstrip() |
1008 | | - if newline.startswith('....: '): |
| 995 | + # Tab for preparsed version |
| 996 | + from sage.repl.preparse import preparse |
| 997 | + container = TabContainer("", type="tab", new_set=False) |
| 998 | + textnodes = [Text('Python')] |
| 999 | + label = Label("", "", *textnodes) |
| 1000 | + container += label |
| 1001 | + content = Container("", is_div=True, classes=["tab-content"]) |
| 1002 | + example_lines = [] |
| 1003 | + preparsed_lines = ['>>> from sage.all import *'] |
| 1004 | + for line in node.rawsource.splitlines() + ['']: # one extra to process last example |
| 1005 | + newline = line.lstrip() |
| 1006 | + if newline.startswith('....: '): |
| 1007 | + example_lines.append(newline[6:]) |
| 1008 | + else: |
| 1009 | + if example_lines: |
| 1010 | + preparsed_example = preparse('\n'.join(example_lines)) |
| 1011 | + prompt = '>>> ' |
| 1012 | + for preparsed_line in preparsed_example.splitlines(): |
| 1013 | + preparsed_lines.append(prompt + preparsed_line) |
| 1014 | + prompt = '... ' |
| 1015 | + example_lines = [] |
| 1016 | + if newline.startswith('sage: '): |
1009 | 1017 | example_lines.append(newline[6:]) |
1010 | 1018 | else: |
1011 | | - if example_lines: |
1012 | | - preparsed_example = preparse('\n'.join(example_lines)) |
1013 | | - prompt = '>>> ' |
1014 | | - for preparsed_line in preparsed_example.splitlines(): |
1015 | | - preparsed_lines.append(prompt + preparsed_line) |
1016 | | - prompt = '... ' |
1017 | | - example_lines = [] |
1018 | | - if newline.startswith('sage: '): |
1019 | | - example_lines.append(newline[6:]) |
1020 | | - else: |
1021 | | - preparsed_lines.append(line) |
1022 | | - preparsed = '\n'.join(preparsed_lines) |
1023 | | - preparsed_node = LiteralBlock(preparsed, preparsed, language='ipycon') |
1024 | | - content += preparsed_node |
1025 | | - container += content |
1026 | | - parent.insert(index, container) |
1027 | | - index += 1 |
1028 | | - if isinstance(prev_node, nodes.paragraph): |
1029 | | - prev_node['classes'].append('with-python-tab') |
| 1019 | + preparsed_lines.append(line) |
| 1020 | + preparsed = '\n'.join(preparsed_lines) |
| 1021 | + preparsed_node = LiteralBlock(preparsed, preparsed, language='ipycon') |
| 1022 | + content += preparsed_node |
| 1023 | + container += content |
| 1024 | + parent.insert(index, container) |
| 1025 | + index += 1 |
| 1026 | + if isinstance(prev_node, nodes.paragraph): |
| 1027 | + prev_node['classes'].append('with-python-tab') |
| 1028 | + |
1030 | 1029 | if SAGE_LIVE_DOC == 'yes': |
1031 | 1030 | # Tab for Jupyter-sphinx cell |
1032 | 1031 | from jupyter_sphinx.ast import CellInputNode, JupyterCellNode |
@@ -1084,9 +1083,8 @@ def setup(app): |
1084 | 1083 | app.connect('autodoc-process-docstring', skip_TESTS_block) |
1085 | 1084 | app.connect('autodoc-skip-member', skip_member) |
1086 | 1085 | app.add_transform(SagemathTransform) |
1087 | | - if SAGE_LIVE_DOC == 'yes' or SAGE_PREPARSED_DOC == 'yes': |
1088 | | - app.add_transform(SagecodeTransform) |
1089 | | - else: |
| 1086 | + app.add_transform(SagecodeTransform) |
| 1087 | + if SAGE_LIVE_DOC != 'yes': |
1090 | 1088 | app.add_directive("jupyter-execute", Ignore) |
1091 | 1089 | app.add_directive("jupyter-kernel", Ignore) |
1092 | 1090 | app.add_directive("jupyter-input", Ignore) |
|
0 commit comments