Skip to content

Commit daab803

Browse files
agoose77tavin
andauthored
✨ Add text/markdown MIME renderer (#102)
Co-authored-by: Tavin Cole <[email protected]>
1 parent 10bb44f commit daab803

15 files changed

+1304
-622
lines changed

examples/display-markdown.ipynb

+126
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "1445c778-f92f-46c4-a7f9-b9aece94450f",
6+
"metadata": {
7+
"user_expressions": []
8+
},
9+
"source": [
10+
"---\n",
11+
"title: Markdown Rendering in Jupyter using MyST\n",
12+
"subtitle: Using inline widgets in JupyterLab markdown cells\n",
13+
"author:\n",
14+
" - name: Rowan Cockett\n",
15+
" affiliations: Executable Books; Curvenote\n",
16+
" orcid: 0000-0002-7859-8394\n",
17+
" email: [email protected]\n",
18+
" - name: Angus Hollands\n",
19+
" affiliations: Executable Books\n",
20+
" - name: Steve Purves\n",
21+
" affiliations: Executable Books; Curvenote\n",
22+
"date: 2023/02/20\n",
23+
"---\n",
24+
"\n",
25+
"The [JupyterLab MyST extension](https://github.com/executablebooks/jupyterlab-myst) allows you to invoke the MyST renderer from code cell outputs."
26+
]
27+
},
28+
{
29+
"cell_type": "code",
30+
"execution_count": 12,
31+
"id": "53c89be3-63ef-4a5c-b7f3-28ed138fa92e",
32+
"metadata": {
33+
"tags": []
34+
},
35+
"outputs": [],
36+
"source": [
37+
"from IPython.display import Markdown"
38+
]
39+
},
40+
{
41+
"cell_type": "code",
42+
"execution_count": 13,
43+
"id": "32fad109-f60a-4162-b784-4e3d9ed45921",
44+
"metadata": {
45+
"tags": []
46+
},
47+
"outputs": [
48+
{
49+
"data": {
50+
"text/markdown": [
51+
"\n",
52+
"\n",
53+
"\n",
54+
"The [JupyterLab MyST extension](https://github.com/executablebooks/jupyterlab-myst) allows you to have MyST renderer in your markdown cells that includes interactivity and inline-evaluation.\n",
55+
"\n",
56+
":::{warning} Syntax is Subject to Change\n",
57+
":class: dropdown\n",
58+
"The current syntax is based on a myst role, which may change in the future -- for example to be closer to an inline expression `${}`. This will go through a MyST enhancement proposal, and the `{eval}` role will likely still be supported.\n",
59+
":::\n",
60+
"\n",
61+
"\n",
62+
"```python\n",
63+
"import numpy as np\n",
64+
"array = np.arange(4)\n",
65+
"```\n",
66+
"\n"
67+
],
68+
"text/plain": [
69+
"<IPython.core.display.Markdown object>"
70+
]
71+
},
72+
"execution_count": 13,
73+
"metadata": {},
74+
"output_type": "execute_result"
75+
}
76+
],
77+
"source": [
78+
"Markdown('''\n",
79+
"\n",
80+
"\n",
81+
"The [JupyterLab MyST extension](https://github.com/executablebooks/jupyterlab-myst) allows you to have MyST renderer in your markdown cells that includes interactivity and inline-evaluation.\n",
82+
"\n",
83+
":::{warning} Syntax is Subject to Change\n",
84+
":class: dropdown\n",
85+
"The current syntax is based on a myst role, which may change in the future -- for example to be closer to an inline expression `${}`. This will go through a MyST enhancement proposal, and the `{eval}` role will likely still be supported.\n",
86+
":::\n",
87+
"\n",
88+
"\n",
89+
"```python\n",
90+
"import numpy as np\n",
91+
"array = np.arange(4)\n",
92+
"```\n",
93+
"\n",
94+
"''')"
95+
]
96+
}
97+
],
98+
"metadata": {
99+
"kernelspec": {
100+
"display_name": "Python 3 (ipykernel)",
101+
"language": "python",
102+
"name": "python3"
103+
},
104+
"language_info": {
105+
"codemirror_mode": {
106+
"name": "ipython",
107+
"version": 3
108+
},
109+
"file_extension": ".py",
110+
"mimetype": "text/x-python",
111+
"name": "python",
112+
"nbconvert_exporter": "python",
113+
"pygments_lexer": "ipython3",
114+
"version": "3.10.6"
115+
},
116+
"widgets": {
117+
"application/vnd.jupyter.widget-state+json": {
118+
"state": {},
119+
"version_major": 2,
120+
"version_minor": 0
121+
}
122+
}
123+
},
124+
"nbformat": 4,
125+
"nbformat_minor": 5
126+
}

