diff --git a/js/bad_schlüko_parser.js b/js/bad_schlüko_parser.js new file mode 100644 index 0000000..ff38d76 --- /dev/null +++ b/js/bad_schlüko_parser.js @@ -0,0 +1,32 @@ +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)); \ No newline at end of file