/* ARGSUSED */ static int mdoc_lk_pre(MDOC_ARGS) { struct htmlpair tag[2]; if (NULL == (n = n->child)) return(0); assert(MDOC_TEXT == n->type); PAIR_CLASS_INIT(&tag[0], "link-ext"); PAIR_HREF_INIT(&tag[1], n->string); print_otag(h, TAG_A, 2, tag); for (n = n->next; n; n = n->next) { assert(MDOC_TEXT == n->type); print_text(h, n->string); } return(0); }
/* ARGSUSED */ static int mdoc_fl_pre(MDOC_ARGS) { struct htmlpair tag; PAIR_CLASS_INIT(&tag, "flag"); print_otag(h, TAG_B, 1, &tag); /* `Cm' has no leading hyphen. */ if (MDOC_Cm == n->tok) return(1); print_text(h, "\\-"); if (n->child) h->flags |= HTML_NOSPACE; else if (n->next && n->next->line == n->line) h->flags |= HTML_NOSPACE; return(1); }
static int man_UR_pre(MAN_ARGS) { struct htmlpair tag[2]; n = n->child; assert(MAN_HEAD == n->type); if (n->nchild) { assert(MAN_TEXT == n->child->type); PAIR_CLASS_INIT(&tag[0], "link-ext"); PAIR_HREF_INIT(&tag[1], n->child->string); print_otag(h, TAG_A, 2, tag); } assert(MAN_BODY == n->next->type); if (n->next->nchild) n = n->next; print_man_nodelist(man, n->child, mh, h); return(0); }
/* ARGSUSED */ static int mdoc_mt_pre(MDOC_ARGS) { struct htmlpair tag[2]; struct tag *t; PAIR_CLASS_INIT(&tag[0], "link-mail"); for (n = n->child; n; n = n->next) { assert(MDOC_TEXT == n->type); bufinit(h); bufcat(h, "mailto:"); bufcat(h, n->string); PAIR_HREF_INIT(&tag[1], h->buf); t = print_otag(h, TAG_A, 2, tag); print_text(h, n->string); print_tagq(h, t); } return(0); }
static int mdoc_root_pre(MDOC_ARGS) { struct htmlpair tag; struct tag *t, *tt; char *volume, *title; if (NULL == meta->arch) volume = mandoc_strdup(meta->vol); else mandoc_asprintf(&volume, "%s (%s)", meta->vol, meta->arch); if (NULL == meta->msec) title = mandoc_strdup(meta->title); else mandoc_asprintf(&title, "%s(%s)", meta->title, meta->msec); PAIR_CLASS_INIT(&tag, "head"); t = print_otag(h, TAG_TABLE, 1, &tag); print_otag(h, TAG_TBODY, 0, NULL); tt = print_otag(h, TAG_TR, 0, NULL); PAIR_CLASS_INIT(&tag, "head-ltitle"); print_otag(h, TAG_TD, 1, &tag); print_text(h, title); print_stagq(h, tt); PAIR_CLASS_INIT(&tag, "head-vol"); print_otag(h, TAG_TD, 1, &tag); print_text(h, volume); print_stagq(h, tt); PAIR_CLASS_INIT(&tag, "head-rtitle"); print_otag(h, TAG_TD, 1, &tag); print_text(h, title); print_tagq(h, t); free(title); free(volume); return(1); }
static int mdoc_fl_pre(MDOC_ARGS) { struct htmlpair tag; PAIR_CLASS_INIT(&tag, "flag"); print_otag(h, TAG_B, 1, &tag); /* `Cm' has no leading hyphen. */ if (MDOC_Cm == n->tok) return(1); print_text(h, "\\-"); if ( ! (n->nchild == 0 && (n->next == NULL || n->next->type == MDOC_TEXT || n->next->flags & MDOC_LINE))) h->flags |= HTML_NOSPACE; return(1); }
static int man_HP_pre(MAN_ARGS) { struct roffsu sum, sui; const struct roff_node *np; if (n->type == ROFFT_HEAD) return 0; else if (n->type != ROFFT_BLOCK) return 1; np = n->head->child; if (np == NULL || !a2width(np, &sum)) SCALE_HS_INIT(&sum, INDENT); sui.unit = sum.unit; sui.scale = -sum.scale; print_bvspace(h, n); print_otag(h, TAG_DIV, "csului", "Pp", &sum, &sui); return 1; }
static int mdoc_bf_pre(MDOC_ARGS) { const char *cattr; if (n->type == ROFFT_HEAD) return 0; else if (n->type != ROFFT_BODY) return 1; if (FONT_Em == n->norm->Bf.font) cattr = "Bf Em"; else if (FONT_Sy == n->norm->Bf.font) cattr = "Bf Sy"; else if (FONT_Li == n->norm->Bf.font) cattr = "Bf Li"; else cattr = "Bf No"; /* Cannot use TAG_SPAN because it may contain blocks. */ print_otag(h, TAG_DIV, "c", cattr); return 1; }
/* ARGSUSED */ static int mdoc_sp_pre(MDOC_ARGS) { struct roffsu su; struct htmlpair tag; SCALE_VS_INIT(&su, 1); if (MDOC_sp == n->tok) { if (n->child) a2roffsu(n->child->string, &su, SCALE_VS); } else su.scale = 0; bufcat_su(h, "height", &su); PAIR_STYLE_INIT(&tag, h); print_otag(h, TAG_DIV, 1, &tag); /* So the div isn't empty: */ print_text(h, "\\~"); return(0); }
static int mdoc_fo_pre(MDOC_ARGS) { struct tag *t; if (n->type == ROFFT_BODY) { h->flags |= HTML_NOSPACE; print_text(h, "("); h->flags |= HTML_NOSPACE; return 1; } else if (n->type == ROFFT_BLOCK) { synopsis_pre(h, n); return 1; } if (n->child == NULL) return 0; assert(n->child->string); t = print_otag(h, TAG_CODE, "cT", "Fn"); print_text(h, n->child->string); print_tagq(h, t); return 0; }
static int mdoc_lk_pre(MDOC_ARGS) { const struct roff_node *link, *descr, *punct; struct tag *t; if ((link = n->child) == NULL) return 0; /* Find beginning of trailing punctuation. */ punct = n->last; while (punct != link && punct->flags & NODE_DELIMC) punct = punct->prev; punct = punct->next; /* Link target and link text. */ descr = link->next; if (descr == punct) descr = link; /* no text */ t = print_otag(h, TAG_A, "cTh", "Lk", link->string); do { if (descr->flags & (NODE_DELIMC | NODE_DELIMO)) h->flags |= HTML_NOSPACE; print_text(h, descr->string); descr = descr->next; } while (descr != punct); print_tagq(h, t); /* Trailing punctuation. */ while (punct != NULL) { h->flags |= HTML_NOSPACE; print_text(h, punct->string); punct = punct->next; } return 0; }
/* ARGSUSED */ static int mdoc_fn_pre(MDOC_ARGS) { struct tag *t; struct htmlpair tag[2]; char nbuf[BUFSIZ]; const char *sp, *ep; int sz, i, pretty; pretty = MDOC_SYNPRETTY & n->flags; synopsis_pre(h, n); /* Split apart into type and name. */ assert(n->child->string); sp = n->child->string; ep = strchr(sp, ' '); if (NULL != ep) { PAIR_CLASS_INIT(&tag[0], "ftype"); t = print_otag(h, TAG_I, 1, tag); while (ep) { sz = MIN((int)(ep - sp), BUFSIZ - 1); (void)memcpy(nbuf, sp, (size_t)sz); nbuf[sz] = '\0'; print_text(h, nbuf); sp = ++ep; ep = strchr(sp, ' '); } print_tagq(h, t); } PAIR_CLASS_INIT(&tag[0], "fname"); /* * FIXME: only refer to IDs that we know exist. */ #if 0 if (MDOC_SYNPRETTY & n->flags) { nbuf[0] = '\0'; html_idcat(nbuf, sp, BUFSIZ); PAIR_ID_INIT(&tag[1], nbuf); } else { strlcpy(nbuf, "#", BUFSIZ); html_idcat(nbuf, sp, BUFSIZ); PAIR_HREF_INIT(&tag[1], nbuf); } #endif t = print_otag(h, TAG_B, 1, tag); if (sp) { strlcpy(nbuf, sp, BUFSIZ); print_text(h, nbuf); } print_tagq(h, t); h->flags |= HTML_NOSPACE; print_text(h, "("); bufinit(h); PAIR_CLASS_INIT(&tag[0], "farg"); bufcat_style(h, "white-space", "nowrap"); PAIR_STYLE_INIT(&tag[1], h); for (n = n->child->next; n; n = n->next) { i = 1; if (MDOC_SYNPRETTY & n->flags) i = 2; t = print_otag(h, TAG_I, i, tag); print_text(h, n->string); print_tagq(h, t); if (n->next) { h->flags |= HTML_NOSPACE; print_text(h, ","); } } h->flags |= HTML_NOSPACE; print_text(h, ")"); if (pretty) { h->flags |= HTML_NOSPACE; print_text(h, ";"); } return(0); }
/* ARGSUSED */ static int mdoc_bd_pre(MDOC_ARGS) { struct htmlpair tag[2]; int comp, sv; const struct mdoc_node *nn; struct roffsu su; if (MDOC_HEAD == n->type) return(0); if (MDOC_BLOCK == n->type) { comp = n->norm->Bd.comp; for (nn = n; nn && ! comp; nn = nn->parent) { if (MDOC_BLOCK != nn->type) continue; if (MDOC_Ss == nn->tok || MDOC_Sh == nn->tok) comp = 1; if (nn->prev) break; } if ( ! comp) print_otag(h, TAG_P, 0, NULL); return(1); } SCALE_HS_INIT(&su, 0); if (n->norm->Bd.offs) a2offs(n->norm->Bd.offs, &su); bufcat_su(h, "margin-left", &su); PAIR_STYLE_INIT(&tag[0], h); if (DISP_unfilled != n->norm->Bd.type && DISP_literal != n->norm->Bd.type) { PAIR_CLASS_INIT(&tag[1], "display"); print_otag(h, TAG_DIV, 2, tag); return(1); } PAIR_CLASS_INIT(&tag[1], "lit display"); print_otag(h, TAG_PRE, 2, tag); /* This can be recursive: save & set our literal state. */ sv = h->flags & HTML_LITERAL; h->flags |= HTML_LITERAL; for (nn = n->child; nn; nn = nn->next) { print_mdoc_node(m, nn, h); /* * If the printed node flushes its own line, then we * needn't do it here as well. This is hacky, but the * notion of selective eoln whitespace is pretty dumb * anyway, so don't sweat it. */ switch (nn->tok) { case (MDOC_Sm): /* FALLTHROUGH */ case (MDOC_br): /* FALLTHROUGH */ case (MDOC_sp): /* FALLTHROUGH */ case (MDOC_Bl): /* FALLTHROUGH */ case (MDOC_D1): /* FALLTHROUGH */ case (MDOC_Dl): /* FALLTHROUGH */ case (MDOC_Lp): /* FALLTHROUGH */ case (MDOC_Pp): continue; default: break; } if (nn->next && nn->next->line == nn->line) continue; else if (nn->next) print_text(h, "\n"); h->flags |= HTML_NOSPACE; } if (0 == sv) h->flags &= ~HTML_LITERAL; return(0); }
static int mdoc_ad_pre(MDOC_ARGS) { print_otag(h, TAG_SPAN, "c", "Ad"); return 1; }
static int mdoc_pa_pre(MDOC_ARGS) { print_otag(h, TAG_SPAN, "cT", "Pa"); return 1; }
/* ARGSUSED */ static int mdoc_bl_pre(MDOC_ARGS) { int i; struct htmlpair tag[3]; struct roffsu su; char buf[BUFSIZ]; if (MDOC_BODY == n->type) { if (LIST_column == n->norm->Bl.type) print_otag(h, TAG_TBODY, 0, NULL); return(1); } if (MDOC_HEAD == n->type) { if (LIST_column != n->norm->Bl.type) return(0); /* * For each column, print out the <COL> tag with our * suggested width. The last column gets min-width, as * in terminal mode it auto-sizes to the width of the * screen and we want to preserve that behaviour. */ for (i = 0; i < (int)n->norm->Bl.ncols; i++) { a2width(n->norm->Bl.cols[i], &su); bufinit(h); if (i < (int)n->norm->Bl.ncols - 1) bufcat_su(h, "width", &su); else bufcat_su(h, "min-width", &su); PAIR_STYLE_INIT(&tag[0], h); print_otag(h, TAG_COL, 1, tag); } return(0); } SCALE_VS_INIT(&su, 0); bufcat_su(h, "margin-top", &su); bufcat_su(h, "margin-bottom", &su); PAIR_STYLE_INIT(&tag[0], h); assert(lists[n->norm->Bl.type]); strlcpy(buf, "list ", BUFSIZ); strlcat(buf, lists[n->norm->Bl.type], BUFSIZ); PAIR_INIT(&tag[1], ATTR_CLASS, buf); /* Set the block's left-hand margin. */ if (n->norm->Bl.offs) { a2offs(n->norm->Bl.offs, &su); bufcat_su(h, "margin-left", &su); } switch (n->norm->Bl.type) { case(LIST_bullet): /* FALLTHROUGH */ case(LIST_dash): /* FALLTHROUGH */ case(LIST_hyphen): /* FALLTHROUGH */ case(LIST_item): print_otag(h, TAG_UL, 2, tag); break; case(LIST_enum): print_otag(h, TAG_OL, 2, tag); break; case(LIST_diag): /* FALLTHROUGH */ case(LIST_hang): /* FALLTHROUGH */ case(LIST_inset): /* FALLTHROUGH */ case(LIST_ohang): /* FALLTHROUGH */ case(LIST_tag): print_otag(h, TAG_DL, 2, tag); break; case(LIST_column): print_otag(h, TAG_TABLE, 2, tag); break; default: abort(); /* NOTREACHED */ } return(1); }
/* ARGSUSED */ static int mdoc_root_pre(MDOC_ARGS) { struct htmlpair tag[3]; struct tag *t, *tt; char b[BUFSIZ], title[BUFSIZ]; strlcpy(b, m->vol, BUFSIZ); if (m->arch) { strlcat(b, " (", BUFSIZ); strlcat(b, m->arch, BUFSIZ); strlcat(b, ")", BUFSIZ); } snprintf(title, BUFSIZ - 1, "%s(%s)", m->title, m->msec); PAIR_SUMMARY_INIT(&tag[0], "Document Header"); PAIR_CLASS_INIT(&tag[1], "head"); if (NULL == h->style) { PAIR_INIT(&tag[2], ATTR_WIDTH, "100%"); t = print_otag(h, TAG_TABLE, 3, tag); PAIR_INIT(&tag[0], ATTR_WIDTH, "30%"); print_otag(h, TAG_COL, 1, tag); print_otag(h, TAG_COL, 1, tag); print_otag(h, TAG_COL, 1, tag); } else t = print_otag(h, TAG_TABLE, 2, tag); print_otag(h, TAG_TBODY, 0, NULL); tt = print_otag(h, TAG_TR, 0, NULL); PAIR_CLASS_INIT(&tag[0], "head-ltitle"); print_otag(h, TAG_TD, 1, tag); print_text(h, title); print_stagq(h, tt); PAIR_CLASS_INIT(&tag[0], "head-vol"); if (NULL == h->style) { PAIR_INIT(&tag[1], ATTR_ALIGN, "center"); print_otag(h, TAG_TD, 2, tag); } else print_otag(h, TAG_TD, 1, tag); print_text(h, b); print_stagq(h, tt); PAIR_CLASS_INIT(&tag[0], "head-rtitle"); if (NULL == h->style) { PAIR_INIT(&tag[1], ATTR_ALIGN, "right"); print_otag(h, TAG_TD, 2, tag); } else print_otag(h, TAG_TD, 1, tag); print_text(h, title); print_tagq(h, t); return(1); }
static int mdoc_xx_pre(MDOC_ARGS) { print_otag(h, TAG_SPAN, "c", "Ux"); return 1; }
static int mdoc_ar_pre(MDOC_ARGS) { print_otag(h, TAG_VAR, "cT", "Ar"); return 1; }
static void print_mdoc_node(MDOC_ARGS) { int child; struct tag *t; if (n->type == ROFFT_COMMENT || n->flags & NODE_NOPRT) return; child = 1; t = h->tag; n->flags &= ~NODE_ENDED; switch (n->type) { case ROFFT_TEXT: /* No tables in this mode... */ assert(NULL == h->tblt); /* * Make sure that if we're in a literal mode already * (i.e., within a <PRE>) don't print the newline. */ if (*n->string == ' ' && n->flags & NODE_LINE && (h->flags & (HTML_LITERAL | HTML_NONEWLINE)) == 0) print_otag(h, TAG_BR, ""); if (NODE_DELIMC & n->flags) h->flags |= HTML_NOSPACE; print_text(h, n->string); if (NODE_DELIMO & n->flags) h->flags |= HTML_NOSPACE; return; case ROFFT_EQN: print_eqn(h, n->eqn); break; case ROFFT_TBL: /* * This will take care of initialising all of the table * state data for the first table, then tearing it down * for the last one. */ print_tbl(h, n->span); return; default: /* * Close out the current table, if it's open, and unset * the "meta" table state. This will be reopened on the * next table element. */ if (h->tblt != NULL) { print_tblclose(h); t = h->tag; } assert(h->tblt == NULL); if (n->tok < ROFF_MAX) { roff_html_pre(h, n); child = 0; break; } assert(n->tok >= MDOC_Dd && n->tok < MDOC_MAX); if (mdocs[n->tok].pre != NULL && (n->end == ENDBODY_NOT || n->child != NULL)) child = (*mdocs[n->tok].pre)(meta, n, h); break; } if (h->flags & HTML_KEEP && n->flags & NODE_LINE) { h->flags &= ~HTML_KEEP; h->flags |= HTML_PREKEEP; } if (child && n->child) print_mdoc_nodelist(meta, n->child, h); print_stagq(h, t); switch (n->type) { case ROFFT_EQN: break; default: if (n->tok < ROFF_MAX || mdocs[n->tok].post == NULL || n->flags & NODE_ENDED) break; (*mdocs[n->tok].post)(meta, n, h); if (n->end != ENDBODY_NOT) n->body->flags |= NODE_ENDED; break; } }
static int mdoc_it_pre(MDOC_ARGS) { const struct roff_node *bl; struct tag *t; enum mdoc_list type; bl = n->parent; while (bl->tok != MDOC_Bl) bl = bl->parent; type = bl->norm->Bl.type; switch (type) { case LIST_bullet: case LIST_dash: case LIST_hyphen: case LIST_item: case LIST_enum: switch (n->type) { case ROFFT_HEAD: return 0; case ROFFT_BODY: print_otag(h, TAG_LI, ""); break; default: break; } break; case LIST_diag: case LIST_hang: case LIST_inset: case LIST_ohang: switch (n->type) { case ROFFT_HEAD: print_otag(h, TAG_DT, ""); break; case ROFFT_BODY: print_otag(h, TAG_DD, ""); break; default: break; } break; case LIST_tag: switch (n->type) { case ROFFT_HEAD: if (h->style != NULL && !bl->norm->Bl.comp && (n->parent->prev == NULL || n->parent->prev->body == NULL || n->parent->prev->body->child != NULL)) { t = print_otag(h, TAG_DT, ""); print_text(h, "\\ "); print_tagq(h, t); t = print_otag(h, TAG_DD, ""); print_text(h, "\\ "); print_tagq(h, t); } print_otag(h, TAG_DT, ""); break; case ROFFT_BODY: if (n->child == NULL) { print_otag(h, TAG_DD, "s", "width", "auto"); print_text(h, "\\ "); } else print_otag(h, TAG_DD, ""); break; default: break; } break; case LIST_column: switch (n->type) { case ROFFT_HEAD: break; case ROFFT_BODY: print_otag(h, TAG_TD, ""); break; default: print_otag(h, TAG_TR, ""); } default: break; } return 1; }
/* ARGSUSED */ static int mdoc_quote_pre(MDOC_ARGS) { struct htmlpair tag; if (MDOC_BODY != n->type) return(1); switch (n->tok) { case (MDOC_Ao): /* FALLTHROUGH */ case (MDOC_Aq): print_text(h, "\\(la"); break; case (MDOC_Bro): /* FALLTHROUGH */ case (MDOC_Brq): print_text(h, "\\(lC"); break; case (MDOC_Bo): /* FALLTHROUGH */ case (MDOC_Bq): print_text(h, "\\(lB"); break; case (MDOC_Oo): /* FALLTHROUGH */ case (MDOC_Op): print_text(h, "\\(lB"); h->flags |= HTML_NOSPACE; PAIR_CLASS_INIT(&tag, "opt"); print_otag(h, TAG_SPAN, 1, &tag); break; case (MDOC_Do): /* FALLTHROUGH */ case (MDOC_Dq): /* FALLTHROUGH */ case (MDOC_Qo): /* FALLTHROUGH */ case (MDOC_Qq): print_text(h, "\\(lq"); break; case (MDOC_Po): /* FALLTHROUGH */ case (MDOC_Pq): print_text(h, "("); break; case (MDOC_Ql): /* FALLTHROUGH */ case (MDOC_So): /* FALLTHROUGH */ case (MDOC_Sq): print_text(h, "\\(oq"); break; default: abort(); /* NOTREACHED */ } h->flags |= HTML_NOSPACE; return(1); }
/* ARGSUSED */ static int mdoc__x_pre(MDOC_ARGS) { struct htmlpair tag[2]; enum htmltag t; t = TAG_SPAN; switch (n->tok) { case(MDOC__A): PAIR_CLASS_INIT(&tag[0], "ref-auth"); if (n->prev && MDOC__A == n->prev->tok) if (NULL == n->next || MDOC__A != n->next->tok) print_text(h, "and"); break; case(MDOC__B): PAIR_CLASS_INIT(&tag[0], "ref-book"); t = TAG_I; break; case(MDOC__C): PAIR_CLASS_INIT(&tag[0], "ref-city"); break; case(MDOC__D): PAIR_CLASS_INIT(&tag[0], "ref-date"); break; case(MDOC__I): PAIR_CLASS_INIT(&tag[0], "ref-issue"); t = TAG_I; break; case(MDOC__J): PAIR_CLASS_INIT(&tag[0], "ref-jrnl"); t = TAG_I; break; case(MDOC__N): PAIR_CLASS_INIT(&tag[0], "ref-num"); break; case(MDOC__O): PAIR_CLASS_INIT(&tag[0], "ref-opt"); break; case(MDOC__P): PAIR_CLASS_INIT(&tag[0], "ref-page"); break; case(MDOC__Q): PAIR_CLASS_INIT(&tag[0], "ref-corp"); break; case(MDOC__R): PAIR_CLASS_INIT(&tag[0], "ref-rep"); break; case(MDOC__T): PAIR_CLASS_INIT(&tag[0], "ref-title"); break; case(MDOC__U): PAIR_CLASS_INIT(&tag[0], "link-ref"); break; case(MDOC__V): PAIR_CLASS_INIT(&tag[0], "ref-vol"); break; default: abort(); /* NOTREACHED */ } if (MDOC__U != n->tok) { print_otag(h, t, 1, tag); return(1); } PAIR_HREF_INIT(&tag[1], n->child->string); print_otag(h, TAG_A, 2, tag); return(1); }
static int mdoc_bl_pre(MDOC_ARGS) { char cattr[28]; struct mdoc_bl *bl; enum htmltag elemtype; switch (n->type) { case ROFFT_BODY: return 1; case ROFFT_HEAD: return 0; default: break; } bl = &n->norm->Bl; switch (bl->type) { case LIST_bullet: elemtype = TAG_UL; (void)strlcpy(cattr, "Bl-bullet", sizeof(cattr)); break; case LIST_dash: case LIST_hyphen: elemtype = TAG_UL; (void)strlcpy(cattr, "Bl-dash", sizeof(cattr)); break; case LIST_item: elemtype = TAG_UL; (void)strlcpy(cattr, "Bl-item", sizeof(cattr)); break; case LIST_enum: elemtype = TAG_OL; (void)strlcpy(cattr, "Bl-enum", sizeof(cattr)); break; case LIST_diag: elemtype = TAG_DL; (void)strlcpy(cattr, "Bl-diag", sizeof(cattr)); break; case LIST_hang: elemtype = TAG_DL; (void)strlcpy(cattr, "Bl-hang", sizeof(cattr)); break; case LIST_inset: elemtype = TAG_DL; (void)strlcpy(cattr, "Bl-inset", sizeof(cattr)); break; case LIST_ohang: elemtype = TAG_DL; (void)strlcpy(cattr, "Bl-ohang", sizeof(cattr)); break; case LIST_tag: if (bl->offs) print_otag(h, TAG_DIV, "c", "Bd-indent"); print_otag(h, TAG_DL, "c", bl->comp ? "Bl-tag Bl-compact" : "Bl-tag"); return 1; case LIST_column: elemtype = TAG_TABLE; (void)strlcpy(cattr, "Bl-column", sizeof(cattr)); break; default: abort(); } if (bl->offs != NULL) (void)strlcat(cattr, " Bd-indent", sizeof(cattr)); if (bl->comp) (void)strlcat(cattr, " Bl-compact", sizeof(cattr)); print_otag(h, elemtype, "c", cattr); return 1; }
static void print_mdoc_node(MDOC_ARGS) { int child; struct tag *t; struct htmlpair tag; child = 1; t = h->tags.head; bufinit(h); switch (n->type) { case (MDOC_ROOT): child = mdoc_root_pre(m, n, h); break; case (MDOC_TEXT): /* No tables in this mode... */ assert(NULL == h->tblt); /* * Make sure that if we're in a literal mode already * (i.e., within a <PRE>) don't print the newline. */ if (' ' == *n->string && MDOC_LINE & n->flags) if ( ! (HTML_LITERAL & h->flags)) print_otag(h, TAG_BR, 0, NULL); if (MDOC_DELIMC & n->flags) h->flags |= HTML_NOSPACE; print_text(h, n->string); if (MDOC_DELIMO & n->flags) h->flags |= HTML_NOSPACE; return; case (MDOC_EQN): PAIR_CLASS_INIT(&tag, "eqn"); print_otag(h, TAG_SPAN, 1, &tag); print_text(h, n->eqn->data); break; case (MDOC_TBL): /* * This will take care of initialising all of the table * state data for the first table, then tearing it down * for the last one. */ print_tbl(h, n->span); return; default: /* * Close out the current table, if it's open, and unset * the "meta" table state. This will be reopened on the * next table element. */ if (h->tblt) { print_tblclose(h); t = h->tags.head; } assert(NULL == h->tblt); if (mdocs[n->tok].pre && ENDBODY_NOT == n->end) child = (*mdocs[n->tok].pre)(m, n, h); break; } if (HTML_KEEP & h->flags) { if (n->prev && n->prev->line != n->line) { h->flags &= ~HTML_KEEP; h->flags |= HTML_PREKEEP; } else if (NULL == n->prev) { if (n->parent && n->parent->line != n->line) { h->flags &= ~HTML_KEEP; h->flags |= HTML_PREKEEP; } } } if (child && n->child) print_mdoc_nodelist(m, n->child, h); print_stagq(h, t); bufinit(h); switch (n->type) { case (MDOC_ROOT): mdoc_root_post(m, n, h); break; case (MDOC_EQN): break; default: if (mdocs[n->tok].post && ENDBODY_NOT == n->end) (*mdocs[n->tok].post)(m, n, h); break; } }
static int mdoc_st_pre(MDOC_ARGS) { print_otag(h, TAG_SPAN, "cT", "St"); return 1; }
/* ARGSUSED */ static int mdoc_it_pre(MDOC_ARGS) { struct roffsu su; enum mdoc_list type; struct htmlpair tag[2]; const struct mdoc_node *bl; bl = n->parent; while (bl && MDOC_Bl != bl->tok) bl = bl->parent; assert(bl); type = bl->norm->Bl.type; assert(lists[type]); PAIR_CLASS_INIT(&tag[0], lists[type]); if (MDOC_HEAD == n->type) { switch (type) { case(LIST_bullet): /* FALLTHROUGH */ case(LIST_dash): /* FALLTHROUGH */ case(LIST_item): /* FALLTHROUGH */ case(LIST_hyphen): /* FALLTHROUGH */ case(LIST_enum): return(0); case(LIST_diag): /* FALLTHROUGH */ case(LIST_hang): /* FALLTHROUGH */ case(LIST_inset): /* FALLTHROUGH */ case(LIST_ohang): /* FALLTHROUGH */ case(LIST_tag): SCALE_VS_INIT(&su, ! bl->norm->Bl.comp); bufcat_su(h, "margin-top", &su); PAIR_STYLE_INIT(&tag[1], h); print_otag(h, TAG_DT, 2, tag); if (LIST_diag != type) break; PAIR_CLASS_INIT(&tag[0], "diag"); print_otag(h, TAG_B, 1, tag); break; case(LIST_column): break; default: break; } } else if (MDOC_BODY == n->type) { switch (type) { case(LIST_bullet): /* FALLTHROUGH */ case(LIST_hyphen): /* FALLTHROUGH */ case(LIST_dash): /* FALLTHROUGH */ case(LIST_enum): /* FALLTHROUGH */ case(LIST_item): SCALE_VS_INIT(&su, ! bl->norm->Bl.comp); bufcat_su(h, "margin-top", &su); PAIR_STYLE_INIT(&tag[1], h); print_otag(h, TAG_LI, 2, tag); break; case(LIST_diag): /* FALLTHROUGH */ case(LIST_hang): /* FALLTHROUGH */ case(LIST_inset): /* FALLTHROUGH */ case(LIST_ohang): /* FALLTHROUGH */ case(LIST_tag): if (NULL == bl->norm->Bl.width) { print_otag(h, TAG_DD, 1, tag); break; } a2width(bl->norm->Bl.width, &su); bufcat_su(h, "margin-left", &su); PAIR_STYLE_INIT(&tag[1], h); print_otag(h, TAG_DD, 2, tag); break; case(LIST_column): SCALE_VS_INIT(&su, ! bl->norm->Bl.comp); bufcat_su(h, "margin-top", &su); PAIR_STYLE_INIT(&tag[1], h); print_otag(h, TAG_TD, 2, tag); break; default: break; } } else { switch (type) { case (LIST_column): print_otag(h, TAG_TR, 1, tag); break; default: break; } } return(1); }
static int mdoc_em_pre(MDOC_ARGS) { print_otag(h, TAG_I, "cT", "Em"); return 1; }
static void eqn_box(struct html *p, const struct eqn_box *bp) { struct tag *post, *row, *cell, *t; struct htmlpair tag[2]; const struct eqn_box *child, *parent; size_t i, j, rows; if (NULL == bp) return; post = NULL; /* * Special handling for a matrix, which is presented to us in * column order, but must be printed in row-order. */ if (EQN_MATRIX == bp->type) { if (NULL == bp->first) goto out; if (EQN_LIST != bp->first->type) { eqn_box(p, bp->first); goto out; } if (NULL == (parent = bp->first->first)) goto out; /* Estimate the number of rows, first. */ if (NULL == (child = parent->first)) goto out; for (rows = 0; NULL != child; rows++) child = child->next; /* Print row-by-row. */ post = print_otag(p, TAG_MTABLE, 0, NULL); for (i = 0; i < rows; i++) { parent = bp->first->first; row = print_otag(p, TAG_MTR, 0, NULL); while (NULL != parent) { child = parent->first; for (j = 0; j < i; j++) { if (NULL == child) break; child = child->next; } cell = print_otag (p, TAG_MTD, 0, NULL); /* * If we have no data for this * particular cell, then print a * placeholder and continue--don't puke. */ if (NULL != child) eqn_box(p, child->first); print_tagq(p, cell); parent = parent->next; } print_tagq(p, row); } goto out; } switch (bp->pos) { case (EQNPOS_TO): post = print_otag(p, TAG_MOVER, 0, NULL); break; case (EQNPOS_SUP): post = print_otag(p, TAG_MSUP, 0, NULL); break; case (EQNPOS_FROM): post = print_otag(p, TAG_MUNDER, 0, NULL); break; case (EQNPOS_SUB): post = print_otag(p, TAG_MSUB, 0, NULL); break; case (EQNPOS_OVER): post = print_otag(p, TAG_MFRAC, 0, NULL); break; case (EQNPOS_FROMTO): post = print_otag(p, TAG_MUNDEROVER, 0, NULL); break; case (EQNPOS_SUBSUP): post = print_otag(p, TAG_MSUBSUP, 0, NULL); break; case (EQNPOS_SQRT): post = print_otag(p, TAG_MSQRT, 0, NULL); break; default: break; } if (bp->top || bp->bottom) { assert(NULL == post); if (bp->top && NULL == bp->bottom) post = print_otag(p, TAG_MOVER, 0, NULL); else if (bp->top && bp->bottom) post = print_otag(p, TAG_MUNDEROVER, 0, NULL); else if (bp->bottom) post = print_otag(p, TAG_MUNDER, 0, NULL); } if (EQN_PILE == bp->type) { assert(NULL == post); if (bp->first != NULL && bp->first->type == EQN_LIST) post = print_otag(p, TAG_MTABLE, 0, NULL); } else if (bp->type == EQN_LIST && bp->parent && bp->parent->type == EQN_PILE) { assert(NULL == post); post = print_otag(p, TAG_MTR, 0, NULL); print_otag(p, TAG_MTD, 0, NULL); } if (NULL != bp->text) { assert(NULL == post); post = print_otag(p, TAG_MI, 0, NULL); print_text(p, bp->text); } else if (NULL == post) { if (NULL != bp->left || NULL != bp->right) { PAIR_INIT(&tag[0], ATTR_OPEN, NULL == bp->left ? "" : bp->left); PAIR_INIT(&tag[1], ATTR_CLOSE, NULL == bp->right ? "" : bp->right); post = print_otag(p, TAG_MFENCED, 2, tag); } if (NULL == post) post = print_otag(p, TAG_MROW, 0, NULL); else print_otag(p, TAG_MROW, 0, NULL); } eqn_box(p, bp->first); out: if (NULL != bp->bottom) { t = print_otag(p, TAG_MO, 0, NULL); print_text(p, bp->bottom); print_tagq(p, t); } if (NULL != bp->top) { t = print_otag(p, TAG_MO, 0, NULL); print_text(p, bp->top); print_tagq(p, t); } if (NULL != post) print_tagq(p, post); eqn_box(p, bp->next); }
static int mdoc_bd_pre(MDOC_ARGS) { int comp, sv; struct roff_node *nn; if (n->type == ROFFT_HEAD) return 0; if (n->type == ROFFT_BLOCK) { comp = n->norm->Bd.comp; for (nn = n; nn && ! comp; nn = nn->parent) { if (nn->type != ROFFT_BLOCK) continue; if (MDOC_Ss == nn->tok || MDOC_Sh == nn->tok) comp = 1; if (nn->prev) break; } if ( ! comp) print_paragraph(h); return 1; } /* Handle the -offset argument. */ if (n->norm->Bd.offs == NULL || ! strcmp(n->norm->Bd.offs, "left")) print_otag(h, TAG_DIV, "c", "Bd"); else print_otag(h, TAG_DIV, "c", "Bd Bd-indent"); if (n->norm->Bd.type != DISP_unfilled && n->norm->Bd.type != DISP_literal) return 1; print_otag(h, TAG_PRE, "c", "Li"); /* This can be recursive: save & set our literal state. */ sv = h->flags & HTML_LITERAL; h->flags |= HTML_LITERAL; for (nn = n->child; nn; nn = nn->next) { print_mdoc_node(meta, nn, h); /* * If the printed node flushes its own line, then we * needn't do it here as well. This is hacky, but the * notion of selective eoln whitespace is pretty dumb * anyway, so don't sweat it. */ switch (nn->tok) { case ROFF_br: case ROFF_sp: case MDOC_Sm: case MDOC_Bl: case MDOC_D1: case MDOC_Dl: case MDOC_Lp: case MDOC_Pp: continue; default: break; } if (h->flags & HTML_NONEWLINE || (nn->next && ! (nn->next->flags & NODE_LINE))) continue; else if (nn->next) print_text(h, "\n"); h->flags |= HTML_NOSPACE; } if (0 == sv) h->flags &= ~HTML_LITERAL; return 0; }