From 685a4dd0b27ebeec41060702b6ae7ee785fe1dce Mon Sep 17 00:00:00 2001 From: Sergey Konovalov Date: Fri, 8 Aug 2025 16:21:21 +0300 Subject: [PATCH] [ve] Support text delimiters \r\n and \n --- visio/model/ooxmlApi/convertFunctions.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/visio/model/ooxmlApi/convertFunctions.js b/visio/model/ooxmlApi/convertFunctions.js index ef516b7cab..13de871512 100644 --- a/visio/model/ooxmlApi/convertFunctions.js +++ b/visio/model/ooxmlApi/convertFunctions.js @@ -1956,11 +1956,12 @@ if (typeof lastTextEl === "string") { if (lastTextEl.endsWith("\r\n")) { lastTextEl = lastTextEl.slice(0, lastTextEl.length - 2); + textElement.elements[textElement.elements.length - 1] = lastTextEl; } else if (lastTextEl.endsWith("\n")) { lastTextEl = lastTextEl.slice(0, lastTextEl.length - 1); + textElement.elements[textElement.elements.length - 1] = lastTextEl; } } - textElement.elements[textElement.elements.length - 1] = lastTextEl; // read text: // consider CRLF (\r\n) (UPD: \n for binary read) as new paragraph start. @@ -1981,15 +1982,18 @@ if (typeof textElementPart === "string" || textElementPart.kind === AscVisio.c_oVsdxTextKind.FLD) { if (typeof textElementPart === "string") { - // "LSCRLF" transforms to line drop and new paragraph without line drop so we get one - // line drop where should be two line drops so let's add extra line drop - textElementPart = textElementPart.replaceAll("\u2028\n", "\u2028\u2028\n"); // for new open: binary - textElementPart = textElementPart.replaceAll("\u2028\r\n", "\u2028\u2028\r\n"); // for old open - let textArr = textElementPart.split("\n"); + // Split on CRLF, or LF + let textArr = textElementPart.split(/\r\n|\n/); for (let j = 0; j < textArr.length; j++) { let text = textArr[j]; + // "LSCRLF" transforms to line drop and new paragraph without line drop so we get one + // line drop where should be two line drops so let's add extra line drop + if (j !== textArr.length - 1 && text.charAt(text.length - 1) === "\u2028") { + text += "\u2028"; + } + // if j > 0 CR exists in textArr and should be handled as new paragraph start if (j > 0) { let nextPP = searchForPP(textElement.elements, i, text);