Show More
@@ -475,7 +475,8 b' class MarkupRenderer(object):' | |||
|
475 | 475 | |
|
476 | 476 | def as_html(notebook): |
|
477 | 477 | conf = config.Config() |
|
478 | conf.CustomHTMLExporter.preprocessors = [Sandbox] | |
|
478 | conf.CustomHTMLExporter.default_preprocessors = [Sandbox] | |
|
479 | conf.Sandbox.enabled = True | |
|
479 | 480 | html_exporter = CustomHTMLExporter(config=conf) |
|
480 | 481 | |
|
481 | 482 | (body, resources) = html_exporter.from_notebook_node(notebook) |
@@ -518,7 +519,8 b' class MarkupRenderer(object):' | |||
|
518 | 519 | body = '\n'.join([header, css, js, body]) |
|
519 | 520 | return body, resources |
|
520 | 521 | |
|
521 | notebook = nbformat.reads(source, as_version=nbformat.NO_CONVERT) | |
|
522 | # TODO: In the event of a newer jupyter notebook version, consider increasing the as_version parameter | |
|
523 | notebook = nbformat.reads(source, as_version=4) | |
|
522 | 524 | (body, resources) = as_html(notebook) |
|
523 | 525 | return body |
|
524 | 526 |
@@ -683,3 +683,103 b' def test_relative_path(src_path, server_' | |||
|
683 | 683 | def test_relative_links(src_html, expected_html): |
|
684 | 684 | server_paths = {'raw': '/path/raw/file.md', 'standard': '/path/file.md'} |
|
685 | 685 | assert relative_links(src_html, server_paths=server_paths) == expected_html |
|
686 | ||
|
687 | ||
|
688 | @pytest.mark.parametrize("notebook_source, expected_output", [ | |
|
689 | (""" | |
|
690 | { | |
|
691 | "nbformat": 3, | |
|
692 | "nbformat_minor": 0, | |
|
693 | "worksheets": [ | |
|
694 | { | |
|
695 | "cells": [ | |
|
696 | { | |
|
697 | "cell_type": "code", | |
|
698 | "execution_count": 1, | |
|
699 | "metadata": {}, | |
|
700 | "outputs": [ | |
|
701 | { | |
|
702 | "name": "stdout", | |
|
703 | "output_type": "stream", | |
|
704 | "text": [ | |
|
705 | "Hello, World!\\n" | |
|
706 | ] | |
|
707 | } | |
|
708 | ], | |
|
709 | "input": "print('Hello, World!')" | |
|
710 | } | |
|
711 | ] | |
|
712 | } | |
|
713 | ], | |
|
714 | "metadata": { | |
|
715 | "kernelspec": { | |
|
716 | "display_name": "Python 3", | |
|
717 | "language": "python", | |
|
718 | "name": "python3" | |
|
719 | }, | |
|
720 | "language_info": { | |
|
721 | "codemirror_mode": { | |
|
722 | "name": "ipython", | |
|
723 | "version": 3 | |
|
724 | }, | |
|
725 | "file_extension": ".py", | |
|
726 | "mimetype": "text/x-python", | |
|
727 | "name": "python", | |
|
728 | "nbconvert_exporter": "python", | |
|
729 | "pygments_lexer": "ipython3", | |
|
730 | "version": "3.8.5" | |
|
731 | } | |
|
732 | } | |
|
733 | } | |
|
734 | """, "Hello, World!"), | |
|
735 | (""" | |
|
736 | { | |
|
737 | "nbformat": 4, | |
|
738 | "nbformat_minor": 1, | |
|
739 | "cells": [ | |
|
740 | { | |
|
741 | "cell_type": "code", | |
|
742 | "execution_count": 1, | |
|
743 | "metadata": {}, | |
|
744 | "outputs": [ | |
|
745 | { | |
|
746 | "name": "stdout", | |
|
747 | "output_type": "stream", | |
|
748 | "text": [ | |
|
749 | "Hello, World!\\n" | |
|
750 | ] | |
|
751 | } | |
|
752 | ], | |
|
753 | "source": [ | |
|
754 | "print('Hello, World!')" | |
|
755 | ] | |
|
756 | } | |
|
757 | ], | |
|
758 | "metadata": { | |
|
759 | "kernelspec": { | |
|
760 | "display_name": "Python 3", | |
|
761 | "language": "python", | |
|
762 | "name": "python3" | |
|
763 | }, | |
|
764 | "language_info": { | |
|
765 | "codemirror_mode": { | |
|
766 | "name": "ipython", | |
|
767 | "version": 4 | |
|
768 | }, | |
|
769 | "file_extension": ".py", | |
|
770 | "mimetype": "text/x-python", | |
|
771 | "name": "python", | |
|
772 | "nbconvert_exporter": "python", | |
|
773 | "pygments_lexer": "ipython3", | |
|
774 | "version": "3.9.1" | |
|
775 | } | |
|
776 | } | |
|
777 | } | |
|
778 | """, "Hello, World!") | |
|
779 | ]) | |
|
780 | def test_jp_notebook_html_generation(notebook_source, expected_output): | |
|
781 | import mock | |
|
782 | with mock.patch('rhodecode.lib.helpers.asset'): | |
|
783 | body = MarkupRenderer.jupyter(notebook_source) | |
|
784 | assert "<!-- ## IPYTHON NOTEBOOK RENDERING ## -->" in body | |
|
785 | assert expected_output in body |
General Comments 0
You need to be logged in to leave comments.
Login now