version 1.248, 2017/01/17 01:47:51 |
version 1.253, 2017/01/19 15:27:34 |
|
|
html_mdoc(void *arg, const struct roff_man *mdoc) |
html_mdoc(void *arg, const struct roff_man *mdoc) |
{ |
{ |
struct html *h; |
struct html *h; |
struct tag *t, *tt; |
struct tag *t; |
|
|
h = (struct html *)arg; |
h = (struct html *)arg; |
|
|
if ( ! (HTML_FRAGMENT & h->oflags)) { |
if ((h->oflags & HTML_FRAGMENT) == 0) { |
print_gen_decls(h); |
print_gen_decls(h); |
t = print_otag(h, TAG_HTML, ""); |
print_otag(h, TAG_HTML, ""); |
tt = print_otag(h, TAG_HEAD, ""); |
t = print_otag(h, TAG_HEAD, ""); |
print_mdoc_head(&mdoc->meta, mdoc->first->child, h); |
print_mdoc_head(&mdoc->meta, mdoc->first->child, h); |
print_tagq(h, tt); |
print_tagq(h, t); |
print_otag(h, TAG_BODY, ""); |
print_otag(h, TAG_BODY, ""); |
print_otag(h, TAG_DIV, "c", "mandoc"); |
} |
} else |
|
t = print_otag(h, TAG_DIV, "c", "mandoc"); |
|
|
|
mdoc_root_pre(&mdoc->meta, mdoc->first->child, h); |
mdoc_root_pre(&mdoc->meta, mdoc->first->child, h); |
|
t = print_otag(h, TAG_DIV, "c", "manual-text"); |
print_mdoc_nodelist(&mdoc->meta, mdoc->first->child, h); |
print_mdoc_nodelist(&mdoc->meta, mdoc->first->child, h); |
mdoc_root_post(&mdoc->meta, mdoc->first->child, h); |
|
print_tagq(h, t); |
print_tagq(h, t); |
putchar('\n'); |
mdoc_root_post(&mdoc->meta, mdoc->first->child, h); |
|
print_tagq(h, NULL); |
} |
} |
|
|
static void |
static void |
print_mdoc_head(MDOC_ARGS) |
print_mdoc_head(MDOC_ARGS) |
{ |
{ |
|
char *cp; |
|
|
print_gen_head(h); |
print_gen_head(h); |
bufinit(h); |
|
bufcat(h, meta->title); |
|
if (meta->msec) |
|
bufcat_fmt(h, "(%s)", meta->msec); |
|
if (meta->arch) |
|
bufcat_fmt(h, " (%s)", meta->arch); |
|
|
|
|
if (meta->arch != NULL && meta->msec != NULL) |
|
mandoc_asprintf(&cp, "%s(%s) (%s)", meta->title, |
|
meta->msec, meta->arch); |
|
else if (meta->msec != NULL) |
|
mandoc_asprintf(&cp, "%s(%s)", meta->title, meta->msec); |
|
else if (meta->arch != NULL) |
|
mandoc_asprintf(&cp, "%s (%s)", meta->title, meta->arch); |
|
else |
|
cp = mandoc_strdup(meta->title); |
|
|
print_otag(h, TAG_TITLE, ""); |
print_otag(h, TAG_TITLE, ""); |
print_text(h, h->buf); |
print_text(h, cp); |
|
free(cp); |
} |
} |
|
|
static void |
static void |
Line 379 print_mdoc_node(MDOC_ARGS) |
|
Line 384 print_mdoc_node(MDOC_ARGS) |
|
h->flags |= HTML_NOSPACE; |
h->flags |= HTML_NOSPACE; |
return; |
return; |
case ROFFT_EQN: |
case ROFFT_EQN: |
if (n->flags & NODE_LINE) |
|
putchar('\n'); |
|
print_eqn(h, n->eqn); |
print_eqn(h, n->eqn); |
break; |
break; |
case ROFFT_TBL: |
case ROFFT_TBL: |
Line 489 mdoc_root_pre(MDOC_ARGS) |
|
Line 492 mdoc_root_pre(MDOC_ARGS) |
|
return 1; |
return 1; |
} |
} |
|
|
|
char * |
|
make_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; |
|
} |
|
|
static int |
static int |
mdoc_sh_pre(MDOC_ARGS) |
mdoc_sh_pre(MDOC_ARGS) |
{ |
{ |
|
char *id; |
|
|
switch (n->type) { |
switch (n->type) { |
case ROFFT_BLOCK: |
case ROFFT_BLOCK: |
print_otag(h, TAG_DIV, "c", "section"); |
|
return 1; |
return 1; |
case ROFFT_BODY: |
case ROFFT_BODY: |
if (n->sec == SEC_AUTHORS) |
if (n->sec == SEC_AUTHORS) |
Line 504 mdoc_sh_pre(MDOC_ARGS) |
|
Line 530 mdoc_sh_pre(MDOC_ARGS) |
|
break; |
break; |
} |
} |
|
|
bufinit(h); |
if ((id = make_id(n)) != NULL) { |
|
print_otag(h, TAG_H1, "ci", "Sh", id); |
|
free(id); |
|
} else |
|
print_otag(h, TAG_H1, "c", "Sh"); |
|
|
for (n = n->child; n != NULL && n->type == ROFFT_TEXT; ) { |
|
bufcat_id(h, n->string); |
|
if (NULL != (n = n->next)) |
|
bufcat_id(h, " "); |
|
} |
|
|
|
if (NULL == n) |
|
print_otag(h, TAG_H1, "i", h->buf); |
|
else |
|
print_otag(h, TAG_H1, ""); |
|
|
|
return 1; |
return 1; |
} |
} |
|
|
static int |
static int |
mdoc_ss_pre(MDOC_ARGS) |
mdoc_ss_pre(MDOC_ARGS) |
{ |
{ |
if (n->type == ROFFT_BLOCK) { |
char *id; |
print_otag(h, TAG_DIV, "c", "subsection"); |
|
|
if (n->type != ROFFT_HEAD) |
return 1; |
return 1; |
} else if (n->type == ROFFT_BODY) |
|
return 1; |
|
|
|
bufinit(h); |
if ((id = make_id(n)) != NULL) { |
|
print_otag(h, TAG_H2, "ci", "Ss", id); |
|
free(id); |
|
} else |
|
print_otag(h, TAG_H2, "c", "Ss"); |
|
|
for (n = n->child; n != NULL && n->type == ROFFT_TEXT; ) { |
|
bufcat_id(h, n->string); |
|
if (NULL != (n = n->next)) |
|
bufcat_id(h, " "); |
|
} |
|
|
|
if (NULL == n) |
|
print_otag(h, TAG_H2, "i", h->buf); |
|
else |
|
print_otag(h, TAG_H2, ""); |
|
|
|
return 1; |
return 1; |
} |
} |
|
|
Line 623 mdoc_xr_pre(MDOC_ARGS) |
|
Line 634 mdoc_xr_pre(MDOC_ARGS) |
|
if (NULL == n->child) |
if (NULL == n->child) |
return 0; |
return 0; |
|
|
if (h->base_man) { |
if (h->base_man) |
buffmt_man(h, n->child->string, |
print_otag(h, TAG_A, "chM", "link-man", |
n->child->next ? |
n->child->string, n->child->next == NULL ? |
n->child->next->string : NULL); |
NULL : n->child->next->string); |
print_otag(h, TAG_A, "ch", "link-man", h->buf); |
else |
} else |
|
print_otag(h, TAG_A, "c", "link-man"); |
print_otag(h, TAG_A, "c", "link-man"); |
|
|
n = n->child; |
n = n->child; |
Line 850 mdoc_d1_pre(MDOC_ARGS) |
|
Line 860 mdoc_d1_pre(MDOC_ARGS) |
|
static int |
static int |
mdoc_sx_pre(MDOC_ARGS) |
mdoc_sx_pre(MDOC_ARGS) |
{ |
{ |
bufinit(h); |
char *id; |
bufcat(h, "#"); |
|
|
|
for (n = n->child; n; ) { |
|
bufcat_id(h, n->string); |
|
if (NULL != (n = n->next)) |
|
bufcat_id(h, " "); |
|
} |
|
|
|
print_otag(h, TAG_I, "c", "link-sec"); |
print_otag(h, TAG_I, "c", "link-sec"); |
print_otag(h, TAG_A, "ch", "link-sec", h->buf); |
if ((id = make_id(n)) != NULL) { |
|
print_otag(h, TAG_A, "chR", "link-sec", id); |
|
free(id); |
|
} else |
|
print_otag(h, TAG_A, "c", "link-sec"); |
|
|
return 1; |
return 1; |
} |
} |
|
|
Line 1051 mdoc_fa_pre(MDOC_ARGS) |
|
Line 1059 mdoc_fa_pre(MDOC_ARGS) |
|
static int |
static int |
mdoc_fd_pre(MDOC_ARGS) |
mdoc_fd_pre(MDOC_ARGS) |
{ |
{ |
char buf[BUFSIZ]; |
|
size_t sz; |
|
struct tag *t; |
struct tag *t; |
|
char *buf, *cp; |
|
|
synopsis_pre(h, n); |
synopsis_pre(h, n); |
|
|
Line 1073 mdoc_fd_pre(MDOC_ARGS) |
|
Line 1080 mdoc_fd_pre(MDOC_ARGS) |
|
if (NULL != (n = n->next)) { |
if (NULL != (n = n->next)) { |
assert(n->type == ROFFT_TEXT); |
assert(n->type == ROFFT_TEXT); |
|
|
/* |
|
* XXX This is broken and not easy to fix. |
|
* When using -Oincludes, truncation may occur. |
|
* Dynamic allocation wouldn't help because |
|
* passing long strings to buffmt_includes() |
|
* does not work either. |
|
*/ |
|
|
|
strlcpy(buf, '<' == *n->string || '"' == *n->string ? |
|
n->string + 1 : n->string, BUFSIZ); |
|
|
|
sz = strlen(buf); |
|
if (sz && ('>' == buf[sz - 1] || '"' == buf[sz - 1])) |
|
buf[sz - 1] = '\0'; |
|
|
|
if (h->base_includes) { |
if (h->base_includes) { |
buffmt_includes(h, buf); |
cp = n->string; |
t = print_otag(h, TAG_A, "ch", "link-includes", |
if (*cp == '<' || *cp == '"') |
h->buf); |
cp++; |
|
buf = mandoc_strdup(cp); |
|
cp = strchr(buf, '\0') - 1; |
|
if (cp >= buf && (*cp == '>' || *cp == '"')) |
|
*cp = '\0'; |
|
t = print_otag(h, TAG_A, "chI", "link-includes", buf); |
|
free(buf); |
} else |
} else |
t = print_otag(h, TAG_A, "c", "link-includes"); |
t = print_otag(h, TAG_A, "c", "link-includes"); |
|
|
|
|
mdoc_mt_pre(MDOC_ARGS) |
mdoc_mt_pre(MDOC_ARGS) |
{ |
{ |
struct tag *t; |
struct tag *t; |
|
char *cp; |
|
|
for (n = n->child; n; n = n->next) { |
for (n = n->child; n; n = n->next) { |
assert(n->type == ROFFT_TEXT); |
assert(n->type == ROFFT_TEXT); |
|
|
bufinit(h); |
mandoc_asprintf(&cp, "mailto:%s", n->string); |
bufcat(h, "mailto:"); |
t = print_otag(h, TAG_A, "ch", "link-mail", cp); |
bufcat(h, n->string); |
|
t = print_otag(h, TAG_A, "ch", "link-mail", h->buf); |
|
print_text(h, n->string); |
print_text(h, n->string); |
print_tagq(h, t); |
print_tagq(h, t); |
|
free(cp); |
} |
} |
|
|
return 0; |
return 0; |
Line 1355 mdoc_in_pre(MDOC_ARGS) |
|
Line 1353 mdoc_in_pre(MDOC_ARGS) |
|
if (NULL != (n = n->child)) { |
if (NULL != (n = n->child)) { |
assert(n->type == ROFFT_TEXT); |
assert(n->type == ROFFT_TEXT); |
|
|
if (h->base_includes) { |
if (h->base_includes) |
buffmt_includes(h, n->string); |
t = print_otag(h, TAG_A, "chI", "link-includes", |
t = print_otag(h, TAG_A, "ch", "link-includes", |
n->string); |
h->buf); |
else |
} else |
|
t = print_otag(h, TAG_A, "c", "link-includes"); |
t = print_otag(h, TAG_A, "c", "link-includes"); |
print_text(h, n->string); |
print_text(h, n->string); |
print_tagq(h, t); |
print_tagq(h, t); |