diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2023-01-15 16:35:26 -0400 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2023-01-15 16:35:26 -0400 |
commit | 13c70bcce020dd2768eb2ed10d724cdaa276326a (patch) | |
tree | 7cfba4adf7f564aec1de5417ab7ddf0792d53aee | |
parent | 2803b20313cc4c3aa008bdbcd3abd407405ce91f (diff) |
preserve h2 class when stickyalizing it
-rwxr-xr-x | src/upd8.js | 10 |
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'], + })}>`; + }); } } |