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

Simple API for in-memory templates #674

Closed
wants to merge 2 commits into from

Conversation

takluyver
Copy link
Member

Closes #673.

The new API is a method exporter.use_string_template(s), which you pass the string template into.

Example to use it with a subclass:

import sys
from nbconvert.exporters import HTMLExporter

POPPING_TEMPLATE = """
{%- extends 'full.tpl' -%}

{%- block markdowncell -%}
<div style="background-color: hsl(85, 86%, 76%);">
{{ super() }}
</div>
{%- endblock markdowncell -%}
"""

class PopExporter(HTMLExporter):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.use_string_template(POPPING_TEMPLATE)

if __name__ == '__main__':
    out, res = PopExporter().from_filename(sys.argv[1])
    with open('pops.html', 'w') as f:
        f.write(out)

@mpacer
Copy link
Member

mpacer commented Sep 13, 2017

I had a slightly different API in mind, and I'm going to try to write it from scratch but if I find myself using enough patterns similar to yours I'll just rebase it off of this branch.

@takluyver takluyver closed this Sep 19, 2017
@mpacer mpacer added this to the 5.4 milestone Oct 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants