From 9cf21945449596aa7632a583bc9b2fd211d4cf5e Mon Sep 17 00:00:00 2001 From: bptato Date: Sun, 17 Jul 2022 23:04:22 +0200 Subject: Fix a parser bug Plus a few warnings. --- src/html/htmlparser.nim | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) (limited to 'src/html/htmlparser.nim') 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 ) "" => (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(): -- cgit 1.4.1-2-gfad0 ' href='#n27'>27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138