Skip to content

Commit ae7503e

Browse files
committed
fix: render hr/blockquote as div to survive host blog skins
1 parent 26c01ce commit ae7503e

3 files changed

Lines changed: 20 additions & 1 deletion

File tree

js/app.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ async function render() {
1212
tmp.innerHTML = marked.parse(md);
1313
inlineStyle(tmp); // bake inline styles onto every element
1414
applyCallouts(tmp); // turn `[!NOTE]` etc. blockquotes into callout boxes
15+
deSemanticize(tmp); // hr/blockquote → div so host skins can't re-decorate them
1516
await renderMermaid(tmp); // turn mermaid blocks into inline SVG
1617

1718
const html = tmp.innerHTML;

js/convert.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,19 @@ function applyCallouts(container) {
9999
});
100100
return container;
101101
}
102+
103+
/* Replace <hr> and <blockquote> with plain <div>s that keep the same inline style.
104+
Host blog skins (e.g. some Tistory themes) decorate these semantic tags with
105+
their own CSS pseudo-elements — dotted dividers, giant quote marks — that inline
106+
styles can't override. Rendering them as <div> escapes that styling entirely.
107+
Call last, after inlineStyle and applyCallouts have set the styles. */
108+
function deSemanticize(container) {
109+
const toDiv = el => {
110+
const div = document.createElement('div');
111+
if (el.hasAttribute('style')) div.setAttribute('style', el.getAttribute('style'));
112+
while (el.firstChild) div.appendChild(el.firstChild);
113+
el.replaceWith(div);
114+
};
115+
container.querySelectorAll('hr, blockquote').forEach(toDiv);
116+
return container;
117+
}

js/theme.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ const STYLE = {
3838

3939
a: 'color: #1971c2; text-decoration: underline;',
4040
img: 'max-width: 100%; height: auto; border-radius: 6px;',
41-
hr: 'border: none; border-top: 1px solid #eaeaea; margin: 2em 0;',
41+
// Divider — rendered as a <div> (not <hr>) so host skins can't decorate it with
42+
// dotted/image styles. Translucent gray shows on both dark and light backgrounds.
43+
hr: 'height: 0; border: 0; border-top: 1px solid rgba(128,128,128,0.4); margin: 2em 0;',
4244
strong: 'font-weight: 700;',
4345
em: 'font-style: italic;',
4446
del: 'text-decoration: line-through; color: #888;',

0 commit comments

Comments
 (0)