- {"html", HTML_CLRLINE}, /* TAG_HTML */
- {"head", HTML_CLRLINE}, /* TAG_HEAD */
- {"body", HTML_CLRLINE}, /* TAG_BODY */
- {"meta", HTML_CLRLINE | HTML_NOSTACK}, /* TAG_META */
- {"title", HTML_CLRLINE}, /* TAG_TITLE */
- {"div", HTML_CLRLINE}, /* TAG_DIV */
- {"h1", 0}, /* TAG_H1 */
- {"h2", 0}, /* TAG_H2 */
- {"p", HTML_CLRLINE}, /* TAG_P */
- {"span", 0}, /* TAG_SPAN */
- {"link", HTML_CLRLINE | HTML_NOSTACK}, /* TAG_LINK */
- {"br", HTML_CLRLINE | HTML_NOSTACK}, /* TAG_LINK */
- {"a", 0}, /* TAG_A */
- {"table", HTML_CLRLINE}, /* TAG_TABLE */
- {"col", HTML_CLRLINE | HTML_NOSTACK}, /* TAG_COL */
- {"tr", HTML_CLRLINE}, /* TAG_TR */
- {"td", HTML_CLRLINE}, /* TAG_TD */
- {"li", HTML_CLRLINE}, /* TAG_LI */
- {"ul", HTML_CLRLINE}, /* TAG_UL */
- {"ol", HTML_CLRLINE}, /* TAG_OL */
- {"base", HTML_CLRLINE | HTML_NOSTACK}, /* TAG_BASE */
-};
-
-static const char *const htmlattrs[ATTR_MAX] = {
- "http-equiv",
- "content",
- "name",
- "rel",
- "href",
- "type",
- "media",
- "class",
- "style",
- "width",
- "valign",
-};
-
-struct htmlpair {
- enum htmlattr key;
- char *val;
-};
-
-struct tag {
- enum htmltag tag;
- SLIST_ENTRY(tag) entry;
-};
-
-struct ord {
- int pos;
- const void *cookie;
- SLIST_ENTRY(ord) entry;
-};
-
-SLIST_HEAD(tagq, tag);
-SLIST_HEAD(ordq, ord);
-
-struct html {
- int flags;
-#define HTML_NOSPACE (1 << 0)
-#define HTML_NEWLINE (1 << 1)
- struct tagq tags;
- struct ordq ords;
- void *symtab;
- char *base;
- char *style;
-};
-
-#define MDOC_ARGS const struct mdoc_meta *m, \
- const struct mdoc_node *n, \
- struct html *h
-#define MAN_ARGS const struct man_meta *m, \
- const struct man_node *n, \
- struct html *h
-struct htmlmdoc {
- int (*pre)(MDOC_ARGS);
- void (*post)(MDOC_ARGS);
-};
-
-static void print_gen_doctype(struct html *);
-static void print_gen_head(struct html *);
-static void print_mdoc(MDOC_ARGS);
-static void print_mdoc_head(MDOC_ARGS);
-static void print_mdoc_node(MDOC_ARGS);
-static void print_mdoc_nodelist(MDOC_ARGS);
-static void print_man(MAN_ARGS);
-static void print_man_head(MAN_ARGS);
-static struct tag *print_otag(struct html *, enum htmltag,
- int, const struct htmlpair *);
-static void print_tagq(struct html *, const struct tag *);
-static void print_stagq(struct html *, const struct tag *);
-static void print_ctag(struct html *, enum htmltag);
-static void print_encode(struct html *, const char *);
-static void print_escape(struct html *, const char **);
-static void print_text(struct html *, const char *);
-static void print_res(struct html *, const char *, int);
-static void print_spec(struct html *, const char *, int);
-
-static void mdoc_root_post(MDOC_ARGS);
-static int mdoc_root_pre(MDOC_ARGS);
-static int mdoc_tbl_pre(MDOC_ARGS, int);
-static int mdoc_tbl_block_pre(MDOC_ARGS, int, int, int, int);
-static int mdoc_tbl_body_pre(MDOC_ARGS, int, int);
-static int mdoc_tbl_head_pre(MDOC_ARGS, int, int);
-
-static int mdoc_ad_pre(MDOC_ARGS);
-static int mdoc_an_pre(MDOC_ARGS);
-static void mdoc_aq_post(MDOC_ARGS);
-static int mdoc_aq_pre(MDOC_ARGS);
-static int mdoc_ar_pre(MDOC_ARGS);
-static int mdoc_bd_pre(MDOC_ARGS);
-static void mdoc_bl_post(MDOC_ARGS);
-static int mdoc_bl_pre(MDOC_ARGS);
-static int mdoc_cd_pre(MDOC_ARGS);
-static int mdoc_d1_pre(MDOC_ARGS);
-static void mdoc_dq_post(MDOC_ARGS);
-static int mdoc_dq_pre(MDOC_ARGS);
-static int mdoc_dv_pre(MDOC_ARGS);
-static int mdoc_fa_pre(MDOC_ARGS);
-static int mdoc_fd_pre(MDOC_ARGS);
-static int mdoc_fl_pre(MDOC_ARGS);
-static int mdoc_fn_pre(MDOC_ARGS);
-static int mdoc_ft_pre(MDOC_ARGS);
-static int mdoc_em_pre(MDOC_ARGS);
-static int mdoc_er_pre(MDOC_ARGS);
-static int mdoc_ev_pre(MDOC_ARGS);
-static int mdoc_ex_pre(MDOC_ARGS);
-static int mdoc_it_pre(MDOC_ARGS);
-static int mdoc_nd_pre(MDOC_ARGS);
-static int mdoc_nm_pre(MDOC_ARGS);
-static int mdoc_ns_pre(MDOC_ARGS);
-static void mdoc_op_post(MDOC_ARGS);
-static int mdoc_op_pre(MDOC_ARGS);
-static int mdoc_pa_pre(MDOC_ARGS);
-static int mdoc_pp_pre(MDOC_ARGS);
-static void mdoc_pq_post(MDOC_ARGS);
-static int mdoc_pq_pre(MDOC_ARGS);
-static void mdoc_qq_post(MDOC_ARGS);
-static int mdoc_qq_pre(MDOC_ARGS);
-static int mdoc_sh_pre(MDOC_ARGS);
-static void mdoc_sq_post(MDOC_ARGS);
-static int mdoc_sq_pre(MDOC_ARGS);
-static int mdoc_ss_pre(MDOC_ARGS);
-static int mdoc_sx_pre(MDOC_ARGS);
-static int mdoc_vt_pre(MDOC_ARGS);
-static int mdoc_xr_pre(MDOC_ARGS);
-static int mdoc_xx_pre(MDOC_ARGS);
-
-#ifdef __linux__
-extern size_t strlcpy(char *, const char *, size_t);
-extern size_t strlcat(char *, const char *, size_t);
-#endif
-
-static const struct htmlmdoc mdocs[MDOC_MAX] = {
- {mdoc_pp_pre, NULL}, /* Ap */
- {NULL, NULL}, /* Dd */
- {NULL, NULL}, /* Dt */
- {NULL, NULL}, /* Os */
- {mdoc_sh_pre, NULL }, /* Sh */
- {mdoc_ss_pre, NULL }, /* Ss */
- {mdoc_pp_pre, NULL}, /* Pp */
- {mdoc_d1_pre, NULL}, /* D1 */
- {mdoc_d1_pre, NULL}, /* Dl */
- {mdoc_bd_pre, NULL}, /* Bd */
- {NULL, NULL}, /* Ed */
- {mdoc_bl_pre, mdoc_bl_post}, /* Bl */
- {NULL, NULL}, /* El */
- {mdoc_it_pre, NULL}, /* It */
- {mdoc_ad_pre, NULL}, /* Ad */
- {mdoc_an_pre, NULL}, /* An */
- {mdoc_ar_pre, NULL}, /* Ar */
- {mdoc_cd_pre, NULL}, /* Cd */
- {mdoc_fl_pre, NULL}, /* Cm */
- {mdoc_dv_pre, NULL}, /* Dv */
- {mdoc_er_pre, NULL}, /* Er */
- {mdoc_ev_pre, NULL}, /* Ev */
- {mdoc_ex_pre, NULL}, /* Ex */
- {mdoc_fa_pre, NULL}, /* Fa */
- {mdoc_fd_pre, NULL}, /* Fd */
- {mdoc_fl_pre, NULL}, /* Fl */
- {mdoc_fn_pre, NULL}, /* Fn */
- {mdoc_ft_pre, NULL}, /* Ft */
- {NULL, NULL}, /* Ic */
- {NULL, NULL}, /* In */
- {NULL, NULL}, /* Li */
- {mdoc_nd_pre, NULL}, /* Nd */
- {mdoc_nm_pre, NULL}, /* Nm */
- {mdoc_op_pre, mdoc_op_post}, /* Op */
- {NULL, NULL}, /* Ot */
- {mdoc_pa_pre, NULL}, /* Pa */
- {NULL, NULL}, /* Rv */
- {NULL, NULL}, /* St */
- {NULL, NULL}, /* Va */
- {mdoc_vt_pre, NULL}, /* Vt */
- {mdoc_xr_pre, NULL}, /* Xr */
- {NULL, NULL}, /* %A */
- {NULL, NULL}, /* %B */
- {NULL, NULL}, /* %D */
- {NULL, NULL}, /* %I */
- {NULL, NULL}, /* %J */
- {NULL, NULL}, /* %N */
- {NULL, NULL}, /* %O */
- {NULL, NULL}, /* %P */
- {NULL, NULL}, /* %R */
- {NULL, NULL}, /* %T */
- {NULL, NULL}, /* %V */
- {NULL, NULL}, /* Ac */
- {mdoc_aq_pre, mdoc_aq_post}, /* Ao */
- {mdoc_aq_pre, mdoc_aq_post}, /* Aq */
- {NULL, NULL}, /* At */
- {NULL, NULL}, /* Bc */
- {NULL, NULL}, /* Bf */
- {NULL, NULL}, /* Bo */
- {NULL, NULL}, /* Bq */
- {mdoc_xx_pre, NULL}, /* Bsx */
- {NULL, NULL}, /* Bx */
- {NULL, NULL}, /* Db */
- {NULL, NULL}, /* Dc */
- {NULL, NULL}, /* Do */
- {mdoc_dq_pre, mdoc_dq_post}, /* Dq */
- {NULL, NULL}, /* Ec */
- {NULL, NULL}, /* Ef */
- {mdoc_em_pre, NULL}, /* Em */
- {NULL, NULL}, /* Eo */
- {mdoc_xx_pre, NULL}, /* Fx */
- {NULL, NULL}, /* Ms */
- {NULL, NULL}, /* No */
- {mdoc_ns_pre, NULL}, /* Ns */
- {mdoc_xx_pre, NULL}, /* Nx */
- {mdoc_xx_pre, NULL}, /* Ox */
- {NULL, NULL}, /* Pc */
- {NULL, NULL}, /* Pf */
- {mdoc_pq_pre, mdoc_pq_post}, /* Po */
- {mdoc_pq_pre, mdoc_pq_post}, /* Pq */
- {NULL, NULL}, /* Qc */
- {NULL, NULL}, /* Ql */
- {mdoc_qq_pre, mdoc_qq_post}, /* Qo */
- {mdoc_qq_pre, mdoc_qq_post}, /* Qq */
- {NULL, NULL}, /* Re */
- {NULL, NULL}, /* Rs */
- {NULL, NULL}, /* Sc */
- {mdoc_sq_pre, mdoc_sq_post}, /* So */
- {mdoc_sq_pre, mdoc_sq_post}, /* Sq */
- {NULL, NULL}, /* Sm */
- {mdoc_sx_pre, NULL}, /* Sx */
- {NULL, NULL}, /* Sy */
- {NULL, NULL}, /* Tn */
- {mdoc_xx_pre, NULL}, /* Ux */
- {NULL, NULL}, /* Xc */
- {NULL, NULL}, /* Xo */
- {NULL, NULL}, /* Fo */
- {NULL, NULL}, /* Fc */
- {NULL, NULL}, /* Oo */
- {NULL, NULL}, /* Oc */
- {NULL, NULL}, /* Bk */
- {NULL, NULL}, /* Ek */
- {NULL, NULL}, /* Bt */
- {NULL, NULL}, /* Hf */
- {NULL, NULL}, /* Fr */
- {NULL, NULL}, /* Ud */
- {NULL, NULL}, /* Lb */
- {NULL, NULL}, /* Lp */
- {NULL, NULL}, /* Lk */
- {NULL, NULL}, /* Mt */
- {NULL, NULL}, /* Brq */
- {NULL, NULL}, /* Bro */
- {NULL, NULL}, /* Brc */
- {NULL, NULL}, /* %C */
- {NULL, NULL}, /* Es */
- {NULL, NULL}, /* En */
- {mdoc_xx_pre, NULL}, /* Dx */
- {NULL, NULL}, /* %Q */
- {NULL, NULL}, /* br */
- {NULL, NULL}, /* sp */
+ {"html", HTML_NLALL},
+ {"head", HTML_NLALL | HTML_INDENT},
+ {"meta", HTML_NOSTACK | HTML_NLALL},
+ {"link", HTML_NOSTACK | HTML_NLALL},
+ {"style", HTML_NLALL | HTML_INDENT},
+ {"title", HTML_NLAROUND},
+ {"body", HTML_NLALL},
+ {"div", HTML_NLAROUND},
+ {"section", HTML_NLALL},
+ {"table", HTML_NLALL | HTML_INDENT},
+ {"tr", HTML_NLALL | HTML_INDENT},
+ {"td", HTML_NLAROUND},
+ {"li", HTML_NLAROUND | HTML_INDENT},
+ {"ul", HTML_NLALL | HTML_INDENT},
+ {"ol", HTML_NLALL | HTML_INDENT},
+ {"dl", HTML_NLALL | HTML_INDENT},
+ {"dt", HTML_NLAROUND},
+ {"dd", HTML_NLAROUND | HTML_INDENT},
+ {"h1", HTML_TOPHRASE | HTML_NLAROUND},
+ {"h2", HTML_TOPHRASE | HTML_NLAROUND},
+ {"p", HTML_TOPHRASE | HTML_NLAROUND | HTML_INDENT},
+ {"pre", HTML_TOPHRASE | HTML_NLALL | HTML_NOINDENT},
+ {"a", HTML_INPHRASE | HTML_TOPHRASE},
+ {"b", HTML_INPHRASE | HTML_TOPHRASE},
+ {"cite", HTML_INPHRASE | HTML_TOPHRASE},
+ {"code", HTML_INPHRASE | HTML_TOPHRASE},
+ {"i", HTML_INPHRASE | HTML_TOPHRASE},
+ {"small", HTML_INPHRASE | HTML_TOPHRASE},
+ {"span", HTML_INPHRASE | HTML_TOPHRASE},
+ {"var", HTML_INPHRASE | HTML_TOPHRASE},
+ {"br", HTML_INPHRASE | HTML_NOSTACK | HTML_NLALL},
+ {"math", HTML_INPHRASE | HTML_NLALL | HTML_INDENT},
+ {"mrow", 0},
+ {"mi", 0},
+ {"mn", 0},
+ {"mo", 0},
+ {"msup", 0},
+ {"msub", 0},
+ {"msubsup", 0},
+ {"mfrac", 0},
+ {"msqrt", 0},
+ {"mfenced", 0},
+ {"mtable", 0},
+ {"mtr", 0},
+ {"mtd", 0},
+ {"munderover", 0},
+ {"munder", 0},
+ {"mover", 0},