« get me outta code hell

fix incorrect iEnd values on text nodes - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <towerofnix@gmail.com>2021-04-19 11:55:03 -0300
committer(quasar) nebula <towerofnix@gmail.com>2021-04-19 11:58:16 -0300
commit40f6c3b14aacdb96e1b20b4c2e3e1365ccd372c4 (patch)
treeb652a8a4dc5742f3d2c6ceb6db7c5902efc9d5ce
parent211edd269329c7d1ca73b6806030282b07e989ed (diff)
fix incorrect iEnd values on text nodes
The iEnd value (which marks the position a node's length ends at in
input text) is only used for tag nodes at the moment, 8ut it's still
nice to have the right values everywhere, in case we do use it for
something else later (and to just have code that functions like we want,
lol).
-rwxr-xr-xupd8.js9
1 files changed, 5 insertions, 4 deletions
diff --git a/upd8.js b/upd8.js
index 2be0eaaa..de6af973 100755
--- a/upd8.js
+++ b/upd8.js
@@ -1021,6 +1021,7 @@ const replacerSpec = {
         stopped = false;
 
         const pushTextNode = () => {
+            string = input.slice(iString, i);
             if (string.length) {
                 nodes.push({i: iString, iEnd: i, type: 'text', data: string});
                 string = '';
@@ -1053,7 +1054,7 @@ const replacerSpec = {
 
             if (!match) {
                 iString = i;
-                string = input.slice(i, input.length);
+                i = input.length;
                 pushTextNode();
                 break;
             }
@@ -1062,17 +1063,17 @@ const replacerSpec = {
             const closestMatchIndex = i + match.index;
 
             iString = i;
-            string = input.slice(i, closestMatchIndex);
+            i = closestMatchIndex;
             pushTextNode();
 
-            i = closestMatchIndex + closestMatch.length;
+            i += closestMatch.length;
 
             if (closestMatch !== tagBeginning) {
                 stopped = true;
                 stop_iMatch = closestMatchIndex;
                 stop_iParse = i;
                 stop_literal = closestMatch;
-                return nodes;
+                break;
             }
 
             if (closestMatch === tagBeginning) {