Last active
April 13, 2016 15:14
-
-
Save bollwyvl/331311ece13be981c10da62c192b559d 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": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# Hover over links to see previews\n", | |
"> in response to this [forum post](http://groups.google.com/forum/#!topic/jupyter/ut6rDwsb_Jw)\n", | |
"\n", | |
"- [Github](https://github.com)\n", | |
"- [Jupyter](http://jupyter.org)\n", | |
"\n", | |
"## Limitations\n", | |
"- Can only render same level of security: `https` vs `http`\n", | |
"\n", | |
"> powered by [jquery-live-preview](https://github.com/alanphoon/jquery-live-preview)." | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"The code is pretty simple. It could be easily made into an nbextension..." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 37, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"<link href=\"https://cdn.rawgit.com/alanphoon/jquery-live-preview/4e85dfbd0c78446b25b6e56c1dfb730dea7ff99a/css/livepreview-demo.css\" rel=\"stylesheet\" type=\"text/css\"></link>\n", | |
"<script>\n", | |
"\n", | |
"\n", | |
"// probably drop this\n", | |
"requirejs.undef(\"nb-markdown-link-previews\");\n", | |
"\n", | |
"// a real extension would package its own stuff\n", | |
"requirejs.config({\n", | |
" paths: {\n", | |
" \"jquery-live-preview\": \"https://cdn.rawgit.com/alanphoon/jquery-live-preview/4e85dfbd0c78446b25b6e56c1dfb730dea7ff99a/js/jquery-live-preview\",\n", | |
" \"jquery\": \"https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.3/jquery.min\"\n", | |
" },\n", | |
" shim: {\n", | |
" \"jquery-live-preview\": {\n", | |
" deps: [\"jquery\"]\n", | |
" }\n", | |
" }\n", | |
"});\n", | |
"\n", | |
"define(\n", | |
" \"nb-markdown-link-previews\", // probably drop this\n", | |
" [\"jquery-live-preview\"],\n", | |
" function(){\n", | |
" var initialized = false,\n", | |
" protocol = window.location.protocol;\n", | |
" console.info(\"[nb-markdown-link-previews] loaded\")\n", | |
" var api = {\n", | |
" load_ipython_extension: function(){\n", | |
" console.info(\"[nb-markdown-link-previews] initializing...\");\n", | |
" if(!initialized){\n", | |
" console.info(\"[nb-markdown-link-previews] initialized\");\n", | |
" initialized = true;\n", | |
" require([\"base/js/namespace\"], function(Jupyter){\n", | |
" console.info(\"[jquery-live-preview] listening...\");\n", | |
" Jupyter.notebook.events.on(\"rendered.MarkdownCell\", api.update);\n", | |
" });\n", | |
" }\n", | |
" },\n", | |
" update: function(){\n", | |
" console.info(\"[nb-markdown-link-previews] updated\");\n", | |
" $(\".rendered_html a[href^='\" + protocol + \"']\").livePreview();\n", | |
" }\n", | |
" };\n", | |
"\n", | |
" return api;\n", | |
" }\n", | |
");\n", | |
"\n", | |
"// this would be handled by `nbextension enable`\n", | |
"require([\"nb-markdown-link-previews\"], function(ext){\n", | |
" ext.update();\n", | |
" ext.load_ipython_extension();\n", | |
"});\n", | |
"</script>" | |
], | |
"text/plain": [ | |
"<IPython.core.display.HTML object>" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"%%html\n", | |
"<link href=\"https://cdn.rawgit.com/alanphoon/jquery-live-preview/4e85dfbd0c78446b25b6e56c1dfb730dea7ff99a/css/livepreview-demo.css\" rel=\"stylesheet\" type=\"text/css\"></link>\n", | |
"<script>\n", | |
"\n", | |
"\n", | |
"// probably drop this\n", | |
"requirejs.undef(\"nb-markdown-link-previews\");\n", | |
"\n", | |
"// a real extension would package its own stuff\n", | |
"requirejs.config({\n", | |
" paths: {\n", | |
" \"jquery-live-preview\": \"https://cdn.rawgit.com/alanphoon/jquery-live-preview/4e85dfbd0c78446b25b6e56c1dfb730dea7ff99a/js/jquery-live-preview\",\n", | |
" \"jquery\": \"https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.3/jquery.min\"\n", | |
" },\n", | |
" shim: {\n", | |
" \"jquery-live-preview\": {\n", | |
" deps: [\"jquery\"]\n", | |
" }\n", | |
" }\n", | |
"});\n", | |
"\n", | |
"define(\n", | |
" \"nb-markdown-link-previews\", // probably drop this\n", | |
" [\"jquery-live-preview\"],\n", | |
" function(){\n", | |
" var initialized = false,\n", | |
" protocol = window.location.protocol;\n", | |
" console.info(\"[nb-markdown-link-previews] loaded\")\n", | |
" var api = {\n", | |
" load_ipython_extension: function(){\n", | |
" console.info(\"[nb-markdown-link-previews] initializing...\");\n", | |
" if(!initialized){\n", | |
" console.info(\"[nb-markdown-link-previews] initialized\");\n", | |
" initialized = true;\n", | |
" require([\"base/js/namespace\"], function(Jupyter){\n", | |
" console.info(\"[jquery-live-preview] listening...\");\n", | |
" Jupyter.notebook.events.on(\"rendered.MarkdownCell\", api.update);\n", | |
" });\n", | |
" }\n", | |
" },\n", | |
" update: function(){\n", | |
" console.info(\"[nb-markdown-link-previews] updated\");\n", | |
" $(\".rendered_html a[href^='\" + protocol + \"']\").livePreview();\n", | |
" }\n", | |
" };\n", | |
"\n", | |
" return api;\n", | |
" }\n", | |
");\n", | |
"\n", | |
"// this would be handled by `nbextension enable`\n", | |
"require([\"nb-markdown-link-previews\"], function(ext){\n", | |
" ext.update();\n", | |
" ext.load_ipython_extension();\n", | |
"});\n", | |
"</script>" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment