From 12bd22bab458b7be020dcf1316f84096d6cd1891 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Thu, 8 Mar 2018 10:45:43 -0500 Subject: [PATCH] Add pyodide to iodide dynamically using API --- src/pyodide.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/pyodide.js b/src/pyodide.js index 49d0f338a..6d2180987 100644 --- a/src/pyodide.js +++ b/src/pyodide.js @@ -33,4 +33,25 @@ var pyodide = {} }; wasmXHR.send(null); + + if (window.iodide !== undefined) { + iodide.addLanguage({ + name: 'py', + displayName: 'Python', + keybinding: 'p', + evaluate: code => pyodide.runPython(code), + }); + + iodide.addOutputHandler({ + shouldHandle: value => ( + value.$$ !== undefined && + value.$$.ptrType.name === 'Py*' + ), + + render: value => ( + '🐍' + + pyodide.repr(value).replace(/&/g,'&').replace(//g,'>') + + ''), + }); + } }