In [21]:
from docutils.parsers import rst
from docutils.nodes import document
from docutils.utils import new_document
from docutils.frontend import OptionParser
In [11]:
document??
In [19]:
rst??
In [10]:
new_document?
In [22]:
settings = OptionParser(
components=(rst.Parser,)
).get_default_values()
In [23]:
parser = rst.Parser()
document = new_document('.', settings)
In [19]:
infile = '../rest/puppet/puppet.rst'
infile = 'rest/babelfish/chameleon.rst'
In [3]:
!pwd
In [24]:
parser.parse(open(infile).read(), document)
In [6]:
for x in document:
print(x)
for ii in x:
print(ii)
In [45]:
def dump(data, depth=0):
for item in data:
print(len(item.children))
tag = item.tagname
text =
print(' ' * depth, item.tagname, item.astext())
for sub in item:
if str(sub) != sub:
dump(sub, depth+1)
In [59]:
document.walk?
In [54]:
[x.tagname for x in s.children]
Out[54]:
In [47]:
dump(document)
In [28]:
dump(document)
print()
dump(document[0])
In [20]:
cd ..
In [1]:
cd ~/devel/lamlam
In [13]:
run bootstrap.py rest/babelfish/chameleon.rst
In [3]:
run code/babelfish/chameleon.py
In [35]:
for xx in document[0]:
print(xx.tagname, xx.astext())