32 lines
No EOL
1.1 KiB
JavaScript
32 lines
No EOL
1.1 KiB
JavaScript
var fs = require("fs");
|
|
|
|
let file = fs.readFileSync("../Test.md").toString().split("\n");
|
|
|
|
var list = [];
|
|
let last = null;
|
|
|
|
const format = s => s.replace(/(["„“”]([^"„“”]*)["„“”])/g, "„$2“");
|
|
|
|
for (let i = 0; i < file.length; i++) {
|
|
const line = file[i];
|
|
if (line.trim() == "") continue;
|
|
if (!isNaN(Number(line[0]))) {
|
|
if (last != null) list.push(last);
|
|
last = {
|
|
quest: format(line.split(" ").slice(1).join(" ")),
|
|
answers: [],
|
|
correct: -1,
|
|
explanation: null
|
|
};
|
|
}
|
|
if (line[0] == "A") last.answers[0] = format(line.substring(3));
|
|
if (line[0] == "B") last.answers[1] = format(line.substring(3));
|
|
if (line[0] == "C") last.answers[2] = format(line.substring(3));
|
|
if (line[0] == "D") last.answers[3] = format(line.substring(3));
|
|
if (line.startsWith("-> ")) {
|
|
last.correct = "ABCD".indexOf(line.substring(3, 4));
|
|
last.explanation = format(line.substring(6));
|
|
}
|
|
}
|
|
//console.log(list);
|
|
fs.writeFileSync("../Test.json", JSON.stringify({ "name": "schlüko", "questions": list }, null, 2)); |