Thanks @jashkenas . This is helpful. I don’t suppose your notebook on embedding is confusing; rather - I remain confused about Javascript fundamentals (in this case, not intuiting that ‘else if’ would render both statements, rather than just stopping at the first truthy statement).
To close out this thread for others such as myself who are new and don’t immediately see such things, a minor revision to your solution: the addition of document.querySelector
, without which the code you supplied will continue to return console errors.
Here’s the final code:
new Runtime().module(notebook, name => {
if (name === "title") {
return new Inspector(document.querySelector("#title"));
}
else if (name === "map") {
return new Inspector(document.querySelector("#map"));
}
});
-or-
function renderNotebook(notebook, cellNames) {
new Runtime().module(notebook, name => {
if (cellNames.includes(name)) {
return new Inspector(document.querySelector(`#${name}`));
}
});
}
renderNotebook(notebook, ["title", "map"])