{{ message }}

Notebook shortcode#192

Merged
merged 3 commits into from Dec 4, 2016
Merged

Notebook shortcode#192

merged 3 commits into from Dec 4, 2016

Conversation

dwyatte commented Dec 3, 2016

 This is a small shortcode to adapt existing notebooks into markup-based posts. The text was updated successfully, but these errors were encountered:
We are unable to convert the task to an issue at this time. Please try again.
added 2 commits Dec 2, 2016
 initial 
 dd04c6d 
 strip scripts and styles 
 5625af2 

Kwpolska commented Dec 4, 2016

 Pretty nifty! Please add this to README: ipynb must be enabled and configured (COMPILERS, POSTS/PAGES) for CSS to appear properly. If you are using math in your notebook, make sure to add the mathjax tag to your post.  Also, This should not leave any 
in output (if it does).

 extract only div id=notebook-container and children 
 e9ef545 
reviewed
 @@ -52,8 +52,8 @@ def render_notebook(self, filename, site=None, data=None, lang=None, post=None): export_html = HTMLExporter(config=c) (notebook_raw, _) = export_html.from_filename(filename) # The raw HTML contains garbage (scripts and styles), we can’t leave it in # The raw HTML contains garbage (scripts and styles). Extract only div id=notebook-container and children

Kwpolska Dec 4, 2016

id won’t be nice either, I’d prefer to avoid having duplicate id tags if someone uses multiple notebooks in a post. But it seems you can’t fix it any better.

dwyatte Dec 5, 2016

Seems like we could do something like the following to remove the ids (I'm not too familiar with lxml, so there might be a cleaner way iterate over the notebook elements).

notebook_el = notebook_html.xpath('//*[@id="notebook"]')[0]
notebook_el.attrib.pop('id')
notebook_container_el = notebook_html.xpath('//*[@id="notebook-container"]')[0]
notebook_container_el.attrib.pop('id')

notebook_code = lxml.html.tostring(notebook_el, encoding='unicode')


I did a quick pass over the ipython css and nikola doesn't do any selection by id, so this appears to work.

At any rate, the merged version also works (at least in my tests), despite not being valid HTML, so we can leave this for the future.

merged commit 099c636 into getnikola:master Dec 4, 2016
1 check passed

Kwpolska commented Dec 4, 2016

 Thanks for contributing! 🎉 The plugin will be available for download after midnight UTC.