🔨 Update docs Termynal scripts to not include line nums for local dev (#882)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Sebastián Ramírez · committed by GitHub · parent 04eba6b · Browse files · 2 files·+109 added−93 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+109 added−93 removed
- other:+109 added−93 removed
Provenance
- Commit
cae23ed- Tree
876d334- Author
Sebastián Ramírez <tiangolo@gmail.com>- Committer
GitHub <noreply@github.com>- Parent
04eba6b
2 files changed+109 added−93 removed
modified:docs/css/custom.css+8 added
6 unmodified lines7891011121314151617185 unmodified lines24252627282930316 unmodified lines.termy [data-termynal] { white-space: pre-wrap;}
.termy .linenos { display: none;}
a.external-link::after { /* \00A0 is a non-breaking space to make the mark be on the same line as the link */5 unmodified lines to make the mark be on the same line as the link */ content: "\00A0↪";}
.shadow { box-shadow: 5px 5px 10px #999;}modified:docs/js/custom.js+101 added-93 removed
112342345676789101189101112131314151617181920212223242526141516171819202122232425262728293031323328293031343536373839404142433334353637383940414443444546474849505152535455565758596061626364656667686945464748495051525354555657585960616263646566676869707172737475767778798081717273747576777879828182838485868788838485868788899091929093949596979899100101102103104105106107108949596979899100101109110111103104105112113function setupTermynal() {document.querySelectorAll(".use-termynal").forEach(node => { node.style.display = "block"; new Termynal(node, { lineDelay: 500 document.querySelectorAll(".use-termynal").forEach(node => { node.style.display = "block"; new Termynal(node, { lineDelay: 500 }); });});const progressLiteralStart = "---> 100%";const promptLiteralStart = "$ ";const customPromptLiteralStart = "# ";const termynalActivateClass = "termy";let termynals = []; const progressLiteralStart = "---> 100%"; const promptLiteralStart = "$ "; const customPromptLiteralStart = "# "; const termynalActivateClass = "termy"; let termynals = [];
function createTermynals() { document .querySelectorAll(`.${termynalActivateClass} .highlight`) .forEach(node => { const text = node.textContent; const lines = text.split("\n"); const useLines = []; let buffer = []; function saveBuffer() { if (buffer.length) { let isBlankSpace = true; buffer.forEach(line => { if (line) { isBlankSpace = false; function createTermynals() { document .querySelectorAll(`.${termynalActivateClass} .highlight code`) .forEach(node => { const text = node.textContent; const lines = text.split("\n"); const useLines = []; let buffer = []; function saveBuffer() { if (buffer.length) { let isBlankSpace = true; buffer.forEach(line => { if (line) { isBlankSpace = false; } }); dataValue = {}; if (isBlankSpace) { dataValue["delay"] = 0; } }); dataValue = {}; if (isBlankSpace) { dataValue["delay"] = 0; if (buffer[buffer.length - 1] === "") { // A last single <br> won't have effect // so put an additional one buffer.push(""); } const bufferValue = buffer.join("<br>"); dataValue["value"] = bufferValue; useLines.push(dataValue); buffer = []; } if (buffer[buffer.length - 1] === "") { // A last single <br> won't have effect // so put an additional one buffer.push(""); } const bufferValue = buffer.join("<br>"); dataValue["value"] = bufferValue; useLines.push(dataValue); buffer = []; } } for (let line of lines) { if (line === progressLiteralStart) { saveBuffer(); useLines.push({ type: "progress" }); } else if (line.startsWith(promptLiteralStart)) { saveBuffer(); const value = line.replace(promptLiteralStart, "").trimEnd(); useLines.push({ type: "input", value: value }); } else if (line.startsWith("// ")) { saveBuffer(); const value = "💬 " + line.replace("// ", "").trimEnd(); useLines.push({ value: value, class: "termynal-comment", delay: 0 }); } else if (line.startsWith(customPromptLiteralStart)) { saveBuffer(); const promptStart = line.indexOf(promptLiteralStart); if (promptStart === -1) { console.error("Custom prompt found but no end delimiter", line) for (let line of lines) { if (line === progressLiteralStart) { saveBuffer(); useLines.push({ type: "progress" }); } else if (line.startsWith(promptLiteralStart)) { saveBuffer(); const value = line.replace(promptLiteralStart, "").trimEnd(); useLines.push({ type: "input", value: value }); } else if (line.startsWith("// ")) { saveBuffer(); const value = "💬 " + line.replace("// ", "").trimEnd(); useLines.push({ value: value, class: "termynal-comment", delay: 0 }); } else if (line.startsWith(customPromptLiteralStart)) { saveBuffer(); const promptStart = line.indexOf(promptLiteralStart); if (promptStart === -1) { console.error("Custom prompt found but no end delimiter", line) } const prompt = line.slice(0, promptStart).replace(customPromptLiteralStart, "") let value = line.slice(promptStart + promptLiteralStart.length); useLines.push({ type: "input", value: value, prompt: prompt }); } else { buffer.push(line); } const prompt = line.slice(0, promptStart).replace(customPromptLiteralStart, "") let value = line.slice(promptStart + promptLiteralStart.length); useLines.push({ type: "input", value: value, prompt: prompt }); } else { buffer.push(line); } } saveBuffer(); const div = document.createElement("div"); node.replaceWith(div); const termynal = new Termynal(div, { lineData: useLines, noInit: true, lineDelay: 500 saveBuffer(); const div = document.createElement("div"); node.replaceWith(div); const termynal = new Termynal(div, { lineData: useLines, noInit: true, lineDelay: 500 }); termynals.push(termynal); }); termynals.push(termynal); }
function loadVisibleTermynals() { termynals = termynals.filter(termynal => { if (termynal.container.getBoundingClientRect().top - innerHeight <= 0) { termynal.init(); return false; } return true; }); } window.addEventListener("scroll", loadVisibleTermynals); createTermynals(); loadVisibleTermynals();}
function loadVisibleTermynals() { termynals = termynals.filter(termynal => { if (termynal.container.getBoundingClientRect().top - innerHeight <= 0) { termynal.init(); return false; } return true; });async function main() { setupTermynal()}window.addEventListener("scroll", loadVisibleTermynals);createTermynals();loadVisibleTermynals();
main()