From 17681e690eb83f02f07a3d119c9117f241ba26c1 Mon Sep 17 00:00:00 2001 From: KillyMXI Date: Sun, 16 Jul 2017 00:59:10 +0300 Subject: www: fix js markup parser: prevent high-priority rules to run again after low priority rules --- juick-www/src/main/js/killy/index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'juick-www/src/main/js') diff --git a/juick-www/src/main/js/killy/index.js b/juick-www/src/main/js/killy/index.js index 136a5825..5f59225c 100644 --- a/juick-www/src/main/js/killy/index.js +++ b/juick-www/src/main/js/killy/index.js @@ -22,12 +22,13 @@ function formatText(txt, rules) { .sort(([r1,m1],[r2,m2]) => (r1.pr - r2.pr) || (m1.index - m2.index)); if (matches && matches.length > 0) { let [rule, match] = matches[0]; + let subsequentRules = rules.filter(r => r.pr >= rule.pr); let idStr = `<>(${nextId()})<>`; let outerStr = txt.substring(0, match.index) + idStr + txt.substring(rule.re.lastIndex); let innerStr = (rule.brackets) - ? (() => { let [l ,r ,f] = rule.with; return l + ft((f ? f(match[1]) : match[1]), rules) + r; })() + ? (() => { let [l ,r ,f] = rule.with; return l + ft((f ? f(match[1]) : match[1]), subsequentRules) + r; })() : match[0].replace(rule.re, rule.with); - return ft(outerStr, rules).replace(idStr, innerStr); + return ft(outerStr, subsequentRules).replace(idStr, innerStr); } return txt; } -- cgit v1.2.3