diff options
author | bptato <nincsnevem662@gmail.com> | 2021-11-10 18:26:18 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2021-11-10 18:32:25 +0100 |
commit | fcd3a5b204e15fdfc739fd04975977d288e892e0 (patch) | |
tree | 363f3bfd60570ce5fb1f4fbc6c62557609ccc6ea /src/html/parser.nim | |
parent | e6f7cc72ba3343fb81c4f8196446c58eca59191e (diff) | |
download | chawan-fcd3a5b204e15fdfc739fd04975977d288e892e0.tar.gz |
Layout engine improvements, use author style sheet
Diffstat (limited to 'src/html/parser.nim')
-rw-r--r-- | src/html/parser.nim | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/html/parser.nim b/src/html/parser.nim index 536ba434..eed5baa7 100644 --- a/src/html/parser.nim +++ b/src/html/parser.nim @@ -202,12 +202,21 @@ proc processDocumentBody(state: var HTMLParseState) = state.elementNode = state.elementNode.ownerDocument.body proc processDocumentAddNode(state: var HTMLParseState, newNode: Node) = - if state.elementNode.nodeType == ELEMENT_NODE and state.elementNode.tagType == TAG_HTML: + if state.elementNode.tagType == TAG_HTML: if state.in_body: state.elementNode = state.elementNode.ownerDocument.body else: state.elementNode = state.elementNode.ownerDocument.head + #> If the next token is a U+000A LINE FEED (LF) character token, then ignore + #> that token and move on to the next one. (Newlines at the start of pre + #> blocks are ignored as an authoring convenience.) + elif state.elementNode.tagType == TAG_PRE: + if state.elementNode.childNodes.len == 1 and + state.elementNode.childNodes[0].nodeType == TEXT_NODE and + Text(state.elementNode.childNodes[0]).data == "\n": + discard state.elementNode.childNodes.pop() + insertNode(state.elementNode, newNode) proc processDocumentEndNode(state: var HTMLParseState) = @@ -220,7 +229,6 @@ proc processDocumentText(state: var HTMLParseState) = processDocumentBody(state) if state.textNode == nil: state.textNode = newText() - processDocumentAddNode(state, state.textNode) proc processDocumentStartElement(state: var HTMLParseState, element: Element, tag: DOMParsedTag) = @@ -426,7 +434,7 @@ proc parseHtml*(inputStream: Stream): Document = var buf = "" var lineBuf: string while not inputStream.atEnd(): - lineBuf = inputStream.readLine() + lineBuf = inputStream.readLine() & '\n' buf &= lineBuf var at = 0 |