about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-07-25 23:00:14 +0200
committerbptato <nincsnevem662@gmail.com>2023-07-25 23:00:14 +0200
commit7101f7508cfc2ca6a57c18d3ec88f6e9021d7ad3 (patch)
treef6bdb9b3a851687b712b6888592e4aeceb9c36e3 /src
parent3fb64fd6c7e747f76e47576ba37b3d05abd9e2fe (diff)
downloadchawan-7101f7508cfc2ca6a57c18d3ec88f6e9021d7ad3.tar.gz
css: handle unknown tag names correctly
Instead of grouping all of them into TAG_UNKNOWN, match their tag
names.
To-do: this implementation is not very efficient.
Diffstat (limited to 'src')
-rw-r--r--src/css/match.nim2
-rw-r--r--src/css/selectorparser.nim17
-rw-r--r--src/css/sheet.nim2
3 files changed, 16 insertions, 5 deletions
diff --git a/src/css/match.nim b/src/css/match.nim
index 4bc2897f..6f684e8b 100644
--- a/src/css/match.nim
+++ b/src/css/match.nim
@@ -112,6 +112,8 @@ func selectorMatches[T: Element|StyledNode](elem: T, sel: Selector, felem: T = n
   case sel.t
   of TYPE_SELECTOR:
     return elem.tagType == sel.tag
+  of UNKNOWN_TYPE_SELECTOR:
+    return elem.localName == sel.tagstr
   of CLASS_SELECTOR:
     return sel.class in elem.classList
   of ID_SELECTOR:
diff --git a/src/css/selectorparser.nim b/src/css/selectorparser.nim
index 69a1b17f..84e88fa2 100644
--- a/src/css/selectorparser.nim
+++ b/src/css/selectorparser.nim
@@ -8,8 +8,8 @@ import html/tags
 
 type
   SelectorType* = enum
-    TYPE_SELECTOR, ID_SELECTOR, ATTR_SELECTOR, CLASS_SELECTOR,
-    UNIVERSAL_SELECTOR, PSEUDO_SELECTOR, PSELEM_SELECTOR
+    TYPE_SELECTOR, UNKNOWN_TYPE_SELECTOR, ID_SELECTOR, ATTR_SELECTOR,
+    CLASS_SELECTOR, UNIVERSAL_SELECTOR, PSEUDO_SELECTOR, PSELEM_SELECTOR
 
   PseudoElem* = enum
     PSEUDO_NONE, PSEUDO_BEFORE, PSEUDO_AFTER,
@@ -36,6 +36,8 @@ type
     case t*: SelectorType
     of TYPE_SELECTOR:
       tag*: TagType
+    of UNKNOWN_TYPE_SELECTOR:
+      tagstr*: string
     of ID_SELECTOR:
       id*: string
     of ATTR_SELECTOR:
@@ -96,6 +98,8 @@ func `$`*(sel: Selector): string =
   case sel.t
   of TYPE_SELECTOR:
     return tagName(sel.tag)
+  of UNKNOWN_TYPE_SELECTOR:
+    return sel.tagstr
   of ID_SELECTOR:
     return '#' & sel.id
   of ATTR_SELECTOR:
@@ -184,7 +188,7 @@ func getSpecificity(sel: Selector): int =
       result += 1000
     of PSEUDO_WHERE: discard
     else: result += 1000
-  of TYPE_SELECTOR, PSELEM_SELECTOR:
+  of TYPE_SELECTOR, UNKNOWN_TYPE_SELECTOR, PSELEM_SELECTOR:
     result += 1
   of UNIVERSAL_SELECTOR:
     discard
@@ -349,7 +353,12 @@ proc parseCompoundSelector(state: var SelectorParser): CompoundSelector =
       case tok.tokenType
       of CSS_IDENT_TOKEN:
         inc state.at
-        result.add(Selector(t: TYPE_SELECTOR, tag: tagType(tok.value)))
+        let tag = tagType(tok.value)
+        if tag == TAG_UNKNOWN:
+          let s = tok.value.toLowerAscii()
+          result.add(Selector(t: UNKNOWN_TYPE_SELECTOR, tagstr: s))
+        else:
+          result.add(Selector(t: TYPE_SELECTOR, tag: tag))
       of CSS_COLON_TOKEN:
         inc state.at
         result.add(state.parsePseudoSelector())
diff --git a/src/css/sheet.nim b/src/css/sheet.nim
index d1b47f1c..e7a18091 100644
--- a/src/css/sheet.nim
+++ b/src/css/sheet.nim
@@ -63,7 +63,7 @@ proc getSelectorIds(hashes: var SelectorHashes, sel: Selector): bool =
   of ID_SELECTOR:
     hashes.id = sel.id
     return true
-  of ATTR_SELECTOR, PSELEM_SELECTOR, UNIVERSAL_SELECTOR:
+  of ATTR_SELECTOR, PSELEM_SELECTOR, UNIVERSAL_SELECTOR, UNKNOWN_TYPE_SELECTOR:
     return false
   of PSEUDO_SELECTOR:
     if sel.pseudo.t in {PSEUDO_IS, PSEUDO_WHERE}: