Add pyodide to iodide dynamically using API

This commit is contained in:
Michael Droettboom 2018-03-08 10:45:43 -05:00
parent 6914e0f8c8
commit 12bd22bab4
1 changed files with 21 additions and 0 deletions

View File

@ -33,4 +33,25 @@ var pyodide = {}
}; };
wasmXHR.send(null); 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 => (
'<span><span role="img" aria-label="py">🐍</span>' +
pyodide.repr(value).replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;') +
'</span>'),
});
}
} }