uhtml: remove trailing utf BOM marker, html2ms: fix underline handling and escaping

This commit is contained in:
cinap_lenrek 2011-09-20 04:14:29 +02:00
parent 7a29aa57cb
commit 6c91d99ce2
3 changed files with 46 additions and 21 deletions

View file

@ -142,8 +142,24 @@ onfont(Text *text, Tag *tag)
} }
void void
ona(Text *text, Tag *) restoreunderline(Text *text, Tag *tag)
{ {
text->underline = tag->restore;
emit(text, "");
}
void
ona(Text *text, Tag *tag)
{
int i;
for(i=0; i<tag->nattr; i++)
if(cistrcmp(tag->attr[i].attr, "href") == 0)
break;
if(i == tag->nattr)
return;
tag->restore = text->underline;
tag->close = restoreunderline;
text->underline = 1; text->underline = 1;
} }
@ -207,10 +223,13 @@ parsecomment(void)
if(n != 7 || cistrncmp(buf, "[CDATA[", 7)) if(n != 7 || cistrncmp(buf, "[CDATA[", 7))
continue; continue;
while((c = Bgetc(&in)) > 0){ while((c = Bgetc(&in)) > 0){
if(c == ']') if(c == ']'){
if(Bgetc(&in) == ']') if(Bgetc(&in) == ']'){
if(Bgetc(&in) == '>') if(Bgetc(&in) != '>')
return; Bungetc(&in);
return;
}
}
} }
} }
} }
@ -425,18 +444,17 @@ parsetext(Text *text, Tag *tag)
case '\r': case '\r':
case ' ': case ' ':
case '\t': case '\t':
if(text->pre == 0){ text->space = 1;
text->space = 1; if(text->pre == 0)
continue; continue;
}
default: default:
if(r == '\n' || r == '\r') if(r == '\n' || r == '\r')
text->pos = 0; text->pos = 0;
if(text->space){ if(text->space){
text->space = 0; text->space = 0;
if(text->underline){ if(text->underline){
emit(text, ""); emit(text, ".UL ");
text->pos = Bprint(&out, ".UL "); text->pos = 1;
} else if(text->pos >= 70){ } else if(text->pos >= 70){
text->pos = 0; text->pos = 0;
Bputc(&out, '\n'); Bputc(&out, '\n');
@ -445,16 +463,15 @@ parsetext(Text *text, Tag *tag)
Bputc(&out, ' '); Bputc(&out, ' ');
} }
} }
if(text->pos == 0 && r == '.'){ if(text->pos == 0 && r == '.')
text->pos++; text->pos += Bprint(&out, "\\&");
Bputc(&out, ' '); else if(r == '\\')
} text->pos += Bprint(&out, "\\&\\");
text->pos++; else if(r == 0xA0){
if(r == 0xA0){
r = ' '; r = ' ';
Bputc(&out, '\\'); text->pos += Bprint(&out, "\\");
} }
Bprint(&out, "%C", r); text->pos += Bprint(&out, "%C", r);
} }
} }
} }
@ -473,7 +490,10 @@ main(void)
Binit(&out, 1, OWRITE); Binit(&out, 1, OWRITE);
memset(&text, 0, sizeof(text)); memset(&text, 0, sizeof(text));
text.font = "R";
text.output = 1; text.output = 1;
parsetext(&text, nil); parsetext(&text, nil);
emit(&text, "\n"); emit(&text, "\n");
} }

View file

@ -623,9 +623,9 @@ popenfile(Page *p)
p->data = "lp -dstdout"; p->data = "lp -dstdout";
p->open = popengs; p->open = popengs;
} }
else if(cistrncmp(buf, "<?xml", 5) == 0 || else if(cistrstr(buf, "<?xml") ||
cistrncmp(buf, "<!DOCTYPE", 9) == 0 || cistrstr(buf, "<!DOCTYPE") ||
cistrncmp(buf, "<HTML", 5) == 0){ cistrstr(buf, "<HTML")){
p->data = "uhtml | html2ms | troff -ms | lp -dstdout"; p->data = "uhtml | html2ms | troff -ms | lp -dstdout";
p->open = popengs; p->open = popengs;
} }

View file

@ -62,6 +62,11 @@ main(int argc, char *argv[])
if((nbuf = read(0, buf, sizeof(buf)-1)) < 0) if((nbuf = read(0, buf, sizeof(buf)-1)) < 0)
sysfatal("read: %r"); sysfatal("read: %r");
buf[nbuf] = 0; buf[nbuf] = 0;
/* useless BOM marker */
if(memcmp(buf, "\xEF\xBB\xBF", 3)==0)
memmove(buf, buf+3, nbuf-3);
for(;;){ for(;;){
if(s = cistrstr(buf, "encoding=")) if(s = cistrstr(buf, "encoding="))
if(s = strval(s+9)){ if(s = strval(s+9)){