Annotation of mandoc/man_html.c, Revision 1.187
1.187 ! schwarze 1: /* $Id: man_html.c,v 1.186 2023/10/18 16:11:33 schwarze Exp $ */
1.1 kristaps 2: /*
1.187 ! schwarze 3: * Copyright (c) 2013-15,2017-20,2022-23 Ingo Schwarze <schwarze@openbsd.org>
1.104 kristaps 4: * Copyright (c) 2008-2012, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
1.1 kristaps 5: *
6: * Permission to use, copy, modify, and distribute this software for any
7: * purpose with or without fee is hereby granted, provided that the above
8: * copyright notice and this permission notice appear in all copies.
9: *
1.113 schwarze 10: * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
1.1 kristaps 11: * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1.113 schwarze 12: * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
1.1 kristaps 13: * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14: * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15: * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16: * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1.177 schwarze 17: *
18: * HTML formatter for man(7) used by mandoc(1).
1.1 kristaps 19: */
1.25 kristaps 20: #include "config.h"
21:
1.1 kristaps 22: #include <sys/types.h>
23:
1.5 kristaps 24: #include <assert.h>
25: #include <ctype.h>
1.2 kristaps 26: #include <stdio.h>
1.1 kristaps 27: #include <stdlib.h>
1.4 kristaps 28: #include <string.h>
1.1 kristaps 29:
1.94 schwarze 30: #include "mandoc_aux.h"
1.160 schwarze 31: #include "mandoc.h"
1.113 schwarze 32: #include "roff.h"
1.105 schwarze 33: #include "man.h"
1.7 kristaps 34: #include "out.h"
1.1 kristaps 35: #include "html.h"
1.10 kristaps 36: #include "main.h"
1.1 kristaps 37:
1.115 schwarze 38: #define MAN_ARGS const struct roff_meta *man, \
1.176 schwarze 39: struct roff_node *n, \
1.3 kristaps 40: struct html *h
41:
1.155 schwarze 42: struct man_html_act {
1.3 kristaps 43: int (*pre)(MAN_ARGS);
44: int (*post)(MAN_ARGS);
45: };
46:
1.147 schwarze 47: static void print_man_head(const struct roff_meta *,
48: struct html *);
1.4 kristaps 49: static void print_man_nodelist(MAN_ARGS);
50: static void print_man_node(MAN_ARGS);
1.173 schwarze 51: static char list_continues(const struct roff_node *,
52: const struct roff_node *);
1.8 kristaps 53: static int man_B_pre(MAN_ARGS);
1.86 kristaps 54: static int man_IP_pre(MAN_ARGS);
1.8 kristaps 55: static int man_I_pre(MAN_ARGS);
1.187 ! schwarze 56: static int man_MR_pre(MAN_ARGS);
1.86 kristaps 57: static int man_OP_pre(MAN_ARGS);
1.4 kristaps 58: static int man_PP_pre(MAN_ARGS);
1.9 kristaps 59: static int man_RS_pre(MAN_ARGS);
1.4 kristaps 60: static int man_SH_pre(MAN_ARGS);
1.8 kristaps 61: static int man_SM_pre(MAN_ARGS);
1.156 schwarze 62: static int man_SY_pre(MAN_ARGS);
1.90 schwarze 63: static int man_UR_pre(MAN_ARGS);
1.86 kristaps 64: static int man_alt_pre(MAN_ARGS);
65: static int man_ign_pre(MAN_ARGS);
66: static int man_in_pre(MAN_ARGS);
1.147 schwarze 67: static void man_root_post(const struct roff_meta *,
68: struct html *);
69: static void man_root_pre(const struct roff_meta *,
70: struct html *);
1.4 kristaps 71:
1.155 schwarze 72: static const struct man_html_act man_html_acts[MAN_MAX - MAN_TH] = {
1.3 kristaps 73: { NULL, NULL }, /* TH */
1.4 kristaps 74: { man_SH_pre, NULL }, /* SH */
1.166 schwarze 75: { man_SH_pre, NULL }, /* SS */
1.6 kristaps 76: { man_IP_pre, NULL }, /* TP */
1.154 schwarze 77: { man_IP_pre, NULL }, /* TQ */
1.185 schwarze 78: { man_PP_pre, NULL }, /* LP */
1.4 kristaps 79: { man_PP_pre, NULL }, /* PP */
1.185 schwarze 80: { man_PP_pre, NULL }, /* P */
1.5 kristaps 81: { man_IP_pre, NULL }, /* IP */
1.166 schwarze 82: { man_PP_pre, NULL }, /* HP */
1.8 kristaps 83: { man_SM_pre, NULL }, /* SM */
1.56 kristaps 84: { man_SM_pre, NULL }, /* SB */
1.8 kristaps 85: { man_alt_pre, NULL }, /* BI */
86: { man_alt_pre, NULL }, /* IB */
87: { man_alt_pre, NULL }, /* BR */
88: { man_alt_pre, NULL }, /* RB */
1.3 kristaps 89: { NULL, NULL }, /* R */
1.8 kristaps 90: { man_B_pre, NULL }, /* B */
91: { man_I_pre, NULL }, /* I */
92: { man_alt_pre, NULL }, /* IR */
93: { man_alt_pre, NULL }, /* RI */
1.3 kristaps 94: { NULL, NULL }, /* RE */
1.9 kristaps 95: { man_RS_pre, NULL }, /* RS */
1.8 kristaps 96: { man_ign_pre, NULL }, /* DT */
97: { man_ign_pre, NULL }, /* UC */
1.13 kristaps 98: { man_ign_pre, NULL }, /* PD */
1.34 joerg 99: { man_ign_pre, NULL }, /* AT */
1.45 kristaps 100: { man_in_pre, NULL }, /* in */
1.156 schwarze 101: { man_SY_pre, NULL }, /* SY */
102: { NULL, NULL }, /* YS */
1.86 kristaps 103: { man_OP_pre, NULL }, /* OP */
1.132 schwarze 104: { NULL, NULL }, /* EX */
105: { NULL, NULL }, /* EE */
1.90 schwarze 106: { man_UR_pre, NULL }, /* UR */
107: { NULL, NULL }, /* UE */
1.145 schwarze 108: { man_UR_pre, NULL }, /* MT */
109: { NULL, NULL }, /* ME */
1.187 ! schwarze 110: { man_MR_pre, NULL }, /* MR */
1.3 kristaps 111: };
112:
1.93 schwarze 113:
1.1 kristaps 114: void
1.161 schwarze 115: html_man(void *arg, const struct roff_meta *man)
1.1 kristaps 116: {
1.147 schwarze 117: struct html *h;
118: struct roff_node *n;
119: struct tag *t;
1.82 kristaps 120:
1.117 schwarze 121: h = (struct html *)arg;
1.147 schwarze 122: n = man->first->child;
1.3 kristaps 123:
1.126 schwarze 124: if ((h->oflags & HTML_FRAGMENT) == 0) {
1.82 kristaps 125: print_gen_decls(h);
1.126 schwarze 126: print_otag(h, TAG_HTML, "");
127: t = print_otag(h, TAG_HEAD, "");
1.161 schwarze 128: print_man_head(man, h);
1.126 schwarze 129: print_tagq(h, t);
1.181 schwarze 130: if (n != NULL && n->type == ROFFT_COMMENT)
131: print_gen_comment(h, n);
1.122 schwarze 132: print_otag(h, TAG_BODY, "");
1.126 schwarze 133: }
1.53 kristaps 134:
1.161 schwarze 135: man_root_pre(man, h);
1.180 schwarze 136: t = print_otag(h, TAG_MAIN, "c", "manual-text");
1.161 schwarze 137: print_man_nodelist(man, n, h);
1.127 schwarze 138: print_tagq(h, t);
1.161 schwarze 139: man_root_post(man, h);
1.126 schwarze 140: print_tagq(h, NULL);
1.3 kristaps 141: }
142:
143: static void
1.147 schwarze 144: print_man_head(const struct roff_meta *man, struct html *h)
1.3 kristaps 145: {
1.123 schwarze 146: char *cp;
1.3 kristaps 147:
148: print_gen_head(h);
1.123 schwarze 149: mandoc_asprintf(&cp, "%s(%s)", man->title, man->msec);
1.122 schwarze 150: print_otag(h, TAG_TITLE, "");
1.123 schwarze 151: print_text(h, cp);
152: free(cp);
1.1 kristaps 153: }
1.4 kristaps 154:
155: static void
156: print_man_nodelist(MAN_ARGS)
157: {
1.110 schwarze 158: while (n != NULL) {
1.132 schwarze 159: print_man_node(man, n, h);
1.110 schwarze 160: n = n->next;
161: }
1.4 kristaps 162: }
163:
164: static void
165: print_man_node(MAN_ARGS)
166: {
1.132 schwarze 167: struct tag *t;
1.4 kristaps 168: int child;
169:
1.167 schwarze 170: if (n->type == ROFFT_COMMENT || n->flags & NODE_NOPRT)
171: return;
172:
1.179 schwarze 173: if ((n->flags & NODE_NOFILL) == 0)
174: html_fillmode(h, ROFF_fi);
175: else if (html_fillmode(h, ROFF_nf) == ROFF_nf &&
176: n->tok != ROFF_fi && n->flags & NODE_LINE &&
177: (n->prev == NULL || n->prev->tok != MAN_YS))
178: print_endline(h);
1.132 schwarze 179:
180: child = 1;
181: switch (n->type) {
182: case ROFFT_TEXT:
1.163 schwarze 183: if (*n->string == '\0') {
184: print_endline(h);
185: return;
186: }
187: if (*n->string == ' ' && n->flags & NODE_LINE &&
188: (h->flags & HTML_NONEWLINE) == 0)
1.175 schwarze 189: print_otag(h, TAG_BR, "");
1.163 schwarze 190: else if (n->flags & NODE_DELIMC)
191: h->flags |= HTML_NOSPACE;
1.170 schwarze 192: t = h->tag;
193: t->refcnt++;
1.4 kristaps 194: print_text(h, n->string);
1.130 schwarze 195: break;
1.113 schwarze 196: case ROFFT_EQN:
1.170 schwarze 197: t = h->tag;
198: t->refcnt++;
1.80 kristaps 199: print_eqn(h, n->eqn);
1.69 kristaps 200: break;
1.113 schwarze 201: case ROFFT_TBL:
1.66 kristaps 202: /*
203: * This will take care of initialising all of the table
204: * state data for the first table, then tearing it down
205: * for the last one.
206: */
1.60 kristaps 207: print_tbl(h, n->span);
1.64 kristaps 208: return;
1.4 kristaps 209: default:
1.93 schwarze 210: /*
1.21 kristaps 211: * Close out scope of font prior to opening a macro
1.66 kristaps 212: * scope.
1.21 kristaps 213: */
1.174 schwarze 214: if (h->metac != ESCAPE_FONTROMAN) {
1.57 kristaps 215: h->metal = h->metac;
1.174 schwarze 216: h->metac = ESCAPE_FONTROMAN;
1.66 kristaps 217: }
218:
219: /*
220: * Close out the current table, if it's open, and unset
221: * the "meta" table state. This will be reopened on the
222: * next table element.
223: */
1.170 schwarze 224: if (h->tblt != NULL)
1.66 kristaps 225: print_tblclose(h);
1.170 schwarze 226: t = h->tag;
227: t->refcnt++;
1.137 schwarze 228: if (n->tok < ROFF_MAX) {
1.138 schwarze 229: roff_html_pre(h, n);
1.170 schwarze 230: t->refcnt--;
1.167 schwarze 231: print_stagq(h, t);
1.163 schwarze 232: return;
1.137 schwarze 233: }
234: assert(n->tok >= MAN_TH && n->tok < MAN_MAX);
1.155 schwarze 235: if (man_html_acts[n->tok - MAN_TH].pre != NULL)
236: child = (*man_html_acts[n->tok - MAN_TH].pre)(man,
237: n, h);
1.4 kristaps 238: break;
239: }
240:
1.164 schwarze 241: if (child && n->child != NULL)
1.132 schwarze 242: print_man_nodelist(man, n->child, h);
1.21 kristaps 243:
1.24 kristaps 244: /* This will automatically close out any font scope. */
1.170 schwarze 245: t->refcnt--;
1.171 schwarze 246: if (n->type == ROFFT_BLOCK &&
247: (n->tok == MAN_IP || n->tok == MAN_TP || n->tok == MAN_TQ)) {
248: t = h->tag;
1.173 schwarze 249: while (t->tag != TAG_DL && t->tag != TAG_UL)
1.171 schwarze 250: t = t->next;
251: /*
252: * Close the list if no further item of the same type
253: * follows; otherwise, close the item only.
254: */
1.176 schwarze 255: if (list_continues(n, roff_node_next(n)) == '\0') {
1.171 schwarze 256: print_tagq(h, t);
257: t = NULL;
258: }
259: }
260: if (t != NULL)
261: print_stagq(h, t);
1.4 kristaps 262: }
263:
1.65 kristaps 264: static void
1.147 schwarze 265: man_root_pre(const struct roff_meta *man, struct html *h)
1.4 kristaps 266: {
1.182 schwarze 267: struct tag *t;
1.94 schwarze 268: char *title;
1.4 kristaps 269:
1.89 schwarze 270: assert(man->title);
271: assert(man->msec);
1.94 schwarze 272: mandoc_asprintf(&title, "%s(%s)", man->title, man->msec);
1.4 kristaps 273:
1.182 schwarze 274: t = print_otag(h, TAG_DIV, "cr?", "head", "doc-pageheader",
1.184 schwarze 275: "aria-label", "Manual header line");
1.4 kristaps 276:
1.182 schwarze 277: print_otag(h, TAG_SPAN, "c", "head-ltitle");
1.4 kristaps 278: print_text(h, title);
1.182 schwarze 279: print_stagq(h, t);
1.4 kristaps 280:
1.182 schwarze 281: print_otag(h, TAG_SPAN, "c", "head-vol");
1.164 schwarze 282: if (man->vol != NULL)
1.95 schwarze 283: print_text(h, man->vol);
1.182 schwarze 284: print_stagq(h, t);
1.4 kristaps 285:
1.182 schwarze 286: print_otag(h, TAG_SPAN, "c", "head-rtitle");
1.4 kristaps 287: print_text(h, title);
288: print_tagq(h, t);
1.94 schwarze 289: free(title);
1.4 kristaps 290: }
291:
292: static void
1.147 schwarze 293: man_root_post(const struct roff_meta *man, struct html *h)
1.4 kristaps 294: {
1.182 schwarze 295: struct tag *t;
296:
297: t = print_otag(h, TAG_DIV, "cr?", "foot", "doc-pagefooter",
1.184 schwarze 298: "aria-label", "Manual footer line");
1.4 kristaps 299:
1.182 schwarze 300: print_otag(h, TAG_SPAN, "c", "foot-left");
301: print_stagq(h, t);
1.55 kristaps 302:
1.182 schwarze 303: print_otag(h, TAG_SPAN, "c", "foot-date");
1.89 schwarze 304: print_text(h, man->date);
1.182 schwarze 305: print_stagq(h, t);
1.4 kristaps 306:
1.182 schwarze 307: print_otag(h, TAG_SPAN, "c", "foot-os");
1.164 schwarze 308: if (man->os != NULL)
1.115 schwarze 309: print_text(h, man->os);
1.4 kristaps 310: print_tagq(h, t);
311: }
312:
313: static int
314: man_SH_pre(MAN_ARGS)
315: {
1.172 schwarze 316: const char *class;
317: enum htmltag tag;
318:
319: if (n->tok == MAN_SH) {
1.183 schwarze 320: tag = TAG_H2;
1.172 schwarze 321: class = "Sh";
322: } else {
1.183 schwarze 323: tag = TAG_H3;
1.172 schwarze 324: class = "Ss";
325: }
1.166 schwarze 326: switch (n->type) {
327: case ROFFT_BLOCK:
328: html_close_paragraph(h);
1.172 schwarze 329: print_otag(h, TAG_SECTION, "c", class);
1.166 schwarze 330: break;
331: case ROFFT_HEAD:
1.177 schwarze 332: print_otag_id(h, tag, class, n);
1.166 schwarze 333: break;
334: case ROFFT_BODY:
335: break;
336: default:
337: abort();
1.134 schwarze 338: }
1.119 schwarze 339: return 1;
1.4 kristaps 340: }
341:
342: static int
1.8 kristaps 343: man_alt_pre(MAN_ARGS)
344: {
1.114 schwarze 345: const struct roff_node *nn;
1.164 schwarze 346: struct tag *t;
1.130 schwarze 347: int i;
1.57 kristaps 348: enum htmltag fp;
1.8 kristaps 349:
1.164 schwarze 350: for (i = 0, nn = n->child; nn != NULL; nn = nn->next, i++) {
1.8 kristaps 351: switch (n->tok) {
1.93 schwarze 352: case MAN_BI:
1.57 kristaps 353: fp = i % 2 ? TAG_I : TAG_B;
1.8 kristaps 354: break;
1.93 schwarze 355: case MAN_IB:
1.57 kristaps 356: fp = i % 2 ? TAG_B : TAG_I;
1.8 kristaps 357: break;
1.93 schwarze 358: case MAN_RI:
1.57 kristaps 359: fp = i % 2 ? TAG_I : TAG_MAX;
1.8 kristaps 360: break;
1.93 schwarze 361: case MAN_IR:
1.57 kristaps 362: fp = i % 2 ? TAG_MAX : TAG_I;
1.8 kristaps 363: break;
1.93 schwarze 364: case MAN_BR:
1.57 kristaps 365: fp = i % 2 ? TAG_MAX : TAG_B;
1.8 kristaps 366: break;
1.93 schwarze 367: case MAN_RB:
1.57 kristaps 368: fp = i % 2 ? TAG_B : TAG_MAX;
1.8 kristaps 369: break;
370: default:
371: abort();
372: }
373:
374: if (i)
375: h->flags |= HTML_NOSPACE;
376:
1.130 schwarze 377: if (fp != TAG_MAX)
1.122 schwarze 378: t = print_otag(h, fp, "");
1.57 kristaps 379:
1.130 schwarze 380: print_text(h, nn->string);
1.57 kristaps 381:
1.130 schwarze 382: if (fp != TAG_MAX)
1.57 kristaps 383: print_tagq(h, t);
1.8 kristaps 384: }
1.119 schwarze 385: return 0;
1.8 kristaps 386: }
387:
388: static int
1.56 kristaps 389: man_SM_pre(MAN_ARGS)
1.8 kristaps 390: {
1.122 schwarze 391: print_otag(h, TAG_SMALL, "");
1.164 schwarze 392: if (n->tok == MAN_SB)
1.122 schwarze 393: print_otag(h, TAG_B, "");
1.119 schwarze 394: return 1;
1.8 kristaps 395: }
396:
397: static int
1.4 kristaps 398: man_PP_pre(MAN_ARGS)
399: {
1.166 schwarze 400: switch (n->type) {
401: case ROFFT_BLOCK:
402: html_close_paragraph(h);
403: break;
404: case ROFFT_HEAD:
1.119 schwarze 405: return 0;
1.166 schwarze 406: case ROFFT_BODY:
407: if (n->child != NULL &&
408: (n->child->flags & NODE_NOFILL) == 0)
409: print_otag(h, TAG_P, "c",
1.185 schwarze 410: n->tok == MAN_HP ? "Pp HP" : "Pp");
1.166 schwarze 411: break;
412: default:
413: abort();
414: }
1.119 schwarze 415: return 1;
1.5 kristaps 416: }
417:
1.173 schwarze 418: static char
419: list_continues(const struct roff_node *n1, const struct roff_node *n2)
420: {
421: const char *s1, *s2;
422: char c1, c2;
423:
424: if (n1 == NULL || n1->type != ROFFT_BLOCK ||
425: n2 == NULL || n2->type != ROFFT_BLOCK)
426: return '\0';
427: if ((n1->tok == MAN_TP || n1->tok == MAN_TQ) &&
428: (n2->tok == MAN_TP || n2->tok == MAN_TQ))
429: return ' ';
430: if (n1->tok != MAN_IP || n2->tok != MAN_IP)
431: return '\0';
432: n1 = n1->head->child;
433: n2 = n2->head->child;
434: s1 = n1 == NULL ? "" : n1->string;
435: s2 = n2 == NULL ? "" : n2->string;
436: c1 = strcmp(s1, "*") == 0 ? '*' :
437: strcmp(s1, "\\-") == 0 ? '-' :
1.186 schwarze 438: strcmp(s1, "\\(bu") == 0 ? 'b' :
439: strcmp(s1, "\\[bu]") == 0 ? 'b' : ' ';
1.173 schwarze 440: c2 = strcmp(s2, "*") == 0 ? '*' :
441: strcmp(s2, "\\-") == 0 ? '-' :
1.186 schwarze 442: strcmp(s2, "\\(bu") == 0 ? 'b' :
443: strcmp(s2, "\\[bu]") == 0 ? 'b' : ' ';
1.173 schwarze 444: return c1 != c2 ? '\0' : c1 == 'b' ? '*' : c1;
445: }
446:
1.5 kristaps 447: static int
448: man_IP_pre(MAN_ARGS)
449: {
1.176 schwarze 450: struct roff_node *nn;
1.173 schwarze 451: const char *list_class;
452: enum htmltag list_elem, body_elem;
453: char list_type;
454:
455: nn = n->type == ROFFT_BLOCK ? n : n->parent;
1.176 schwarze 456: list_type = list_continues(roff_node_prev(nn), nn);
457: if (list_type == '\0') {
1.173 schwarze 458: /* Start a new list. */
1.176 schwarze 459: list_type = list_continues(nn, roff_node_next(nn));
460: if (list_type == '\0')
1.173 schwarze 461: list_type = ' ';
462: switch (list_type) {
463: case ' ':
464: list_class = "Bl-tag";
465: list_elem = TAG_DL;
466: break;
467: case '*':
468: list_class = "Bl-bullet";
469: list_elem = TAG_UL;
470: break;
471: case '-':
472: list_class = "Bl-dash";
473: list_elem = TAG_UL;
474: break;
475: default:
476: abort();
477: }
478: } else {
479: /* Continue a list that was started earlier. */
480: list_class = NULL;
481: list_elem = TAG_MAX;
482: }
483: body_elem = list_type == ' ' ? TAG_DD : TAG_LI;
1.5 kristaps 484:
1.166 schwarze 485: switch (n->type) {
486: case ROFFT_BLOCK:
487: html_close_paragraph(h);
1.173 schwarze 488: if (list_elem != TAG_MAX)
489: print_otag(h, list_elem, "c", list_class);
1.166 schwarze 490: return 1;
491: case ROFFT_HEAD:
1.173 schwarze 492: if (body_elem == TAG_LI)
493: return 0;
1.177 schwarze 494: print_otag_id(h, TAG_DT, NULL, n);
1.166 schwarze 495: break;
496: case ROFFT_BODY:
1.173 schwarze 497: print_otag(h, body_elem, "");
1.119 schwarze 498: return 1;
1.166 schwarze 499: default:
500: abort();
1.6 kristaps 501: }
1.154 schwarze 502: switch(n->tok) {
503: case MAN_IP: /* Only print the first header element. */
504: if (n->child != NULL)
505: print_man_node(man, n->child, h);
506: break;
507: case MAN_TP: /* Only print next-line header elements. */
508: case MAN_TQ:
1.91 schwarze 509: nn = n->child;
1.154 schwarze 510: while (nn != NULL && (NODE_LINE & nn->flags) == 0)
1.91 schwarze 511: nn = nn->next;
1.154 schwarze 512: while (nn != NULL) {
1.132 schwarze 513: print_man_node(man, nn, h);
1.91 schwarze 514: nn = nn->next;
515: }
1.154 schwarze 516: break;
517: default:
518: abort();
1.187 ! schwarze 519: }
! 520: return 0;
! 521: }
! 522:
! 523: static int
! 524: man_MR_pre(MAN_ARGS)
! 525: {
! 526: struct tag *t;
! 527: const char *name, *section, *suffix;
! 528: char *label;
! 529:
! 530: html_setfont(h, ESCAPE_FONTROMAN);
! 531: name = section = suffix = label = NULL;
! 532: if (n->child != NULL) {
! 533: name = n->child->string;
! 534: if (n->child->next != NULL) {
! 535: section = n->child->next->string;
! 536: mandoc_asprintf(&label,
! 537: "%s, section %s", name, section);
! 538: if (n->child->next->next != NULL)
! 539: suffix = n->child->next->next->string;
! 540: }
! 541: }
! 542:
! 543: if (name != NULL && section != NULL && h->base_man1 != NULL)
! 544: t = print_otag(h, TAG_A, "chM?", "Xr",
! 545: name, section, "aria-label", label);
! 546: else
! 547: t = print_otag(h, TAG_A, "c?", "Xr", "aria-label", label);
! 548:
! 549: free(label);
! 550: if (name != NULL) {
! 551: print_text(h, name);
! 552: h->flags |= HTML_NOSPACE;
! 553: }
! 554: print_text(h, "(");
! 555: h->flags |= HTML_NOSPACE;
! 556: if (section != NULL) {
! 557: print_text(h, section);
! 558: h->flags |= HTML_NOSPACE;
! 559: }
! 560: print_text(h, ")");
! 561: print_tagq(h, t);
! 562: if (suffix != NULL) {
! 563: h->flags |= HTML_NOSPACE;
! 564: print_text(h, suffix);
1.91 schwarze 565: }
1.119 schwarze 566: return 0;
1.6 kristaps 567: }
568:
569: static int
1.86 kristaps 570: man_OP_pre(MAN_ARGS)
571: {
572: struct tag *tt;
573:
574: print_text(h, "[");
575: h->flags |= HTML_NOSPACE;
1.128 schwarze 576: tt = print_otag(h, TAG_SPAN, "c", "Op");
1.86 kristaps 577:
1.164 schwarze 578: if ((n = n->child) != NULL) {
1.122 schwarze 579: print_otag(h, TAG_B, "");
1.86 kristaps 580: print_text(h, n->string);
581: }
582:
583: print_stagq(h, tt);
584:
1.164 schwarze 585: if (n != NULL && n->next != NULL) {
1.122 schwarze 586: print_otag(h, TAG_I, "");
1.86 kristaps 587: print_text(h, n->next->string);
588: }
589:
590: print_stagq(h, tt);
591: h->flags |= HTML_NOSPACE;
592: print_text(h, "]");
1.119 schwarze 593: return 0;
1.86 kristaps 594: }
595:
1.8 kristaps 596: static int
597: man_B_pre(MAN_ARGS)
598: {
1.122 schwarze 599: print_otag(h, TAG_B, "");
1.119 schwarze 600: return 1;
1.8 kristaps 601: }
602:
603: static int
604: man_I_pre(MAN_ARGS)
605: {
1.122 schwarze 606: print_otag(h, TAG_I, "");
1.119 schwarze 607: return 1;
1.45 kristaps 608: }
609:
610: static int
611: man_in_pre(MAN_ARGS)
612: {
1.122 schwarze 613: print_otag(h, TAG_BR, "");
1.119 schwarze 614: return 0;
1.8 kristaps 615: }
616:
617: static int
618: man_ign_pre(MAN_ARGS)
619: {
1.119 schwarze 620: return 0;
1.8 kristaps 621: }
1.9 kristaps 622:
623: static int
624: man_RS_pre(MAN_ARGS)
625: {
1.166 schwarze 626: switch (n->type) {
627: case ROFFT_BLOCK:
628: html_close_paragraph(h);
629: break;
630: case ROFFT_HEAD:
1.119 schwarze 631: return 0;
1.166 schwarze 632: case ROFFT_BODY:
1.152 schwarze 633: print_otag(h, TAG_DIV, "c", "Bd-indent");
1.166 schwarze 634: break;
635: default:
636: abort();
637: }
1.156 schwarze 638: return 1;
639: }
640:
641: static int
642: man_SY_pre(MAN_ARGS)
643: {
644: switch (n->type) {
645: case ROFFT_BLOCK:
1.166 schwarze 646: html_close_paragraph(h);
1.156 schwarze 647: print_otag(h, TAG_TABLE, "c", "Nm");
648: print_otag(h, TAG_TR, "");
649: break;
650: case ROFFT_HEAD:
651: print_otag(h, TAG_TD, "");
1.168 schwarze 652: print_otag(h, TAG_CODE, "c", "Nm");
1.156 schwarze 653: break;
654: case ROFFT_BODY:
655: print_otag(h, TAG_TD, "");
656: break;
657: default:
658: abort();
659: }
1.119 schwarze 660: return 1;
1.90 schwarze 661: }
662:
663: static int
664: man_UR_pre(MAN_ARGS)
665: {
1.145 schwarze 666: char *cp;
1.164 schwarze 667:
1.90 schwarze 668: n = n->child;
1.113 schwarze 669: assert(n->type == ROFFT_HEAD);
1.120 schwarze 670: if (n->child != NULL) {
1.113 schwarze 671: assert(n->child->type == ROFFT_TEXT);
1.145 schwarze 672: if (n->tok == MAN_MT) {
673: mandoc_asprintf(&cp, "mailto:%s", n->child->string);
1.168 schwarze 674: print_otag(h, TAG_A, "ch", "Mt", cp);
1.145 schwarze 675: free(cp);
676: } else
1.168 schwarze 677: print_otag(h, TAG_A, "ch", "Lk", n->child->string);
1.90 schwarze 678: }
679:
1.113 schwarze 680: assert(n->next->type == ROFFT_BODY);
1.120 schwarze 681: if (n->next->child != NULL)
1.90 schwarze 682: n = n->next;
683:
1.132 schwarze 684: print_man_nodelist(man, n->child, h);
1.119 schwarze 685: return 0;
1.9 kristaps 686: }
CVSweb