#!/usr/bin/python import os import sys try: nbconvert = sys.argv[1] notebook = sys.argv[2] except: print "usage: python octopress_notebook.py /path/to/nbconvert.py /path/to/notebook_file.ipynb" sys.exit(-1) # convert notebook os.system('%s -f blogger-html %s' % (nbconvert, notebook)) # get out filenames outfile_root = os.path.splitext(notebook)[0] body_file = outfile_root + '.html' header_file = outfile_root + '_header.html' # read the files body = open(body_file).read() header = open(header_file).read() # replace the highlight tags body = body.replace('class="highlight"', 'class="highlight-ipynb"') header = header.replace('highlight', 'highlight-ipynb') # specify
tags body = body.replace('" header = header.replace('body {', 'div.ipynb {') # specialize headers header = header.replace('html, body,', '\n'.join((('h1.ipynb h2.ipynb h3.ipynb ' 'h4.ipynb h5.ipynb h6.ipynb {'), 'h1.ipynb h2.ipynb ... {', ' margin: 0;', ' padding: 0;', ' border: 0;', ' font-size: 100%;', ' font: inherit;', ' vertical-align: baseline;', '}\n', 'html, body,'))) for h in '123456': body = body.replace('