« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/common-util
diff options
context:
space:
mode:
Diffstat (limited to 'src/common-util')
-rw-r--r--src/common-util/wiki-data.js29
1 files changed, 27 insertions, 2 deletions
diff --git a/src/common-util/wiki-data.js b/src/common-util/wiki-data.js
index 0aa18ddb..a4c6b3bd 100644
--- a/src/common-util/wiki-data.js
+++ b/src/common-util/wiki-data.js
@@ -103,10 +103,35 @@ export const commentaryRegexCaseSensitiveOneShot =
   new RegExp(commentaryRegexRaw);
 
 // The #validators function isOldStyleLyrics() describes
-// what this regular expression detects.
-export const oldStyleLyricsDetectionRegex =
+// what this regular expression detects against.
+export const multipleLyricsDetectionRegex =
   /^<i>.*:<\/i>/m;
 
+export function matchContentEntries(sourceText) {
+  const matchEntries = [];
+
+  let previousMatchEntry = null;
+  let previousEndIndex = null;
+
+  for (const {0: matchText, index: startIndex, groups: matchEntry}
+          of sourceText.matchAll(commentaryRegexCaseSensitive)) {
+    if (previousMatchEntry) {
+      previousMatchEntry.body = sourceText.slice(previousEndIndex, startIndex);
+    }
+
+    matchEntries.push(matchEntry);
+
+    previousMatchEntry = matchEntry;
+    previousEndIndex = startIndex + matchText.length;
+  }
+
+  if (previousMatchEntry) {
+    previousMatchEntry.body = sourceText.slice(previousEndIndex);
+  }
+
+  return matchEntries;
+}
+
 export function filterAlbumsByCommentary(albums) {
   return albums
     .filter((album) => [album, ...album.tracks].some((x) => x.commentary));