-
-
Notifications
You must be signed in to change notification settings - Fork 292
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PLJ-785 CodeMirror Eject to TextArea - Reload from TextArea in Offlin…
…e HTML export (#805) * Replace CM with TextArea on export - reload CM from TextArea on load * Make CMs readonly * Disallow focus on CM * Fix small bug: InnerHTML->OuterHTML * Fix CellInput & tests * Enable copy (and cursor) * Disable cursor
- Loading branch information
Παναγιώτης Γεωργακόπουλος
authored
Jan 23, 2021
1 parent
1818c10
commit d5b8c77
Showing
3 changed files
with
55 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,12 +11,14 @@ export const offline_html = async ({ pluto_version, body, head }) => { | |
} | ||
|
||
try { | ||
const oldBody = body | ||
body = body.cloneNode(true) | ||
|
||
for (let sizer of body.querySelectorAll(".CodeMirror-sizer")) { | ||
sizer.style.minHeight = "23px" | ||
} | ||
|
||
const oldBodyCMs = oldBody.querySelectorAll("pluto-input .CodeMirror") | ||
body.querySelectorAll("pluto-input .CodeMirror").forEach((cm, i) => { | ||
const oldCM = oldBodyCMs[i].CodeMirror | ||
oldCM.save() | ||
cm.outerHTML = `<textarea class="init-cm">${oldCM.getTextArea().value}</textarea>` | ||
}) | ||
for (let iframe of body.querySelectorAll("iframe")) { | ||
if (iframe.dataset.datauri) { | ||
iframe.src = iframe.dataset.datauri | ||
|
@@ -52,13 +54,33 @@ export const offline_html = async ({ pluto_version, body, head }) => { | |
<link rel="stylesheet" href="${CDNified(pluto_version, "treeview.css")}" type="text/css" /> | ||
<link rel="stylesheet" href="${CDNified(pluto_version, "hide-ui.css")}" type="text/css" /> | ||
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/lib/codemirror.min.css" type="text/css" /> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/lib/codemirror.min.js" defer></script> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/mode/julia/julia.min.js" defer></script> | ||
${head.querySelector("style#MJX-SVG-styles").outerHTML} | ||
</head> | ||
<body> | ||
${body.querySelector("main").outerHTML} | ||
${body.querySelector("svg#MJX-SVG-global-cache").outerHTML} | ||
</body> | ||
<script> | ||
const cmOptions = { | ||
lineNumbers: true, | ||
mode: "julia", | ||
lineWrapping: true, | ||
viewportMargin: Infinity, | ||
placeholder: "Enter cell code...", | ||
indentWithTabs: true, | ||
indentUnit: 4, | ||
cursorBlinkRate: -1, | ||
readOnly: false, | ||
} | ||
document.addEventListener("DOMContentLoaded", () => | ||
document.querySelectorAll(".init-cm").forEach(textArea => { | ||
CodeMirror.fromTextArea(textArea, cmOptions) | ||
}) | ||
) | ||
</script> | ||
</html> | ||
` | ||
} catch (error) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters