{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Unsafe `JupyterLab` API\n", "For giggles, the `JupyterLab` application is available inside your kernel. You can use it do useful things like loading files:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "JupyterLab.serviceManager.contents.get(\"index.ipynb\")\n", " .then((x) => {\n", " display.display({\n", " \"text/plain\": JSON.stringify(x.content[\"cells\"][0], null, 2)\n", " })\n", " })" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Or dangerous things, like open new notebooks:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "JupyterLab.commands.execute(\"notebook:create-new\")\n", " .then((notebook) => {\n", " display.display({\n", " \"text/markdown\": `## Notebook\\n - ${\n", " [].concat(Object.keys(notebook)).join('\\n - ')\n", " }`\n", " })\n", " })" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Commands are really powerful. Here's all the trouble you could get up to:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "let keys = Object.keys(JupyterLab.commands._commands);\n", "keys.sort();\n", "let namespaces = keys.reduce(function(m, k){\n", " let ns = k.split(\":\")[0];\n", " m[ns] = m[ns] || [];\n", " m[ns].push(k);\n", " return m;\n", "}, {});\n", "\n", "display.display({\n", " \"text/markdown\": \"> ## _click the links to search the JupyterLab repository_\\n\\n\" + Object.keys(namespaces).map((ns) => {\n", " return `### ${ns}\\n- ` + namespaces[ns].map(function(cmd){\n", "// return `${cmd}`;\n", " return `[${cmd.split(\":\")[1]}](https://github.com/jupyterlab/jupyterlab/search?q=\"${cmd}\")`\n", " }).join(\"\\n- \");\n", " }).join(\"\\n\")\n", "})" ] } ], "metadata": { "kernelspec": { "display_name": "JS (unsafe) — Jyve", "language": "javascript", "name": "jyve-kyrnel-js-unsafe" }, "language_info": { "codemirror_mode": { "name": "javascript" }, "file_extension": ".js", "mimetype": "text/javascript", "name": "javascript", "nbconvert_exporter": "javascript", "pygments_lexer": "javascript", "version": "ES2015" } }, "nbformat": 4, "nbformat_minor": 2 }