Python生态无人不晓[Jupyter Notebook](https://ipython.org/notebook.html)的`.ipynb`格式,堪称文本代码两开花的典范。但如何在网页上,尤其是自己的博客发布平台上完整地展示`.ipynb`格式文件呢?
[Jupyter Book](https://jupyterbook.org/en/stable/intro.html) 这样的框架自带支持当然最好。但如果是使用其他框架(比如[mdbook](https://rust-lang.github.io/mdBook/) 或者[Obsidian Publish](https://obsidian.md/publish))呢?
经过多种方法试错,目前的一条可行的路径是:使用[Quarto](https://quarto.org/)。
```bash
quarto render hello.ipynb --to md
```
以下是样例输出:
# Quarto Basics
## Polar Axis
For a demonstration of a line plot on a polar axis, see
<a href="#fig-polar" class="quarto-xref">Figure 1</a>.
``` python
import numpy as np
import matplotlib.pyplot as plt
r = np.arange(0, 2, 0.01)
theta = 3 * np.pi * r
fig, ax = plt.subplots(
subplot_kw = {'projection': 'polar'}
)
ax.plot(theta, r)
ax.set_rticks([0.5, 1, 1.5, 2])
ax.grid(True)
plt.show()
```
![[fig-polar-output-1.png]]
``` python
1/7
```
0.14285714285714285