« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/util')
-rw-r--r--src/util/html.js12
-rw-r--r--src/util/replacer.js5
2 files changed, 13 insertions, 4 deletions
diff --git a/src/util/html.js b/src/util/html.js
index 712a0a68..4e243f7d 100644
--- a/src/util/html.js
+++ b/src/util/html.js
@@ -470,6 +470,18 @@ export class Attributes {
     return delete this.#attributes[attribute];
   }
 
+  push(attribute, ...values) {
+    const oldValue = this.get(attribute);
+    const newValue =
+      (Array.isArray(oldValue)
+        ? oldValue.concat(values)
+     : oldValue
+        ? [oldValue, ...values]
+        : values);
+    this.set(attribute, newValue);
+    return newValue;
+  }
+
   toString() {
     return Object.entries(this.attributes)
       .map(([key, val]) => {
diff --git a/src/util/replacer.js b/src/util/replacer.js
index ac23bf46..028cd3ba 100644
--- a/src/util/replacer.js
+++ b/src/util/replacer.js
@@ -382,10 +382,7 @@ export function postprocessHeadings(inputNodes) {
       parseFrom = match.index + match[0].length;
 
       const attributes = html.attributes(parseAttributes(match[1]));
-
-      attributes.set('class',
-        (attributes.get('class') ?? [])
-          .concat(['content-heading']));
+      attributes.push('class', 'content-heading');
 
       // We're only modifying the opening tag here. The remaining content,
       // including the closing tag, will be pushed as-is.