Lines Matching defs:h
22 #include "config.h"
24 #include <sys/types.h>
25 #include <sys/stat.h>
27 #include <assert.h>
28 #include <ctype.h>
29 #include <stdarg.h>
30 #include <stddef.h>
31 #include <stdio.h>
32 #include <stdint.h>
33 #include <stdlib.h>
34 #include <string.h>
35 #include <unistd.h>
37 #include "mandoc_aux.h"
38 #include "mandoc_ohash.h"
39 #include "mandoc.h"
40 #include "roff.h"
41 #include "out.h"
42 #include "html.h"
43 #include "manconf.h"
44 #include "main.h"
142 struct html *h;
144 h = mandoc_calloc(1, sizeof(struct html));
146 h->tag = NULL;
147 h->metac = h->metal = ESCAPE_FONTROMAN;
148 h->style = outopts->style;
149 if ((h->base_man1 = outopts->man) == NULL)
150 h->base_man2 = NULL;
151 else if ((h->base_man2 = strchr(h->base_man1, ';')) != NULL)
152 *h->base_man2++ = '\0';
153 h->base_includes = outopts->includes;
155 h->oflags |= HTML_FRAGMENT;
157 h->oflags |= HTML_TOC;
161 return h;
165 html_reset_internal(struct html *h)
171 while ((tag = h->tag) != NULL) {
172 h->tag = tag->next;
198 print_gen_head(struct html *h)
202 print_otag(h, TAG_META, "?", "charset", "utf-8");
203 print_otag(h, TAG_META, "??", "name", "viewport",
205 if (h->style != NULL) {
206 print_otag(h, TAG_LINK, "?h??", "rel", "stylesheet",
207 h->style, "type", "text/css", "media", "all");
215 t = print_otag(h, TAG_STYLE, "");
216 print_text(h, "table.head, table.foot { width: 100%; }");
217 print_endline(h);
218 print_text(h, "td.head-rtitle, td.foot-os { text-align: right; }");
219 print_endline(h);
220 print_text(h, "td.head-vol { text-align: center; }");
221 print_endline(h);
222 print_text(h, ".Nd, .Bf, .Op { display: inline; }");
223 print_endline(h);
224 print_text(h, ".Pa, .Ad { font-style: italic; }");
225 print_endline(h);
226 print_text(h, ".Ms { font-weight: bold; }");
227 print_endline(h);
228 print_text(h, ".Bl-diag ");
229 print_byte(h, '>');
230 print_text(h, " dt { font-weight: bold; }");
231 print_endline(h);
232 print_text(h, "code.Nm, .Fl, .Cm, .Ic, code.In, .Fd, .Fn, .Cd "
234 print_tagq(h, t);
238 html_setfont(struct html *h, enum mandoc_esc font)
242 font = h->metal;
258 h->metal = h->metac;
259 h->metac = font;
264 print_metaf(struct html *h)
266 if (h->metaf) {
267 print_tagq(h, h->metaf);
268 h->metaf = NULL;
270 switch (h->metac) {
272 h->metaf = print_otag(h, TAG_I, "");
275 h->metaf = print_otag(h, TAG_B, "");
278 h->metaf = print_otag(h, TAG_B, "");
279 print_otag(h, TAG_I, "");
282 h->metaf = print_otag(h, TAG_SPAN, "c", "Li");
285 h->metaf = print_otag(h, TAG_SPAN, "c", "Li");
286 print_otag(h, TAG_B, "");
289 h->metaf = print_otag(h, TAG_SPAN, "c", "Li");
290 print_otag(h, TAG_I, "");
298 html_close_paragraph(struct html *h)
303 this = h->tag;
308 print_ctag(h, this);
320 html_fillmode(struct html *h, enum roff_tok want)
325 for (t = h->tag; t != NULL; t = t->next)
334 print_tagq(h, t);
337 html_close_paragraph(h);
338 print_otag(h, TAG_PRE, "");
438 print_escape(struct html *h, char c)
443 print_word(h, "<");
446 print_word(h, ">");
449 print_word(h, "&");
452 print_word(h, """);
455 print_word(h, " ");
458 print_byte(h, '-');
469 print_encode(struct html *h, const char *p, const char *pend, int norecurse)
486 if (HTML_SKIPCHAR & h->flags && '\\' != *p) {
487 h->flags &= ~HTML_SKIPCHAR;
493 print_byte(h, *p);
497 print_otag(h, TAG_BR, "");
508 print_endword(h);
513 if (print_escape(h, *p++))
528 h->flags |= HTML_NOSPACE;
529 if (html_setfont(h, esc))
530 print_metaf(h);
531 h->flags &= ~HTML_NOSPACE;
535 h->flags |= HTML_SKIPCHAR;
543 if (h->flags & HTML_SKIPCHAR) {
544 h->flags &= ~HTML_SKIPCHAR;
567 print_word(h, "html");
589 print_word(h, numbuf);
590 } else if (print_escape(h, c) == 0)
591 print_byte(h, c);
598 print_href(struct html *h, const char *name, const char *sec, int man)
605 pp = h->base_man1;
606 if (h->base_man2 != NULL) {
609 pp = h->base_man2;
613 pp = h->base_includes;
616 print_encode(h, pp, p, 1);
619 print_byte(h, '1');
621 print_encode(h, sec, NULL, 1);
624 print_encode(h, name, NULL, 1);
626 print_encode(h, p, p + 2, 1);
630 print_encode(h, pp, NULL, 1);
634 print_otag(struct html *h, enum htmltag tag, const char *fmt, ...)
647 for (t = h->tag; t != NULL; t = t->next) {
660 } else if (tflags & HTML_TOPHRASE && h->tag->tag == TAG_SECTION)
661 print_otag(h, TAG_P, "c", "Pp");
668 t->next = h->tag;
671 h->tag = t;
676 print_endline(h);
677 if (h->col == 0)
678 print_indent(h);
679 else if ((h->flags & HTML_NOSPACE) == 0) {
680 if (h->flags & HTML_KEEP)
681 print_word(h, " ");
683 if (h->flags & HTML_PREKEEP)
684 h->flags |= HTML_KEEP;
685 print_endword(h);
689 if ( ! (h->flags & HTML_NONOSPACE))
690 h->flags &= ~HTML_NOSPACE;
692 h->flags |= HTML_NOSPACE;
696 print_byte(h, '<');
697 print_word(h, htmltags[tag].name);
711 case 'h':
734 print_byte(h, ' ');
735 print_word(h, attr);
736 print_byte(h, '=');
737 print_byte(h, '"');
740 print_href(h, arg1, NULL, 0);
744 print_href(h, arg1, arg2, 1);
748 print_byte(h, '#');
749 print_encode(h, arg1, NULL, 1);
753 print_encode(h, arg1, NULL, 1);
756 print_byte(h, '"');
765 print_byte(h, ' ');
767 print_word(h, "style=\"");
770 print_word(h, arg1);
771 print_byte(h, ':');
772 print_byte(h, ' ');
773 print_word(h, arg2);
774 print_byte(h, ';');
777 print_byte(h, '"');
784 print_byte(h, '/');
786 print_byte(h, '>');
789 print_endline(h);
791 h->flags |= HTML_NOSPACE;
794 h->indent++;
796 h->noindent++;
808 print_otag_id(struct html *h, enum htmltag elemtype, const char *cattr,
822 ret = print_otag(h, TAG_A, "chR", "permalink", href);
823 t = print_otag(h, elemtype, "ci", cattr, id);
835 print_otag(h, TAG_A, "chR", "permalink", href);
845 print_ctag(struct html *h, struct tag *tag)
851 if (tag == h->metaf)
852 h->metaf = NULL;
853 if (tag == h->tblt)
854 h->tblt = NULL;
858 h->indent--;
860 h->noindent--;
862 print_endline(h);
863 print_indent(h);
864 print_byte(h, '<');
865 print_byte(h, '/');
866 print_word(h, htmltags[tag->tag].name);
867 print_byte(h, '>');
869 print_endline(h);
872 h->tag = tag->next;
878 print_gen_decls(struct html *h)
880 print_word(h, "<!DOCTYPE html>");
881 print_endline(h);
885 print_gen_comment(struct html *h, struct roff_node *n)
889 print_word(h, "<!-- This is an automatically generated file."
891 h->indent = 1;
896 print_endline(h);
897 print_indent(h);
898 print_word(h, n->string);
904 print_endline(h);
905 print_word(h, " -->");
906 print_endline(h);
907 h->indent = 0;
911 print_text(struct html *h, const char *word)
913 print_tagged_text(h, word, NULL);
917 print_tagged_text(struct html *h, const char *word, struct roff_node *n)
927 if (h->tag->tag == TAG_SECTION)
928 print_otag(h, TAG_P, "c", "Pp");
932 if (h->col && (h->flags & HTML_NOSPACE) == 0) {
933 if ( ! (HTML_KEEP & h->flags)) {
934 if (HTML_PREKEEP & h->flags)
935 h->flags |= HTML_KEEP;
936 print_endword(h);
938 print_word(h, " ");
946 assert(h->metaf == NULL);
947 print_metaf(h);
948 print_indent(h);
951 t = print_otag(h, TAG_A, "chR", "permalink", href);
956 if ( ! print_encode(h, word, NULL, 0)) {
957 if ( ! (h->flags & HTML_NONOSPACE))
958 h->flags &= ~HTML_NOSPACE;
959 h->flags &= ~HTML_NONEWLINE;
961 h->flags |= HTML_NOSPACE | HTML_NONEWLINE;
963 if (h->metaf != NULL) {
964 print_tagq(h, h->metaf);
965 h->metaf = NULL;
967 print_tagq(h, t);
969 h->flags &= ~HTML_IGNDELIM;
973 print_tagq(struct html *h, const struct tag *until)
977 for (this = h->tag; this != NULL; this = next) {
979 print_ctag(h, this);
989 print_stagq(struct html *h, const struct tag *suntil)
993 for (this = h->tag; this != NULL; this = next) {
998 print_ctag(h, this);
1014 print_byte(struct html *h, char c)
1016 if ((h->flags & HTML_BUFFER) == 0) {
1018 h->col++;
1022 if (h->col + h->bufcol < sizeof(h->buf)) {
1023 h->buf[h->bufcol++] = c;
1028 h->col = 0;
1029 print_indent(h);
1032 fwrite(h->buf, h->bufcol, 1, stdout);
1034 h->col = (h->indent + 1) * 2 + h->bufcol + 1;
1035 h->bufcol = 0;
1036 h->flags &= ~HTML_BUFFER;
1044 print_endline(struct html *h)
1046 if (h->col == 0)
1049 if (h->bufcol) {
1051 fwrite(h->buf, h->bufcol, 1, stdout);
1052 h->bufcol = 0;
1055 h->col = 0;
1056 h->flags |= HTML_NOSPACE;
1057 h->flags &= ~HTML_BUFFER;
1065 print_endword(struct html *h)
1067 if (h->noindent) {
1068 print_byte(h, ' ');
1072 if ((h->flags & HTML_BUFFER) == 0) {
1073 h->col++;
1074 h->flags |= HTML_BUFFER;
1075 } else if (h->bufcol) {
1077 fwrite(h->buf, h->bufcol, 1, stdout);
1078 h->col += h->bufcol + 1;
1080 h->bufcol = 0;
1090 print_indent(struct html *h)
1094 if (h->col || h->noindent)
1097 h->col = h->indent * 2;
1098 for (i = 0; i < h->col; i++)
1107 print_word(struct html *h, const char *cp)
1110 print_byte(h, *cp++);