2119 words
11 minutes
Code blocks
testing blog

Example Blocks#

Output:
shape: (3, 7) ┌──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬───────┬──────┬──────┬──────┐ │ col1 ┆ col2 ┆ col3 ┆ col3 ┆ col3 ┆ col3 ┆ col3 ┆ col3 ┆ col3 ┆ col3 ┆ col3 ┆ col3 ┆ col3 ┆ col3 ┆ col3 ┆ col3 ┆ col4 ┆ col5 ┆ col6 ┆ col7 │ │ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- │ │ i64 ┆ str ┆ f64 ┆ f64 ┆ f64 ┆ f64 ┆ f64 ┆ f64 ┆ f64 ┆ f64 ┆ f64 ┆ f64 ┆ f64 ┆ f64 ┆ f64 ┆ f64 ┆ bool ┆ i64 ┆ str ┆ f64 │ ╞══════╪══════╪══════╪══════╪══════╪══════╪══════╪══════╪══════╪══════╪══════╪══════╪══════╪══════╪══════╪══════╪═══════╪══════╪══════╪══════╡ │ 1 ┆ a ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ true ┆ 100 ┆ x ┆ 0.1 │ │ 1 ┆ a ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ true ┆ 100 ┆ x ┆ 0.1 │ │ 1 ┆ a ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ true ┆ 100 ┆ x ┆ 0.1 │ │ 1 ┆ a ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ true ┆ 100 ┆ x ┆ 0.1 │ │ 1 ┆ a ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ true ┆ 100 ┆ x ┆ 0.1 │ │ 1 ┆ a ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ true ┆ 100 ┆ x ┆ 0.1 │ │ 1 ┆ a ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ true ┆ 100 ┆ x ┆ 0.1 │ │ 2 ┆ b ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ false ┆ 200 ┆ y ┆ 0.2 │ │ 1 ┆ a ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ true ┆ 100 ┆ x ┆ 0.1 │ │ 1 ┆ a ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ true ┆ 100 ┆ x ┆ 0.1 │ │ 1 ┆ a ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ true ┆ 100 ┆ x ┆ 0.1 │ │ 2 ┆ b ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ false ┆ 200 ┆ y ┆ 0.2 │ │ 2 ┆ b ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ false ┆ 200 ┆ y ┆ 0.2 │ │ 2 ┆ b ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ false ┆ 200 ┆ y ┆ 0.2 │ │ 2 ┆ b ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ false ┆ 200 ┆ y ┆ 0.2 │ │ 2 ┆ b ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ false ┆ 200 ┆ y ┆ 0.2 │ │ 2 ┆ b ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ false ┆ 200 ┆ y ┆ 0.2 │ │ 2 ┆ b ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ false ┆ 200 ┆ y ┆ 0.2 │ │ 1 ┆ a ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ true ┆ 100 ┆ x ┆ 0.1 │ │ 1 ┆ a ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ true ┆ 100 ┆ x ┆ 0.1 │ │ 1 ┆ a ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ true ┆ 100 ┆ x ┆ 0.1 │ │ 1 ┆ a ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ 10.5 ┆ true ┆ 100 ┆ x ┆ 0.1 │ │ 2 ┆ b ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ false ┆ 200 ┆ y ┆ 0.2 │ │ 2 ┆ b ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ false ┆ 200 ┆ y ┆ 0.2 │ │ 2 ┆ b ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ false ┆ 200 ┆ y ┆ 0.2 │ │ 2 ┆ b ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ false ┆ 200 ┆ y ┆ 0.2 │ │ 2 ┆ b ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ false ┆ 200 ┆ y ┆ 0.2 │ │ 2 ┆ b ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ 20.1 ┆ false ┆ 200 ┆ y ┆ 0.2 │ │ 3 ┆ c ┆ 30.2 ┆ 30.2 ┆ 30.2 ┆ 30.2 ┆ 30.2 ┆ 30.2 ┆ 30.2 ┆ 30.2 ┆ 30.2 ┆ 30.2 ┆ 30.2 ┆ 30.2 ┆ 30.2 ┆ 30.2 ┆ true ┆ 300 ┆ z ┆ 0.3 │ └──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┴───────┴──────┴──────┴──────┘

smaller scrollbar

Output:
┌──────┬──────┬──────┬───────┬──────┬──────┬──────┐ │ col1 ┆ col2 ┆ col3 ┆ col4 ┆ col5 ┆ col6 ┆ col7 │ │ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- │ │ i64 ┆ str ┆ f64 ┆ bool ┆ i64 ┆ str ┆ f64 │ ╞══════╪══════╪══════╪═══════╪══════╪══════╪══════╡ │ 1 ┆ a ┆ 10.5 ┆ true ┆ 100 ┆ x ┆ 0.1 │ │ 2 ┆ b ┆ 20.1 ┆ false ┆ 200 ┆ y ┆ 0.2 │ │ 3 ┆ c ┆ 30.2 ┆ true ┆ 300 ┆ z ┆ 0.3 │ └──────┴──────┴──────┴───────┴──────┴──────┴──────┘

Empty blocks are not going to be exported

Sql Blocks#

