Fix markup code block layout (#36578)

This commit is contained in:
wxiaoguang
2026-02-11 11:22:33 +08:00
committed by GitHub
parent 018a88590c
commit fd89ceef79
8 changed files with 84 additions and 119 deletions

View File

@@ -301,7 +301,7 @@ export function createElementFromHTML<T extends HTMLElement>(htmlString: string)
return div.firstChild as T;
}
export function createElementFromAttrs(tagName: string, attrs: Record<string, any> | null, ...children: (Node | string)[]): HTMLElement {
export function createElementFromAttrs<T extends HTMLElement>(tagName: string, attrs: Record<string, any> | null, ...children: (Node | string)[]): T {
const el = document.createElement(tagName);
for (const [key, value] of Object.entries(attrs || {})) {
if (value === undefined || value === null) continue;
@@ -314,7 +314,7 @@ export function createElementFromAttrs(tagName: string, attrs: Record<string, an
for (const child of children) {
el.append(child instanceof Node ? child : document.createTextNode(child));
}
return el;
return el as T;
}
export function animateOnce(el: Element, animationClassName: string): Promise<void> {
@@ -352,22 +352,6 @@ export function isPlainClick(e: MouseEvent) {
return e.button === 0 && !e.ctrlKey && !e.metaKey && !e.altKey && !e.shiftKey;
}
let cssRootVariablesTextCache: string = '';
export function getCssRootVariablesText(): string {
if (cssRootVariablesTextCache) return cssRootVariablesTextCache;
const style = getComputedStyle(document.documentElement);
let text = ':root {\n';
for (let i = 0; i < style.length; i++) {
const name = style.item(i);
if (name.startsWith('--')) {
text += ` ${name}: ${style.getPropertyValue(name)};\n`;
}
}
text += '}\n';
cssRootVariablesTextCache = text;
return text;
}
let elemIdCounter = 0;
export function generateElemId(prefix: string = ''): string {
return `${prefix}${elemIdCounter++}`;