diff --git a/demo/World population.mystnb b/demo/World population.mystnb index cf606a1b7..1031875de 100644 --- a/demo/World population.mystnb +++ b/demo/World population.mystnb @@ -15,7 +15,7 @@ In the below we retrieve population data from the [World Bank](http://www.worldbank.org/) using the [wbdata](https://github.com/OliverSherouse/wbdata) python package -```{nb-code} ipython3 +```{code-cell} ipython3 import pandas as pd import wbdata as wb @@ -26,7 +26,7 @@ pd.options.display.max_columns = 20 Corresponding indicator is found using search method - or, directly, the World Bank site. -```{nb-code} ipython3 +```{code-cell} ipython3 wb.search_indicators('Population, total') # SP.POP.TOTL # wb.search_indicators('area') # => https://data.worldbank.org/indicator is easier to use @@ -34,7 +34,7 @@ wb.search_indicators('Population, total') # SP.POP.TOTL Now we download the population data -```{nb-code} ipython3 +```{code-cell} ipython3 indicators = {'SP.POP.TOTL': 'Population, total', 'AG.SRF.TOTL.K2': 'Surface area (sq. km)', 'AG.LND.TOTL.K2': 'Land area (sq. km)', @@ -45,20 +45,20 @@ data World is one of the countries -```{nb-code} ipython3 +```{code-cell} ipython3 data.loc['World'] ``` Can we classify over continents? -```{nb-code} ipython3 +```{code-cell} ipython3 data.loc[(slice(None), '2017-01-01'), :]['Population, total'].dropna( ).sort_values().tail(60).index.get_level_values('country') ``` Extract zones manually (in order of increasing population) -```{nb-code} ipython3 +```{code-cell} ipython3 zones = ['North America', 'Middle East & North Africa', 'Latin America & Caribbean', 'Europe & Central Asia', 'Sub-Saharan Africa', 'South Asia', @@ -67,7 +67,7 @@ zones = ['North America', 'Middle East & North Africa', And extract population information (and check total is right) -```{nb-code} ipython3 +```{code-cell} ipython3 population = data.loc[zones]['Population, total'].swaplevel().unstack() population = population[zones] assert all(data.loc['World']['Population, total'] == population.sum(axis=1)) @@ -75,11 +75,11 @@ assert all(data.loc['World']['Population, total'] == population.sum(axis=1)) ## Stacked area plot with matplotlib -```{nb-code} ipython3 +```{code-cell} ipython3 import matplotlib.pyplot as plt ``` -```{nb-code} ipython3 +```{code-cell} ipython3 plt.clf() plt.figure(figsize=(10, 5), dpi=100) plt.stackplot(population.index, population.values.T / 1e9) @@ -97,14 +97,14 @@ selected legends) are [on their way](https://github.com/plotly/plotly.js/pull/2960) at Plotly. For now we just do a stacked bar plot. -```{nb-code} ipython3 +```{code-cell} ipython3 import plotly.offline as offline import plotly.graph_objs as go offline.init_notebook_mode() ``` -```{nb-code} ipython3 +```{code-cell} ipython3 bars = [go.Bar(x=population.index, y=population[zone], name=zone) for zone in zones] fig = go.Figure(data=bars, diff --git a/docs/formats.md b/docs/formats.md index e2bb020b8..0ae54e024 100644 --- a/docs/formats.md +++ b/docs/formats.md @@ -93,7 +93,7 @@ Similar to the Markdown format, MyST-NB uses code blocks to contain code cells. The difference though, is that the metadata is contained in a YAML block: ````md -```{nb-code} ipython3 +```{code-cell} ipython3 --- other: more: true @@ -111,7 +111,7 @@ Also, where possible the conversion will use the short-hand metadata format (see the [MyST guide](https://myst-parser.readthedocs.io/en/latest/using/syntax.html#parameterizing-directives)): ````md -```{nb-code} ipython3 +```{code-cell} ipython3 :tags: [hide-output, show-input] print("Hallo!") @@ -121,7 +121,7 @@ print("Hallo!") Raw cells are also represented in a similare fashion: ````md -```{nb-raw} +```{raw-cell} :raw_mimetype: text/html Bold text diff --git a/jupytext/myst.py b/jupytext/myst.py index d72d3d078..fe6da3198 100644 --- a/jupytext/myst.py +++ b/jupytext/myst.py @@ -8,8 +8,8 @@ import yaml MYST_FORMAT_NAME = "mystnb" -CODE_DIRECTIVE = "nb-code" -RAW_DIRECTIVE = "nb-raw" +CODE_DIRECTIVE = "code-cell" +RAW_DIRECTIVE = "raw-cell" class CompactDumper(yaml.SafeDumper): diff --git a/tests/notebooks/mirror/ipynb_to_myst/Notebook with function and cell metadata 164.mystnb b/tests/notebooks/mirror/ipynb_to_myst/Notebook with function and cell metadata 164.mystnb index 643af3397..9b2a9f00d 100644 --- a/tests/notebooks/mirror/ipynb_to_myst/Notebook with function and cell metadata 164.mystnb +++ b/tests/notebooks/mirror/ipynb_to_myst/Notebook with function and cell metadata 164.mystnb @@ -7,14 +7,14 @@ nbformat: 4 nbformat_minor: 2 --- -```{nb-code} ipython3 +```{code-cell} ipython3 1 + 1 ``` A markdown cell And below, the cell for function f has non trivial cell metadata. And the next cell as well. -```{nb-code} ipython3 +```{code-cell} ipython3 --- attributes: classes: [] @@ -25,7 +25,7 @@ def f(x): return x ``` -```{nb-code} ipython3 +```{code-cell} ipython3 --- attributes: classes: [] @@ -37,6 +37,6 @@ f(5) More text -```{nb-code} ipython3 +```{code-cell} ipython3 2 + 2 ``` diff --git a/tests/notebooks/mirror/ipynb_to_myst/Notebook with html and latex cells.mystnb b/tests/notebooks/mirror/ipynb_to_myst/Notebook with html and latex cells.mystnb index 386e64260..765d51644 100644 --- a/tests/notebooks/mirror/ipynb_to_myst/Notebook with html and latex cells.mystnb +++ b/tests/notebooks/mirror/ipynb_to_myst/Notebook with html and latex cells.mystnb @@ -7,27 +7,27 @@ nbformat: 4 nbformat_minor: 2 --- -```{nb-code} ipython3 +```{code-cell} ipython3 %%html

Jupytext on GitHub

``` -```{nb-code} ipython3 +```{code-cell} ipython3 %%latex $\frac{\pi}{2}$ ``` -```{nb-code} ipython3 +```{code-cell} ipython3 %load_ext rpy2.ipython ``` -```{nb-code} ipython3 +```{code-cell} ipython3 %%R library(ggplot2) ggplot(data=data.frame(x=c('A', 'B'), y=c(5, 2)), aes(x,weight=y)) + geom_bar() ``` -```{nb-code} ipython3 +```{code-cell} ipython3 %matplotlib inline import pandas as pd pd.Series({'A':5, 'B':2}).plot(figsize=(3,2), kind='bar') diff --git a/tests/notebooks/mirror/ipynb_to_myst/Notebook with many hash signs.mystnb b/tests/notebooks/mirror/ipynb_to_myst/Notebook with many hash signs.mystnb index a83d13a42..3055620cd 100644 --- a/tests/notebooks/mirror/ipynb_to_myst/Notebook with many hash signs.mystnb +++ b/tests/notebooks/mirror/ipynb_to_myst/Notebook with many hash signs.mystnb @@ -12,7 +12,7 @@ This is a notebook that contains many hash signs. Hopefully its python representation is not recognized as a Sphinx Gallery script... ################################################################## -```{nb-code} ipython3 +```{code-cell} ipython3 some = 1 code = 2 some+code diff --git a/tests/notebooks/mirror/ipynb_to_myst/Notebook with metadata and long cells.mystnb b/tests/notebooks/mirror/ipynb_to_myst/Notebook with metadata and long cells.mystnb index a836a3250..2221f240d 100644 --- a/tests/notebooks/mirror/ipynb_to_myst/Notebook with metadata and long cells.mystnb +++ b/tests/notebooks/mirror/ipynb_to_myst/Notebook with metadata and long cells.mystnb @@ -27,7 +27,7 @@ with a code block inside it After that cell we'll have a code cell -```{nb-code} ipython3 +```{code-cell} ipython3 2 + 2 @@ -36,7 +36,7 @@ After that cell we'll have a code cell Followed by a raw cell -```{nb-raw} +```{raw-cell} This is the content of the raw cell @@ -48,7 +48,7 @@ of the raw cell This is a markdown cell with cell metadata `{"key": "value"}` -```{nb-code} ipython3 +```{code-cell} ipython3 --- .class: null tags: [parameters] @@ -56,7 +56,7 @@ tags: [parameters] """This is a code cell with metadata `{"tags":["parameters"], ".class":null}`""" ``` -```{nb-raw} +```{raw-cell} :key: value This is a raw cell with cell metadata `{"key": "value"}` diff --git a/tests/notebooks/mirror/ipynb_to_myst/Notebook_with_R_magic.mystnb b/tests/notebooks/mirror/ipynb_to_myst/Notebook_with_R_magic.mystnb index f58a11c0c..21b50fefe 100644 --- a/tests/notebooks/mirror/ipynb_to_myst/Notebook_with_R_magic.mystnb +++ b/tests/notebooks/mirror/ipynb_to_myst/Notebook_with_R_magic.mystnb @@ -11,23 +11,23 @@ nbformat_minor: 2 This notebook shows the use of R cells to generate plots -```{nb-code} ipython2 +```{code-cell} ipython2 %load_ext rpy2.ipython ``` -```{nb-code} ipython2 +```{code-cell} ipython2 %%R suppressMessages(require(tidyverse)) ``` -```{nb-code} ipython2 +```{code-cell} ipython2 %%R ggplot(iris, aes(x = Sepal.Length, y = Petal.Length, color=Species)) + geom_point() ``` The default plot dimensions are not good for us, so we use the -w and -h parameters in %%R magic to set the plot size -```{nb-code} ipython2 +```{code-cell} ipython2 %%R -w 400 -h 240 ggplot(iris, aes(x = Sepal.Length, y = Petal.Length, color=Species)) + geom_point() ``` diff --git a/tests/notebooks/mirror/ipynb_to_myst/Notebook_with_more_R_magic_111.mystnb b/tests/notebooks/mirror/ipynb_to_myst/Notebook_with_more_R_magic_111.mystnb index 3d62e7b4f..e2ef4883c 100644 --- a/tests/notebooks/mirror/ipynb_to_myst/Notebook_with_more_R_magic_111.mystnb +++ b/tests/notebooks/mirror/ipynb_to_myst/Notebook_with_more_R_magic_111.mystnb @@ -7,7 +7,7 @@ nbformat: 4 nbformat_minor: 2 --- -```{nb-code} ipython3 +```{code-cell} ipython3 %load_ext rpy2.ipython import pandas as pd @@ -21,7 +21,7 @@ df = pd.DataFrame( ) ``` -```{nb-code} ipython3 +```{code-cell} ipython3 %%R -i df library("ggplot2") ggplot(data = df) + geom_point(aes(x = X, y = Y, color = Letter, size = Z)) diff --git a/tests/notebooks/mirror/ipynb_to_myst/R notebook with invalid cell keys.mystnb b/tests/notebooks/mirror/ipynb_to_myst/R notebook with invalid cell keys.mystnb index ffc1c578c..73a5eb305 100644 --- a/tests/notebooks/mirror/ipynb_to_myst/R notebook with invalid cell keys.mystnb +++ b/tests/notebooks/mirror/ipynb_to_myst/R notebook with invalid cell keys.mystnb @@ -9,7 +9,7 @@ nbformat_minor: 2 This notebook was created with IRKernel 0.8.12, and is not completely valid, as the code cell below contains an unexpected 'source' entry. This did cause https://github.com/mwouts/jupytext/issues/234. Note that the problem is solved when one upgrades to IRKernel 1.0.0. -```{nb-code} r +```{code-cell} r library("ggplot2") ggplot(mtcars, aes(mpg)) + stat_ecdf() ``` diff --git a/tests/notebooks/mirror/ipynb_to_myst/Reference Guide for Calysto Scheme.mystnb b/tests/notebooks/mirror/ipynb_to_myst/Reference Guide for Calysto Scheme.mystnb index f7af16537..a29544249 100644 --- a/tests/notebooks/mirror/ipynb_to_myst/Reference Guide for Calysto Scheme.mystnb +++ b/tests/notebooks/mirror/ipynb_to_myst/Reference Guide for Calysto Scheme.mystnb @@ -86,15 +86,15 @@ Calysto Scheme may not implement all of those. Some useful and suggestive ones: * \Sigma - Σ * \_i - subscript i, such as vectorᵢ -```{nb-code} scheme +```{code-cell} scheme (define α 67) ``` -```{nb-code} scheme +```{code-cell} scheme α ``` -```{nb-code} scheme +```{code-cell} scheme (define i 2) (define vectorᵢ (vector-ref (vector 0 6 3 2) i)) vectorᵢ @@ -102,33 +102,33 @@ vectorᵢ ### Rich media -```{nb-code} scheme +```{code-cell} scheme (import "calysto.display") ``` -```{nb-code} scheme +```{code-cell} scheme (calysto.display.HTML "This is bold, italics, underlined.") ``` -```{nb-code} scheme +```{code-cell} scheme (import "calysto.graphics") ``` -```{nb-code} scheme +```{code-cell} scheme (define canvas (calysto.graphics.Canvas)) ``` -```{nb-code} scheme +```{code-cell} scheme (define ball (calysto.graphics.Circle '(150 150) 100)) ``` -```{nb-code} scheme +```{code-cell} scheme (ball.draw canvas) ``` ### Shell commands -```{nb-code} scheme +```{code-cell} scheme ! ls /tmp ``` @@ -159,11 +159,11 @@ You can import and use any Python library in Calysto Scheme. In addition, if you wish, you can execute expressions and statements in a Python environment: -```{nb-code} scheme +```{code-cell} scheme (python-eval "1 + 2") ``` -```{nb-code} scheme +```{code-cell} scheme (python-exec " def mypyfunc(a, b): @@ -173,17 +173,17 @@ def mypyfunc(a, b): This is a shared environment with Scheme: -```{nb-code} scheme +```{code-cell} scheme (mypyfunc 4 5) ``` You can use `func` to turn a Scheme procedure into a Python function, and `define!` to put it into the shared enviornment with Python: -```{nb-code} scheme +```{code-cell} scheme (define! mypyfunc2 (func (lambda (n) n))) ``` -```{nb-code} scheme +```{code-cell} scheme (python-eval "mypyfunc2(34)") ``` @@ -211,7 +211,7 @@ You can use `func` to turn a Scheme procedure into a Python function, and `defin Calysto Scheme acts as if it has a call stack, for easier debugging. For example: -```{nb-code} scheme +```{code-cell} scheme (define fact (lambda (n) (if (= n 1) @@ -219,7 +219,7 @@ Calysto Scheme acts as if it has a call stack, for easier debugging. For example (* n (fact (- n 1)))))) ``` -```{nb-code} scheme +```{code-cell} scheme (fact 5) ``` @@ -237,15 +237,15 @@ That will allow infinite recursive loops without keeping track of the "stack". ## SCHEMEPATH SCHEMEPATH is a list of search directories used with (load NAME). This is a reference, so you should append to it rather than attempting to redefine it. -```{nb-code} scheme +```{code-cell} scheme SCHEMEPATH ``` -```{nb-code} scheme +```{code-cell} scheme (set-cdr! (cdr SCHEMEPATH) (list "/var/modules")) ``` -```{nb-code} scheme +```{code-cell} scheme SCHEMEPATH ``` @@ -253,7 +253,7 @@ SCHEMEPATH Note that you can use the word `lambda` or \lambda and then press [TAB] -```{nb-code} scheme +```{code-cell} scheme (define factorial (λ (n) (cond @@ -261,25 +261,25 @@ Note that you can use the word `lambda` or \lambda and then press [TAB] (else (* n (factorial (- n 1))))))) ``` -```{nb-code} scheme +```{code-cell} scheme (factorial 5) ``` ## define-syntax (define-syntax NAME RULES): a method for creating macros -```{nb-code} scheme +```{code-cell} scheme (define-syntax time [(time ?exp) (let ((start (current-time))) ?exp (- (current-time) start))]) ``` -```{nb-code} scheme +```{code-cell} scheme (time (car '(1 2 3 4))) ``` -```{nb-code} scheme +```{code-cell} scheme ;;--------------------------------------------------------------------- ;; collect is like list comprehension in Python @@ -298,19 +298,19 @@ Note that you can use the word `lambda` or \lambda and then press [TAB] (filter-map f pred? (cdr values)))))) ``` -```{nb-code} scheme +```{code-cell} scheme (collect (* n n) for n in (range 10)) ``` -```{nb-code} scheme +```{code-cell} scheme (collect (* n n) for n in (range 5 20 3)) ``` -```{nb-code} scheme +```{code-cell} scheme (collect (* n n) for n in (range 10) if (> n 5)) ``` -```{nb-code} scheme +```{code-cell} scheme ;;--------------------------------------------------------------------- ;; for loops @@ -350,7 +350,7 @@ Note that you can use the word `lambda` or \lambda and then press [TAB] (for-iterate2 (+ i 1) (cdr values) f))))) ``` -```{nb-code} scheme +```{code-cell} scheme (define matrix2d '((10 20) (30 40) @@ -364,7 +364,7 @@ Note that you can use the word `lambda` or \lambda and then press [TAB] ((190 200 210) (220 230 240)))) ``` -```{nb-code} scheme +```{code-cell} scheme (begin (define hello 0) (for 5 times do (set! hello (+ hello 1))) @@ -372,23 +372,23 @@ Note that you can use the word `lambda` or \lambda and then press [TAB] ) ``` -```{nb-code} scheme +```{code-cell} scheme (for sym in '(a b c d) do (define x 1) (set! x sym) (print x)) ``` -```{nb-code} scheme +```{code-cell} scheme (for n in (range 10 20 2) do (print n)) ``` -```{nb-code} scheme +```{code-cell} scheme (for n at (i j) in matrix2d do (print (list n 'coords: i j))) ``` -```{nb-code} scheme +```{code-cell} scheme (for n at (i j k) in matrix3d do (print (list n 'coords: i j k))) ``` -```{nb-code} scheme +```{code-cell} scheme (define-syntax scons [(scons ?x ?y) (cons ?x (lambda () ?y))]) @@ -431,33 +431,33 @@ Note that you can use the word `lambda` or \lambda and then press [TAB] (define ! (lambda (n) (nth n facts))) ``` -```{nb-code} scheme +```{code-cell} scheme (! 5) ``` -```{nb-code} scheme +```{code-cell} scheme (nth 10 facts) ``` -```{nb-code} scheme +```{code-cell} scheme (nth 20 fibs) ``` -```{nb-code} scheme +```{code-cell} scheme (first 30 fibs) ``` ## for-each (for-each PROCEDURE LIST): apply PROCEDURE to each item in LIST; like `map` but don't return results -```{nb-code} scheme +```{code-cell} scheme (for-each (lambda (n) (print n)) '(3 4 5)) ``` ## format (format STRING ITEM ...): format the string with ITEMS as arguments -```{nb-code} scheme +```{code-cell} scheme (format "This uses formatting ~a ~s ~%" 'apple 'apple) ``` @@ -467,7 +467,7 @@ Turns a lambda into a Python function. (func (lambda ...)) -```{nb-code} scheme +```{code-cell} scheme (func (lambda (n) n)) ``` diff --git a/tests/notebooks/mirror/ipynb_to_myst/The flavors of raw cells.mystnb b/tests/notebooks/mirror/ipynb_to_myst/The flavors of raw cells.mystnb index ae7a8876d..40b7bd95a 100644 --- a/tests/notebooks/mirror/ipynb_to_myst/The flavors of raw cells.mystnb +++ b/tests/notebooks/mirror/ipynb_to_myst/The flavors of raw cells.mystnb @@ -7,36 +7,36 @@ nbformat: 4 nbformat_minor: 2 --- -```{nb-raw} +```{raw-cell} :raw_mimetype: text/latex $1+1$ ``` -```{nb-raw} +```{raw-cell} :raw_mimetype: text/restructuredtext :math:`1+1` ``` -```{nb-raw} +```{raw-cell} :raw_mimetype: text/html Bold text ``` -```{nb-raw} +```{raw-cell} :raw_mimetype: text/markdown **Bold text** ``` -```{nb-raw} +```{raw-cell} :raw_mimetype: text/x-python 1 + 1 ``` -```{nb-raw} +```{raw-cell} Not formatted ``` diff --git a/tests/notebooks/mirror/ipynb_to_myst/World population.mystnb b/tests/notebooks/mirror/ipynb_to_myst/World population.mystnb index cf606a1b7..1031875de 100644 --- a/tests/notebooks/mirror/ipynb_to_myst/World population.mystnb +++ b/tests/notebooks/mirror/ipynb_to_myst/World population.mystnb @@ -15,7 +15,7 @@ In the below we retrieve population data from the [World Bank](http://www.worldbank.org/) using the [wbdata](https://github.com/OliverSherouse/wbdata) python package -```{nb-code} ipython3 +```{code-cell} ipython3 import pandas as pd import wbdata as wb @@ -26,7 +26,7 @@ pd.options.display.max_columns = 20 Corresponding indicator is found using search method - or, directly, the World Bank site. -```{nb-code} ipython3 +```{code-cell} ipython3 wb.search_indicators('Population, total') # SP.POP.TOTL # wb.search_indicators('area') # => https://data.worldbank.org/indicator is easier to use @@ -34,7 +34,7 @@ wb.search_indicators('Population, total') # SP.POP.TOTL Now we download the population data -```{nb-code} ipython3 +```{code-cell} ipython3 indicators = {'SP.POP.TOTL': 'Population, total', 'AG.SRF.TOTL.K2': 'Surface area (sq. km)', 'AG.LND.TOTL.K2': 'Land area (sq. km)', @@ -45,20 +45,20 @@ data World is one of the countries -```{nb-code} ipython3 +```{code-cell} ipython3 data.loc['World'] ``` Can we classify over continents? -```{nb-code} ipython3 +```{code-cell} ipython3 data.loc[(slice(None), '2017-01-01'), :]['Population, total'].dropna( ).sort_values().tail(60).index.get_level_values('country') ``` Extract zones manually (in order of increasing population) -```{nb-code} ipython3 +```{code-cell} ipython3 zones = ['North America', 'Middle East & North Africa', 'Latin America & Caribbean', 'Europe & Central Asia', 'Sub-Saharan Africa', 'South Asia', @@ -67,7 +67,7 @@ zones = ['North America', 'Middle East & North Africa', And extract population information (and check total is right) -```{nb-code} ipython3 +```{code-cell} ipython3 population = data.loc[zones]['Population, total'].swaplevel().unstack() population = population[zones] assert all(data.loc['World']['Population, total'] == population.sum(axis=1)) @@ -75,11 +75,11 @@ assert all(data.loc['World']['Population, total'] == population.sum(axis=1)) ## Stacked area plot with matplotlib -```{nb-code} ipython3 +```{code-cell} ipython3 import matplotlib.pyplot as plt ``` -```{nb-code} ipython3 +```{code-cell} ipython3 plt.clf() plt.figure(figsize=(10, 5), dpi=100) plt.stackplot(population.index, population.values.T / 1e9) @@ -97,14 +97,14 @@ selected legends) are [on their way](https://github.com/plotly/plotly.js/pull/2960) at Plotly. For now we just do a stacked bar plot. -```{nb-code} ipython3 +```{code-cell} ipython3 import plotly.offline as offline import plotly.graph_objs as go offline.init_notebook_mode() ``` -```{nb-code} ipython3 +```{code-cell} ipython3 bars = [go.Bar(x=population.index, y=population[zone], name=zone) for zone in zones] fig = go.Figure(data=bars, diff --git a/tests/notebooks/mirror/ipynb_to_myst/cat_variable.mystnb b/tests/notebooks/mirror/ipynb_to_myst/cat_variable.mystnb index 5f3f73a75..c8c496684 100644 --- a/tests/notebooks/mirror/ipynb_to_myst/cat_variable.mystnb +++ b/tests/notebooks/mirror/ipynb_to_myst/cat_variable.mystnb @@ -7,6 +7,6 @@ nbformat: 4 nbformat_minor: 2 --- -```{nb-code} ipython3 +```{code-cell} ipython3 cat = 42 ``` diff --git a/tests/notebooks/mirror/ipynb_to_myst/convert_to_py_then_test_with_update83.mystnb b/tests/notebooks/mirror/ipynb_to_myst/convert_to_py_then_test_with_update83.mystnb index 0fd8a165a..90ecd5dd0 100644 --- a/tests/notebooks/mirror/ipynb_to_myst/convert_to_py_then_test_with_update83.mystnb +++ b/tests/notebooks/mirror/ipynb_to_myst/convert_to_py_then_test_with_update83.mystnb @@ -7,7 +7,7 @@ nbformat: 4 nbformat_minor: 2 --- -```{nb-code} ipython3 +```{code-cell} ipython3 %%time print('asdf') @@ -15,6 +15,6 @@ print('asdf') Thanks for jupytext! -```{nb-code} ipython3 +```{code-cell} ipython3 ``` diff --git a/tests/notebooks/mirror/ipynb_to_myst/csharp.mystnb b/tests/notebooks/mirror/ipynb_to_myst/csharp.mystnb index 51c96049e..b18b07049 100644 --- a/tests/notebooks/mirror/ipynb_to_myst/csharp.mystnb +++ b/tests/notebooks/mirror/ipynb_to_myst/csharp.mystnb @@ -9,13 +9,13 @@ nbformat_minor: 1 We start with... -```{nb-code} csharp +```{code-cell} csharp Console.WriteLine("Hello World!"); ``` Then we do a plot with Plotly, following the [Plotting with XPlot](https://github.com/dotnet/interactive/blob/master/NotebookExamples/csharp/Docs/Plotting%20with%20Xplot.ipynb) example from `dotnet/interactive`: -```{nb-code} csharp +```{code-cell} csharp using XPlot.Plotly; var bar = new Graph.Bar @@ -32,10 +32,10 @@ display(chart); We also test the math outputs as in the [Math and Latex](https://github.com/dotnet/interactive/blob/master/NotebookExamples/csharp/Docs/Math%20and%20LaTeX.ipynb) example: -```{nb-code} csharp +```{code-cell} csharp (LaTeXString)@"\begin{align} e^{i \pi} = -1\end{align}" ``` -```{nb-code} csharp +```{code-cell} csharp (MathString)@"e^{i \pi} = -1" ``` diff --git a/tests/notebooks/mirror/ipynb_to_myst/demo_gdl_fbp.mystnb b/tests/notebooks/mirror/ipynb_to_myst/demo_gdl_fbp.mystnb index 90f4ff13a..a1d7e9a81 100644 --- a/tests/notebooks/mirror/ipynb_to_myst/demo_gdl_fbp.mystnb +++ b/tests/notebooks/mirror/ipynb_to_myst/demo_gdl_fbp.mystnb @@ -15,7 +15,7 @@ Demonstration of GDL [(gnudatalanguage)](https://github.com/gnudatalanguage/gdl) This notebook creates a Shepp-Logan phantom, projects it and then performs an FBP reconstruction. -```{nb-code} +```{code-cell} ;; L.A. Shepp and B.F. Logan, “The Fourier reconstruction of a head section,” ;; IEEE Trans. Nucl. Sci. 21(3), 21–43 (1974). function shepplogan, size = size @@ -61,12 +61,12 @@ function shepplogan, size = size end ``` -```{nb-code} +```{code-cell} ;; Enable inline plotting !inline=1 ``` -```{nb-code} +```{code-cell} phantom = shepplogan() window, 0, xsize=256, ysize=256 tvscl, phantom > 0.95 @@ -74,7 +74,7 @@ tvscl, phantom > 0.95 Now we define simple forward and backprojection functions: -```{nb-code} +```{code-cell} function proj, image, angle sino_size_x = max(size(image,/dim)) @@ -93,7 +93,7 @@ function proj, image, angle end ``` -```{nb-code} +```{code-cell} function back, sino, angle image_size = n_elements(sino[*,0]) @@ -112,7 +112,7 @@ end This allows us to create a sinogram: -```{nb-code} +```{code-cell} angles = findgen(360) sino = proj(phantom, angles) window, 0, xsize=256, ysize=360 @@ -121,7 +121,7 @@ tvscl, sino On this we can apply a simple FBP reconstruction: -```{nb-code} +```{code-cell} ;; G.L. Zeng, “Revisit of the Ramp Filter,” ;; IEEE Trans. Nucl. Sci. 62(1), 131–136 (2015). function fbp, sino, angles @@ -155,7 +155,7 @@ function fbp, sino, angles end ``` -```{nb-code} +```{code-cell} reconstruction = fbp(sino, angles) window, 0, xsize=512, ysize=256 diff --git a/tests/notebooks/mirror/ipynb_to_myst/evcxr_jupyter_tour.mystnb b/tests/notebooks/mirror/ipynb_to_myst/evcxr_jupyter_tour.mystnb index 73db0bf07..127ca11c9 100644 --- a/tests/notebooks/mirror/ipynb_to_myst/evcxr_jupyter_tour.mystnb +++ b/tests/notebooks/mirror/ipynb_to_myst/evcxr_jupyter_tour.mystnb @@ -13,7 +13,7 @@ For those not already familiar with Jupyter notebook, it lets you write code int ## Printing to outputs and evaluating expressions Lets print something to stdout and stderr then return a final expression to see how that's presented. Note that stdout and stderr are separate streams, so may not appear in the same order is their respective print statements. -```{nb-code} +```{code-cell} println!("Hello world"); eprintln!("Hello error"); format!("Hello {}", "world") @@ -22,40 +22,40 @@ format!("Hello {}", "world") ## Assigning and making use of variables We define a variable `message`, then in the subsequent cell, modify the string and finally print it out. We could also do all this in the one cell if we wanted. -```{nb-code} +```{code-cell} let mut message = "Hello ".to_owned(); ``` -```{nb-code} +```{code-cell} message.push_str("world!"); ``` -```{nb-code} +```{code-cell} message ``` ## Defining and redefining functions Next we'll define a function -```{nb-code} +```{code-cell} pub fn fib(x: i32) -> i32 { if x <= 2 {0} else {fib(x - 2) + fib(x - 1)} } ``` -```{nb-code} +```{code-cell} (1..13).map(fib).collect::>() ``` Hmm, that doesn't look right. Lets redefine the function. In practice, we'd go back and edit the function above and reevalute it, but here, lets redefine it in a separate cell. -```{nb-code} +```{code-cell} pub fn fib(x: i32) -> i32 { if x <= 2 {2} else {fib(x - 2) + fib(x - 1)} } ``` -```{nb-code} +```{code-cell} let values = (1..13).map(fib).collect::>(); values ``` @@ -63,7 +63,7 @@ values ## Spawning a separate thread and communicating with it We can spawn a thread to do stuff in the background, then continue executing code in other cells. -```{nb-code} +```{code-cell} use std::sync::{Mutex, Arc}; let counter = Arc::new(Mutex::new(0i32)); std::thread::spawn({ @@ -76,18 +76,18 @@ std::thread::spawn({ }}); ``` -```{nb-code} +```{code-cell} *counter.lock().unwrap() ``` -```{nb-code} +```{code-cell} *counter.lock().unwrap() ``` ## Loading external crates We can load external crates. This one takes a while to compile, but once it's compiled, subsequent cells shouldn't need to recompile it, so it should be much quicker. -```{nb-code} +```{code-cell} :dep base64 = "0.10.1" base64::encode(&vec![1, 2, 3, 4]) @@ -96,7 +96,7 @@ base64::encode(&vec![1, 2, 3, 4]) ## Customizing how types are displayed We can also customize how our types are displayed, including presenting them as HTML. Here's an example where we define a custom display function for a type `Matrix`. -```{nb-code} +```{code-cell} use std::fmt::Debug; pub struct Matrix {pub values: Vec, pub row_size: usize} impl Matrix { @@ -118,14 +118,14 @@ impl Matrix { } ``` -```{nb-code} +```{code-cell} let m = Matrix {values: vec![1,2,3,4,5,6,7,8,9], row_size: 3}; m ``` We can also return images, we just need to base64 encode them. First, we set up code for displaying RGB and grayscale images. -```{nb-code} +```{code-cell} extern crate image; extern crate base64; pub trait EvcxrResult {fn evcxr_display(&self);} @@ -149,7 +149,7 @@ impl EvcxrResult for image::GrayImage { } ``` -```{nb-code} +```{code-cell} image::ImageBuffer::from_fn(256, 256, |x, y| { if (x as i32 - y as i32).abs() < 3 { image::Rgb([0, 0, 255]) @@ -162,7 +162,7 @@ image::ImageBuffer::from_fn(256, 256, |x, y| { ## Display of compilation errors Here's how compilation errors are presented. Here we forgot an & and passed a String instead of an &str. -```{nb-code} +```{code-cell} let mut s = String::new(); s.push_str(format!("foo {}", 42)); ``` @@ -170,18 +170,18 @@ s.push_str(format!("foo {}", 42)); ## Seeing what variables have been defined We can print a table of defined variables and their types with the :vars command. -```{nb-code} +```{code-cell} :vars ``` Other built-in commands can be found via :help -```{nb-code} +```{code-cell} :help ``` -```{nb-code} +```{code-cell} ``` diff --git a/tests/notebooks/mirror/ipynb_to_myst/frozen_cell.mystnb b/tests/notebooks/mirror/ipynb_to_myst/frozen_cell.mystnb index fe5c11c81..ae1bfb6b6 100644 --- a/tests/notebooks/mirror/ipynb_to_myst/frozen_cell.mystnb +++ b/tests/notebooks/mirror/ipynb_to_myst/frozen_cell.mystnb @@ -7,12 +7,12 @@ nbformat: 4 nbformat_minor: 2 --- -```{nb-code} ipython3 +```{code-cell} ipython3 # This is an unfrozen cell. Works as usual. print("I'm a regular cell so I run and print!") ``` -```{nb-code} ipython3 +```{code-cell} ipython3 --- deletable: false editable: false diff --git a/tests/notebooks/mirror/ipynb_to_myst/fsharp.mystnb b/tests/notebooks/mirror/ipynb_to_myst/fsharp.mystnb index dd9ef4bf4..8458120c8 100644 --- a/tests/notebooks/mirror/ipynb_to_myst/fsharp.mystnb +++ b/tests/notebooks/mirror/ipynb_to_myst/fsharp.mystnb @@ -9,11 +9,11 @@ nbformat_minor: 2 This notebook was inspired by [Plottting with XPlot](https://github.com/dotnet/interactive/blob/master/NotebookExamples/fsharp/Docs/Plotting%20with%20Xplot.ipynb). -```{nb-code} fsharp +```{code-cell} fsharp open XPlot.Plotly ``` -```{nb-code} fsharp +```{code-cell} fsharp let bar = Bar( name = "Bar 1", diff --git a/tests/notebooks/mirror/ipynb_to_myst/html-demo.mystnb b/tests/notebooks/mirror/ipynb_to_myst/html-demo.mystnb index 409cb8745..6a5d426af 100644 --- a/tests/notebooks/mirror/ipynb_to_myst/html-demo.mystnb +++ b/tests/notebooks/mirror/ipynb_to_myst/html-demo.mystnb @@ -18,11 +18,11 @@ This notebook demonstrates some of the more advanced features of Clojupyter. To display HTML, you'll need to require a clojupyter helper function to change the cell output -```{nb-code} +```{code-cell} (require '[clojupyter.misc.display :as display]) ``` -```{nb-code} +```{code-cell} (println ">> should print some text") ;; displaying html (display/hiccup-html @@ -34,7 +34,7 @@ To display HTML, you'll need to require a clojupyter helper function to change t We can also use this to render SVG: -```{nb-code} +```{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"}]]) @@ -44,16 +44,16 @@ We can also use this to render SVG: You can fetch external Clojure dependcies using the `clojupyter.misc.helper` namespace. -```{nb-code} +```{code-cell} (require '[clojupyter.misc.helper :as helper]) ``` -```{nb-code} +```{code-cell} (helper/add-dependencies '[org.clojure/data.json "0.2.6"]) (require '[clojure.data.json :as json]) ``` -```{nb-code} +```{code-cell} (json/write-str {:a 1 :b [2, 3] :c "c"}) ``` @@ -63,13 +63,13 @@ Since you can render arbitrary HTML using `display/hiccup-html`, it's pretty eas First, we use a cell to add javascript to the running notebook: -```{nb-code} +```{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: -```{nb-code} +```{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))] @@ -80,7 +80,7 @@ Now we define a function which takes Clojure data and returns hiccup HTML to dis Now we can make generate interactive plots (try hovering over plot): -```{nb-code} +```{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))) @@ -90,6 +90,6 @@ Now we can make generate interactive plots (try hovering over plot): :series [{:data data-1} {:data data-2}]}) ``` -```{nb-code} +```{code-cell} ``` diff --git a/tests/notebooks/mirror/ipynb_to_myst/ijavascript.mystnb b/tests/notebooks/mirror/ipynb_to_myst/ijavascript.mystnb index 5da95b112..c37ae4fb1 100644 --- a/tests/notebooks/mirror/ipynb_to_myst/ijavascript.mystnb +++ b/tests/notebooks/mirror/ipynb_to_myst/ijavascript.mystnb @@ -9,35 +9,35 @@ nbformat_minor: 2 ## A notebook that uses IJavascript kernel -```{nb-code} +```{code-cell} let x = 5; const y = 6; var z = 10; ``` -```{nb-code} +```{code-cell} x + y; ``` -```{nb-code} +```{code-cell} function add(num1, num2) { return num1 + num2 } ``` -```{nb-code} +```{code-cell} add(x, y); ``` -```{nb-code} +```{code-cell} const arrowAdd = (num1, num2) => num1 + num2; ``` -```{nb-code} +```{code-cell} arrowAdd(x, y); ``` -```{nb-code} +```{code-cell} const myCar = { color: "blue", weight: 850, @@ -47,25 +47,25 @@ const myCar = { } ``` -```{nb-code} +```{code-cell} console.log("color:", myCar.color); ``` -```{nb-code} +```{code-cell} console.log("start:", myCar.start()); ``` -```{nb-code} +```{code-cell} for (let door of myCar.doors) { console.log("I'm door", door) } ``` -```{nb-code} +```{code-cell} myCar; ``` -```{nb-code} +```{code-cell} class User { constructor(name){ this.name = name; @@ -76,7 +76,7 @@ class User { } ``` -```{nb-code} +```{code-cell} let John = new User("John"); John.sayHello(); ``` diff --git a/tests/notebooks/mirror/ipynb_to_myst/ir_notebook.mystnb b/tests/notebooks/mirror/ipynb_to_myst/ir_notebook.mystnb index 7745ea8ee..702d6d704 100644 --- a/tests/notebooks/mirror/ipynb_to_myst/ir_notebook.mystnb +++ b/tests/notebooks/mirror/ipynb_to_myst/ir_notebook.mystnb @@ -9,14 +9,14 @@ nbformat_minor: 2 This is a jupyter notebook that uses the IR kernel. -```{nb-code} r +```{code-cell} r sum(1:10) ``` -```{nb-code} r +```{code-cell} r plot(cars) ``` -```{nb-code} r +```{code-cell} r ``` diff --git a/tests/notebooks/mirror/ipynb_to_myst/itypescript.mystnb b/tests/notebooks/mirror/ipynb_to_myst/itypescript.mystnb index 95a94b1f1..a9fc73102 100644 --- a/tests/notebooks/mirror/ipynb_to_myst/itypescript.mystnb +++ b/tests/notebooks/mirror/ipynb_to_myst/itypescript.mystnb @@ -7,7 +7,7 @@ nbformat: 4 nbformat_minor: 2 --- -```{nb-code} +```{code-cell} let x: number = 5; const y: number = 6; var z: string = "hi"; @@ -15,19 +15,19 @@ console.log(z); x + y; ``` -```{nb-code} +```{code-cell} function add(num1: number, num2: number): number { return num1 + num2 } add(x, y); ``` -```{nb-code} +```{code-cell} const arrowAdd = (num1: number, num2: number) => num1 + num2; arrowAdd(x, y); ``` -```{nb-code} +```{code-cell} class User { constructor(private name: string) { this.name = name; diff --git a/tests/notebooks/mirror/ipynb_to_myst/julia_benchmark_plotly_barchart.mystnb b/tests/notebooks/mirror/ipynb_to_myst/julia_benchmark_plotly_barchart.mystnb index 41d7284bc..a6fc5ca78 100644 --- a/tests/notebooks/mirror/ipynb_to_myst/julia_benchmark_plotly_barchart.mystnb +++ b/tests/notebooks/mirror/ipynb_to_myst/julia_benchmark_plotly_barchart.mystnb @@ -7,7 +7,7 @@ nbformat: 4 nbformat_minor: 1 --- -```{nb-code} +```{code-cell} # IJulia rocks! So does Plotly. Check it out using Plotly @@ -17,7 +17,7 @@ username = "" Plotly.signin(username, api_key) ``` -```{nb-code} +```{code-cell} # Following data taken from http://julialang.org/ frontpage benchmarks = ["fib", "parse_int", "quicksort3", "mandel", "pi_sum", "rand_mat_stat", "rand_mat_mul"] platforms = ["Fortran", "Julia", "Python", "R", "Matlab", "Mathematica", "Javascript", "Go"] @@ -64,7 +64,7 @@ s = string("