In [20]: for node in nodetree.traverse(lambda node: isinstance(node, nodes.title)):
print(node.line)
....:
6
11
In [21]: list(zip(range(1,100), docstring.split("\n")))
Out[21]:
[(1, ''),
(2, 'This is just an example.'),
(3, 'Nothing serious.'),
(4, ''),
(5, 'Setup'),
(6, '====='),
(7, ''),
(8, 'This is a description of a setup.'),
(9, ''),
(10, 'Test Steps'),
(11, '=========='),
(12, ''),
(13, 'And now some test steps.'),
(14, '')]
In [22]:
In [29]: list(zip(range(1,100), docstring.split("\n")))
Out[29]:
[(1, ''),
(2, 'This is just an exxample. Nothing seriuos.'),
(3, ''),
(4 'Setup'),
(5, '====='),
(6, ''),
(7, 'This is a description of a setup.'),
(8, ''),
(9, 'Very peculiar and detailed indeed.'),
(10, ''),
(11, 'Test Steps'),
(12, '=========='),
(13, ''),
(14, 'And now, some steps.'),
(15, ''),
(16, '.. note:: hello'),
(17, ''),
(18, ' This is a content of the node.'),
(19, ''),
(20, "That's all."),
(21, ''),
(22, 'Teardown'),
(23, '========'),
(24, ''),
(25, 'Just turn it off.'),
(26, '')]
In [54]: for node in nodetree.traverse():
print("{0}\t{1}".format(node.line, node.tagname))
....:
None document
2 paragraph
None #text
6 section
6 title
None #text
8 paragraph
None #text
11 section
11 title
None #text
13 paragraph
None #text