-#include "libmdocml.h"
-#include "private.h"
-#include "ml.h"
-
-
-static int html_loadcss(struct md_mbuf *, const char *);
-
-static ssize_t html_endtag(struct md_mbuf *,
- const struct md_args *,
- enum md_ns, int);
-static ssize_t html_begintag(struct md_mbuf *,
- const struct md_args *,
- enum md_ns, int,
- const int *, const char **);
-static int html_begin(struct md_mbuf *,
- const struct md_args *,
- const struct tm *,
- const char *, const char *,
- const char *, const char *);
-static int html_end(struct md_mbuf *,
- const struct md_args *);
-static ssize_t html_blocktagname(struct md_mbuf *,
- const struct md_args *, int);
-static ssize_t html_blocktagargs(struct md_mbuf *,
- const struct md_args *, int,
- const int *, const char **);
-static ssize_t html_blockheadtagname(struct md_mbuf *,
- const struct md_args *, int);
-static ssize_t html_blockheadtagargs(struct md_mbuf *,
- const struct md_args *, int,
- const int *, const char **);
-static ssize_t html_blockbodytagname(struct md_mbuf *,
- const struct md_args *, int);
-static ssize_t html_blockbodytagargs(struct md_mbuf *,
- const struct md_args *, int,
- const int *, const char **);
-static ssize_t html_inlinetagname(struct md_mbuf *,
- const struct md_args *, int);
-static ssize_t html_inlinetagargs(struct md_mbuf *,
- const struct md_args *, int,
- const int *, const char **);
+#include "mandoc.h"
+#include "libmandoc.h"
+#include "out.h"
+#include "html.h"
+#include "main.h"
+
+struct htmldata {
+ const char *name;
+ int flags;
+#define HTML_CLRLINE (1 << 0)
+#define HTML_NOSTACK (1 << 1)
+#define HTML_AUTOCLOSE (1 << 2) /* Tag has auto-closure. */
+};
+
+static const struct htmldata htmltags[TAG_MAX] = {
+ {"html", HTML_CLRLINE}, /* TAG_HTML */
+ {"head", HTML_CLRLINE}, /* TAG_HEAD */
+ {"body", HTML_CLRLINE}, /* TAG_BODY */
+ {"meta", HTML_CLRLINE | HTML_NOSTACK | HTML_AUTOCLOSE}, /* TAG_META */
+ {"title", HTML_CLRLINE}, /* TAG_TITLE */
+ {"div", HTML_CLRLINE}, /* TAG_DIV */
+ {"h1", 0}, /* TAG_H1 */
+ {"h2", 0}, /* TAG_H2 */
+ {"span", 0}, /* TAG_SPAN */
+ {"link", HTML_CLRLINE | HTML_NOSTACK | HTML_AUTOCLOSE}, /* TAG_LINK */
+ {"br", HTML_CLRLINE | HTML_NOSTACK | HTML_AUTOCLOSE}, /* TAG_BR */
+ {"a", 0}, /* TAG_A */
+ {"table", HTML_CLRLINE}, /* TAG_TABLE */
+ {"tbody", HTML_CLRLINE}, /* TAG_TBODY */
+ {"col", HTML_CLRLINE | HTML_NOSTACK | HTML_AUTOCLOSE}, /* TAG_COL */
+ {"tr", HTML_CLRLINE}, /* TAG_TR */
+ {"td", HTML_CLRLINE}, /* TAG_TD */
+ {"li", HTML_CLRLINE}, /* TAG_LI */
+ {"ul", HTML_CLRLINE}, /* TAG_UL */
+ {"ol", HTML_CLRLINE}, /* TAG_OL */
+ {"dl", HTML_CLRLINE}, /* TAG_DL */
+ {"dt", HTML_CLRLINE}, /* TAG_DT */
+ {"dd", HTML_CLRLINE}, /* TAG_DD */
+ {"blockquote", HTML_CLRLINE}, /* TAG_BLOCKQUOTE */
+ {"p", HTML_CLRLINE | HTML_NOSTACK | HTML_AUTOCLOSE}, /* TAG_P */
+ {"pre", HTML_CLRLINE }, /* TAG_PRE */
+ {"b", 0 }, /* TAG_B */
+ {"i", 0 }, /* TAG_I */
+ {"code", 0 }, /* TAG_CODE */
+ {"small", 0 }, /* TAG_SMALL */
+};
+
+static const char *const htmlattrs[ATTR_MAX] = {
+ "http-equiv", /* ATTR_HTTPEQUIV */
+ "content", /* ATTR_CONTENT */
+ "name", /* ATTR_NAME */
+ "rel", /* ATTR_REL */
+ "href", /* ATTR_HREF */
+ "type", /* ATTR_TYPE */
+ "media", /* ATTR_MEDIA */
+ "class", /* ATTR_CLASS */
+ "style", /* ATTR_STYLE */
+ "width", /* ATTR_WIDTH */
+ "id", /* ATTR_ID */
+ "summary", /* ATTR_SUMMARY */
+ "align", /* ATTR_ALIGN */
+ "colspan", /* ATTR_COLSPAN */
+};
+
+static const char *const roffscales[SCALE_MAX] = {
+ "cm", /* SCALE_CM */
+ "in", /* SCALE_IN */
+ "pc", /* SCALE_PC */
+ "pt", /* SCALE_PT */
+ "em", /* SCALE_EM */
+ "em", /* SCALE_MM */
+ "ex", /* SCALE_EN */
+ "ex", /* SCALE_BU */
+ "em", /* SCALE_VS */
+ "ex", /* SCALE_FS */
+};
+
+static void bufncat(struct html *, const char *, size_t);
+static void print_ctag(struct html *, enum htmltag);
+static int print_encode(struct html *, const char *, int);
+static void print_metaf(struct html *, enum mandoc_esc);
+static void print_attr(struct html *, const char *, const char *);
+static void *ml_alloc(char *, enum htmltype);
+
+static void *
+ml_alloc(char *outopts, enum htmltype type)
+{
+ struct html *h;
+ const char *toks[4];
+ char *v;