Permalink
Browse files

update .rst output script

  • Loading branch information...
1 parent 4dd503b commit cfb59f4268669357adad04d7d233808cddd02a8e @wardi committed Feb 26, 2013
Showing with 15 additions and 6 deletions.
  1. +2 −2 Makefile
  2. +13 −4 rst.py
View
@@ -11,5 +11,5 @@ rps_server.py: Iterables,\ Iterators,\ Generators.ipynb
run: rps_server.py
python $<
-part1.rst: Iterables,\ Iterators,\ Generators.ipynb rst.py
- python rst.py "$<" "$@"
+rst: Iterables,\ Iterators,\ Generators.ipynb rst.py
+ python rst.py "$<" part1.rst part2.rst
View
17 rst.py
@@ -9,14 +9,15 @@ def restify(nb):
for w in nb['worksheets']:
for c in w['cells'][1:]:
if c['cell_type'] == 'code':
+ lines = [ln.rstrip() for ln in c['input']]
out.extend(['', '.. sourcecode:: python', ''])
- out.extend(' ' + line for line in c['input'] if line != '##')
+ out.extend(' ' + line for line in lines if line != '##')
out.extend(['', '::', ''])
for o in c['outputs']:
if 'text' in o:
if o['text'][:1] == [""]:
del o['text'][0]
- out.extend(' ' + line for line in o['text'])
+ out.extend(' ' + line.rstrip() for line in o['text'])
elif 'traceback' in o:
for line in o['traceback']:
uf = unfunk(line)
@@ -26,8 +27,11 @@ def restify(nb):
elif c['cell_type'] == 'markdown':
out.append('')
for line in c['source']:
+ line = line.rstrip()
if line == '-----':
- return out
+ part1 = out
+ out = []
+ continue
if line.startswith('!['):
cap, link = line.split('](',1)
cap = cap[2:]
@@ -47,6 +51,7 @@ def restify(nb):
out.append('`' + line + '`__')
out.append('-' * (len(line) + 4))
out.extend(['', '__ ' + target + '_'])
+ return part1, out
def unfunk(s):
f = not_funk()
@@ -70,6 +75,10 @@ def not_funk():
with open(sys.argv[1]) as f:
nb = json.load(f)
+part1, part2 = restify(nb)
with open(sys.argv[2], 'w') as f:
- for line in restify(nb):
+ for line in part1:
+ f.write(line.encode('utf-8') + '\n')
+with open(sys.argv[3], 'w') as f:
+ for line in part2:
f.write(line.encode('utf-8') + '\n')

0 comments on commit cfb59f4

Please sign in to comment.