From a44ebe6c0790ed5a1dc08bc27e4e8c59155e931a Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Wed, 9 Aug 2023 18:36:35 -0300 Subject: content: transformContent: fix lyrics-mode line break bugs --- src/content/dependencies/transformContent.js | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/content/dependencies/transformContent.js b/src/content/dependencies/transformContent.js index 93669cc..cc4e7a3 100644 --- a/src/content/dependencies/transformContent.js +++ b/src/content/dependencies/transformContent.js @@ -517,12 +517,29 @@ export default { // multiline. return marked.parse( contentFromNodes - .map(node => { - if (node.type === 'text') { - return node.data.replace(/\b\n\b/g, '
\n'); - } else { + .map((node, index) => { + if (node.type !== 'text') { return node.data.toString(); } + + // First, replace line breaks that follow text content with + //
tags. + let content = node.data.replace(/(?!^)\n/gm, '
\n'); + + // Scrap line breaks that are at the end of a verse. + content = content.replace(/
$(?=\n\n)/gm, ''); + + // If the node started with a line break, and it's not the + // very first node, then whatever came before it was inline. + // (This is an assumption based on text links being basically + // the only tag that shows up in lyrics.) Since this text is + // following content that was already inline, restore that + // initial line break. + if (node.data[0] === '\n' && index !== 0) { + content = '
' + content; + } + + return content; }) .join(''), markedOptions); -- cgit 1.3.0-6-gf8a5