Example #1
0
def test_nbexport_latex_empty(ipynb_app):
    template = str_to_jinja('', "template_name")
    config = dict_to_config({'LatexExporter.template_file': "template_name"})
    exporter_cls = create_exporter_cls('nbconvert.exporters.LatexExporter')
    nb, path = nbmerge.merge_notebooks(ipynb_app.input_file)
    exporter, body, resources = IpyPubMain().export_notebook(
        nb, exporter_cls, config, template)
    assert exporter.output_mimetype == 'text/latex'
    assert body == ''
Example #2
0
def test_nbexport_html_empty(ipynb_app):
    template = str_to_jinja("", "template_name")
    config = dict_to_config({"HTMLExporter.template_file": "template_name"})
    nb, path = nbmerge.merge_notebooks(ipynb_app.input_file)
    exporter_cls = create_exporter_cls("nbconvert.exporters.HTMLExporter")
    exporter, body, resources = IpyPubMain().export_notebook(
        nb, exporter_cls, config, template)
    assert exporter.output_mimetype == "text/html"

    assert body == ""
Example #3
0
def test_nbexport_latex_mkdown1(ipynb_app):
    template = str_to_jinja(
        """
((* block markdowncell scoped *))
test123
((* endblock markdowncell *))
    """, "template_name")
    config = dict_to_config({'LatexExporter.template_file': "template_name"})
    nb, path = nbmerge.merge_notebooks(ipynb_app.input_file)
    exporter_cls = create_exporter_cls('nbconvert.exporters.LatexExporter')
    exporter, body, resources = IpyPubMain().export_notebook(
        nb, exporter_cls, config, template)
    assert exporter.output_mimetype == 'text/latex'
    assert body.strip() == 'test123'
Example #4
0
def test_nbexport_html_mkdown2(ipynb_app):
    template = str_to_jinja(
        """
{%- extends 'display_priority.tpl' -%}
{% block markdowncell scoped %}
{{cell.source}}
{% endblock markdowncell %}
    """, "template_name")
    config = dict_to_config({'HTMLExporter.template_file': "template_name"})
    nb, path = nbmerge.merge_notebooks(ipynb_app.input_file)
    exporter_cls = create_exporter_cls('nbconvert.exporters.HTMLExporter')
    exporter, body, resources = IpyPubMain().export_notebook(
        nb, exporter_cls, config, template)
    assert exporter.output_mimetype == 'text/html'

    assert body.strip() == '# a title\n\nsome text'
Example #5
0
def test_nbexport_html_mkdown1(ipynb_app):
    template = str_to_jinja(
        """
{% block markdowncell scoped %}
test123
{% endblock markdowncell %}
    """,
        "template_name",
    )
    config = dict_to_config({"HTMLExporter.template_file": "template_name"})
    nb, path = nbmerge.merge_notebooks(ipynb_app.input_file)
    exporter_cls = create_exporter_cls("nbconvert.exporters.HTMLExporter")
    exporter, body, resources = IpyPubMain().export_notebook(
        nb, exporter_cls, config, template)
    assert exporter.output_mimetype == "text/html"

    assert body.strip() == "test123"
Example #6
0
def test_nbexport_latex_mkdown2(ipynb_app):
    template = str_to_jinja(
        """
((*- extends 'display_priority.tplx' -*))
((* block markdowncell scoped *))
(((cell.source)))
((* endblock markdowncell *))
    """,
        "template_name",
    )
    config = dict_to_config({"LatexExporter.template_file": "template_name"})
    nb, path = nbmerge.merge_notebooks(ipynb_app.input_file)
    exporter_cls = create_exporter_cls("nbconvert.exporters.LatexExporter")
    exporter, body, resources = IpyPubMain().export_notebook(
        nb, exporter_cls, config, template)
    assert exporter.output_mimetype == "text/latex"

    assert body.strip() == "# a title\n\nsome text"
Example #7
0
    def _load_config_file(self, replacements):
        # find conversion configuration
        self.logger.info("finding conversion configuration: {}".format(
            self.conversion))
        export_config_path = None
        if isinstance(self.conversion, string_types):
            outformat_path = pathlib.Path(self.conversion)
        else:
            outformat_path = self.conversion
        if outformat_path.exists():  # TODO use pathlib approach
            # if is outformat is a path that exists, use that
            export_config_path = outformat_path
        else:
            # else search internally
            export_config_path = get_export_config_path(
                self.conversion, self.plugin_folder_paths)

        if export_config_path is None:
            handle_error(
                "could not find conversion configuration: {}".format(
                    self.conversion),
                IOError,
                self.logger,
            )

        # read conversion configuration and create
        self.logger.info("loading conversion configuration")
        data = load_export_config(export_config_path)
        self.logger.info("creating exporter")
        exporter_cls = create_exporter_cls(data["exporter"]["class"])
        self.logger.info("creating template and loading filters")
        template_name = "template_file"
        jinja_template = load_template(template_name, data["template"])
        self.logger.info("creating process configuration")
        export_config = self._create_export_config(data["exporter"],
                                                   template_name, replacements)
        pprocs, pproc_config = self._create_pproc_config(
            data.get("postprocessors", {}), replacements)

        return (exporter_cls, jinja_template, export_config, pprocs,
                pproc_config)