Created
April 16, 2016 18:43
-
-
Save tonyfast/caa23350a09d0dac24295a399970bca2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"from literacy import Literate\n", | |
"library=Literate(default_lang='python')" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 28, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"application/javascript": [ | |
"console.log(10)" | |
], | |
"text/plain": [ | |
"<IPython.core.display.Javascript object>" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
}, | |
{ | |
"data": { | |
"text/html": [ | |
"\n", | |
"<h1>This code cell is content editable.</h1><p>Use <code>ctrl+enter</code> to execute the javascript.</p>\n", | |
"<hr><pre><code>%%javascript\n", | |
"console.log(10)\n", | |
"</code></pre><hr>" | |
], | |
"text/plain": [ | |
"<literacy.Cell object>" | |
] | |
}, | |
"execution_count": 28, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"%%literate\n", | |
"\n", | |
"# This code cell is content editable. \n", | |
"\n", | |
"Use ``ctrl+enter`` to execute the javascript.\n", | |
"\n", | |
" %%javascript\n", | |
" console.log(10)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 30, | |
"metadata": { | |
"collapsed": false, | |
"scrolled": true | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"application/javascript": [ | |
"$('code').each(function(d,i){\n", | |
" if(this.innerText.startsWith('%%javascript')){\n", | |
" $(this).attr('contenteditable','true');\n", | |
" $(this).keydown(function (e) {\n", | |
" if (e.ctrlKey && e.keyCode == 13) {\n", | |
" eval(this.innerText.split('\\n').slice(1).join('\\n'));\n", | |
" };\n", | |
" });\n", | |
" };\n", | |
" })" | |
], | |
"text/plain": [ | |
"<IPython.core.display.Javascript object>" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
}, | |
{ | |
"data": { | |
"text/html": [ | |
"\n", | |
"<h1>Executable javascript code in the browser.</h1><p>Select <code>%%javascript</code> cell magics. Make the contenteditable and executable.</p>\n", | |
"<hr><pre><code>%%javascript\n", | |
"$('code').each(function(d,i){\n", | |
" if(this.innerText.startsWith('%%javascript')){\n", | |
" $(this).attr('contenteditable','true');\n", | |
" $(this).keydown(function (e) {\n", | |
" if (e.ctrlKey && e.keyCode == 13) {\n", | |
" eval(this.innerText.split('\\n').slice(1).join('\\n'));\n", | |
" };\n", | |
" });\n", | |
" };\n", | |
" })\n", | |
"</code></pre><hr>" | |
], | |
"text/plain": [ | |
"<literacy.Cell object>" | |
] | |
}, | |
"execution_count": 30, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"%%literate\n", | |
"# Executable javascript code in the browser.\n", | |
"\n", | |
"Select ``%%javascript`` cell magics. Make the contenteditable and executable.\n", | |
"\n", | |
" %%javascript\n", | |
" $('code').each(function(d,i){\n", | |
" if(this.innerText.startsWith('%%javascript')){\n", | |
" $(this).attr('contenteditable','true');\n", | |
" $(this).keydown(function (e) {\n", | |
" if (e.ctrlKey && e.keyCode == 13) {\n", | |
" eval(this.innerText.split('\\n').slice(1).join('\\n'));\n", | |
" };\n", | |
" });\n", | |
" };\n", | |
" })" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python [Root]", | |
"language": "python", | |
"name": "Python [Root]" | |
}, | |
"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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment