html2ms: fix broken closetag handling

front
cinap_lenrek 2011-09-21 17:56:42 +02:00
parent f616a4c597
commit b118d0c449
1 changed files with 40 additions and 25 deletions

View File

@ -285,23 +285,6 @@ tabletag(Tag *tag)
return tabletag(tag->up); return tabletag(tag->up);
} }
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 void
dumprows(Text *text, Table *s, Table *e) dumprows(Text *text, Table *s, Table *e)
{ {
@ -510,6 +493,7 @@ struct {
"head", ongarbage, "head", ongarbage,
"hr", onbr, "hr", onbr,
"i", oni, "i", oni,
"img", onmeta,
"kbd", ontt, "kbd", ontt,
"li", onli, "li", onli,
"link", onmeta, "link", onmeta,
@ -782,14 +766,33 @@ gotstyle(Tag *tag, char *style, char *val)
return 1; return 1;
} }
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 void
parsetext(Text *text, Tag *tag) parsetext(Text *text, Tag *tag)
{ {
int hidden, c; int hidden, c;
Tag t, *p; Tag t, *up;
Rune r; Rune r;
if(tag){ if(tag){
up = tag->up;
debugtag(tag, "open"); debugtag(tag, "open");
for(c = 0; c < nelem(ontag); c++){ for(c = 0; c < nelem(ontag); c++){
if(cistrcmp(tag->tag, ontag[c].tag) == 0){ if(cistrcmp(tag->tag, ontag[c].tag) == 0){
@ -798,8 +801,10 @@ parsetext(Text *text, Tag *tag)
} }
} }
hidden = getattr(tag, "hidden") || gotstyle(tag, "display", "none"); hidden = getattr(tag, "hidden") || gotstyle(tag, "display", "none");
} else } else {
up = nil;
hidden = 0; hidden = 0;
}
if(tag == nil || tag->closing == 0){ if(tag == nil || tag->closing == 0){
while((c = Bgetc(&in)) > 0){ while((c = Bgetc(&in)) > 0){
if(c == '<'){ if(c == '<'){
@ -809,16 +814,22 @@ parsetext(Text *text, Tag *tag)
if(t.opening){ if(t.opening){
t.up = tag; t.up = tag;
parsetext(text, &t); parsetext(text, &t);
if(t.up != tag) if(t.up != tag){
debugtag(tag, "skip");
up = t.up;
break; break;
}
debugtag(tag, "back");
} else if(t.closing){ } else if(t.closing){
p = tag; up = tag;
while(p && cistrcmp(p->tag, t.tag)) while(up && cistrcmp(up->tag, t.tag))
p = p->up; up = up->up;
if(p) if(up){
up = up->up;
break; break;
} }
} }
}
continue; continue;
} }
if(hidden || !text->output) if(hidden || !text->output)
@ -856,8 +867,12 @@ parsetext(Text *text, Tag *tag)
} }
if(tag){ if(tag){
debugtag(tag, "close"); debugtag(tag, "close");
if(tag->close) if(tag->close){
tag->close(text, tag); tag->close(text, tag);
tag->close = nil;
}
if(up)
tag->up = up;
} }
} }