« get me outta code hell

no paragraph break if previous line ends with <br> - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2022-03-07 20:57:40 -0400
committer(quasar) nebula <qznebula@protonmail.com>2022-03-07 20:57:40 -0400
commitfc6561a9b8603f2ab7732991b5b68a316413c1d2 (patch)
tree028decb4d7a243a6f3f29d07eb80ddf843e24725
parente7c19e97447c69fdda5a89fcabda47f136578753 (diff)
no paragraph break if previous line ends with <br>
-rwxr-xr-xsrc/upd8.js24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/upd8.js b/src/upd8.js
index 96fb310..0d5a3ec 100755
--- a/src/upd8.js
+++ b/src/upd8.js
@@ -484,6 +484,26 @@ function parseAttributes(string, {to}) {
     ]));
 }
 
+function joinLineBreaks(sourceLines) {
+    const outLines = [];
+
+    let lineSoFar = '';
+    for (let i = 0; i < sourceLines.length; i++) {
+        const line = sourceLines[i];
+        lineSoFar += line;
+        if (!line.endsWith('<br>')) {
+            outLines.push(lineSoFar);
+            lineSoFar = '';
+        }
+    }
+
+    if (lineSoFar) {
+        outLines.push(lineSoFar);
+    }
+
+    return outLines;
+}
+
 function transformMultiline(text, {
     parseAttributes,
     transformInline
@@ -529,7 +549,9 @@ function transformMultiline(text, {
     // interested in doing lol. sorry!!!
     let inBlockquote = false;
 
-    for (let line of splitLines(text)) {
+    let lines = splitLines(text);
+    lines = joinLineBreaks(lines);
+    for (let line of lines) {
         const imageLine = line.startsWith('<img');
         line = line.replace(/<img (.*?)>/g, (match, attributes) => img({
             lazy: true,