diff options
| author | bptato <nincsnevem662@gmail.com> | 2025-01-17 21:09:56 +0100 |
|---|---|---|
| committer | bptato <nincsnevem662@gmail.com> | 2025-01-17 21:09:56 +0100 |
| commit | 4c2028eb6d85b93fac25cc5ba2cdbb2ba0aaf7ff (patch) | |
| tree | b54e309e8c2052525ffe9c57e4976ea5b639dfc8 /src/html | |
| parent | 60821d1053c22dc281498f5f9cec4dfb655f04e7 (diff) | |
| download | chawan-4c2028eb6d85b93fac25cc5ba2cdbb2ba0aaf7ff.tar.gz | |
dom: compare rel case insensitively
Diffstat (limited to 'src/html')
| -rw-r--r-- | src/html/catom.nim | 4 | ||||
| -rw-r--r-- | src/html/dom.nim | 15 |
2 files changed, 12 insertions, 7 deletions
diff --git a/src/html/catom.nim b/src/html/catom.nim index c9927ab3..75ae5670 100644 --- a/src/html/catom.nim +++ b/src/html/catom.nim @@ -259,6 +259,10 @@ func toAtom*(factory: CAtomFactory; attrType: StaticAtom): CAtom = func toAtomLower*(factory: CAtomFactory; s: string): CAtom = return factory.lowerMap[int32(factory.toAtom(s))] +func containsIgnoreCase*(factory: CAtomFactory; aa: openArray[CAtom]; + a: StaticAtom): bool = + return factory.containsIgnoreCase(aa, factory.toAtom(a)) + func toStr*(factory: CAtomFactory; atom: CAtom): string = return factory.atomMap[int(atom)] diff --git a/src/html/dom.nim b/src/html/dom.nim index 4394f1a4..73bd52a4 100644 --- a/src/html/dom.nim +++ b/src/html/dom.nim @@ -1522,15 +1522,16 @@ proc item(ctx: JSContext; tokenList: DOMTokenList; u: uint32): JSValue return ctx.toJS(tokenList.toks[i]) return JS_NULL -func contains*(tokenList: DOMTokenList; a: CAtom): bool = +func contains(tokenList: DOMTokenList; a: CAtom): bool = return a in tokenList.toks -func contains(tokenList: DOMTokenList; a: StaticAtom): bool = - return tokenList.element.document.toAtom(a) in tokenList.toks +func containsIgnoreCase(tokenList: DOMTokenList; a: StaticAtom): bool = + let document = tokenList.element.document + return document.factory.containsIgnoreCase(tokenList.toks, a) func jsContains(tokenList: DOMTokenList; s: string): bool {.jsfunc: "contains".} = - return tokenList.element.document.toAtom(s) in tokenList + return tokenList.element.document.toAtom(s) in tokenList.toks func `$`(tokenList: DOMTokenList): string {.jsfunc: "toString".} = var s = "" @@ -2654,7 +2655,7 @@ proc sheets*(document: Document): seq[CSSStylesheet] = document.cachedSheets.add(style.sheet) elif elem of HTMLLinkElement: let link = HTMLLinkElement(elem) - if link.enabled.get(satAlternate notin link.relList): + if link.enabled.get(not link.relList.containsIgnoreCase(satAlternate)): document.cachedSheets.add(link.sheets) else: discard document.cachedSheetsInvalid = false @@ -3915,9 +3916,9 @@ proc loadSheet(window: Window; link: HTMLLinkElement; url: URL; applies: bool) = # see https://html.spec.whatwg.org/multipage/links.html#link-type-stylesheet #TODO make this somewhat compliant with ^this proc loadResource(window: Window; link: HTMLLinkElement) = - if not window.styling or satStylesheet notin link.relList or + if not window.styling or not link.relList.containsIgnoreCase(satStylesheet) or link.fetchStarted or - not link.enabled.get(satAlternate notin link.relList): + not link.enabled.get(not link.relList.containsIgnoreCase(satAlternate)): return link.fetchStarted = true let href = link.attr(satHref) |