@@ -139,91 +139,58 @@ def test_linenos(doctree):
139
139
cell , = tree .traverse (JupyterCellNode )
140
140
assert len (cell .children ) == 2
141
141
assert cell .attributes ['linenos' ] is True
142
- #
143
- #
144
- # def test_continue_linenos(doctree):
145
- # source = '''
146
- # .. jupyter-execute::
147
- # :linenos:
148
- #
149
- # 2 + 2
150
- #
151
- # .. jupyter-execute::
152
- # :continue-linenos:
153
- #
154
- # 3 + 3
155
- # '''
156
- # tree = doctree(source)
157
- # (cell0, cell1) = tree.traverse(JupyterCellNode)
158
- # # :linenos:
159
- # assert cell0.attributes['linenos']
160
- # assert cell0.attributes['continue_linenos'] is False
161
- # assert cell0.children[0].attributes['linenos']
162
- # assert 'highlight_args' not in cell0.children[0].attributes
163
- # assert cell0.children[0].rawsource.strip() == "2 + 2"
164
- # assert cell0.children[1].rawsource.strip() == "4"
165
- # # :continue-linenos:
166
- # assert cell1.attributes['linenos'] is False
167
- # assert cell1.attributes['continue_linenos']
168
- # assert 'highlight_args' not in cell1.attributes
169
- # assert cell1.children[0].attributes['linenos']
170
- # assert cell1.children[0].attributes['highlight_args']['linenostart'] == 2
171
- # assert cell1.children[0].rawsource.strip() == "3 + 3"
172
- # assert cell1.children[1].rawsource.strip() == "6"
173
- #
174
- # source2 = '''
175
- # .. jupyter-execute::
176
- # :linenos:
177
- #
178
- # 'cell0' # will be line number 1
179
- #
180
- # .. jupyter-execute::
181
- # :linenos:
182
- #
183
- # 'cell1' # should restart with line number 1
184
- #
185
- # .. jupyter-execute::
186
- # :continue-linenos:
187
- #
188
- # 'cell2' # should be line number 2
189
- #
190
- # .. jupyter-execute::
191
- #
192
- # 'cell3' # no line number directive
193
- #
194
- # .. jupyter-execute::
195
- # :continue-linenos:
196
- #
197
- # 'cell4' # should restart at line number 1
198
- #
199
- # .. jupyter-execute::
200
- # :continue-linenos:
201
- #
202
- # 'cell5' # should continue with line number 2
203
- # '''
204
- # tree2 = doctree(source2)
205
- # cells = tree2.traverse(JupyterCellNode)
206
- # assert len(cells) == 6
207
- # (cell0, cell1, cell2, cell3, cell4, cell5) = cells
208
- # # :linenos:
209
- # assert cell0.children[0].attributes["linenos"]
210
- # assert "highlight_args" not in cell0.children[0].attributes
211
- # # :linenos:
212
- # assert cell1.children[0].attributes["linenos"]
213
- # assert "highlight_args" not in cell1.children[0].attributes
214
- # # :continue-linenos:
215
- # assert cell2.children[0].attributes["linenos"]
216
- # assert cell2.children[0].attributes["highlight_args"]["linenostart"] == 2
217
- # # (No line number directive)
218
- # assert "linenos" not in cell3.children[0].attributes
219
- # assert "highlight_args" not in cell3.children[0].attributes
220
- # # :continue-linenos:
221
- # assert cell4.children[0].attributes["linenos"]
222
- # assert cell4.children[0].attributes["highlight_args"]["linenostart"] == 1
223
- # # :continue-linenos:
224
- # assert cell5.children[0].attributes["linenos"]
225
- # assert cell5.children[0].attributes["highlight_args"]["linenostart"] == 2
226
- #
142
+
143
+
144
+ def test_linenos_conf_option (doctree ):
145
+ source = '''
146
+ .. jupyter-execute::
147
+
148
+ 2 + 2
149
+ '''
150
+ tree = doctree (source , config = "jupyter_sphinx_linenos = True" )
151
+ cell , = tree .traverse (JupyterCellNode )
152
+ assert cell .children [0 ].attributes ['linenos' ]
153
+ assert 'highlight_args' not in cell .children [0 ].attributes
154
+ assert cell .children [0 ].rawsource .strip () == "2 + 2"
155
+ assert cell .children [1 ].rawsource .strip () == "4"
156
+
157
+
158
+ def test_continue_linenos_conf_option (doctree ):
159
+ source = '''
160
+ .. jupyter-execute::
161
+
162
+ 2 + 2
163
+
164
+ .. jupyter-execute::
165
+
166
+ 3 + 3
167
+
168
+ .. jupyter-execute::
169
+ :linenos:
170
+
171
+ 4 + 4
172
+
173
+ '''
174
+ continue_linenos_config = "jupyter_sphinx_continue_linenos = True"
175
+ tree = doctree (source , config = continue_linenos_config )
176
+ cell0 , cell1 , cell2 = tree .traverse (JupyterCellNode )
177
+ assert cell0 .children [0 ].attributes ['linenos' ]
178
+ assert cell0 .children [0 ].attributes ['highlight_args' ]['linenostart' ] == 1
179
+ assert cell0 .children [0 ].rawsource .strip () == "2 + 2"
180
+ assert cell0 .children [1 ].rawsource .strip () == "4"
181
+
182
+ assert cell1 .children [0 ].attributes ['linenos' ]
183
+ assert cell1 .children [0 ].attributes ['highlight_args' ]['linenostart' ] == 2
184
+ assert cell1 .children [0 ].rawsource .strip () == "3 + 3"
185
+ assert cell1 .children [1 ].rawsource .strip () == "6"
186
+
187
+ # :linenos: directive should restart line numbering at one.
188
+ assert cell2 .attributes ['linenos' ]
189
+ assert cell2 .children [0 ].attributes ['linenos' ]
190
+ assert cell2 .children [0 ].attributes ['highlight_args' ]['linenostart' ] == 1
191
+ assert cell2 .children [0 ].rawsource .strip () == "4 + 4"
192
+ assert cell2 .children [1 ].rawsource .strip () == "8"
193
+
227
194
228
195
def test_execution_environment_carries_over (doctree ):
229
196
source = '''
0 commit comments