version 1.330, 2019/09/03 15:09:44 |
version 1.334, 2020/02/27 01:43:52 |
|
|
/* $Id$ */ |
/* $Id$ */ |
/* |
/* |
* Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv> |
* Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv> |
* Copyright (c) 2014-2019 Ingo Schwarze <schwarze@openbsd.org> |
* Copyright (c) 2014-2020 Ingo Schwarze <schwarze@openbsd.org> |
* |
* |
* Permission to use, copy, modify, and distribute this software for any |
* Permission to use, copy, modify, and distribute this software for any |
* purpose with or without fee is hereby granted, provided that the above |
* purpose with or without fee is hereby granted, provided that the above |
Line 52 static void print_mdoc_head(const struct roff_meta |
|
Line 52 static void print_mdoc_head(const struct roff_meta |
|
struct html *); |
struct html *); |
static void print_mdoc_node(MDOC_ARGS); |
static void print_mdoc_node(MDOC_ARGS); |
static void print_mdoc_nodelist(MDOC_ARGS); |
static void print_mdoc_nodelist(MDOC_ARGS); |
static void synopsis_pre(struct html *, |
static void synopsis_pre(struct html *, struct roff_node *); |
const struct roff_node *); |
|
|
|
static void mdoc_root_post(const struct roff_meta *, |
static void mdoc_root_post(const struct roff_meta *, |
struct html *); |
struct html *); |
Line 115 static int mdoc_ss_pre(MDOC_ARGS); |
|
Line 114 static int mdoc_ss_pre(MDOC_ARGS); |
|
static int mdoc_st_pre(MDOC_ARGS); |
static int mdoc_st_pre(MDOC_ARGS); |
static int mdoc_sx_pre(MDOC_ARGS); |
static int mdoc_sx_pre(MDOC_ARGS); |
static int mdoc_sy_pre(MDOC_ARGS); |
static int mdoc_sy_pre(MDOC_ARGS); |
|
static int mdoc_tg_pre(MDOC_ARGS); |
static int mdoc_va_pre(MDOC_ARGS); |
static int mdoc_va_pre(MDOC_ARGS); |
static int mdoc_vt_pre(MDOC_ARGS); |
static int mdoc_vt_pre(MDOC_ARGS); |
static int mdoc_xr_pre(MDOC_ARGS); |
static int mdoc_xr_pre(MDOC_ARGS); |
Line 241 static const struct mdoc_html_act mdoc_html_acts[MDOC_ |
|
Line 241 static const struct mdoc_html_act mdoc_html_acts[MDOC_ |
|
{mdoc__x_pre, mdoc__x_post}, /* %Q */ |
{mdoc__x_pre, mdoc__x_post}, /* %Q */ |
{mdoc__x_pre, mdoc__x_post}, /* %U */ |
{mdoc__x_pre, mdoc__x_post}, /* %U */ |
{NULL, NULL}, /* Ta */ |
{NULL, NULL}, /* Ta */ |
|
{mdoc_tg_pre, NULL}, /* Tg */ |
}; |
}; |
|
|
|
|
Line 248 static const struct mdoc_html_act mdoc_html_acts[MDOC_ |
|
Line 249 static const struct mdoc_html_act mdoc_html_acts[MDOC_ |
|
* See the same function in mdoc_term.c for documentation. |
* See the same function in mdoc_term.c for documentation. |
*/ |
*/ |
static void |
static void |
synopsis_pre(struct html *h, const struct roff_node *n) |
synopsis_pre(struct html *h, struct roff_node *n) |
{ |
{ |
|
struct roff_node *np; |
|
|
if (NULL == n->prev || ! (NODE_SYNPRETTY & n->flags)) |
if ((n->flags & NODE_SYNPRETTY) == 0 || |
|
(np = roff_node_prev(n)) == NULL) |
return; |
return; |
|
|
if (n->prev->tok == n->tok && |
if (np->tok == n->tok && |
MDOC_Fo != n->tok && |
MDOC_Fo != n->tok && |
MDOC_Ft != n->tok && |
MDOC_Ft != n->tok && |
MDOC_Fn != n->tok) { |
MDOC_Fn != n->tok) { |
Line 262 synopsis_pre(struct html *h, const struct roff_node *n |
|
Line 265 synopsis_pre(struct html *h, const struct roff_node *n |
|
return; |
return; |
} |
} |
|
|
switch (n->prev->tok) { |
switch (np->tok) { |
case MDOC_Fd: |
case MDOC_Fd: |
case MDOC_Fn: |
case MDOC_Fn: |
case MDOC_Fo: |
case MDOC_Fo: |
Line 351 print_mdoc_node(MDOC_ARGS) |
|
Line 354 print_mdoc_node(MDOC_ARGS) |
|
if (n->type == ROFFT_COMMENT || n->flags & NODE_NOPRT) |
if (n->type == ROFFT_COMMENT || n->flags & NODE_NOPRT) |
return; |
return; |
|
|
html_fillmode(h, n->flags & NODE_NOFILL ? ROFF_nf : ROFF_fi); |
if (n->flags & NODE_NOFILL) { |
|
html_fillmode(h, ROFF_nf); |
|
if (n->flags & NODE_LINE) |
|
print_endline(h); |
|
} else |
|
html_fillmode(h, ROFF_fi); |
|
|
child = 1; |
child = 1; |
n->flags &= ~NODE_ENDED; |
n->flags &= ~NODE_ENDED; |
switch (n->type) { |
switch (n->type) { |
case ROFFT_TEXT: |
case ROFFT_TEXT: |
|
if (n->flags & NODE_LINE) { |
|
switch (*n->string) { |
|
case '\0': |
|
h->col = 1; |
|
print_endline(h); |
|
return; |
|
case ' ': |
|
if ((h->flags & HTML_NONEWLINE) == 0 && |
|
(n->flags & NODE_NOFILL) == 0) |
|
print_otag(h, TAG_BR, ""); |
|
break; |
|
default: |
|
break; |
|
} |
|
} |
t = h->tag; |
t = h->tag; |
t->refcnt++; |
t->refcnt++; |
|
|
/* 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_NONEWLINE) == 0 && |
|
(n->flags & NODE_NOFILL) == 0) |
|
print_otag(h, TAG_BR, ""); |
|
if (NODE_DELIMC & n->flags) |
if (NODE_DELIMC & n->flags) |
h->flags |= HTML_NOSPACE; |
h->flags |= HTML_NOSPACE; |
print_text(h, n->string); |
print_text(h, n->string); |
Line 439 print_mdoc_node(MDOC_ARGS) |
|
Line 450 print_mdoc_node(MDOC_ARGS) |
|
n->body->flags |= NODE_ENDED; |
n->body->flags |= NODE_ENDED; |
break; |
break; |
} |
} |
|
|
if (n->flags & NODE_NOFILL && |
|
(n->next == NULL || n->next->flags & NODE_LINE)) { |
|
h->col++; |
|
print_endline(h); |
|
} |
|
} |
} |
|
|
static void |
static void |
Line 621 mdoc_ss_pre(MDOC_ARGS) |
|
Line 626 mdoc_ss_pre(MDOC_ARGS) |
|
static int |
static int |
mdoc_fl_pre(MDOC_ARGS) |
mdoc_fl_pre(MDOC_ARGS) |
{ |
{ |
char *id; |
struct roff_node *nn; |
|
char *id; |
|
|
if ((id = cond_id(n)) != NULL) |
if ((id = cond_id(n)) != NULL) |
print_otag(h, TAG_A, "chR", "permalink", id); |
print_otag(h, TAG_A, "chR", "permalink", id); |
print_otag(h, TAG_CODE, "ci", "Fl", id); |
print_otag(h, TAG_CODE, "ci", "Fl", id); |
|
|
print_text(h, "\\-"); |
print_text(h, "\\-"); |
if (!(n->child == NULL && |
if (n->child != NULL || |
(n->next == NULL || |
((nn = roff_node_next(n)) != NULL && |
n->next->type == ROFFT_TEXT || |
nn->type != ROFFT_TEXT && |
n->next->flags & NODE_LINE))) |
(nn->flags & NODE_LINE) == 0)) |
h->flags |= HTML_NOSPACE; |
h->flags |= HTML_NOSPACE; |
|
|
return 1; |
return 1; |
Line 720 mdoc_xr_pre(MDOC_ARGS) |
|
Line 726 mdoc_xr_pre(MDOC_ARGS) |
|
} |
} |
|
|
static int |
static int |
|
mdoc_tg_pre(MDOC_ARGS) |
|
{ |
|
char *id; |
|
|
|
if ((id = html_make_id(n, 1)) != NULL) |
|
print_otag(h, TAG_MARK, "i", id); |
|
return 0; |
|
} |
|
|
|
static int |
mdoc_ns_pre(MDOC_ARGS) |
mdoc_ns_pre(MDOC_ARGS) |
{ |
{ |
|
|
Line 895 mdoc_bl_pre(MDOC_ARGS) |
|
Line 911 mdoc_bl_pre(MDOC_ARGS) |
|
static int |
static int |
mdoc_ex_pre(MDOC_ARGS) |
mdoc_ex_pre(MDOC_ARGS) |
{ |
{ |
if (n->prev) |
if (roff_node_prev(n) != NULL) |
print_otag(h, TAG_BR, ""); |
print_otag(h, TAG_BR, ""); |
return 1; |
return 1; |
} |
} |
Line 972 mdoc_bd_pre(MDOC_ARGS) |
|
Line 988 mdoc_bd_pre(MDOC_ARGS) |
|
continue; |
continue; |
if (nn->tok == MDOC_Sh || nn->tok == MDOC_Ss) |
if (nn->tok == MDOC_Sh || nn->tok == MDOC_Ss) |
comp = 1; |
comp = 1; |
if (nn->prev != NULL) |
if (roff_node_prev(nn) != NULL) |
break; |
break; |
} |
} |
(void)strlcpy(buf, "Bd", sizeof(buf)); |
(void)strlcpy(buf, "Bd", sizeof(buf)); |
Line 1084 mdoc_fa_pre(MDOC_ARGS) |
|
Line 1100 mdoc_fa_pre(MDOC_ARGS) |
|
print_otag(h, TAG_VAR, "c", "Fa"); |
print_otag(h, TAG_VAR, "c", "Fa"); |
return 1; |
return 1; |
} |
} |
|
for (nn = n->child; nn != NULL; nn = nn->next) { |
for (nn = n->child; nn; nn = nn->next) { |
|
t = print_otag(h, TAG_VAR, "c", "Fa"); |
t = print_otag(h, TAG_VAR, "c", "Fa"); |
print_text(h, nn->string); |
print_text(h, nn->string); |
print_tagq(h, t); |
print_tagq(h, t); |
if (nn->next) { |
if (nn->next != NULL) { |
h->flags |= HTML_NOSPACE; |
h->flags |= HTML_NOSPACE; |
print_text(h, ","); |
print_text(h, ","); |
} |
} |
} |
} |
|
if (n->child != NULL && |
if (n->child && n->next && n->next->tok == MDOC_Fa) { |
(nn = roff_node_next(n)) != NULL && |
|
nn->tok == MDOC_Fa) { |
h->flags |= HTML_NOSPACE; |
h->flags |= HTML_NOSPACE; |
print_text(h, ","); |
print_text(h, ","); |
} |
} |
|
|
return 0; |
return 0; |
} |
} |
|
|
Line 1270 mdoc_skip_pre(MDOC_ARGS) |
|
Line 1285 mdoc_skip_pre(MDOC_ARGS) |
|
static int |
static int |
mdoc_pp_pre(MDOC_ARGS) |
mdoc_pp_pre(MDOC_ARGS) |
{ |
{ |
if ((n->flags & NODE_NOFILL) == 0) { |
if (n->flags & NODE_NOFILL) { |
|
print_endline(h); |
|
h->col = 1; |
|
print_endline(h); |
|
} else { |
html_close_paragraph(h); |
html_close_paragraph(h); |
print_otag(h, TAG_P, "c", "Pp"); |
print_otag(h, TAG_P, "c", "Pp"); |
} |
} |
Line 1554 mdoc_sy_pre(MDOC_ARGS) |
|
Line 1573 mdoc_sy_pre(MDOC_ARGS) |
|
static int |
static int |
mdoc_lb_pre(MDOC_ARGS) |
mdoc_lb_pre(MDOC_ARGS) |
{ |
{ |
if (SEC_LIBRARY == n->sec && NODE_LINE & n->flags && n->prev) |
if (n->sec == SEC_LIBRARY && |
|
n->flags & NODE_LINE && |
|
roff_node_prev(n) != NULL) |
print_otag(h, TAG_BR, ""); |
print_otag(h, TAG_BR, ""); |
|
|
print_otag(h, TAG_SPAN, "c", "Lb"); |
print_otag(h, TAG_SPAN, "c", "Lb"); |
Line 1564 mdoc_lb_pre(MDOC_ARGS) |
|
Line 1585 mdoc_lb_pre(MDOC_ARGS) |
|
static int |
static int |
mdoc__x_pre(MDOC_ARGS) |
mdoc__x_pre(MDOC_ARGS) |
{ |
{ |
const char *cattr; |
struct roff_node *nn; |
enum htmltag t; |
const char *cattr; |
|
enum htmltag t; |
|
|
t = TAG_SPAN; |
t = TAG_SPAN; |
|
|
switch (n->tok) { |
switch (n->tok) { |
case MDOC__A: |
case MDOC__A: |
cattr = "RsA"; |
cattr = "RsA"; |
if (n->prev && MDOC__A == n->prev->tok) |
if ((nn = roff_node_prev(n)) != NULL && nn->tok == MDOC__A && |
if (NULL == n->next || MDOC__A != n->next->tok) |
((nn = roff_node_next(n)) == NULL || nn->tok != MDOC__A)) |
print_text(h, "and"); |
print_text(h, "and"); |
break; |
break; |
case MDOC__B: |
case MDOC__B: |
t = TAG_I; |
t = TAG_I; |
Line 1629 mdoc__x_pre(MDOC_ARGS) |
|
Line 1651 mdoc__x_pre(MDOC_ARGS) |
|
static void |
static void |
mdoc__x_post(MDOC_ARGS) |
mdoc__x_post(MDOC_ARGS) |
{ |
{ |
|
struct roff_node *nn; |
|
|
if (MDOC__A == n->tok && n->next && MDOC__A == n->next->tok) |
if (n->tok == MDOC__A && |
if (NULL == n->next->next || MDOC__A != n->next->next->tok) |
(nn = roff_node_next(n)) != NULL && nn->tok == MDOC__A && |
if (NULL == n->prev || MDOC__A != n->prev->tok) |
((nn = roff_node_next(nn)) == NULL || nn->tok != MDOC__A) && |
return; |
((nn = roff_node_prev(n)) == NULL || nn->tok != MDOC__A)) |
|
return; |
|
|
/* TODO: %U */ |
/* TODO: %U */ |
|
|
if (NULL == n->parent || MDOC_Rs != n->parent->tok) |
if (n->parent == NULL || n->parent->tok != MDOC_Rs) |
return; |
return; |
|
|
h->flags |= HTML_NOSPACE; |
h->flags |= HTML_NOSPACE; |
print_text(h, n->next ? "," : "."); |
print_text(h, roff_node_next(n) ? "," : "."); |
} |
} |
|
|
static int |
static int |
Line 1713 mdoc_quote_pre(MDOC_ARGS) |
|
Line 1737 mdoc_quote_pre(MDOC_ARGS) |
|
break; |
break; |
case MDOC_Do: |
case MDOC_Do: |
case MDOC_Dq: |
case MDOC_Dq: |
|
print_text(h, "\\(lq"); |
|
break; |
case MDOC_Qo: |
case MDOC_Qo: |
case MDOC_Qq: |
case MDOC_Qq: |
print_text(h, "\\(lq"); |
print_text(h, "\""); |
break; |
break; |
case MDOC_Po: |
case MDOC_Po: |
case MDOC_Pq: |
case MDOC_Pq: |
Line 1771 mdoc_quote_post(MDOC_ARGS) |
|
Line 1797 mdoc_quote_post(MDOC_ARGS) |
|
else |
else |
print_text(h, n->norm->Es->child->next->string); |
print_text(h, n->norm->Es->child->next->string); |
break; |
break; |
case MDOC_Qo: |
|
case MDOC_Qq: |
|
case MDOC_Do: |
case MDOC_Do: |
case MDOC_Dq: |
case MDOC_Dq: |
print_text(h, "\\(rq"); |
print_text(h, "\\(rq"); |
|
break; |
|
case MDOC_Qo: |
|
case MDOC_Qq: |
|
print_text(h, "\""); |
break; |
break; |
case MDOC_Po: |
case MDOC_Po: |
case MDOC_Pq: |
case MDOC_Pq: |