diff options
author | bptato <nincsnevem662@gmail.com> | 2024-02-13 21:16:12 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-02-25 02:46:21 +0100 |
commit | 6e98894199442e2213dc89e0c5fe970029f05b65 (patch) | |
tree | 57bf69a6fa825d72be1654482e8865b5e9b82829 /src/html | |
parent | d41d4803b5ed15b7e8461394ee07ce5ab1de143a (diff) | |
download | chawan-6e98894199442e2213dc89e0c5fe970029f05b65.tar.gz |
Separate ANSI text decoding from main binary
Handling text/plain as ANSI colored text was problematic for two reasons: * You couldn't actually look at the real source of HTML pages or text files that used ANSI colors in the source. In general, I only want ANSI colors when piping something into my pager, not when viewing any random file. * More importantly, it introduced a separate rendering mode for plaintext documents, which resulted in the problem that only some buffers had DOMs. This made it impossible to add functionality that would operate on the buffer's DOM, to e.g. implement w3m's MARK_URL. Also, it locked us into the horribly inefficient line-based rendering model of entire documents. Now we solve the problem in two separate parts: * text/x-ansi is used automatically for documents received through stdin. A text/x-ansi handler ansi2html converts ANSI formatting to HTML. text/x-ansi is also used for .ans, .asc file extensions. * text/plain is a separate input mode in buffer, which places all text in a single <plaintext> tag. Crucially, this does not invoke the HTML parser; that would eat NUL characters, which we should avoid. One blind spot still remains: copiousoutput used to display ANSI colors, and now it doesn't. To solve this, users can put the x-ansioutput extension field to their mailcap entries, which behaves like x-htmloutput except it first pipes the output into ansi2html.
Diffstat (limited to 'src/html')
-rw-r--r-- | src/html/dom.nim | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/src/html/dom.nim b/src/html/dom.nim index f8ddaad5..1104ee90 100644 --- a/src/html/dom.nim +++ b/src/html/dom.nim @@ -1781,21 +1781,19 @@ proc write(document: Document, text: varargs[string]): Err[DOMException] CDB_parseDocumentWriteChunk(document.parser) return ok() -func html*(document: Document): HTMLElement = - for element in document.elements(TAG_HTML): +func findFirst*(document: Document, tagType: TagType): HTMLElement = + for element in document.elements(tagType): return HTMLElement(element) + nil + +func html*(document: Document): HTMLElement = + return document.findFirst(TAG_HTML) func head*(document: Document): HTMLElement {.jsfget.} = - let html = document.html - if html != nil: - for element in html.elements(TAG_HEAD): - return HTMLElement(element) + return document.findFirst(TAG_HEAD) func body*(document: Document): HTMLElement {.jsfget.} = - let html = document.html - if html != nil: - for element in html.elements(TAG_BODY): - return HTMLElement(element) + return document.findFirst(TAG_BODY) func select*(option: HTMLOptionElement): HTMLSelectElement = for anc in option.ancestors: |