« get me outta code hell

Merge pull request #139 from hsmusic/preserve-h2-class - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2023-01-15 20:28:54 -0400
committerGitHub <noreply@github.com>2023-01-15 20:28:54 -0400
commitae2cbbcdf08628bb51cb1579b3195e676c3da5be (patch)
tree8f70e4cdb354c0615368209e21bd837dcc6ddc2a
parentacc7f548dd73c36d86acd6497e67040a824dcc72 (diff)
parent13c70bcce020dd2768eb2ed10d724cdaa276326a (diff)
Merge pull request #139 from hsmusic/preserve-h2-class
Preserve <h2> class when stickyalizing it
-rwxr-xr-xsrc/upd8.js10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/upd8.js b/src/upd8.js
index 920f9039..a793feb6 100755
--- a/src/upd8.js
+++ b/src/upd8.js
@@ -572,8 +572,14 @@ function transformMultiline(text, {
       }
 
       // for sticky headings!
-      if (elementMatch) {
-        lineContent = lineContent.replace(/<h2/, `<h2 class="content-heading"`)
+      if (elementMatch && elementMatch[1] === 'h2') {
+        lineContent = lineContent.replace(/<h2(.*?)>/g, (match, attributes) => {
+          const parsedAttributes = parseAttributes(attributes, {to});
+          return `<h2 ${html.attributes({
+            ...parsedAttributes,
+            class: [...parsedAttributes.class?.split(' ') ?? [], 'content-heading'],
+          })}>`;
+        });
       }
     }