diff options
author | bptato <nincsnevem662@gmail.com> | 2021-12-18 16:03:24 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2021-12-18 16:03:47 +0100 |
commit | eddf377277f85b172df453b5c3d5763d3a4467c6 (patch) | |
tree | ceaa7b7faef7670704a11868659b87bedfae8d4c /src/html/parser.nim | |
parent | a125464839927fd04f761c530e90888e340758ef (diff) | |
download | chawan-eddf377277f85b172df453b5c3d5763d3a4467c6.tar.gz |
Refactor selector code, optimize style tags
Diffstat (limited to 'src/html/parser.nim')
-rw-r--r-- | src/html/parser.nim | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/src/html/parser.nim b/src/html/parser.nim index 153df1c5..c3e12300 100644 --- a/src/html/parser.nim +++ b/src/html/parser.nim @@ -10,6 +10,7 @@ import utils/radixtree import html/dom import html/entity import html/tags +import css/selparser type HTMLParseState = object @@ -306,18 +307,27 @@ proc processDocumentStartElement(state: var HTMLParseState, element: Element, ta else: discard proc processDocumentEndElement(state: var HTMLParseState, tag: DOMParsedTag) = - if tag.tagid in VoidTagTypes: - return - if tag.tagid == TAG_HEAD: - processDocumentBody(state) - return - if tag.tagid == TAG_BODY: - return - if state.elementNode.nodeType == ELEMENT_NODE and tag.tagid != state.elementNode.tagType: + if tag.tagid != state.elementNode.tagType: if state.elementNode.tagType in SelfClosingTagTypes: processDocumentEndNode(state) - - processDocumentEndNode(state) + processDocumentEndNode(state) + else: + case tag.tagid + of VoidTagTypes: + return + of TAG_HEAD: + processDocumentBody(state) + return + of TAG_BODY: + return + of TAG_STYLE: + let style = HTMLStyleElement(state.elementNode) + var str = "" + for child in style.textNodes: + str &= child.data + style.stylesheet = newStringStream(str).parseStylesheet() + else: discard + processDocumentEndNode(state) proc processDocumentTag(state: var HTMLParseState, tag: DOMParsedTag) = if state.in_script: |