about summary refs log tree commit diff stats
path: root/src/io/buffer.nim
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2022-06-27 23:53:44 +0200
committerbptato <nincsnevem662@gmail.com>2022-07-11 21:08:10 +0200
commit62cba694e47a7a1f4bedc7fd48ceac9c26aa3aa1 (patch)
treee20a9f39a293c256f707162c46e117d13f3d5621 /src/io/buffer.nim
parent84882cb8a6f9bca58d178a1f2b8fb5cafa8b3a56 (diff)
downloadchawan-62cba694e47a7a1f4bedc7fd48ceac9c26aa3aa1.tar.gz
Implement HTML5 parsing
Completely replaced the previous HTML2 (?) parser, which was a bad
re-implementation of w3m's parser in the first place. Now we have a
(sort of) compliant HTML5 parser.
Needs tests, badly.
Diffstat (limited to 'src/io/buffer.nim')
-rw-r--r--src/io/buffer.nim26
1 files changed, 12 insertions, 14 deletions
diff --git a/src/io/buffer.nim b/src/io/buffer.nim
index 654bdbe7..3d317afe 100644
--- a/src/io/buffer.nim
+++ b/src/io/buffer.nim
@@ -189,7 +189,7 @@ func acursory(buffer: Buffer): int =
 func cellOrigin(buffer: Buffer, x, y: int): int =
   let row = y * buffer.width
   var ox = x
-  while buffer.display[row + ox].runes.len == 0 and ox > 0:
+  while ox > 0 and buffer.display[row + ox].runes.len == 0:
     dec ox
   return ox
 
@@ -280,13 +280,10 @@ func getTitle(buffer: Buffer): string =
   if buffer.document != nil:
     let titles = buffer.document.getElementsByTag(TAG_TITLE)
     if titles.len > 0:
-      for text in titles[0].textNodes:
-        result &= text.data.strip().clearControls()
-    return
+      return titles[0].textContent.strip().clearControls()
   if buffer.ispipe:
-    result = "*pipe*"
-  else:
-    result = $buffer.location
+    return "*pipe*"
+  return $buffer.location
 
 proc clearDisplay(buffer: Buffer) =
   buffer.prevdisplay = buffer.display
@@ -737,8 +734,9 @@ proc updateHover(buffer: Buffer) =
 
 proc loadResources(buffer: Buffer, document: Document) =
   var stack: seq[Element]
-  stack.add(document.root)
-  while stack.len > 0:
+  if document.html != nil:
+    stack.add(document.html)
+  while stack.len > 0 and false: #TODO actually implement this
     let elem = stack.pop()
 
     if elem.tagType == TAG_LINK:
@@ -750,7 +748,7 @@ proc loadResources(buffer: Buffer, document: Document) =
             let res = buffer.loader.getPage(url.get)
             if res.s != nil and res.contenttype == "text/css":
               let sheet = parseStylesheet(res.s)
-              elem.parentElement.sheets.add(sheet)
+              #elem.parentElement.sheets.add(sheet) #TODO this is broken...
 
     for i in countdown(elem.children.high, 0):
       let child = elem.children[i]
@@ -760,10 +758,10 @@ proc load*(buffer: Buffer) =
   case buffer.contenttype
   of "text/html":
     if not buffer.streamclosed:
-      buffer.document = parseHtml(buffer.istream, buffer.source)
+      buffer.document = parseHTML5(buffer.istream)
       buffer.streamclosed = true
     else:
-      buffer.document = parseHtml(newStringStream(buffer.source))
+      buffer.document = parseHTML5(newStringStream(buffer.source))
     buffer.document.location = buffer.location
     buffer.loadResources(buffer.document)
   else:
@@ -937,11 +935,11 @@ proc submitForm(form: HTMLFormElement, submitter: Element): Option[ClickAction]
   let entrylist = form.constructEntryList(submitter)
 
   let action = if submitter.action() == "":
-    $form.ownerDocument.location
+    $form.document.location
   else:
     submitter.action()
 
-  let url = parseUrl(action, submitter.ownerDocument.baseUrl.some)
+  let url = parseUrl(action, submitter.document.baseUrl.some)
   if url.isnone:
     return none(ClickAction)