From 3540f1997837102324f9e7abb61ab97ab9ba74d8 Mon Sep 17 00:00:00 2001 From: HF Date: Sun, 10 Jul 2022 13:32:27 +0200 Subject: [PATCH] remove escape characters after parsing enclosure --- src/core/MString.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/core/MString.js b/src/core/MString.js index e9f397e..e451a86 100644 --- a/src/core/MString.js +++ b/src/core/MString.js @@ -112,13 +112,15 @@ export default class MString { * moves iter to last closing braked if it is enclosure */ checkIfEnclosure(zIsLink) { - const yStart = this.iter + 1; + let yStart = this.iter + 1; let yEnd = yStart; + const escapePositions = []; while (this.txt[yEnd] !== ']') { const chr = this.txt[yEnd]; if (chr === '\\') { // escape character + escapePositions.push(yEnd); yEnd += 2; continue; } @@ -168,7 +170,17 @@ export default class MString { if (!zIsLink) { z = this.txt.slice(zStart, zEnd); } - const y = this.txt.slice(yStart, yEnd); + + let y = ''; + // remove escape characters + for (let iter = 0; iter < escapePositions.length; iter += 1) { + const escapePosition = escapePositions[iter]; + y += this.txt.slice(yStart, escapePosition); + yStart = escapePosition + 1; + } + if (yStart < yEnd) { + y += this.txt.slice(yStart, yEnd); + } this.iter = zEnd; return [y, z];