Markdown Format Reference

A reference Notebook for observing Changes in our Markdown Format for all available Content-Types

Philipp Markovics, Andrea Amantini

This notebook is meant for testing our Markdown Format.

Paragraphs and Lists

The paragraph is the simplest Nextjournal node type. Internally, paragraphs use a rich-text editing component for text styles: italic, bold, monospaced text and links. Now with strike-trough text as well.

You can embed inline nodes in paragraphs: mathematical formulas, like inline_formula not implemented, references to a file, like

Anomaly2014.jpg
, and numbers that can be referenced in code cells, like temperature = 70ºC.

Experimental features: inline reference to a cell file results

test.txt
and inline data nodes like this blue node.

Lists

Lists are restricted to a single level at the moment. Typing * followed by a space into an empty paragraph quickly transforms the paragraph into a list:

  • A list items

  • followed by another list item

and todo lists

  • one item

  • and a checked one

Section Numbering

Section numbering is a key at :article -> :settings, re-importing this markdown should bring back section numbering.

Block Quotes

This is to quote Ted Nelson:

blockquote not implemented

and he couldn't just be more right.

Files and Images

Files can be uploaded straight to an article. Here is an example of an uploaded CSV file with global temperature data:

Files

global-temperature.csv

Images

If the uploaded file is an image, including SVGs, it will be rendered inline. If the image size exceeds the article’s default content width, layout controls allow expanding the image width beyond the article boundaries.

Images may be captioned.

Wide Images

Standard Width Image

Avid ProTools 9

Framed Images

Code Cells

Executable code cells form the core of the editor. Some cells execute remotely, on the Nextjournal cluster (Bash, Clojure, Python, R and Julia) while others execute in the browser (Javascript and ClojureScript).

Runtimes and Environments

Python

When adding the first cell for a particular language, a runtime is created along with it and added to the code panel. New cells using the same language are appended to the previously existing runtime.

Runtimes provide an isolated computational resource for code cells to run in. For remote execution, code cells that share a runtime share process state and an ephemeral filesystem in the form of a Docker container. Browser-based runtimes execute in a web worker.

Remote runtimes are templated from an environment: a Docker image providing initial filesystem state, a language runtime, and preinstalled software packages.

By default, each new runtime is based on the Nextjournal Default environment.

Bash Cells and Runtimes

Bash cells exhibit special behavior. If another language runtime exists, bash cells will be appended to that runtime. This way, you can perform command line work underneath the language process, such as installing Python packages or downloading data.

echo "test" > /results/test.txt
0.3s
Bash in Clojure
empty

Referencing Files

As noted above, files can be uploaded directly to an article. They can be referenced in a code cell or paragraph by typing Ctrl/Cmd+E and selecting the file you want to reference.

This example takes the global-temperature.csv file uploaded above, reads it, and returns the first character from the file.

(require '[clojure.java.io :as io])
(with-open [reader (io/reader 
global-temperature.csv
)]
  (char (.read reader)))
0.4s
Clojure
"Y"

Results

Code cells, by default, display the result of the last expression and standard output it generates.

Certain result types, like simple data structures, plots and images, are given special treatment or enhanced by the editor.

Currently, Nextjournal provides the following result viewers:

Data (the default)

If the last expression is a data structure, it's rendered as an expandable tree.

{:number 1
 :string "A string"
 :nested-map {:key-1 1 :key-2 2}
 :nested-vector [1 2 3 [4 5 6]]}
0.1s
Clojure
Map{:number: 1, :string: "A string", :nested-map: Map, :nested-vector: Vector(4)}

Image Results

Images generated by cells are displayed automatically, under certain conditions. Here is an example of a R cell that’s generating an image of a plot. Note: R produces always named outputs.

svg('/results/my-plot.svg')
hist(rnorm(200, 1), breaks=100)
dev.off()
0.4s
R

Main cell output should be (de)serializable to markdown along with named result.

import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0, 2*np.pi)
plt.plot(x, np.sin(x))
plt.savefig('/results/my-sine.svg')
0.5s
Python

Table Results

If the results is a data frame or CSV file, it will render as table that shows the first 10 entries of the result. Here’s a R cell that renders the mtcars demo data:

mtcars
0.2s
R
0 items

Console Output

Process standard output and standard error are streamed to the browser, between the source code and the final result. Cell output can be toggled. This Bash cell lists the installed PyPi Python packages.

pip freeze
1.9s
Bash in Python

Working With Results

Writing Results to the Filesystem

Files written to a runtime are only accessible from within that runtime.

The special /results path exists for making a result file referenceable, permanent and downloadable. The cell below writes a file to /results and Nextjournal automatically does the rest:

echo "some results" >> /results/results-file.txt
ls /results
0.9s
Bash in Python
empty

Referencing Results

The file is now downloadable in the browser and can be referenced from other code cells, or even from another article. All results on the filesystem can be referenced using the @ menu in a code cell, followed by Insert Reference:

cat 
results-file.txt
0.9s
snowy-kingBash in Python

Code Listings

Code listings are not executable — they're for showing syntax-highlighted code in a larger variety of languages.

(->> (read)
     eval
     prn
     (while true))
Clojure

Custom Languages

Code Listings also have a special option for custom languages. Selection "Custom" from the languages menu removes syntax highlighting from the code listing and allows for a custom language label.

AddExp = AddExp "+" MulExp  -- plus
         | AddExp "-" MulExp  -- minus
         | MulExp
(Custom)

Formulas

Formula can appear as block, where take up the whole width of the article, or inline, where they appear in the flow of a paragraph. Formula are written in LaTeX and rendered in-browser using katex.

Block Formulas

formula not implemented

Inline Formulas

Here is some text showing inlined LaTeX for an amplitude inline_formula not implemented, a frequency inline_formula not implemented and a phase inline_formula not implemented.

Exporting as .ipynb

this extra cell will make Python the dominant language and hence should export Python kernel spec metadata in .ipynb

from IPython.display import display, HTML
display(HTML("<strong>👋 Nextjournal!</strong>"))
import plotly.express as px
px.line(x=["a","b","c"], y=[1,3,2], title="sample figure")
2.9s
Python
👋 Nextjournal!

Embedding Tweets and Videos

Insert an embed node and simply paste in a link to a tweet or YouTube or Vimeo video. If the link is recognizable, the media will show.

Tweets

Video

External Data Access

Github Repository

This repo is mounted by: Clojure

AWS S3 Bucket

kommen-nextjournal-bucket-test
Public

Accessing the External Data via Mounts

ls /git-component-demo
ls /kommen-nextjournal-bucket-test
0.8s
Bash in Clojure

Appendix

Here is some content that’s initially invisible because it lives in the collapsed appendix section of this article.

Runtimes (3)