examples/inline-interactivity.ipynb

+138-8
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
},
5454
{
5555
"cell_type": "code",
56-
"execution_count": 9,
56+
"execution_count": 1,
5757
"id": "90dffa46-b084-4b24-a650-e5f5a9aa526e",
5858
"metadata": {
5959
"tags": []
@@ -123,7 +123,7 @@
123123
},
124124
{
125125
"cell_type": "code",
126-
"execution_count": 10,
126+
"execution_count": 2,
127127
"id": "5ffba1f7-e455-4dce-a645-38988d97b01b",
128128
"metadata": {
129129
"tags": []
@@ -170,7 +170,7 @@
170170
"result": {
171171
"data": {
172172
"application/vnd.jupyter.widget-view+json": {
173-
"model_id": "164397fa815540bda67c6789e23fc2f2",
173+
"model_id": "99c2b3b4f0634fb19a6586a1b7c048ad",
174174
"version_major": 2,
175175
"version_minor": 0
176176
},
@@ -185,7 +185,7 @@
185185
"result": {
186186
"data": {
187187
"application/vnd.jupyter.widget-view+json": {
188-
"model_id": "55495b9c0d0a4752b156300c63c1727f",
188+
"model_id": "1e8ab668a82f4bca84d0731092af405f",
189189
"version_major": 2,
190190
"version_minor": 0
191191
},
@@ -200,7 +200,7 @@
200200
"result": {
201201
"data": {
202202
"application/vnd.jupyter.widget-view+json": {
203-
"model_id": "99043a572d5b4229ad08203899d80425",
203+
"model_id": "38bb524a0a544221a6d57312a1b24323",
204204
"version_major": 2,
205205
"version_minor": 0
206206
},
@@ -215,7 +215,7 @@
215215
"result": {
216216
"data": {
217217
"application/vnd.jupyter.widget-view+json": {
218-
"model_id": "47a2a63cb5304db28dd220ff347fb093",
218+
"model_id": "b026379e864a457585df0502be54ba98",
219219
"version_major": 2,
220220
"version_minor": 0
221221
},
@@ -260,7 +260,7 @@
260260
},
261261
{
262262
"cell_type": "code",
263-
"execution_count": 11,
263+
"execution_count": 3,
264264
"id": "17290f9d-034c-41d0-828b-5af14e14edfa",
265265
"metadata": {
266266
"tags": []
@@ -582,7 +582,137 @@
582582
},
583583
"widgets": {
584584
"application/vnd.jupyter.widget-state+json": {
585-
"state": {},
585+
"state": {
586+
"0475c9891b1041ac958732b3f3dfde80": {
587+
"model_module": "@jupyter-widgets/base",
588+
"model_module_version": "2.0.0",
589+
"model_name": "LayoutModel",
590+
"state": {}
591+
},
592+
"1e8ab668a82f4bca84d0731092af405f": {
593+
"model_module": "@jupyter-widgets/controls",
594+
"model_module_version": "2.0.0",
595+
"model_name": "LabelModel",
596+
"state": {
597+
"layout": "IPY_MODEL_2e78dacf92a94dd6aa3919a29722948b",
598+
"style": "IPY_MODEL_480aadd6662c4c2bbcca8ef67255e64a",
599+
"value": "500"
600+
}
601+
},
602+
"274ed93dcd0f4897a95f314dc1f3b1fb": {
603+
"model_module": "@jupyter-widgets/base",
604+
"model_module_version": "2.0.0",
605+
"model_name": "LayoutModel",
606+
"state": {}
607+
},
608+
"2766f4faadcd443f8c195bf614a30035": {
609+
"model_module": "@jupyter-widgets/controls",
610+
"model_module_version": "2.0.0",
611+
"model_name": "DescriptionStyleModel",
612+
"state": {
613+
"description_width": ""
614+
}
615+
},
616+
"2e78dacf92a94dd6aa3919a29722948b": {
617+
"model_module": "@jupyter-widgets/base",
618+
"model_module_version": "2.0.0",
619+
"model_name": "LayoutModel",
620+
"state": {}
621+
},
622+
"38bb524a0a544221a6d57312a1b24323": {
623+
"model_module": "@jupyter-widgets/controls",
624+
"model_module_version": "2.0.0",
625+
"model_name": "LabelModel",
626+
"state": {
627+
"layout": "IPY_MODEL_274ed93dcd0f4897a95f314dc1f3b1fb",
628+
"style": "IPY_MODEL_64cee23ec9524879aa172d0271642964",
629+
"value": "23.8"
630+
}
631+
},
632+
"480aadd6662c4c2bbcca8ef67255e64a": {
633+
"model_module": "@jupyter-widgets/controls",
634+
"model_module_version": "2.0.0",
635+
"model_name": "LabelStyleModel",
636+
"state": {
637+
"description_width": "",
638+
"font_family": null,
639+
"font_size": null,
640+
"font_style": null,
641+
"font_variant": null,
642+
"font_weight": null,
643+
"text_color": null,
644+
"text_decoration": null
645+
}
646+
},
647+
"62a7cd9328f142c98184357d8951af13": {
648+
"model_module": "@jupyter-widgets/controls",
649+
"model_module_version": "2.0.0",
650+
"model_name": "SliderStyleModel",
651+
"state": {
652+
"description_width": ""
653+
}
654+
},
655+
"64cee23ec9524879aa172d0271642964": {
656+
"model_module": "@jupyter-widgets/controls",
657+
"model_module_version": "2.0.0",
658+
"model_name": "LabelStyleModel",
659+
"state": {
660+
"description_width": "",
661+
"font_family": null,
662+
"font_size": null,
663+
"font_style": null,
664+
"font_variant": null,
665+
"font_weight": null,
666+
"text_color": null,
667+
"text_decoration": null
668+
}
669+
},
670+
"72a3e705505044a49019394d40092e25": {
671+
"model_module": "@jupyter-widgets/base",
672+
"model_module_version": "2.0.0",
673+
"model_name": "LayoutModel",
674+
"state": {}
675+
},
676+
"888a2a0691f44d008052ded919537342": {
677+
"model_module": "@jupyter-widgets/controls",
678+
"model_module_version": "2.0.0",
679+
"model_name": "LinkModel",
680+
"state": {
681+
"source": [
682+
"IPY_MODEL_b026379e864a457585df0502be54ba98",
683+
"value"
684+
],
685+
"target": [
686+
"IPY_MODEL_99c2b3b4f0634fb19a6586a1b7c048ad",
687+
"value"
688+
]
689+
}
690+
},
691+
"99c2b3b4f0634fb19a6586a1b7c048ad": {
692+
"model_module": "@jupyter-widgets/controls",
693+
"model_module_version": "2.0.0",
694+
"model_name": "BoundedIntTextModel",
695+
"state": {
696+
"layout": "IPY_MODEL_72a3e705505044a49019394d40092e25",
697+
"max": 30,
698+
"style": "IPY_MODEL_2766f4faadcd443f8c195bf614a30035",
699+
"value": 10
700+
}
701+
},
702+
"b026379e864a457585df0502be54ba98": {
703+
"model_module": "@jupyter-widgets/controls",
704+
"model_module_version": "2.0.0",
705+
"model_name": "IntSliderModel",
706+
"state": {
707+
"behavior": "drag-tap",
708+
"description": "Cookies: ",
709+
"layout": "IPY_MODEL_0475c9891b1041ac958732b3f3dfde80",
710+
"max": 30,
711+
"style": "IPY_MODEL_62a7cd9328f142c98184357d8951af13",
712+
"value": 10
713+
}
714+
}
715+
},
586716
"version_major": 2,
587717
"version_minor": 0
588718
}

examples/myst_tests.ipynb

+1-1
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@
228228
"name": "python",
229229
"nbconvert_exporter": "python",
230230
"pygments_lexer": "ipython3",
231-
"version": "3.9.7"
231+
"version": "3.10.6"
232232
},
233233
"vscode": {
234234
"interpreter": {

0 commit comments

Comments
 (0)