=================================================================== RCS file: /cvs/mandoc/mdoc_html.c,v retrieving revision 1.274 retrieving revision 1.277 diff -u -p -r1.274 -r1.277 --- mandoc/mdoc_html.c 2017/03/13 19:01:38 1.274 +++ mandoc/mdoc_html.c 2017/03/15 11:29:53 1.277 @@ -1,4 +1,4 @@ -/* $Id: mdoc_html.c,v 1.274 2017/03/13 19:01:38 schwarze Exp $ */ +/* $Id: mdoc_html.c,v 1.277 2017/03/15 11:29:53 schwarze Exp $ */ /* * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons * Copyright (c) 2014, 2015, 2016, 2017 Ingo Schwarze @@ -48,7 +48,7 @@ struct htmlmdoc { void (*post)(MDOC_ARGS); }; -static char *make_id(const struct roff_node *); +static char *cond_id(const struct roff_node *); static void print_mdoc_head(MDOC_ARGS); static void print_mdoc_node(MDOC_ARGS); static void print_mdoc_nodelist(MDOC_ARGS); @@ -477,25 +477,19 @@ mdoc_root_pre(MDOC_ARGS) } static char * -make_id(const struct roff_node *n) +cond_id(const struct roff_node *n) { - const struct roff_node *nch; - char *buf, *cp; - - for (nch = n->child; nch != NULL; nch = nch->next) - if (nch->type != ROFFT_TEXT) - return NULL; - - buf = NULL; - deroff(&buf, n); - - /* http://www.w3.org/TR/html5/dom.html#the-id-attribute */ - - for (cp = buf; *cp != '\0'; cp++) - if (*cp == ' ') - *cp = '_'; - - return buf; + if (n->child != NULL && + n->child->type == ROFFT_TEXT && + (n->prev == NULL || + (n->prev->type == ROFFT_TEXT && + strcmp(n->prev->string, "|") == 0)) && + (n->parent->tok == MDOC_It || + (n->parent->tok == MDOC_Xo && + n->parent->parent->prev == NULL && + n->parent->parent->parent->tok == MDOC_It))) + return html_make_id(n); + return NULL; } static int @@ -505,8 +499,9 @@ mdoc_sh_pre(MDOC_ARGS) switch (n->type) { case ROFFT_HEAD: - id = make_id(n); + id = html_make_id(n); print_otag(h, TAG_H1, "cTi", "Sh", id); + print_otag(h, TAG_A, "chR", "selflink", id); free(id); break; case ROFFT_BODY: @@ -527,8 +522,9 @@ mdoc_ss_pre(MDOC_ARGS) if (n->type != ROFFT_HEAD) return 1; - id = make_id(n); + id = html_make_id(n); print_otag(h, TAG_H2, "cTi", "Ss", id); + print_otag(h, TAG_A, "chR", "selflink", id); free(id); return 1; } @@ -536,9 +532,14 @@ mdoc_ss_pre(MDOC_ARGS) static int mdoc_fl_pre(MDOC_ARGS) { - print_otag(h, TAG_B, "cT", "Fl"); - print_text(h, "\\-"); + char *id; + if ((id = cond_id(n)) != NULL) + print_otag(h, TAG_A, "chR", "selflink", id); + print_otag(h, TAG_B, "cTi", "Fl", id); + free(id); + + print_text(h, "\\-"); if (!(n->child == NULL && (n->next == NULL || n->next->type == ROFFT_TEXT || @@ -551,7 +552,12 @@ mdoc_fl_pre(MDOC_ARGS) static int mdoc_cm_pre(MDOC_ARGS) { - print_otag(h, TAG_B, "cT", "Cm"); + char *id; + + if ((id = cond_id(n)) != NULL) + print_otag(h, TAG_A, "chR", "selflink", id); + print_otag(h, TAG_B, "cTi", "Cm", id); + free(id); return 1; } @@ -599,7 +605,8 @@ mdoc_nm_pre(MDOC_ARGS) len = html_strlen(meta->name); t = print_otag(h, TAG_COLGROUP, ""); - print_otag(h, TAG_COL, "shw", len); + /* Increase width to make even bold text fit. */ + print_otag(h, TAG_COL, "shw", len + 2); print_otag(h, TAG_COL, ""); print_tagq(h, t); print_otag(h, TAG_TR, ""); @@ -925,7 +932,7 @@ mdoc_sx_pre(MDOC_ARGS) { char *id; - id = make_id(n); + id = html_make_id(n); print_otag(h, TAG_A, "cThR", "Sx", id); free(id); return 1; @@ -1068,21 +1075,42 @@ mdoc_cd_pre(MDOC_ARGS) static int mdoc_dv_pre(MDOC_ARGS) { - print_otag(h, TAG_CODE, "cT", "Dv"); + char *id; + + if ((id = cond_id(n)) != NULL) + print_otag(h, TAG_A, "chR", "selflink", id); + print_otag(h, TAG_CODE, "cTi", "Dv", id); + free(id); return 1; } static int mdoc_ev_pre(MDOC_ARGS) { - print_otag(h, TAG_CODE, "cT", "Ev"); + char *id; + + if ((id = cond_id(n)) != NULL) + print_otag(h, TAG_A, "chR", "selflink", id); + print_otag(h, TAG_CODE, "cTi", "Ev", id); + free(id); return 1; } static int mdoc_er_pre(MDOC_ARGS) { - print_otag(h, TAG_CODE, "cT", "Er"); + char *id; + + id = n->sec == SEC_ERRORS && + (n->parent->tok == MDOC_It || + (n->parent->tok == MDOC_Bq && + n->parent->parent->parent->tok == MDOC_It)) ? + html_make_id(n) : NULL; + + if (id != NULL) + print_otag(h, TAG_A, "chR", "selflink", id); + print_otag(h, TAG_CODE, "cTi", "Er", id); + free(id); return 1; } @@ -1436,7 +1464,12 @@ mdoc_in_pre(MDOC_ARGS) static int mdoc_ic_pre(MDOC_ARGS) { - print_otag(h, TAG_B, "cT", "Ic"); + char *id; + + if ((id = cond_id(n)) != NULL) + print_otag(h, TAG_A, "chR", "selflink", id); + print_otag(h, TAG_B, "cTi", "Ic", id); + free(id); return 1; } @@ -1488,7 +1521,12 @@ mdoc_bf_pre(MDOC_ARGS) static int mdoc_ms_pre(MDOC_ARGS) { - print_otag(h, TAG_B, "cT", "Ms"); + char *id; + + if ((id = cond_id(n)) != NULL) + print_otag(h, TAG_A, "chR", "selflink", id); + print_otag(h, TAG_B, "cTi", "Ms", id); + free(id); return 1; } @@ -1524,14 +1562,24 @@ mdoc_rs_pre(MDOC_ARGS) static int mdoc_no_pre(MDOC_ARGS) { - print_otag(h, TAG_SPAN, "c", "No"); + char *id; + + if ((id = cond_id(n)) != NULL) + print_otag(h, TAG_A, "chR", "selflink", id); + print_otag(h, TAG_SPAN, "ci", "No", id); + free(id); return 1; } static int mdoc_li_pre(MDOC_ARGS) { - print_otag(h, TAG_CODE, "c", "Li"); + char *id; + + if ((id = cond_id(n)) != NULL) + print_otag(h, TAG_A, "chR", "selflink", id); + print_otag(h, TAG_CODE, "ci", "Li", id); + free(id); return 1; }