ta-bu-ta read-block
·
3 mins read
·
edit
result
26c14.html
<div id="container"><div>
<script src="26b39.js"></script>
<script src="26b41.js"></script>
<script src="26b43.js"></script>
<script src="26b10.js"></script>
<script src="26b12.js"></script>
<script src="26b14.js"></script>
<script>
// Define global variables
let blockA = null, blockB = null;
// Instantiate containers, output textarea, and buttons
const cnt = getContainer("container");
const inTxa = createTextarea("text-input");
const outTxa = createTextarea("text-output");
const btnDiv = createDiv("button-container");
const ciBtn = createButton("ci-button", "Clear input");
const coBtn = createButton("co-button", "Clear output");
const deBtn = createButton("de-button", "Default");
const rbBtn = createButton("rp-button", "Read blocks");
// Append textarea to container
cnt.append(inTxa);
cnt.append(btnDiv);
cnt.append(outTxa);
btnDiv.append(ciBtn);
btnDiv.append(coBtn);
btnDiv.append(deBtn);
btnDiv.append(rbBtn);
// Change elements flex value
changeElementsFlex(
["text-input", "3"],
["button-container", "3"] ,
["text-output", "3"],
);
// Change ui height
cnt.style.height = "19em";
inTxa.style.height = "100%";
outTxa.style.height = "100%";
// Bind consolex output to textarea and set EOL character
consolex.setOutput(outTxa);
consolex.setEOL("");
// Set onclick event to each button
ciBtn.addEventListener("click", () => {
clearTextarea("text-input");
});
coBtn.addEventListener("click", () => {
clearTextarea("text-output");
});
deBtn.addEventListener("click", () => {
inTxa.value = "";
inTxa.value += "# dataset 1";
inTxa.value += "\n" + "X;Y";
inTxa.value += "\n" + "1;1";
inTxa.value += "\n" + "2;4";
inTxa.value += "\n" + "3;9";
inTxa.value += "\n" + "4;16";
inTxa.value += "\n" + "5;25";
inTxa.value += "\n";
inTxa.value += "\n# dataset 2";
inTxa.value += "\n" + "X;Y;Z";
inTxa.value += "\n" + "1;2;5";
inTxa.value += "\n" + "2;4;10";
inTxa.value += "\n" + "3;6;15";
inTxa.value += "\n" + "4;8;20";
inTxa.value += "\n" + "5;10;25";
inTxa.value += "\n";
});
rbBtn.addEventListener("click", () => {
let key;
key = "# dataset 1";
blockA = readBlockFromTextarea("text-input", key);
outTxa.value += "BLOCKA=\n" + blockA + "\n";
key = "# dataset 2";
blockB = readBlockFromTextarea("text-input", key);
outTxa.value += "BLOCKB=\n" + blockB + "\n";
});
</script>
26c14.js
/**
* 26c14.js
* Helper functions for butiran-x/26c14 note.
*
* Author: Sparisoma Viridi (https://github.com/dudung)
* Created: 2026-03-03
*
* Exports:
* - readBlockFromTexarea(id, key)
*/
/**
* Reads a block from a textarea element that starts with the specified key
* and ends with a blank line.
*
* @param {string} id - The ID of the textarea element to read from.
* @param {string} key - The key (first word) identifying the start of the block.
* @returns {string} The extracted block as a string (excluding the terminating blank line).
*
* @example
* const block = readBlockFromTextarea("text-input", "KEY");
*/
function readBlockFromTextarea(id, key) {
/** @type {HTMLTextareaElement|null} */
const el = document.getElementById(id);
if (!(el instanceof HTMLTextAreaElement)) return null;
let reading_block = false;
const lines = el.value.split("\n");
let block = null;
for(l of lines) {
if(l.length == 0) {
reading_block = false;
}
if(reading_block) {
block.push(l);
}
if(l.indexOf(key) == 0) {
block = [];
reading_block = true;
}
}
if(block != null) {
let block2 = block.join("\n");
block = block2;
}
return block;
}
// marker: 26c14.js
(() => {
console.log("[marker] 26c14.js loaded");
})();