Write HTML sanely in the IPython notebook with Jade (ne Pug)
BSD-3-CLAUSE License
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# jademagic\n",
"> an IPython magic for authoring HTML in Jade ne Pug."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Install\n",
"From the command line (or with !
in a notebook cell):\n",
"bash\n", "pip install jademagic\n", "
"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Enable\n",
"### Ad-hoc\n",
"In the notebook, you can use the %load_ext
or %reload_ext
line magic."
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"%reload_ext jademagic"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Configuration\n",
"In your profile's ipython_kernel_config.py
, you can add the following line to automatically load jademagic
into all your running kernels:\n",
"\n",
"python\n", "c.InteractiveShellApp.extensions = ['jade_magic']\n", "
"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Use\n",
"The %%jade
cell magic will either act as simple parser:"
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"application/javascript": [
"\n",
" require(\n",
" [\n",
" "notebook/js/codecell",\n",
" "codemirror/mode/jade/jade"\n",
" ],\n",
" function(cc){\n",
" cc.CodeCell.options_default.highlight_modes.magic_jade = {\n",
" reg: ["^%%jade"]\n",
" }\n",
" }\n",
" );\n",
" "
],
"text/plain": [
"<IPython.core.display.Javascript object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"\n",
"\n",
" <i class="fa fa-gift fa-1x">\n",
" \n",
" <i class="fa fa-gift fa-2x">\n",
" \n",
" <i class="fa fa-gift fa-3x">\n",
" \n",
" <i class="fa fa-gift fa-4x">\n",
" \n",
" <i class="fa fa-gift fa-5x">\n",
" \n",
""
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%%jade\n",
"ul\n",
" each x in [1, 2, 3, 4, 5]\n",
" li: i.fa.fa-gift(class='fa-#{x}x')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"which can be accessed by the special last result variable _
:"
]
},
{
"cell_type": "code",
"execution_count": 34,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
" <i class="fa fa-gift fa-1x">\n",
" \n",
" <i class="fa fa-gift fa-2x">\n",
" \n",
" <i class="fa fa-gift fa-3x">\n",
" \n",
" <i class="fa fa-gift fa-4x">\n",
" \n",
" <i class="fa fa-gift fa-5x">\n",
" \n",
""
],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"execution_count": 34,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"_"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Or will update a named variable with the parsed document:"
]
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"application/javascript": [
"\n",
" require(\n",
" [\n",
" "notebook/js/codecell",\n",
" "codemirror/mode/jade/jade"\n",
" ],\n",
" function(cc){\n",
" cc.CodeCell.options_default.highlight_modes.magic_jade = {\n",
" reg: ["^%%jade"]\n",
" }\n",
" }\n",
" );\n",
" "
],
"text/plain": [
"<IPython.core.display.Javascript object>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%%jade spock\n",
"i.fa.fa-spock.fa-5x"
]
},
{
"cell_type": "code",
"execution_count": 36,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"'<i class="fa fa-spock fa-5x">'"
]
},
"execution_count": 36,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"spock"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Contribute\n",
"Issues and pull requests welcome!"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## License\n",
"jademagic
is released as free software under the BSD 3-Clause license."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Thank\n",
"- @lbustelo for challenging me to an alternative to %%html
"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.5.1"
}
},
"nbformat": 4,
"nbformat_minor": 0
}