Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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
Copy link
Contributor

dwyatte commented Dec 3, 2016

This is a small shortcode to adapt existing notebooks into markup-based posts.

@Kwpolska
Copy link
Member

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 <div id="notebook"> in output (if it does).

@@ -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

This comment has been minimized.

Copy link
@Kwpolska

Kwpolska Dec 4, 2016

Member

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.

This comment has been minimized.

Copy link
@dwyatte

dwyatte Dec 5, 2016

Author Contributor

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.

@Kwpolska Kwpolska merged commit 099c636 into getnikola:master Dec 4, 2016
1 check passed
1 check passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@Kwpolska
Copy link
Member

Kwpolska commented Dec 4, 2016

Thanks for contributing! 🎉

The plugin will be available for download after midnight UTC.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.