« get me outta code hell

Merge branch 'commentary-entries' into album-commentary-tweaks - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/content/dependencies
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-11-18 20:41:08 -0400
committer(quasar) nebula <qznebula@protonmail.com>2023-11-18 20:41:08 -0400
commit5bc43a8bc8132a9d2cfa57937aa46fda56b663e5 (patch)
tree95f770dfa3c3bb5ed7e2abc30663b275da2973ff /src/content/dependencies
parentf481591b859282e1ea5483c89552375f5570e9e5 (diff)
parente35d23f4e9492b497138dce3f21382872e329e71 (diff)
Merge branch 'commentary-entries' into album-commentary-tweaks
Diffstat (limited to 'src/content/dependencies')
-rw-r--r--src/content/dependencies/generateCommentaryEntry.js13
-rw-r--r--src/content/dependencies/transformContent.js57
2 files changed, 47 insertions, 23 deletions
diff --git a/src/content/dependencies/generateCommentaryEntry.js b/src/content/dependencies/generateCommentaryEntry.js
index b265ed41..0b2b2558 100644
--- a/src/content/dependencies/generateCommentaryEntry.js
+++ b/src/content/dependencies/generateCommentaryEntry.js
@@ -1,3 +1,5 @@
+import {empty} from '#sugar';
+
 export default {
   contentDependencies: [
     'generateColorStyleVariables',
@@ -8,9 +10,10 @@ export default {
   extraDependencies: ['html', 'language'],
 
   relations: (relation, entry) => ({
-    artistLink:
-      (entry.artist && !entry.artistDisplayText
-        ? relation('linkArtist', entry.artist)
+    artistLinks:
+      (!empty(entry.artists) && !entry.artistDisplayText
+        ? entry.artists
+            .map(artist => relation('linkArtist', artist))
         : null),
 
     artistsContent:
@@ -45,8 +48,8 @@ export default {
       html.tag('span', {class: 'commentary-entry-artists'},
         (relations.artistsContent
           ? relations.artistsContent.slot('mode', 'inline')
-       : relations.artistLink
-          ? relations.artistLink
+       : relations.artistLinks
+          ? language.formatConjunctionList(relations.artistLinks)
           : language.$('misc.artistCommentary.entry.title.noArtists')));
 
     const accentParts = ['misc.artistCommentary.entry.title.accent'];
diff --git a/src/content/dependencies/transformContent.js b/src/content/dependencies/transformContent.js
index a85ac158..b0a7796c 100644
--- a/src/content/dependencies/transformContent.js
+++ b/src/content/dependencies/transformContent.js
@@ -1,7 +1,7 @@
 import {bindFind} from '#find';
 import {parseInput} from '#replacer';
 
-import {marked} from 'marked';
+import {Marked} from 'marked';
 
 export const replacerSpec = {
   album: {
@@ -147,6 +147,29 @@ const linkIndexRelationMap = {
   newsIndex: 'linkNewsIndex',
 };
 
+const commonMarkedOptions = {
+  headerIds: false,
+  mangle: false,
+};
+
+const multilineMarked = new Marked({
+  ...commonMarkedOptions,
+});
+
+const inlineMarked = new Marked({
+  ...commonMarkedOptions,
+
+  renderer: {
+    paragraph(text) {
+      return text;
+    },
+  },
+});
+
+const lyricsMarked = new Marked({
+  ...commonMarkedOptions,
+});
+
 function getPlaceholder(node, content) {
   return {type: 'text', data: content.slice(node.i, node.iEnd)};
 }
@@ -447,21 +470,9 @@ export default {
       return link.data;
     }
 
-    // In inline mode, no further processing is needed!
-
-    if (slots.mode === 'inline') {
-      return html.tags(
-        contentFromNodes.map(node => node.data),
-        {[html.joinChildren]: ''});
-    }
-
-    // Multiline mode has a secondary processing stage where it's passed...
-    // through marked! Rolling your own Markdown only gets you so far :D
-
-    const markedOptions = {
-      headerIds: false,
-      mangle: false,
-    };
+    // Content always goes through marked (i.e. parsing as Markdown).
+    // This does require some attention to detail, mostly to do with line
+    // breaks (in multiline mode) and extracting/re-inserting non-text nodes.
 
     // The content of non-text nodes can end up getting mangled by marked.
     // To avoid this, we replace them with mundane placeholders, then
@@ -536,6 +547,16 @@ export default {
       return html.tags(tags, {[html.joinChildren]: ''});
     };
 
+    if (slots.mode === 'inline') {
+      const markedInput =
+        extractNonTextNodes();
+
+      const markedOutput =
+        inlineMarked.parse(markedInput);
+
+      return reinsertNonTextNodes(markedOutput);
+    }
+
     // This is separated into its own function just since we're gonna reuse
     // it in a minute if everything goes to heck in lyrics mode.
     const transformMultiline = () => {
@@ -552,7 +573,7 @@ export default {
           .replace(/(?<=^>.*)\n+(?!^>)/gm, '\n\n');
 
       const markedOutput =
-        marked.parse(markedInput, markedOptions);
+        multilineMarked.parse(markedInput);
 
       return reinsertNonTextNodes(markedOutput);
     }
@@ -602,7 +623,7 @@ export default {
         });
 
       const markedOutput =
-        marked.parse(markedInput, markedOptions);
+        lyricsMarked.parse(markedInput);
 
       return reinsertNonTextNodes(markedOutput);
     }