Skip to content

Commit fdfdfe2

Browse files
committed
Fix block bug
1 parent 6e147f1 commit fdfdfe2

5 files changed

Lines changed: 45 additions & 5 deletions

File tree

.github/workflows/docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
with:
2424
node-version: 22
2525
- name: Build docs
26-
run: npx -y mystmd build --html
26+
run: npx -y mystmd build --html --execute
2727
env:
2828
BASE_URL: /myst-lightbox/
2929
working-directory: docs

docs/myst.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@ project:
33
id: myst-lightbox
44
title: myst-lightbox
55
github: https://github.com/choldgraf/myst-lightbox
6+
jupyter:
7+
binder:
8+
repo: https://github.com/executablebooks/thebe-binder-base
69
plugins:
710
- ../src/index.mjs
811
toc:
912
- file: index.md
13+
- file: reference.md
1014

1115
site:
1216
template: book-theme

docs/reference.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
title: Reference example with Binder
3+
jupyter:
4+
kernelspec:
5+
display_name: Python 3
6+
language: python
7+
name: python3
8+
---
9+
10+
# Reference example with Binder
11+
12+
This page demonstrates that the lightbox plugin coexists with executable code cells and a Binder kernel.
13+
14+
```{code-cell} python
15+
from matplotlib import pyplot as plt
16+
fig, ax = plt.subplots()
17+
ax.scatter([1, 2, 3], [1, 3, 2])
18+
```
19+
20+
The figure below remains a clickable lightbox while compute is enabled:
21+
22+
:::{figure} https://images.unsplash.com/photo-1501785888041-af3ef285b470?w=1600
23+
:alt: A mountain lake at dusk
24+
:width: 80%
25+
26+
A mountain lake at dusk.
27+
:::

docs/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
jupyter
2+
matplotlib

src/index.mjs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,18 @@ const injectWidgetTransform = {
4848
utils.selectAll('image', tree).length > 0 ||
4949
utils.selectAll('container[kind="figure"]', tree).length > 0;
5050
if (!hasImages) return;
51+
// Wrap in a `block` because thebe execution seems to assume that everything
52+
// is a block-level item
5153
tree.children.push({
52-
type: 'anywidget',
53-
esm: pathMod.relative(pathMod.dirname(file.path), PLUGIN_PATH),
54-
model: {},
55-
id: crypto.randomUUID(),
54+
type: 'block',
55+
children: [
56+
{
57+
type: 'anywidget',
58+
esm: pathMod.relative(pathMod.dirname(file.path), PLUGIN_PATH),
59+
model: {},
60+
id: crypto.randomUUID(),
61+
},
62+
],
5663
});
5764
},
5865
};

0 commit comments

Comments
 (0)