print("hello world")
-- %%sql --save not_nulls --no-execute
-- %%sql --save not_nulls --no-execute
SELECT *
FROM penguins.csv
WHERE bill_length_mm IS NOT NULL
AND bill_depth_mm IS NOT NULL
%sqlplot boxplot --column bill_length_mm bill_depth_mm --table not_nulls

Code Blocks with mdparams and Attributes folded#

The next block has complex :mdparams and other attributes. The filter should:

  • Put js as the language
  • Inline all attributes into the fence header
  • Leave attribute order and values intact
5 collapsed lines
function demo() {
// Mark any given text inside lines
return 'Multiple matches of the given text are supported';
}
echo "Test" > /home/test.txt
// All this boilerplate setup code will be collapsed
import { someBoilerplateEngine } from '@example/some-boilerplate'
import { evenMoreBoilerplate } from '@example/even-more-boilerplate'

Here is some simple JavaScript code with :del and :ins attributes:

console.log('This code is syntax highlighted!')

Here is a separator to visually break sections in the output:


Code block attributes are transferred as-is from Org header args:

console.log('Title attribute example')

This line mimics a “title” attribute in the rendered Markdown:

js title”my-test-file.js”

Shell code block without any special attributes:

Terminal window
echo "This terminal frame has no title"

Diff block that should be highlighted as JavaScript due to :lang js:

function thisIsJavaScript() {
// This entire block gets highlighted as JavaScript,
// and we can still add diff markers to it!
console.log('Old code to be removed')
console.log('New and shiny code!')
}

A block that uses :mdparams "given text" to mark text inside lines:

function demo() {
// Mark any given text inside lines
return 'Multiple matches of the given text are supported';
}

Jupyter / Session-Based Code and Example Output ATTACH#

Jupyter-like block with a Python session and simple text output:

print("hi there")
Output:
hi there

More complex Jupyter block that produces a table-like textual result and an image:

import matplotlib.pyplot as plt
import polars as pl
df = pl.DataFrame({
"col1": [1, 2, 3],
"col2": ["a", "b", "c"],
"col3": [10.5, 20.1, 30.2],
"col4": [True, False, True],
"col5": [100, 200, 300],
"col6": ["x", "y", "z"],
"col7": [0.1, 0.2, 0.3],
})
print(df)
Output:
shape: (3, 7) ┌──────┬──────┬──────┬───────┬──────┬──────┬──────┐ │ col1 ┆ col2 ┆ col3 ┆ col4 ┆ col5 ┆ col6 ┆ col7 │ │ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- │ │ i64 ┆ str ┆ f64 ┆ bool ┆ i64 ┆ str ┆ f64 │ ╞══════╪══════╪══════╪═══════╪══════╪══════╪══════╡ │ 1 ┆ a ┆ 10.5 ┆ true ┆ 100 ┆ x ┆ 0.1 │ │ 2 ┆ b ┆ 20.1 ┆ false ┆ 200 ┆ y ┆ 0.2 │ │ 3 ┆ c ┆ 30.2 ┆ true ┆ 300 ┆ z ┆ 0.3 │ └──────┴──────┴──────┴───────┴──────┴──────┴──────┘

See go to section two

import matplotlib.pyplot as plt
x = [1, 2, 3, 4]
y = [2, 4, 6, 8]
plt.plot(x, y)
plt.savefig('output.svg')
# import polars as pl
# df = pl.DataFrame({
# "col1": [1, 2, 3],
# "col2": ["a", "b", "c"],
# "col3": [10.5, 20.1, 30.2],
# "col4": [True, False, True],
# "col5": [100, 200, 300],
# "col6": ["x", "y", "z"],
# "col7": [0.1, 0.2, 0.3],
# })
# print(df)

Output:
shape: (3, 7) ┌──────┬──────┬──────┬───────┬──────┬──────┬──────┐ │ col1 ┆ col2 ┆ col3 ┆ col4 ┆ col5 ┆ col6 ┆ col7 │ │ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- │ │ i64 ┆ str ┆ f64 ┆ bool ┆ i64 ┆ str ┆ f64 │ ╞══════╪══════╪══════╪═══════╪══════╪══════╪══════╡ │ 1 ┆ a ┆ 10.5 ┆ true ┆ 100 ┆ x ┆ 0.1 │ │ 2 ┆ b ┆ 20.1 ┆ false ┆ 200 ┆ y ┆ 0.2 │ │ 3 ┆ c ┆ 30.2 ┆ true ┆ 300 ┆ z ┆ 0.3 │ └──────┴──────┴──────┴───────┴──────┴──────┴──────┘
import duckdb
duckdb.sql("""SELECT *,
CASE WHEN n % 2 = 0 THEN 'Even' ELSE 'Odd' END AS parity
FROM (SELECT * FROM generate_series(1, 10000000) AS t(n))
WHERE n % 99999 = 0 LIMIT 4;""").show()
Output:
┌────────┬─────────┐ │ n │ parity │ │ int64 │ varchar │ ├────────┼─────────┤ │ 99999 │ Odd │ │ 199998 │ Even │ │ 299997 │ Odd │ │ 399996 │ Even │ └────────┴─────────┘
Code blocks
https://aneeqasif.github.io/posts/testing/coding/
Author
Aneeq Asif Azad
Published at
2026-09-09
License
CC BY-NC-SA 4.0