Skip to content

Commit

Permalink
fix: issue with header in callout font size (#521)
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianWoelki committed Jul 21, 2024
1 parent f5fdbc3 commit bbc8e92
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/editor/markdown-processors/icon-in-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ export const processIconInTextMarkdown = (
rootSpan.style.display = 'inline-flex';
rootSpan.style.transform = 'translateY(13%)';

const tagName = toReplace.parentElement?.tagName?.toLowerCase() ?? '';
const parentElement = toReplace.parentElement;
const tagName = parentElement?.tagName?.toLowerCase() ?? '';
let fontSize = calculateFontTextSize();

if (isHeader(tagName)) {
Expand All @@ -123,8 +124,24 @@ export const processIconInTextMarkdown = (
rootSpan.innerHTML = svgElement;
}

toReplace.parentElement?.insertBefore(rootSpan, toReplace);
parentElement?.insertBefore(rootSpan, toReplace);
toReplace.textContent = toReplace.wholeText.substring(code.text.length);

// Set the font size to its parent font size if defined.
// We do this after that to not freeze the insertion while iterating over the tree.
// We are also updating the size after the animation because the styling won't be set
// in the first place.
requestAnimationFrame(() => {
const parentFontSize = parseFloat(
getComputedStyle(parentElement).fontSize,
);
if (!isNaN(parentFontSize)) {
rootSpan.innerHTML = svg.setFontSize(
rootSpan.innerHTML,
parentFontSize,
);
}
});
}
});

Expand Down

0 comments on commit bbc8e92

Please sign in to comment.