mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
Change logic to detect inline elements, as the display style property may not be set after setting innerHTML
This commit is contained in:
parent
520c4a3b4d
commit
feddf96f2a
1 changed files with 59 additions and 5 deletions
|
@ -117,14 +117,68 @@ function nodeIsText(node: Node): node is Text {
|
||||||
return node.nodeType === Node.TEXT_NODE;
|
return node.nodeType === Node.TEXT_NODE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const INLINE_TAGS = [
|
||||||
|
"A",
|
||||||
|
"ABBR",
|
||||||
|
"ACRONYM",
|
||||||
|
"AUDIO",
|
||||||
|
"B",
|
||||||
|
"BDI",
|
||||||
|
"BDO",
|
||||||
|
"BIG",
|
||||||
|
"BR",
|
||||||
|
"BUTTON",
|
||||||
|
"CANVAS",
|
||||||
|
"CITE",
|
||||||
|
"CODE",
|
||||||
|
"DATA",
|
||||||
|
"DATALIST",
|
||||||
|
"DEL",
|
||||||
|
"DFN",
|
||||||
|
"EM",
|
||||||
|
"EMBED",
|
||||||
|
"I",
|
||||||
|
"IFRAME",
|
||||||
|
"IMG",
|
||||||
|
"INPUT",
|
||||||
|
"INS",
|
||||||
|
"KBD",
|
||||||
|
"LABEL",
|
||||||
|
"MAP",
|
||||||
|
"MARK",
|
||||||
|
"METER",
|
||||||
|
"NOSCRIPT",
|
||||||
|
"OBJECT",
|
||||||
|
"OUTPUT",
|
||||||
|
"PICTURE",
|
||||||
|
"PROGRESS",
|
||||||
|
"Q",
|
||||||
|
"RUBY",
|
||||||
|
"S",
|
||||||
|
"SAMP",
|
||||||
|
"SCRIPT",
|
||||||
|
"SELECT",
|
||||||
|
"SLOT",
|
||||||
|
"SMALL",
|
||||||
|
"SPAN",
|
||||||
|
"STRONG",
|
||||||
|
"SUB",
|
||||||
|
"SUP",
|
||||||
|
"SVG",
|
||||||
|
"TEMPLATE",
|
||||||
|
"TEXTAREA",
|
||||||
|
"TIME",
|
||||||
|
"U",
|
||||||
|
"TT",
|
||||||
|
"VAR",
|
||||||
|
"VIDEO",
|
||||||
|
"WBR",
|
||||||
|
];
|
||||||
|
|
||||||
function nodeIsInline(node: Node): boolean {
|
function nodeIsInline(node: Node): boolean {
|
||||||
return (
|
return (
|
||||||
nodeIsText(node) ||
|
nodeIsText(node) ||
|
||||||
nodeIsBRElement(node) ||
|
INLINE_TAGS.includes((node as Element).tagName)
|
||||||
window
|
|
||||||
.getComputedStyle(node as Element)
|
|
||||||
.getPropertyValue("display")
|
|
||||||
.startsWith("inline")
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue