Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix multiline jupyter notebook cells #44

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 15 additions & 23 deletions lib/jupyter.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,33 +185,25 @@ nbNext=async dir=>{
log(newCell.cell_type);
switch (newCell.cell_type) {
case "code":
// todo, jupyter dinput
var firstChar = cellSource[0].replace(/\s/g, '')[0];
if (firstChar === "∇" || firstChar === "]") {
let firstLine = cellSource[0].replace(/\s/g, '');
let isTradfn = firstLine[0] === "∇";
let hasDinput = !!firstLine.match(/]dinput/i);
if (isTradfn || hasDinput) {
log("tradfn or ]dinput here")
// Submit whole definition
if (cellSource[0].replace(/\s/g, '') === "]dinput") {
//dfn
fnDef = replaceAll(cellSource.slice(1,cellSource.length).join(""), "\n", "") + "\n".repeat(cellSource.length - 1);
} else {
// tradfn
fnDef = cellSource.join("");
}
submitLine(fnDef).then(fn=>{
// Format definition with line numbers [1]
for (let i = 1; i < cellSource.length; i++) {
log("----------");
log(cellSource[i]);
cellSource[i] = "[" + i + "]" + "&nbsp;&nbsp;" + cellSource[i];
}
newLine = cellSource.join("");
// if first line is ]dinput, we don't want to send that to the interpreter so skip it
fnDef = cellSource.slice(+hasDinput, cellSource.length);
// all but the first line should start with a tab to not mess up editing in session history
fnDef[0] = " ".repeat(8) + fnDef[0];
for (let i = 1; i < fnDef.length; i++) {
fnDef[i] = "\t" + fnDef[i];
}
submitLine(fnDef.join("")).then(fn=>{
log(fnDef);
newLine = fnDef.join("");
var div = document.createElement("div");
div.innerHTML = "<pre class=\"apl\">" + "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + newLine + "</code>";
div.innerHTML = "<pre class=\"apl\">" + newLine + "</code>";
//div.onclick=e=>{replaceLine(e.target.innerHTML)};
mdrender.append(div);
// Replace session appendage from submitLine
session.value = session.value.split("\n").slice(0,-cellSource.length-1).join("\n") + "\n ";
insertLine(replaceAll(newLine + "\n ", "&nbsp;", " "))
});
} else {
log("ONE LINER");
Expand Down