Skip to content

Commit 1865cbe

Browse files
committed
Keep style & class attributes of heading tag
1 parent 16b31d9 commit 1865cbe

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

web/src/components/AutoStarlightPage.astro

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ const root = parse(slot ?? '', { lowerCaseTagName: false });
1414
const headings = [];
1515
1616
// AnchorHeading component source
17-
function renderAnchorHeading(level, id, text) {
17+
function renderAnchorHeading(level, id, text, classAttr = '', styleAttr = '') {
1818
const accessibleLabel = `Section ${text}`;
1919
2020
return `
2121
<div class="sl-heading-wrapper level-h${level}">
22-
<h${level} id="${id}">${text}</h${level}>
22+
<h${level} id="${id}" class="${classAttr}" style="${styleAttr}">${text}</h${level}>
2323
<a class="sl-anchor-link" href="#${id}">
2424
<span aria-hidden="true" class="sl-anchor-icon">
2525
<svg width="16" height="16" viewBox="0 0 24 24">
@@ -49,7 +49,10 @@ root.querySelectorAll('h2, h3').forEach((el) => {
4949
5050
headings.push({ depth: level, slug, text });
5151
52-
el.replaceWith(renderAnchorHeading(level, slug, escapeHtml(text)));
52+
const classAttr = el.getAttribute('class') || '';
53+
const styleAttr = el.getAttribute('style') || '';
54+
55+
el.replaceWith(renderAnchorHeading(level, slug, escapeHtml(text), classAttr, styleAttr));
5356
});
5457
5558
const finalHtml = root.toString();

0 commit comments

Comments
 (0)