Skip to content

Instantly share code, notes, and snippets.

@manzt
Created August 3, 2022 19:28
Show Gist options
  • Save manzt/f4b94d5e10138c9db2577c3dc3d6dafd to your computer and use it in GitHub Desktop.
Save manzt/f4b94d5e10138c9db2577c3dc3d6dafd to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "ce3b0218",
"metadata": {},
"outputs": [],
"source": [
"import jinja2\n",
"import uuid\n",
"\n",
"HTML_TEMPLATE = jinja2.Template(\"\"\"\n",
"<!doctype html>\n",
"<div id=\"{{ output_id }}\"></div>\n",
"<script type=\"module\">\n",
" import confetti from 'https://cdn.skypack.dev/canvas-confetti';\n",
" let el = document.querySelector(\"#{{ output_id }}\"); \n",
" el.innerText = \"It worked!\"\n",
" confetti();\n",
"</script>\n",
"\"\"\")\n",
"\n",
"\n",
"\n",
"class Foo:\n",
" \n",
" def _repr_mimebundle_(self, *args, **kwargs):\n",
" \n",
" return {\n",
" \"text/html\": HTML_TEMPLATE.render(output_id=\"vis\")\n",
" }\n",
" \n",
" \n",
"Foo()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d4134eb6",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.4"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment