int pos;
int space;
int output;
- int aftertag;
char *bp;
char *wp;
fontstyle(text, "B");
}
+void onsmall(Text *text, Tag *tag);
+void onsup(Text *text, Tag *tag);
+
+void
+onsub(Text *text, Tag *tag)
+{
+ emit(text, "\\v\'0.5\'");
+ if(cistrcmp(tag->tag, "sub") == 0){
+ emit(text, "\\x\'0.5\'");
+ onsmall(text, tag);
+ } else
+ restorefontsize(text, tag);
+ tag->close = onsup;
+}
+
+void
+onsup(Text *text, Tag *tag)
+{
+ emit(text, "\\v\'-0.5\'");
+ if(cistrcmp(tag->tag, "sup") == 0){
+ emit(text, "\\x\'-0.5\'");
+ onsmall(text, tag);
+ }else
+ restorefontsize(text, tag);
+ tag->close = onsub;
+}
+
+/*
+ * this is poor mans CSS handler.
+ */
+void
+onspan(Text *text, Tag *tag)
+{
+ Attr *a;
+
+ if(!tag->opening)
+ return;
+
+ for(a=tag->attr; a < tag->attr+tag->nattr; a++){
+ if(cistrcmp(a->attr, "class") != 0)
+ continue;
+
+ if(cistrcmp(a->val, "bold") == 0){
+ onb(text, tag);
+ return;
+ }
+ if(cistrcmp(a->val, "italic") == 0){
+ oni(text, tag);
+ return;
+ }
+ if(cistrcmp(a->val, "subscript") == 0){
+ strcpy(tag->tag, "sub");
+ onsub(text, tag);
+ strcpy(tag->tag, "span");
+ return;
+ }
+ if(cistrcmp(a->val, "superscript") == 0){
+ strcpy(tag->tag, "sup");
+ onsup(text, tag);
+ strcpy(tag->tag, "span");
+ return;
+ }
+ }
+}
+
void
ontt(Text *text, Tag *tag)
{
typedef struct Table Table;
struct Table
{
- char *fmt;
-
char *bp;
int nb;
int enclose;
int brk;
+ char fmt[4];
+
Text save;
};
if(t->brk){
while(i < cols){
s = mallocz(sizeof(Table), 1);
- s->fmt = "L";
+ strcpy(s->fmt, "L");
s->brk = t->brk;
t->brk = 0;
s->next = t->next;
t->enclose = 1;
}
if(gotstyle(tag, "text-align", "center") || gotstyle(tt, "text-align", "center"))
- t->fmt = "c";
+ strcpy(t->fmt, "C");
else
- t->fmt = "L";
+ strcpy(t->fmt, "L");
+ if(strcmp(tag->tag, "th") == 0)
+ strcpy(t->fmt+1, "B");
t->prev = tt->aux;
tt->aux = t;
*text = t->save;
"td", oncell,
"th", oncell,
"tr", oncell,
+ "sub", onsub,
+ "sup", onsup,
+ "span", onspan,
"tt", ontt,
"var", oni,
};
return '>';
if(strcmp(buf, "quot") == 0)
return '"';
+ if(strcmp(buf, "apos") == 0)
+ return '\'';
if(strcmp(buf, "amp") == 0)
return '&';
/* use tcs -f html to handle the rest. */
void
debugtag(Tag *tag, char *dbg)
{
- if(1) return;
+ if(1){
+ USED(tag);
+ USED(dbg);
+ return;
+ }
if(tag == nil)
return;
if(c == '<'){
memset(&t, 0, sizeof(t));
if(parsetag(&t)){
- text->aftertag = 1;
if(t.opening){
t.up = tag;
parsetext(text, &t);
switch(r){
case '\n':
case '\r':
- if(text->pre == 0 && text->aftertag)
- break;
case ' ':
case '\t':
if(text->pre == 0){
if(r == 0xA0)
r = ' ';
emitrune(text, r);
- text->aftertag = 0;
text->space = 0;
}
}