diff options
| author | bptato <nincsnevem662@gmail.com> | 2022-01-22 18:34:23 +0100 |
|---|---|---|
| committer | bptato <nincsnevem662@gmail.com> | 2022-01-22 18:34:23 +0100 |
| commit | 7b06c22d8f24de727ce5b62b4d7fd8cd4007123d (patch) | |
| tree | c92bd6243e249516ea51a0221c0e1b6c97adee48 /src/html | |
| parent | 4b5a3cbbf3ef3c75915f92d9ce487c0c9ff2884a (diff) | |
| download | chawan-7b06c22d8f24de727ce5b62b4d7fd8cd4007123d.tar.gz | |
Fix page navigation
Diffstat (limited to 'src/html')
| -rw-r--r-- | src/html/dom.nim | 11 | ||||
| -rw-r--r-- | src/html/parser.nim | 5 |
2 files changed, 10 insertions, 6 deletions
diff --git a/src/html/dom.nim b/src/html/dom.nim index f6d2878b..0105b72f 100644 --- a/src/html/dom.nim +++ b/src/html/dom.nim @@ -22,6 +22,7 @@ type parentNode*: Node parentElement*: Element ownerDocument*: Document + uid*: int # Unique id Attr* = ref AttrObj AttrObj = object of NodeObj @@ -266,7 +267,7 @@ func newComment*(): Comment = new(result) result.nodeType = COMMENT_NODE -func newHtmlElement*(tagType: TagType): HTMLElement = +func newHtmlElement*(document: Document, tagType: TagType): HTMLElement = case tagType of TAG_INPUT: result = new(HTMLInputElement) @@ -300,12 +301,14 @@ func newHtmlElement*(tagType: TagType): HTMLElement = result.nodeType = ELEMENT_NODE result.tagType = tagType result.css = rootProperties() + result.uid = document.all_elements.len + document.all_elements.add(result) func newDocument*(): Document = new(result) - result.root = newHtmlElement(TAG_HTML) - result.head = newHtmlElement(TAG_HEAD) - result.body = newHtmlElement(TAG_BODY) + result.root = result.newHtmlElement(TAG_HTML) + result.head = result.newHtmlElement(TAG_HEAD) + result.body = result.newHtmlElement(TAG_BODY) result.nodeType = DOCUMENT_NODE func newAttr*(parent: Element, key, value: string): Attr = diff --git a/src/html/parser.nim b/src/html/parser.nim index 0d2ccd3e..7488534a 100644 --- a/src/html/parser.nim +++ b/src/html/parser.nim @@ -23,6 +23,7 @@ type elementNode: Element textNode: Text commentNode: Comment + document: Document func inputSize*(str: string): int = if str.len == 0: @@ -189,7 +190,6 @@ proc insertNode(parent, node: Node) = let element = (Element(node)) if element.ownerDocument != nil: - node.ownerDocument.all_elements.add(Element(node)) element.ownerDocument.type_elements[element.tagType].add(element) if element.id != "": if not (element.id in element.ownerDocument.id_elements): @@ -351,7 +351,7 @@ proc processDocumentTag(state: var HTMLParseState, tag: DOMParsedTag) = return if tag.open: - processDocumentStartElement(state, newHtmlElement(tag.tagid), tag) + processDocumentStartElement(state, state.document.newHtmlElement(tag.tagid), tag) else: processDocumentEndElement(state, tag) @@ -455,6 +455,7 @@ proc parseHtml*(inputStream: Stream): Document = insertNode(document.root, document.body) var state = HTMLParseState() + state.document = document state.elementNode = document.root var till_when = false |