From 62351f45a843f0c877dcc9bfdc6a33016cc388fb Mon Sep 17 00:00:00 2001 From: Chris Sewell Date: Tue, 17 Mar 2020 18:19:34 +0000 Subject: [PATCH] make myst's default extension `.md` --- demo/Benchmarking Jupytext.py | 4 +- ...opulation.mnb => World population.myst.md} | 6 +- docs/formats.md | 6 +- jupytext/formats.py | 16 +- jupytext/jupytext.py | 6 +- jupytext/myst.py | 81 ++- ...eX_305.mnb => Line_breaks_in_LateX_305.md} | 0 ...ok with function and cell metadata 164.md} | 0 ... => Notebook with html and latex cells.md} | 0 ...s.mnb => Notebook with many hash signs.md} | 0 ... Notebook with metadata and long cells.md} | 0 ...h_R_magic.mnb => Notebook_with_R_magic.md} | 0 ....mnb => Notebook_with_more_R_magic_111.md} | 0 ...b => R notebook with invalid cell keys.md} | 0 ... => Reference Guide for Calysto Scheme.md} | 0 ... cells.mnb => The flavors of raw cells.md} | 0 ...rld population.mnb => World population.md} | 0 .../{cat_variable.mnb => cat_variable.md} | 0 ... convert_to_py_then_test_with_update83.md} | 0 .../ipynb_to_myst/{csharp.mnb => csharp.md} | 0 .../{demo_gdl_fbp.mnb => demo_gdl_fbp.md} | 0 ...jupyter_tour.mnb => evcxr_jupyter_tour.md} | 0 .../{frozen_cell.mnb => frozen_cell.md} | 0 .../ipynb_to_myst/{fsharp.mnb => fsharp.md} | 0 .../mirror/ipynb_to_myst/html-demo.mnb | 93 ---- .../{ijavascript.mnb => ijavascript.md} | 0 .../{ir_notebook.mnb => ir_notebook.md} | 0 .../{itypescript.mnb => itypescript.md} | 0 ...mnb => julia_benchmark_plotly_barchart.md} | 0 .../julia_functional_geometry.mnb | 133 ----- .../ipynb_to_myst/{jupyter.mnb => jupyter.md} | 0 .../{jupyter_again.mnb => jupyter_again.md} | 0 ...y.mnb => jupyter_with_raw_cell_in_body.md} | 0 ...op.mnb => jupyter_with_raw_cell_on_top.md} | 0 ...eplication.mnb => jupytext_replication.md} | 0 ...mnb => kalman_filter_and_visualization.md} | 0 ....mnb => notebook_with_complex_metadata.md} | 0 ...arameter.mnb => nteract_with_parameter.md} | 0 ...octave_notebook.mnb => octave_notebook.md} | 0 .../{plotly_graphs.mnb => plotly_graphs.md} | 0 .../{powershell.mnb => powershell.md} | 0 ...h_notebook.mnb => sample_bash_notebook.md} | 0 ...book_66.mnb => sample_rise_notebook_66.md} | 0 ..._notebook.mnb => simple_robot_notebook.md} | 0 ..._notebook.mnb => simple_scala_notebook.md} | 0 ..._images.mnb => text_outputs_and_images.md} | 0 .../ipynb_to_myst/xcpp_by_quantstack.mnb | 467 ------------------ tests/test_ipynb_to_myst.py | 30 ++ tests/test_mirror.py | 2 +- 49 files changed, 116 insertions(+), 728 deletions(-) rename demo/{World population.mnb => World population.myst.md} (97%) rename tests/notebooks/mirror/ipynb_to_myst/{Line_breaks_in_LateX_305.mnb => Line_breaks_in_LateX_305.md} (100%) rename tests/notebooks/mirror/ipynb_to_myst/{Notebook with function and cell metadata 164.mnb => Notebook with function and cell metadata 164.md} (100%) rename tests/notebooks/mirror/ipynb_to_myst/{Notebook with html and latex cells.mnb => Notebook with html and latex cells.md} (100%) rename tests/notebooks/mirror/ipynb_to_myst/{Notebook with many hash signs.mnb => Notebook with many hash signs.md} (100%) rename tests/notebooks/mirror/ipynb_to_myst/{Notebook with metadata and long cells.mnb => Notebook with metadata and long cells.md} (100%) rename tests/notebooks/mirror/ipynb_to_myst/{Notebook_with_R_magic.mnb => Notebook_with_R_magic.md} (100%) rename tests/notebooks/mirror/ipynb_to_myst/{Notebook_with_more_R_magic_111.mnb => Notebook_with_more_R_magic_111.md} (100%) rename tests/notebooks/mirror/ipynb_to_myst/{R notebook with invalid cell keys.mnb => R notebook with invalid cell keys.md} (100%) rename tests/notebooks/mirror/ipynb_to_myst/{Reference Guide for Calysto Scheme.mnb => Reference Guide for Calysto Scheme.md} (100%) rename tests/notebooks/mirror/ipynb_to_myst/{The flavors of raw cells.mnb => The flavors of raw cells.md} (100%) rename tests/notebooks/mirror/ipynb_to_myst/{World population.mnb => World population.md} (100%) rename tests/notebooks/mirror/ipynb_to_myst/{cat_variable.mnb => cat_variable.md} (100%) rename tests/notebooks/mirror/ipynb_to_myst/{convert_to_py_then_test_with_update83.mnb => convert_to_py_then_test_with_update83.md} (100%) rename tests/notebooks/mirror/ipynb_to_myst/{csharp.mnb => csharp.md} (100%) rename tests/notebooks/mirror/ipynb_to_myst/{demo_gdl_fbp.mnb => demo_gdl_fbp.md} (100%) rename tests/notebooks/mirror/ipynb_to_myst/{evcxr_jupyter_tour.mnb => evcxr_jupyter_tour.md} (100%) rename tests/notebooks/mirror/ipynb_to_myst/{frozen_cell.mnb => frozen_cell.md} (100%) rename tests/notebooks/mirror/ipynb_to_myst/{fsharp.mnb => fsharp.md} (100%) delete mode 100644 tests/notebooks/mirror/ipynb_to_myst/html-demo.mnb rename tests/notebooks/mirror/ipynb_to_myst/{ijavascript.mnb => ijavascript.md} (100%) rename tests/notebooks/mirror/ipynb_to_myst/{ir_notebook.mnb => ir_notebook.md} (100%) rename tests/notebooks/mirror/ipynb_to_myst/{itypescript.mnb => itypescript.md} (100%) rename tests/notebooks/mirror/ipynb_to_myst/{julia_benchmark_plotly_barchart.mnb => julia_benchmark_plotly_barchart.md} (100%) delete mode 100644 tests/notebooks/mirror/ipynb_to_myst/julia_functional_geometry.mnb rename tests/notebooks/mirror/ipynb_to_myst/{jupyter.mnb => jupyter.md} (100%) rename tests/notebooks/mirror/ipynb_to_myst/{jupyter_again.mnb => jupyter_again.md} (100%) rename tests/notebooks/mirror/ipynb_to_myst/{jupyter_with_raw_cell_in_body.mnb => jupyter_with_raw_cell_in_body.md} (100%) rename tests/notebooks/mirror/ipynb_to_myst/{jupyter_with_raw_cell_on_top.mnb => jupyter_with_raw_cell_on_top.md} (100%) rename tests/notebooks/mirror/ipynb_to_myst/{jupytext_replication.mnb => jupytext_replication.md} (100%) rename tests/notebooks/mirror/ipynb_to_myst/{kalman_filter_and_visualization.mnb => kalman_filter_and_visualization.md} (100%) rename tests/notebooks/mirror/ipynb_to_myst/{notebook_with_complex_metadata.mnb => notebook_with_complex_metadata.md} (100%) rename tests/notebooks/mirror/ipynb_to_myst/{nteract_with_parameter.mnb => nteract_with_parameter.md} (100%) rename tests/notebooks/mirror/ipynb_to_myst/{octave_notebook.mnb => octave_notebook.md} (100%) rename tests/notebooks/mirror/ipynb_to_myst/{plotly_graphs.mnb => plotly_graphs.md} (100%) rename tests/notebooks/mirror/ipynb_to_myst/{powershell.mnb => powershell.md} (100%) rename tests/notebooks/mirror/ipynb_to_myst/{sample_bash_notebook.mnb => sample_bash_notebook.md} (100%) rename tests/notebooks/mirror/ipynb_to_myst/{sample_rise_notebook_66.mnb => sample_rise_notebook_66.md} (100%) rename tests/notebooks/mirror/ipynb_to_myst/{simple_robot_notebook.mnb => simple_robot_notebook.md} (100%) rename tests/notebooks/mirror/ipynb_to_myst/{simple_scala_notebook.mnb => simple_scala_notebook.md} (100%) rename tests/notebooks/mirror/ipynb_to_myst/{text_outputs_and_images.mnb => text_outputs_and_images.md} (100%) delete mode 100644 tests/notebooks/mirror/ipynb_to_myst/xcpp_by_quantstack.mnb diff --git a/demo/Benchmarking Jupytext.py b/demo/Benchmarking Jupytext.py index c6869f2e3..e350e8a55 100644 --- a/demo/Benchmarking Jupytext.py +++ b/demo/Benchmarking Jupytext.py @@ -32,8 +32,8 @@ # Let's see if we have myst-parser installed here try: - jupytext.writes(notebook, fmt='mystnb') - JUPYTEXT_FORMATS.append('mystnb') + jupytext.writes(notebook, fmt='myst') + JUPYTEXT_FORMATS.append('myst') except jupytext.formats.JupytextFormatError as err: print(str(err)) diff --git a/demo/World population.mnb b/demo/World population.myst.md similarity index 97% rename from demo/World population.mnb rename to demo/World population.myst.md index 0d93a1b65..fc7b05380 100644 --- a/demo/World population.mnb +++ b/demo/World population.myst.md @@ -1,9 +1,9 @@ --- jupytext: - formats: ipynb,.pct.py:percent,.lgt.py:light,.spx.py:sphinx,md,Rmd,.pandoc.md:pandoc + formats: ipynb,.pct.py:percent,.lgt.py:light,.spx.py:sphinx,md,Rmd,.pandoc.md:pandoc,.myst.md:myst text_representation: - extension: .mnb - format_name: mystnb + extension: '.md' + format_name: myst format_version: 0.7.1 jupytext_version: 1.4.0+dev kernelspec: diff --git a/docs/formats.md b/docs/formats.md index 1c90723fe..4be8579ec 100644 --- a/docs/formats.md +++ b/docs/formats.md @@ -83,13 +83,13 @@ See for instance how our `World population.ipynb` notebook is [represented](http If you wish to use that format, please install `pandoc` in version 2.7.2 or above, with e.g. `conda install pandoc -c conda-forge`. -### MyST-NB Markdown +### MyST Markdown [MyST (Markedly Structured Text)][myst-parser] is a markdown flavor that "implements the best parts of reStructuredText". It provides a way to call Sphinx directives and roles from within Markdown, using a *slight* extension of CommonMark markdown. [MyST-NB][myst-nb] builds on this markdown flavor, to offer direct conversion of Jupyter Notebooks into Sphinx documents. -Similar to the Markdown format, MyST-NB uses code blocks to contain code cells. +Similar to the jupytext Markdown format, MyST Markdown uses code blocks to contain code cells. The difference though, is that the metadata is contained in a YAML block: ````md @@ -142,7 +142,7 @@ This is a markdown cell with metadata This is a new markdown cell with no metadata ``` -See for instance how our `World population.ipynb` notebook is [represented](https://github.com/mwouts/jupytext/blob/master/demo/World%20population.mnb#) in the `mystnb` format. +See for instance how our `World population.ipynb` notebook is [represented](https://github.com/mwouts/jupytext/blob/master/demo/World%20population.myst.md#) in the `myst` format. If you wish to use that format, please install `conda install -c conda-forge myst-parser`, or `pip install jupytext[myst]`. diff --git a/jupytext/formats.py b/jupytext/formats.py index 6c5e8799f..826e65045 100644 --- a/jupytext/formats.py +++ b/jupytext/formats.py @@ -24,6 +24,7 @@ is_myst_available, myst_version, myst_extensions, + matches_mystnb, ) @@ -231,6 +232,8 @@ def read_format_from_metadata(text, ext): def guess_format(text, ext): """Guess the format and format options of the file, given its extension and content""" + if matches_mystnb(text, ext): + return MYST_FORMAT_NAME, {} lines = text.splitlines() metadata = read_metadata(text, ext) @@ -465,11 +468,14 @@ def long_form_one_format(jupytext_format, metadata=None, update=None, auto_ext_r if not jupytext_format: return {} - common_name_to_ext = {'notebook': 'ipynb', - 'rmarkdown': 'Rmd', - 'markdown': 'md', - 'script': 'auto', - 'c++': 'cpp'} + common_name_to_ext = { + 'notebook': 'ipynb', + 'rmarkdown': 'Rmd', + 'markdown': 'md', + 'script': 'auto', + 'c++': 'cpp', + 'myst': 'md' + } if jupytext_format.lower() in common_name_to_ext: jupytext_format = common_name_to_ext[jupytext_format.lower()] diff --git a/jupytext/jupytext.py b/jupytext/jupytext.py index 9999d1d99..0a31651d6 100644 --- a/jupytext/jupytext.py +++ b/jupytext/jupytext.py @@ -19,7 +19,7 @@ from .languages import default_language_from_metadata_and_ext, set_main_and_cell_language from .pep8 import pep8_lines_between_cells from .pandoc import md_to_notebook, notebook_to_md -from .myst import myst_extensions, myst_to_notebook, notebook_to_myst +from .myst import myst_extensions, myst_to_notebook, notebook_to_myst, MYST_FORMAT_NAME class TextNotebookConverter(NotebookReader, NotebookWriter): @@ -55,7 +55,7 @@ def reads(self, s, **_): if self.fmt.get('format_name') == 'pandoc': return md_to_notebook(s) - if self.ext in myst_extensions(): + if self.fmt.get('format_name') == MYST_FORMAT_NAME: return myst_to_notebook(s) lines = s.splitlines() @@ -127,7 +127,7 @@ def writes(self, nb, metadata=None, **kwargs): metadata=metadata, cells=cells)) - if self.ext in myst_extensions(): + if self.fmt.get('format_name') == MYST_FORMAT_NAME or self.ext in myst_extensions(no_md=True): pygments_lexer = metadata.get("language_info", {}).get("pygments_lexer", None) metadata = insert_jupytext_info_and_filter_metadata(metadata, self.ext, self.implementation) diff --git a/jupytext/myst.py b/jupytext/myst.py index e921d0104..c1449e8f5 100644 --- a/jupytext/myst.py +++ b/jupytext/myst.py @@ -7,12 +7,13 @@ import nbformat as nbf import yaml -MYST_FORMAT_NAME = "mystnb" +MYST_FORMAT_NAME = "myst" CODE_DIRECTIVE = "code-cell" RAW_DIRECTIVE = "raw-cell" def is_myst_available(): + """Whether the myst-parser package is available.""" try: import myst_parser # noqa except ImportError: @@ -21,13 +22,50 @@ def is_myst_available(): def myst_version(): + """The version of myst parser.""" from myst_parser import __version__ return __version__ -def myst_extensions(): - return [".myst.md", ".mnb"] +def myst_extensions(no_md=False): + """The allowed extensions for the myst format.""" + if no_md: + return [".myst", ".mystnb", ".mnb"] + return [".md", ".myst", ".mystnb", ".mnb"] + + +def matches_mystnb(text, ext=None, requires_meta=True, require_non_md=True): + """Attempt to distinguish a file as mystnb, only given its extension and content. + + :param ext: the extension of the file + :param requires_meta: requires the file to contain top matter metadata + :param require_non_md: whether to require that a non-markdown cell is present + """ + if ext and (ext+".").rsplit(".", 1)[1] in ["myst", "mystnb"]: + return True + if requires_meta and not text.startswith("---"): + return False + try: + nb = myst_to_notebook(text, ignore_bad_meta=True) + except Exception: + return False + + from jupytext.formats import format_name_for_ext + + # Is the format information available in the jupytext text representation? + try: + format_name = format_name_for_ext(nb.metadata, ext or ".md") + except AttributeError: + pass + else: + if format_name == MYST_FORMAT_NAME: + return True + + if require_non_md and not any(c.cell_type != "markdown" for c in nb.cells): + return False + + return True class CompactDumper(yaml.SafeDumper): @@ -96,13 +134,14 @@ def _fmt_md(text): def myst_to_notebook( - text, code_directive=CODE_DIRECTIVE, raw_directive=RAW_DIRECTIVE, + text, code_directive=CODE_DIRECTIVE, raw_directive=RAW_DIRECTIVE, ignore_bad_meta=False ): """Convert text written in the myst format to a notebook. :param text: the file text :param code_directive: the name of the directive to search for containing code cells :param raw_directive: the name of the directive to search for containing raw cells + :param ignore_bad_meta: ignore metadata that cannot be parsed as JSON/YAML NOTE: we assume here that all of these directives are at the top-level, i.e. not nested in other directives. @@ -136,11 +175,12 @@ def myst_to_notebook( try: set_parse_context(parse_context) doc = Document.read(lines, front_matter=True) + metadata_nb = {} try: metadata_nb = doc.front_matter.get_data() if doc.front_matter else {} except (yaml.parser.ParserError, yaml.scanner.ScannerError) as error: - raise MystMetadataParsingError("Notebook metadata: {}".format(error)) - + if not ignore_bad_meta: + raise MystMetadataParsingError("Notebook metadata: {}".format(error)) nbf_version = nbf.v4 kwargs = {"metadata": nbf.from_dict(metadata_nb)} notebook = nbf_version.new_notebook(**kwargs) @@ -161,20 +201,23 @@ def myst_to_notebook( ) ) if token.content: + md_metadata = {} try: md_metadata = json.loads(token.content.strip()) except Exception as err: - raise MystMetadataParsingError( - "markdown cell {0} at {1} could not be read: {2}".format( - len(notebook.cells) + 1, token.position, err + if not ignore_bad_meta: + raise MystMetadataParsingError( + "markdown cell {0} at {1} could not be read: {2}".format( + len(notebook.cells) + 1, token.position, err + ) ) - ) if not isinstance(md_metadata, dict): - raise MystMetadataParsingError( - "markdown cell {0} at {1} is not a dict".format( - len(notebook.cells) + 1, token.position + if not ignore_bad_meta: + raise MystMetadataParsingError( + "markdown cell {0} at {1} is not a dict".format( + len(notebook.cells) + 1, token.position + ) ) - ) else: md_metadata = {} current_line = token.position.line_start @@ -187,6 +230,7 @@ def myst_to_notebook( # this is reserved for the optional lexer name # TODO: could log warning about if token.arguments != lexer name + options, body_lines = {}, [] try: _, options, body_lines = parse_directive_text( directive_class=MockDirective, @@ -195,11 +239,12 @@ def myst_to_notebook( validate_options=False, ) except DirectiveParsingError as err: - raise MystMetadataParsingError( - "Code cell {0} at {1} could not be read: {2}".format( - len(notebook.cells) + 1, token.position, err + if not ignore_bad_meta: + raise MystMetadataParsingError( + "Code cell {0} at {1} could not be read: {2}".format( + len(notebook.cells) + 1, token.position, err + ) ) - ) md_source = _fmt_md( "".join(lines.lines[current_line:token.position.line_start - 1]) diff --git a/tests/notebooks/mirror/ipynb_to_myst/Line_breaks_in_LateX_305.mnb b/tests/notebooks/mirror/ipynb_to_myst/Line_breaks_in_LateX_305.md similarity index 100% rename from tests/notebooks/mirror/ipynb_to_myst/Line_breaks_in_LateX_305.mnb rename to tests/notebooks/mirror/ipynb_to_myst/Line_breaks_in_LateX_305.md diff --git a/tests/notebooks/mirror/ipynb_to_myst/Notebook with function and cell metadata 164.mnb b/tests/notebooks/mirror/ipynb_to_myst/Notebook with function and cell metadata 164.md similarity index 100% rename from tests/notebooks/mirror/ipynb_to_myst/Notebook with function and cell metadata 164.mnb rename to tests/notebooks/mirror/ipynb_to_myst/Notebook with function and cell metadata 164.md diff --git a/tests/notebooks/mirror/ipynb_to_myst/Notebook with html and latex cells.mnb b/tests/notebooks/mirror/ipynb_to_myst/Notebook with html and latex cells.md similarity index 100% rename from tests/notebooks/mirror/ipynb_to_myst/Notebook with html and latex cells.mnb rename to tests/notebooks/mirror/ipynb_to_myst/Notebook with html and latex cells.md diff --git a/tests/notebooks/mirror/ipynb_to_myst/Notebook with many hash signs.mnb b/tests/notebooks/mirror/ipynb_to_myst/Notebook with many hash signs.md similarity index 100% rename from tests/notebooks/mirror/ipynb_to_myst/Notebook with many hash signs.mnb rename to tests/notebooks/mirror/ipynb_to_myst/Notebook with many hash signs.md diff --git a/tests/notebooks/mirror/ipynb_to_myst/Notebook with metadata and long cells.mnb b/tests/notebooks/mirror/ipynb_to_myst/Notebook with metadata and long cells.md similarity index 100% rename from tests/notebooks/mirror/ipynb_to_myst/Notebook with metadata and long cells.mnb rename to tests/notebooks/mirror/ipynb_to_myst/Notebook with metadata and long cells.md diff --git a/tests/notebooks/mirror/ipynb_to_myst/Notebook_with_R_magic.mnb b/tests/notebooks/mirror/ipynb_to_myst/Notebook_with_R_magic.md similarity index 100% rename from tests/notebooks/mirror/ipynb_to_myst/Notebook_with_R_magic.mnb rename to tests/notebooks/mirror/ipynb_to_myst/Notebook_with_R_magic.md diff --git a/tests/notebooks/mirror/ipynb_to_myst/Notebook_with_more_R_magic_111.mnb b/tests/notebooks/mirror/ipynb_to_myst/Notebook_with_more_R_magic_111.md similarity index 100% rename from tests/notebooks/mirror/ipynb_to_myst/Notebook_with_more_R_magic_111.mnb rename to tests/notebooks/mirror/ipynb_to_myst/Notebook_with_more_R_magic_111.md diff --git a/tests/notebooks/mirror/ipynb_to_myst/R notebook with invalid cell keys.mnb b/tests/notebooks/mirror/ipynb_to_myst/R notebook with invalid cell keys.md similarity index 100% rename from tests/notebooks/mirror/ipynb_to_myst/R notebook with invalid cell keys.mnb rename to tests/notebooks/mirror/ipynb_to_myst/R notebook with invalid cell keys.md diff --git a/tests/notebooks/mirror/ipynb_to_myst/Reference Guide for Calysto Scheme.mnb b/tests/notebooks/mirror/ipynb_to_myst/Reference Guide for Calysto Scheme.md similarity index 100% rename from tests/notebooks/mirror/ipynb_to_myst/Reference Guide for Calysto Scheme.mnb rename to tests/notebooks/mirror/ipynb_to_myst/Reference Guide for Calysto Scheme.md diff --git a/tests/notebooks/mirror/ipynb_to_myst/The flavors of raw cells.mnb b/tests/notebooks/mirror/ipynb_to_myst/The flavors of raw cells.md similarity index 100% rename from tests/notebooks/mirror/ipynb_to_myst/The flavors of raw cells.mnb rename to tests/notebooks/mirror/ipynb_to_myst/The flavors of raw cells.md diff --git a/tests/notebooks/mirror/ipynb_to_myst/World population.mnb b/tests/notebooks/mirror/ipynb_to_myst/World population.md similarity index 100% rename from tests/notebooks/mirror/ipynb_to_myst/World population.mnb rename to tests/notebooks/mirror/ipynb_to_myst/World population.md diff --git a/tests/notebooks/mirror/ipynb_to_myst/cat_variable.mnb b/tests/notebooks/mirror/ipynb_to_myst/cat_variable.md similarity index 100% rename from tests/notebooks/mirror/ipynb_to_myst/cat_variable.mnb rename to tests/notebooks/mirror/ipynb_to_myst/cat_variable.md diff --git a/tests/notebooks/mirror/ipynb_to_myst/convert_to_py_then_test_with_update83.mnb b/tests/notebooks/mirror/ipynb_to_myst/convert_to_py_then_test_with_update83.md similarity index 100% rename from tests/notebooks/mirror/ipynb_to_myst/convert_to_py_then_test_with_update83.mnb rename to tests/notebooks/mirror/ipynb_to_myst/convert_to_py_then_test_with_update83.md diff --git a/tests/notebooks/mirror/ipynb_to_myst/csharp.mnb b/tests/notebooks/mirror/ipynb_to_myst/csharp.md similarity index 100% rename from tests/notebooks/mirror/ipynb_to_myst/csharp.mnb rename to tests/notebooks/mirror/ipynb_to_myst/csharp.md diff --git a/tests/notebooks/mirror/ipynb_to_myst/demo_gdl_fbp.mnb b/tests/notebooks/mirror/ipynb_to_myst/demo_gdl_fbp.md similarity index 100% rename from tests/notebooks/mirror/ipynb_to_myst/demo_gdl_fbp.mnb rename to tests/notebooks/mirror/ipynb_to_myst/demo_gdl_fbp.md diff --git a/tests/notebooks/mirror/ipynb_to_myst/evcxr_jupyter_tour.mnb b/tests/notebooks/mirror/ipynb_to_myst/evcxr_jupyter_tour.md similarity index 100% rename from tests/notebooks/mirror/ipynb_to_myst/evcxr_jupyter_tour.mnb rename to tests/notebooks/mirror/ipynb_to_myst/evcxr_jupyter_tour.md diff --git a/tests/notebooks/mirror/ipynb_to_myst/frozen_cell.mnb b/tests/notebooks/mirror/ipynb_to_myst/frozen_cell.md similarity index 100% rename from tests/notebooks/mirror/ipynb_to_myst/frozen_cell.mnb rename to tests/notebooks/mirror/ipynb_to_myst/frozen_cell.md diff --git a/tests/notebooks/mirror/ipynb_to_myst/fsharp.mnb b/tests/notebooks/mirror/ipynb_to_myst/fsharp.md similarity index 100% rename from tests/notebooks/mirror/ipynb_to_myst/fsharp.mnb rename to tests/notebooks/mirror/ipynb_to_myst/fsharp.md diff --git a/tests/notebooks/mirror/ipynb_to_myst/html-demo.mnb b/tests/notebooks/mirror/ipynb_to_myst/html-demo.mnb deleted file mode 100644 index dc8653c90..000000000 --- a/tests/notebooks/mirror/ipynb_to_myst/html-demo.mnb +++ /dev/null @@ -1,93 +0,0 @@ ---- -kernelspec: - display_name: Clojure - language: clojure - name: clojure ---- - -# Clojupyter Demo - -This example notebook is from the [Clojupyter](https://github.com/clojupyter/clojupyter/blob/1637f6b2557f01db1e35bae5389bc38522eefe9a/examples/html-demo.ipynb) project. -This notebook demonstrates some of the more advanced features of Clojupyter. - -+++ - -## Displaying HTML - -To display HTML, you'll need to require a clojupyter helper function to change the cell output - -```{code-cell} -(require '[clojupyter.misc.display :as display]) -``` - -```{code-cell} -(println ">> should print some text") -;; displaying html -(display/hiccup-html - [:ul - [:li "a " [:i "emphatic"] " idea"] - [:li "a " [:b "bold"] " idea"] - [:li "an " [:span {:style "text-decoration: underline;"} "important"] " idea"]]) -``` - -We can also use this to render SVG: - -```{code-cell} -(display/hiccup-html - [:svg {:height 100 :width 100 :xmlns "http://www.w3.org/2000/svg"} - [:circle {:cx 50 :cy 40 :r 40 :fill "red"}]]) -``` - -## Adding External Clojure Dependencies - -You can fetch external Clojure dependcies using the `clojupyter.misc.helper` namespace. - -```{code-cell} -(require '[clojupyter.misc.helper :as helper]) -``` - -```{code-cell} -(helper/add-dependencies '[org.clojure/data.json "0.2.6"]) -(require '[clojure.data.json :as json]) -``` - -```{code-cell} -(json/write-str {:a 1 :b [2, 3] :c "c"}) -``` - -## Adding External Javascript Dependency - -Since you can render arbitrary HTML using `display/hiccup-html`, it's pretty easy to use external Javascript libraries to do things like generate charts. Here's an example using [Highcharts](https://www.highcharts.com/). - -First, we use a cell to add javascript to the running notebook: - -```{code-cell} -(helper/add-javascript "https://code.highcharts.com/highcharts.js") -``` - -Now we define a function which takes Clojure data and returns hiccup HTML to display: - -```{code-cell} -(defn plot-highchart [highchart-json] - (let [id (str (java.util.UUID/randomUUID)) - code (format "Highcharts.chart('%s', %s );" id, (json/write-str highchart-json))] - (display/hiccup-html - [:div [:div {:id id :style {:background-color "red"}}] - [:script code]]))) -``` - -Now we can make generate interactive plots (try hovering over plot): - -```{code-cell} -(def raw-data (map #(+ (* 22 (+ % (Math/random)) 78)) (range))) -(def data-1 (take 500 raw-data)) -(def data-2 (take 500 (drop 500 raw-data))) - -(plot-highchart {:chart {:type "line"} - :title {:text "Plot of random data"} - :series [{:data data-1} {:data data-2}]}) -``` - -```{code-cell} - -``` diff --git a/tests/notebooks/mirror/ipynb_to_myst/ijavascript.mnb b/tests/notebooks/mirror/ipynb_to_myst/ijavascript.md similarity index 100% rename from tests/notebooks/mirror/ipynb_to_myst/ijavascript.mnb rename to tests/notebooks/mirror/ipynb_to_myst/ijavascript.md diff --git a/tests/notebooks/mirror/ipynb_to_myst/ir_notebook.mnb b/tests/notebooks/mirror/ipynb_to_myst/ir_notebook.md similarity index 100% rename from tests/notebooks/mirror/ipynb_to_myst/ir_notebook.mnb rename to tests/notebooks/mirror/ipynb_to_myst/ir_notebook.md diff --git a/tests/notebooks/mirror/ipynb_to_myst/itypescript.mnb b/tests/notebooks/mirror/ipynb_to_myst/itypescript.md similarity index 100% rename from tests/notebooks/mirror/ipynb_to_myst/itypescript.mnb rename to tests/notebooks/mirror/ipynb_to_myst/itypescript.md diff --git a/tests/notebooks/mirror/ipynb_to_myst/julia_benchmark_plotly_barchart.mnb b/tests/notebooks/mirror/ipynb_to_myst/julia_benchmark_plotly_barchart.md similarity index 100% rename from tests/notebooks/mirror/ipynb_to_myst/julia_benchmark_plotly_barchart.mnb rename to tests/notebooks/mirror/ipynb_to_myst/julia_benchmark_plotly_barchart.md diff --git a/tests/notebooks/mirror/ipynb_to_myst/julia_functional_geometry.mnb b/tests/notebooks/mirror/ipynb_to_myst/julia_functional_geometry.mnb deleted file mode 100644 index 77679ed00..000000000 --- a/tests/notebooks/mirror/ipynb_to_myst/julia_functional_geometry.mnb +++ /dev/null @@ -1,133 +0,0 @@ ---- -kernelspec: - display_name: Julia 1.1.1 - language: julia - name: julia-1.1 ---- - -```{code-cell} -# This notebook is a semi top-down explanation. This cell needs to be -# executed first so that the operators and helper functions are defined -# All of this is explained in the later half of the notebook - -using Compose, Interact -Compose.set_default_graphic_size(2inch, 2inch) - -points_f = [ - (.1, .1), - (.9, .1), - (.9, .2), - (.2, .2), - (.2, .4), - (.6, .4), - (.6, .5), - (.2, .5), - (.2, .9), - (.1, .9), - (.1, .1) -] - -f = compose(context(), stroke("black"), line(points_f)) - -rot(pic) = compose(context(rotation=Rotation(-deg2rad(90))), pic) -flip(pic) = compose(context(mirror=Mirror(deg2rad(90), 0.5w, 0.5h)), pic) -above(m, n, p, q) = - compose(context(), - (context(0, 0, 1, m/(m+n)), p), - (context(0, m/(m+n), 1, n/(m+n)), q)) - -above(p, q) = above(1, 1, p, q) - -beside(m, n, p, q) = - compose(context(), - (context(0, 0, m/(m+n), 1), p), - (context(m/(m+n), 0, n/(m+n), 1), q)) - -beside(p, q) = beside(1, 1, p, q) - -over(p, q) = compose(context(), - (context(), p), (context(), q)) - -rot45(pic) = - compose(context(0, 0, 1/sqrt(2), 1/sqrt(2), - rotation=Rotation(-deg2rad(45), 0w, 0h)), pic) - -# Utility function to zoom out and look at the context -zoomout(pic) = compose(context(), - (context(0.2, 0.2, 0.6, 0.6), pic), - (context(0.2, 0.2, 0.6, 0.6), fill(nothing), stroke("black"), strokedash([0.5mm, 0.5mm]), - polygon([(0, 0), (1, 0), (1, 1), (0, 1)]))) - -function read_path(p_str) - tokens = [try parsefloat(x) catch symbol(x) end for x in split(p_str, r"[\s,]+")] - path(tokens) -end - -fish = compose(context(units=UnitBox(260, 260)), stroke("black"), - read_path(strip(readall("fish.path")))) - -rotatable(pic) = @manipulate for θ=0:0.001:2π - compose(context(rotation=Rotation(θ)), pic) -end - -blank = compose(context()) - -fliprot45(pic) = rot45(compose(context(mirror=Mirror(deg2rad(-45))),pic)) - -# Hide this cell. -display(MIME("text/html"), """""") -``` - -# Functional Geometry -*Functional Geometry* is a paper by Peter Henderson ([original (1982)](users.ecs.soton.ac.uk/peter/funcgeo.pdf), [revisited (2002)](https://cs.au.dk/~hosc/local/HOSC-15-4-pp349-365.pdf)) which deconstructs the MC Escher woodcut *Square Limit* - -![Square Limit](http://i.imgur.com/LjRzmNM.png) - -+++ - -> A picture is an example of a complex object that can be described in terms of its parts. -Yet a picture needs to be rendered on a printer or a screen by a device that expects to -be given a sequence of commands. Programming that sequence of commands directly is -much harder than having an application generate the commands automatically from the -simpler, denotational description. - -+++ - -A `picture` is a *denotation* of something to draw. - -e.g. The value of f here denotes the picture of the letter F - -+++ - -Original at http://nbviewer.jupyter.org/github/shashi/ijulia-notebooks/blob/master/funcgeo/Functional%20Geometry.ipynb - -+++ - -## In conclusion - -We described Escher's *Square Limit* from the description of its smaller parts, which in turn were described in terms of their smaller parts. - -This seemed simple because we chose to talk in terms of an *algebra* to describe pictures. The primitives `rot`, `flip`, `fliprot45`, `above`, `beside` and `over` fit the job perfectly. - -We were able to describe these primitves in terms of `compose` `contexts`, which the Compose library knows how to render. - -Denotation can be an easy way to describe a system as well as a practical implementation method. - -[Abstraction barriers](https://mitpress.mit.edu/sicp/full-text/sicp/book/node29.html) are useful tools that can reduce the cognitive overhead on the programmer. It entails creating layers consisting of functions which only use functions in the same layer or layers below in their own implementation. The layers in our language were: - - ------------------[ squarelimit ]------------------ - -------------[ quartet, cycle, nonet ]------------- - ---[ rot, flip, fliprot45, above, beside, over ]--- - -------[ compose, context, line, path,... ]-------- - -Drawing this diagram out is a useful way to begin building any library. diff --git a/tests/notebooks/mirror/ipynb_to_myst/jupyter.mnb b/tests/notebooks/mirror/ipynb_to_myst/jupyter.md similarity index 100% rename from tests/notebooks/mirror/ipynb_to_myst/jupyter.mnb rename to tests/notebooks/mirror/ipynb_to_myst/jupyter.md diff --git a/tests/notebooks/mirror/ipynb_to_myst/jupyter_again.mnb b/tests/notebooks/mirror/ipynb_to_myst/jupyter_again.md similarity index 100% rename from tests/notebooks/mirror/ipynb_to_myst/jupyter_again.mnb rename to tests/notebooks/mirror/ipynb_to_myst/jupyter_again.md diff --git a/tests/notebooks/mirror/ipynb_to_myst/jupyter_with_raw_cell_in_body.mnb b/tests/notebooks/mirror/ipynb_to_myst/jupyter_with_raw_cell_in_body.md similarity index 100% rename from tests/notebooks/mirror/ipynb_to_myst/jupyter_with_raw_cell_in_body.mnb rename to tests/notebooks/mirror/ipynb_to_myst/jupyter_with_raw_cell_in_body.md diff --git a/tests/notebooks/mirror/ipynb_to_myst/jupyter_with_raw_cell_on_top.mnb b/tests/notebooks/mirror/ipynb_to_myst/jupyter_with_raw_cell_on_top.md similarity index 100% rename from tests/notebooks/mirror/ipynb_to_myst/jupyter_with_raw_cell_on_top.mnb rename to tests/notebooks/mirror/ipynb_to_myst/jupyter_with_raw_cell_on_top.md diff --git a/tests/notebooks/mirror/ipynb_to_myst/jupytext_replication.mnb b/tests/notebooks/mirror/ipynb_to_myst/jupytext_replication.md similarity index 100% rename from tests/notebooks/mirror/ipynb_to_myst/jupytext_replication.mnb rename to tests/notebooks/mirror/ipynb_to_myst/jupytext_replication.md diff --git a/tests/notebooks/mirror/ipynb_to_myst/kalman_filter_and_visualization.mnb b/tests/notebooks/mirror/ipynb_to_myst/kalman_filter_and_visualization.md similarity index 100% rename from tests/notebooks/mirror/ipynb_to_myst/kalman_filter_and_visualization.mnb rename to tests/notebooks/mirror/ipynb_to_myst/kalman_filter_and_visualization.md diff --git a/tests/notebooks/mirror/ipynb_to_myst/notebook_with_complex_metadata.mnb b/tests/notebooks/mirror/ipynb_to_myst/notebook_with_complex_metadata.md similarity index 100% rename from tests/notebooks/mirror/ipynb_to_myst/notebook_with_complex_metadata.mnb rename to tests/notebooks/mirror/ipynb_to_myst/notebook_with_complex_metadata.md diff --git a/tests/notebooks/mirror/ipynb_to_myst/nteract_with_parameter.mnb b/tests/notebooks/mirror/ipynb_to_myst/nteract_with_parameter.md similarity index 100% rename from tests/notebooks/mirror/ipynb_to_myst/nteract_with_parameter.mnb rename to tests/notebooks/mirror/ipynb_to_myst/nteract_with_parameter.md diff --git a/tests/notebooks/mirror/ipynb_to_myst/octave_notebook.mnb b/tests/notebooks/mirror/ipynb_to_myst/octave_notebook.md similarity index 100% rename from tests/notebooks/mirror/ipynb_to_myst/octave_notebook.mnb rename to tests/notebooks/mirror/ipynb_to_myst/octave_notebook.md diff --git a/tests/notebooks/mirror/ipynb_to_myst/plotly_graphs.mnb b/tests/notebooks/mirror/ipynb_to_myst/plotly_graphs.md similarity index 100% rename from tests/notebooks/mirror/ipynb_to_myst/plotly_graphs.mnb rename to tests/notebooks/mirror/ipynb_to_myst/plotly_graphs.md diff --git a/tests/notebooks/mirror/ipynb_to_myst/powershell.mnb b/tests/notebooks/mirror/ipynb_to_myst/powershell.md similarity index 100% rename from tests/notebooks/mirror/ipynb_to_myst/powershell.mnb rename to tests/notebooks/mirror/ipynb_to_myst/powershell.md diff --git a/tests/notebooks/mirror/ipynb_to_myst/sample_bash_notebook.mnb b/tests/notebooks/mirror/ipynb_to_myst/sample_bash_notebook.md similarity index 100% rename from tests/notebooks/mirror/ipynb_to_myst/sample_bash_notebook.mnb rename to tests/notebooks/mirror/ipynb_to_myst/sample_bash_notebook.md diff --git a/tests/notebooks/mirror/ipynb_to_myst/sample_rise_notebook_66.mnb b/tests/notebooks/mirror/ipynb_to_myst/sample_rise_notebook_66.md similarity index 100% rename from tests/notebooks/mirror/ipynb_to_myst/sample_rise_notebook_66.mnb rename to tests/notebooks/mirror/ipynb_to_myst/sample_rise_notebook_66.md diff --git a/tests/notebooks/mirror/ipynb_to_myst/simple_robot_notebook.mnb b/tests/notebooks/mirror/ipynb_to_myst/simple_robot_notebook.md similarity index 100% rename from tests/notebooks/mirror/ipynb_to_myst/simple_robot_notebook.mnb rename to tests/notebooks/mirror/ipynb_to_myst/simple_robot_notebook.md diff --git a/tests/notebooks/mirror/ipynb_to_myst/simple_scala_notebook.mnb b/tests/notebooks/mirror/ipynb_to_myst/simple_scala_notebook.md similarity index 100% rename from tests/notebooks/mirror/ipynb_to_myst/simple_scala_notebook.mnb rename to tests/notebooks/mirror/ipynb_to_myst/simple_scala_notebook.md diff --git a/tests/notebooks/mirror/ipynb_to_myst/text_outputs_and_images.mnb b/tests/notebooks/mirror/ipynb_to_myst/text_outputs_and_images.md similarity index 100% rename from tests/notebooks/mirror/ipynb_to_myst/text_outputs_and_images.mnb rename to tests/notebooks/mirror/ipynb_to_myst/text_outputs_and_images.md diff --git a/tests/notebooks/mirror/ipynb_to_myst/xcpp_by_quantstack.mnb b/tests/notebooks/mirror/ipynb_to_myst/xcpp_by_quantstack.mnb deleted file mode 100644 index 0203fb1e9..000000000 --- a/tests/notebooks/mirror/ipynb_to_myst/xcpp_by_quantstack.mnb +++ /dev/null @@ -1,467 +0,0 @@ ---- -kernelspec: - display_name: C++14 - language: C++14 - name: xeus-cling-cpp14 ---- - -[![xeus-cling](images/xeus-cling.png)](https://github.com/QuantStack/xeus-cling/) - -A Jupyter kernel for C++ based on the `cling` C++ interpreter and the `xeus` native implementation of the Jupyter protocol, xeus. - -- GitHub repository: https://github.com/QuantStack/xeus-cling/ -- Online documentation: https://xeus-cling.readthedocs.io/ - -+++ - -## Usage - -
- - -
- To run the selected code cell, hit
Shift + Enter
-
-
- -+++ - -## Output and error streams - -`std::cout` and `std::cerr` are redirected to the notebook frontend. - -```{code-cell} -#include - -std::cout << "some output" << std::endl; -``` - -```{code-cell} -std::cerr << "some error" << std::endl; -``` - -```{code-cell} -#include -``` - -```{code-cell} -throw std::runtime_error("Unknown exception"); -``` - -Omitting the `;` in the last statement of a cell results in an output being printed - -```{code-cell} -int j = 5; -``` - -```{code-cell} -j -``` - -# Interpreting the C++ programming language - -`cling` has a broad support of the features of C++. You can define functions, classes, templates, etc ... - -+++ - -## Functions - -```{code-cell} -double sqr(double a) -{ - return a * a; -} -``` - -```{code-cell} -double a = 2.5; -double asqr = sqr(a); -asqr -``` - -## Classes - -```{code-cell} -class Foo -{ -public: - - virtual ~Foo() {} - - virtual void print(double value) const - { - std::cout << "Foo value = " << value << std::endl; - } -}; -``` - -```{code-cell} -Foo bar; -bar.print(1.2); -``` - -## Polymorphism - -```{code-cell} -class Bar : public Foo -{ -public: - - virtual ~Bar() {} - - virtual void print(double value) const - { - std::cout << "Bar value = " << 2 * value << std::endl; - } -}; -``` - -```{code-cell} -Foo* bar2 = new Bar; -bar2->print(1.2); -delete bar2; -``` - -## Templates - -```{code-cell} -#include - -template -class FooT -{ -public: - - explicit FooT(const T& t) : m_t(t) {} - - void print() const - { - std::cout << typeid(T).name() << " m_t = " << m_t << std::endl; - } - -private: - - T m_t; -}; - -template <> -class FooT -{ -public: - - explicit FooT(const int& t) : m_t(t) {} - - void print() const - { - std::cout << "m_t = " << m_t << std::endl; - } - -private: - - int m_t; -}; -``` - -```{code-cell} -FooT foot1(1.2); -foot1.print(); -``` - -```{code-cell} -FooT foot2(4); -foot2.print(); -``` - -## C++11 / C++14 support - -```{code-cell} -class Foo11 -{ -public: - - Foo11() { std::cout << "Foo11 default constructor" << std::endl; } - Foo11(const Foo11&) { std::cout << "Foo11 copy constructor" << std::endl; } - Foo11(Foo11&&) { std::cout << "Foo11 move constructor" << std::endl; } -}; -``` - -```{code-cell} -Foo11 f1; -Foo11 f2(f1); -Foo11 f3(std::move(f1)); -``` - -```{code-cell} -#include - -std::vector v = { 1, 2, 3}; -auto iter = ++v.begin(); -v -``` - -```{code-cell} -*iter -``` - -... and also lambda, universal references, `decltype`, etc ... - -+++ - -## Documentation and completion - - - Documentation for types of the standard library is retrieved on cppreference.com. - - The quick-help feature can also be enabled for user-defined types and third-party libraries. More documentation on this feature is available at https://xeus-cling.readthedocs.io/en/latest/inline_help.html. - -```{code-cell} -?std::vector -``` - -## Using the `display_data` mechanism - -+++ - -For a user-defined type `T`, the rich rendering in the notebook and JupyterLab can be enabled by by implementing the function `xeus::xjson mime_bundle_repr(const T& im)`, which returns the JSON mime bundle for that type. - -More documentation on the rich display system of Jupyter and Xeus-cling is available at https://xeus-cling.readthedocs.io/en/latest/rich_display.html - -+++ - -### Image example - -```{code-cell} -#include -#include - -#include "xtl/xbase64.hpp" -#include "xeus/xjson.hpp" - -namespace im -{ - struct image - { - inline image(const std::string& filename) - { - std::ifstream fin(filename, std::ios::binary); - m_buffer << fin.rdbuf(); - } - - std::stringstream m_buffer; - }; - - xeus::xjson mime_bundle_repr(const image& i) - { - auto bundle = xeus::xjson::object(); - bundle["image/png"] = xtl::base64encode(i.m_buffer.str()); - return bundle; - } -} -``` - -```{code-cell} -im::image marie("images/marie.png"); -marie -``` - -### Audio example - -```{code-cell} -#include -#include - -#include "xtl/xbase64.hpp" -#include "xeus/xjson.hpp" - -namespace au -{ - struct audio - { - inline audio(const std::string& filename) - { - std::ifstream fin(filename, std::ios::binary); - m_buffer << fin.rdbuf(); - } - - std::stringstream m_buffer; - }; - - xeus::xjson mime_bundle_repr(const audio& a) - { - auto bundle = xeus::xjson::object(); - bundle["text/html"] = - std::string(""; - return bundle; - } -} -``` - -```{code-cell} -au::audio drums("audio/audio.wav"); -drums -``` - -### Display - -```{code-cell} -#include "xcpp/xdisplay.hpp" -``` - -```{code-cell} -xcpp::display(drums); -``` - -### Update-display - -```{code-cell} -#include -#include "xcpp/xdisplay.hpp" - -namespace ht -{ - struct html - { - inline html(const std::string& content) - { - m_content = content; - } - std::string m_content; - }; - - xeus::xjson mime_bundle_repr(const html& a) - { - auto bundle = xeus::xjson::object(); - bundle["text/html"] = a.m_content; - return bundle; - } -} - -// A red rectangle -ht::html rect(R"( -
-Original -
)"); -``` - -```{code-cell} -xcpp::display(rect, "some_display_id"); -``` - -```{code-cell} -// Update the rectangle to be blue -rect.m_content = R"( -
-Updated -
)"; - -xcpp::display(rect, "some_display_id", true); -``` - -## Magics - -Magics are special commands for the kernel that are not part of the C++ language. - -They are defined with the symbol `%` for a line magic and `%%` for a cell magic. - -More documentation for magics is available at https://xeus-cling.readthedocs.io/en/latest/magics.html. - -```{code-cell} -#include -#include -``` - -```{code-cell} -std::vector to_shuffle = {1, 2, 3, 4}; -``` - -```{code-cell} -%timeit std::random_shuffle(to_shuffle.begin(), to_shuffle.end()); -``` - -[![xtensor](images/xtensor.png)](https://github.com/QuantStack/xtensor/) - -- GitHub repository: https://github.com/QuantStack/xtensor/ -- Online documentation: https://xtensor.readthedocs.io/ -- NumPy to xtensor cheat sheet: http://xtensor.readthedocs.io/en/latest/numpy.html - -`xtensor` is a C++ library for manipulating N-D arrays with an API very similar to that of numpy. - -```{code-cell} -#include - -#include "xtensor/xarray.hpp" -#include "xtensor/xio.hpp" -#include "xtensor/xview.hpp" - -xt::xarray arr1 - {{1.0, 2.0, 3.0}, - {2.0, 5.0, 7.0}, - {2.0, 5.0, 7.0}}; - -xt::xarray arr2 - {5.0, 6.0, 7.0}; - -xt::view(arr1, 1) + arr2 -``` - -Together with the C++ Jupyter kernel, `xtensor` offers a similar experience as `NumPy` in the Python Jupyter kernel, including broadcasting and universal functions. - -```{code-cell} -#include -#include "xtensor/xarray.hpp" -#include "xtensor/xio.hpp" -``` - -```{code-cell} -xt::xarray arr - {1, 2, 3, 4, 5, 6, 7, 8, 9}; - -arr.reshape({3, 3}); - -std::cout << arr; -``` - -```{code-cell} -#include "xtensor-blas/xlinalg.hpp" -``` - -```{code-cell} -xt::xtensor m = {{1.5, 0.5}, {0.7, 1.0}}; -std::cout << "Matrix rank: " << std::endl << xt::linalg::matrix_rank(m) << std::endl; -std::cout << "Matrix inverse: " << std::endl << xt::linalg::inv(m) << std::endl; -std::cout << "Eigen values: " << std::endl << xt::linalg::eigvals(m) << std::endl; -``` - -```{code-cell} -xt::xarray arg1 = xt::arange(9); -xt::xarray arg2 = xt::arange(18); - -arg1.reshape({3, 3}); -arg2.reshape({2, 3, 3}); - -std::cout << xt::linalg::dot(arg1, arg2) << std::endl; -``` - -```{code-cell} - -``` diff --git a/tests/test_ipynb_to_myst.py b/tests/test_ipynb_to_myst.py index 4cf18e7b0..1b88b9bef 100644 --- a/tests/test_ipynb_to_myst.py +++ b/tests/test_ipynb_to_myst.py @@ -4,6 +4,7 @@ myst_to_notebook, CODE_DIRECTIVE, MystMetadataParsingError, + matches_mystnb, ) from .utils import requires_myst @@ -64,3 +65,32 @@ def test_bad_markdown_metadata2(): """ ) ) + + +@requires_myst +def test_matches_mystnb(): + assert matches_mystnb("") is False + assert matches_mystnb("```{code-cell}\n```") is False + assert matches_mystnb("---\njupytext: true\n---") is False + text = dedent( + """\ + --- + {{a + --- + ```{code-cell} + :b: {{c + ``` + """ + ) + assert matches_mystnb(text) is True + text = dedent( + """\ + --- + jupytext: + text_representation: + format_name: myst + extension: .md + --- + """ + ) + assert matches_mystnb(text) is True diff --git a/tests/test_mirror.py b/tests/test_mirror.py index 84b52dc96..7811706eb 100644 --- a/tests/test_mirror.py +++ b/tests/test_mirror.py @@ -135,7 +135,7 @@ def test_ipynb_to_pandoc(nb_file, no_jupytext_version_number): @pytest.mark.parametrize('nb_file', list_notebooks('ipynb_all', skip='html-demo|julia_functional_geometry|xcpp_by_quantstack')) def test_ipynb_to_myst(nb_file, no_jupytext_version_number): - assert_conversion_same_as_mirror(nb_file, 'mnb', 'ipynb_to_myst') + assert_conversion_same_as_mirror(nb_file, 'md:myst', 'ipynb_to_myst') @requires_sphinx_gallery