hold inline markers in a struct marker array
[ctxt.git] / html.c
blobc27b4579793cddac5d7c792e7bff3480db9aa25f
1 #include <string.h>
2 #include "ctxt.h"
4 static void html_doc_beg(struct doc *doc)
6 doc_write(doc, "<body>\n");
9 static void html_doc_end(struct doc *doc)
11 doc_write(doc, "</body>\n");
14 static int digits(int n)
16 int d = 1;
17 while ((n /= 10))
18 d++;
19 return d;
22 static char *putint(char *s, int n)
24 int i;
25 int d = digits(n);
26 for (i = 0; i < d; i++) {
27 s[d - i - 1] = n % 10 + '0';
28 n /= 10;
30 s[d] = '\0';
31 return s + d;
34 static char *putstr(char *dst, char *src)
36 strcpy(dst, src);
37 return strchr(dst, '\0');
40 static void html_head_beg(struct doc *doc, int level)
42 char buf[64];
43 char *s = buf;
44 s = putstr(s, "<h");
45 s = putint(s, level + 1);
46 putstr(s, ">");
47 doc_write(doc, buf);
50 static void html_head_end(struct doc *doc, int level)
52 char buf[64];
53 char *s = buf;
54 s = putstr(s, "</h");
55 s = putint(s, level + 1);
56 putstr(s, ">");
57 doc_write(doc, buf);
60 static void html_par_beg(struct doc *doc)
62 doc_write(doc, "<p>\n");
65 static void html_par_end(struct doc *doc)
69 static void html_put(struct doc *doc, char *s)
71 doc_write(doc, s);
74 static void html_list_beg(struct doc *doc)
76 doc_write(doc, "<ul>\n");
79 static void html_list_end(struct doc *doc)
81 doc_write(doc, "</ul>\n");
84 static void html_item_beg(struct doc *doc)
86 doc_write(doc, "<li>");
89 static void html_item_end(struct doc *doc)
91 doc_write(doc, "</li>\n");
94 static void html_pre_beg(struct doc *doc)
96 doc_write(doc, "<pre>");
99 static void html_pre_end(struct doc *doc)
101 doc_write(doc, "</pre>");
104 static void html_formula_beg(struct doc *doc)
106 doc_write(doc, "<p><i>");
109 static void html_formula_end(struct doc *doc)
111 doc_write(doc, "</i>\n");
114 static void html_put_txt(struct doc *doc, char *s, int marker)
116 switch (marker) {
117 case M_EMPH:
118 doc_write(doc, "<b>");
119 doc_write(doc, s);
120 doc_write(doc, "</b>");
121 break;
122 case M_RAW:
123 doc_write(doc, s);
124 break;
125 case M_LINK:
126 doc_write(doc, "<a href=\"");
127 doc_write(doc, s);
128 doc_write(doc, "\">");
129 doc_write(doc, s);
130 doc_write(doc, "</a>");
131 break;
132 case M_FOOT:
133 doc_write(doc, "[");
134 doc_write(doc, s);
135 doc_write(doc, "]");
136 break;
137 default:
138 html_put(doc, s);
143 static void html_table_beg(struct doc *doc, int columns)
145 doc_write(doc, "<table>\n");
148 static void html_table_end(struct doc *doc)
150 doc_write(doc, "</table>\n");
153 static void html_row_beg(struct doc *doc)
155 doc_write(doc, "<tr>");
158 static void html_row_end(struct doc *doc)
160 doc_write(doc, "</tr>\n");
163 static void html_entry_beg(struct doc *doc)
165 doc_write(doc, "<td>");
168 static void html_entry_end(struct doc *doc)
170 doc_write(doc, "</td>");
173 struct fmt_ops html_ops = {
174 .doc_beg = html_doc_beg,
175 .doc_end = html_doc_end,
176 .head_beg = html_head_beg,
177 .head_end = html_head_end,
178 .par_beg = html_par_beg,
179 .par_end = html_par_end,
180 .list_beg = html_list_beg,
181 .list_end = html_list_end,
182 .item_beg = html_item_beg,
183 .item_end = html_item_end,
184 .pre_beg = html_pre_beg,
185 .pre_end = html_pre_end,
186 .formula_beg = html_formula_beg,
187 .formula_end = html_formula_end,
188 .table_beg = html_table_beg,
189 .table_end = html_table_end,
190 .row_beg = html_row_beg,
191 .row_end = html_row_end,
192 .entry_beg = html_entry_beg,
193 .entry_end = html_entry_end,
194 .put = html_put,
195 .put_txt = html_put_txt