From d40dd4bf4c58e105ff6bc80c44aedf525dcb8d96 Mon Sep 17 00:00:00 2001 From: kor Date: Sun, 26 Aug 2018 01:31:20 +1200 Subject: [PATCH] Fix runic parse render order for media/quote with other runes. --- docs/logic/lib/runic.js | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/docs/logic/lib/runic.js b/docs/logic/lib/runic.js index 964e145..ce2e5d5 100644 --- a/docs/logic/lib/runic.js +++ b/docs/logic/lib/runic.js @@ -50,12 +50,22 @@ function Runic(raw) var lines = raw; var lines = !Array.isArray(raw) ? raw.split("\n") : raw; - for(id in lines){ + for(let id in lines) + { var char = lines[id].substr(0,1).trim().toString() var rune = this.runes[char]; + var trail = lines[id].substr(1,1); - if(char == "%"){ html += this.media(lines[id].substr(2)); continue; } - if(char == "@"){ html += this.quote(lines[id].substr(2)); continue; } + if(char == "%"){ + if(this.stash.is_pop(rune)){ html += this.render_stash(); } + html += this.media(lines[id].substr(2)); + continue; + } + if(char == "@"){ + if(this.stash.is_pop(rune)){ html += this.render_stash(); } + html += this.media(lines[id].substr(2)); + continue; + } var line = lines[id].substr(2).to_markup(); if(!line || line.trim() == ""){ continue; } if(!rune){ console.log(`Unknown rune:${char} : ${line}`); } @@ -75,7 +85,7 @@ function Runic(raw) var stash = this.stash.pop(); var html = ""; - for(id in stash){ + for(let id in stash){ var rune = stash[id].rune; var line = stash[id].item; html += rune.wrap ? `<${rune.sub}><${rune.wrap}>${line.replace(/\|/g,`<${rune.wrap}>`).trim()}` : `<${rune.sub}>${line}`; @@ -94,21 +104,21 @@ function Runic(raw) this.media = function(val) { var service = val.split(" ")[0]; - var id = val.split(" ")[1]; + let id = val.split(" ")[1]; if(service == "itchio"){ - return ``; + return ``; } if(service == "bandcamp"){ return ``; } if(service == "youtube"){ - return ``; + return ``; } if(service == "custom"){ return ``; } - return `` + return `` } this.quote = function(content) @@ -156,7 +166,7 @@ String.prototype.to_markup = function() html = html.replace(/{\#/g,"").replace(/\#}/g,"") var parts = html.split("{{") - for(id in parts){ + for(let id in parts){ var part = parts[id]; if(part.indexOf("}}") == -1){ continue; } var content = part.split("}}")[0]; @@ -168,4 +178,7 @@ String.prototype.to_markup = function() return html; } - +String.prototype.toProperCase = function () +{ + return this.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();}); +} \ No newline at end of file