ref: b118d0c449931045c85c424556684d6ae4854531
parent: f616a4c597defe57dcade8bb85f5866de2bd60f0
author: cinap_lenrek <cinap_lenrek@centraldogma>
date: Wed Sep 21 13:56:42 EDT 2011
html2ms: fix broken closetag handling
--- a/sys/src/cmd/html2ms.c
+++ b/sys/src/cmd/html2ms.c
@@ -286,23 +286,6 @@
}
void
-reparent(Text *text, Tag *tag, Tag *up)
-{
- Tag *old;
-
- old = tag->up;
- while(old != up){
- if(old->close){
- debugtag(old, "reparent close");
- old->close(text, old);
- old->close = nil;
- }
- old = old->up;
- }
- tag->up = up;
-}
-
-void
dumprows(Text *text, Table *s, Table *e)
{
@@ -510,6 +493,7 @@
"head", ongarbage,
"hr", onbr,
"i", oni,
+ "img", onmeta,
"kbd", ontt,
"li", onli,
"link", onmeta,
@@ -783,13 +767,32 @@
}
void
+reparent(Text *text, Tag *tag, Tag *up)
+{
+ Tag *old;
+
+ old = tag->up;
+ while(old != up){
+ debugtag(old, "reparent");
+ if(old->close){
+ old->close(text, old);
+ old->close = nil;
+ }
+ old = old->up;
+ }
+ tag->up = up;
+}
+
+
+void
parsetext(Text *text, Tag *tag)
{
int hidden, c;
- Tag t, *p;
+ Tag t, *up;
Rune r;
if(tag){
+ up = tag->up;
debugtag(tag, "open");
for(c = 0; c < nelem(ontag); c++){
if(cistrcmp(tag->tag, ontag[c].tag) == 0){
@@ -798,8 +801,10 @@
}
}
hidden = getattr(tag, "hidden") || gotstyle(tag, "display", "none");
- } else
+ } else {
+ up = nil;
hidden = 0;
+ }
if(tag == nil || tag->closing == 0){
while((c = Bgetc(&in)) > 0){
if(c == '<'){
@@ -809,14 +814,20 @@
if(t.opening){
t.up = tag;
parsetext(text, &t);
- if(t.up != tag)
+ if(t.up != tag){
+ debugtag(tag, "skip");
+ up = t.up;
break;
+ }
+ debugtag(tag, "back");
} else if(t.closing){
- p = tag;
- while(p && cistrcmp(p->tag, t.tag))
- p = p->up;
- if(p)
+ up = tag;
+ while(up && cistrcmp(up->tag, t.tag))
+ up = up->up;
+ if(up){
+ up = up->up;
break;
+ }
}
}
continue;
@@ -856,8 +867,12 @@
}
if(tag){
debugtag(tag, "close");
- if(tag->close)
+ if(tag->close){
tag->close(text, tag);
+ tag->close = nil;
+ }
+ if(up)
+ tag->up = up;
}
}