about summary refs log tree commit diff stats
path: root/src/html
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2022-07-17 23:04:22 +0200
committerbptato <nincsnevem662@gmail.com>2022-07-17 23:04:22 +0200
commit9cf21945449596aa7632a583bc9b2fd211d4cf5e (patch)
tree499930437e39f4f28645b5649c0f1fbd5e8f404e /src/html
parent24fc8e940a935f0579cf7bc03bf01e27e5853b80 (diff)
downloadchawan-9cf21945449596aa7632a583bc9b2fd211d4cf5e.tar.gz
Fix a parser bug
Plus a few warnings.
Diffstat (limited to 'src/html')
-rw-r--r--src/html/htmlparser.nim49
1 files changed, 47 insertions, 2 deletions
diff --git a/src/html/htmlparser.nim b/src/html/htmlparser.nim
index 835e6de0..b46a3dfa 100644
--- a/src/html/htmlparser.nim
+++ b/src/html/htmlparser.nim
@@ -222,7 +222,7 @@ proc insertForeignElement(parser: var HTML5Parser, token: Token, namespace: Name
 proc insertHTMLElement(parser: var HTML5Parser, token: Token): Element =
   return parser.insertForeignElement(token, Namespace.HTML)
 
-proc adjustSVGAttributes(token: var Token) =
+proc adjustSVGAttributes(token: Token) =
   const adjusted = {
     "attributename": "attributeName",
     "attributetype": "attributeType",
@@ -825,6 +825,7 @@ proc processInHTMLContent(parser: var HTML5Parser, token: Token, insertionMode =
         location.insert(element)
         parser.openElements.add(element)
         parser.tokenizer.state = SCRIPT_DATA
+        parser.oldInsertionMode = parser.insertionMode
         parser.insertionMode = TEXT
       )
       "</head>" => (block:
@@ -1967,6 +1968,7 @@ proc processInForeignContent(parser: var HTML5Parser, token: Token) =
     pop_current_node
     #TODO document.write (?)
     #TODO SVG
+
   template any_other_end_tag() =
     if parser.currentNode.localName != token.tagname: parse_error
     for i in countdown(parser.openElements.high, 1):
@@ -1976,6 +1978,45 @@ proc processInForeignContent(parser: var HTML5Parser, token: Token) =
         break
       if node.namespace == Namespace.HTML: break
       parser.processInHTMLContent(token)
+  const CaseTable = {
+    "altglyph": "altGlyph",
+    "altglyphdef": "altGlyphDef",
+    "altglyphitem": "altGlyphItem",
+    "animatecolor": "animateColor",
+    "animatemotion": "animateMotion",
+    "animatetransform": "animateTransform",
+    "clippath": "clipPath",
+    "feblend": "feBlend",
+    "fecolormatrix": "feColorMatrix",
+    "fecomponenttransfer": "feComponentTransfer",
+    "fecomposite": "feComposite",
+    "feconvolvematrix": "feConvolveMatrix",
+    "fediffuselighting": "feDiffuseLighting",
+    "fedisplacementmap": "feDisplacementMap",
+    "fedistantlight": "feDistantLight",
+    "fedropshadow": "feDropShadow",
+    "feflood": "feFlood",
+    "fefunca": "feFuncA",
+    "fefuncb": "feFuncB",
+    "fefuncg": "feFuncG",
+    "fefuncr": "feFuncR",
+    "fegaussianblur": "feGaussianBlur",
+    "feimage": "feImage",
+    "femerge": "feMerge",
+    "femergenode": "feMergeNode",
+    "femorphology": "feMorphology",
+    "feoffset": "feOffset",
+    "fepointlight": "fePointLight",
+    "fespecularlighting": "feSpecularLighting",
+    "fespotlight": "feSpotLight",
+    "fetile": "feTile",
+    "feturbulence": "feTurbulence",
+    "foreignobject": "foreignObject",
+    "glyphref": "glyphRef",
+    "lineargradient": "linearGradient",
+    "radialgradient": "radialGradient",
+    "textpath": "textPath",
+  }.toTable()
 
   match token:
     '\0' => (block:
@@ -2000,7 +2041,11 @@ proc processInForeignContent(parser: var HTML5Parser, token: Token) =
     )
     TokenType.START_TAG => (block:
       #NOTE MathML not implemented
-      #TODO SVG
+
+      if parser.adjustedCurrentNode.namespace == Namespace.SVG:
+        if token.tagname in CaseTable:
+          token.tagname = CaseTable[token.tagname]
+        adjustSVGAttributes(token)
       #TODO adjust foreign attributes
       let element = parser.insertForeignElement(token, parser.adjustedCurrentNode.namespace)
       if token.selfclosing and element.inSVGNamespace():