« get me outta code hell

let lyrics be specified w/o terrible <br> format - 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-01-29 12:42:22 -0400
committer(quasar) nebula <towerofnix@gmail.com>2021-02-01 12:25:20 -0400
commit8d678d9f4688266d12323b06fa23810731147bef (patch)
tree6800f485b7d305cf6dda7d25440855e711a8adb7
parentbb50b1788d4d25d549a38d85c02d2de5f23bf1cb (diff)
let lyrics be specified w/o terrible <br> format
-rw-r--r--upd8.js37
1 files changed, 35 insertions, 2 deletions
diff --git a/upd8.js b/upd8.js
index 94cb4368..77e2a3d7 100644
--- a/upd8.js
+++ b/upd8.js
@@ -571,7 +571,40 @@ function transformMultiline(text, treatAsDocument=false) {
     }
 
     return outLines.join('\n');
-};
+}
+
+function transformLyrics(text) {
+    // Different from transformMultiline 'cuz it joins multiple lines together
+    // with line 8reaks (<br>); transformMultiline treats each line as its own
+    // complete paragraph (or list, etc).
+
+    // If it looks like old data, then like, oh god.
+    // Use the normal transformMultiline tool.
+    if (text.includes('<br')) {
+        return transformMultiline(text);
+    }
+
+    text = transformInline(text.trim());
+
+    let buildLine = '';
+    const addLine = () => outLines.push(`<p>${buildLine}</p>`);
+    const outLines = [];
+    for (const line of text.split('\n')) {
+        if (line.length) {
+            if (buildLine.length) {
+                buildLine += '<br>';
+            }
+            buildLine += line;
+        } else if (buildLine.length) {
+            addLine();
+            buildLine = '';
+        }
+    }
+    if (buildLine.length) {
+        addLine();
+    }
+    return outLines.join('\n');
+}
 
 function getCommentaryField(lines) {
     const text = getMultilineField(lines, 'Commentary');
@@ -2174,7 +2207,7 @@ async function writeTrackPage(track) {
                 ${track.lyrics && fixWS`
                     <p>Lyrics:</p>
                     <blockquote>
-                        ${transformMultiline(track.lyrics)}
+                        ${transformLyrics(track.lyrics)}
                     </blockquote>
                 `}
                 ${commentary && fixWS`