-#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_aux.h"
+#include "mandoc_ohash.h"
+#include "mandoc.h"
+#include "roff.h"
+#include "out.h"
+#include "html.h"
+#include "manconf.h"
+#include "main.h"
+
+struct htmldata {
+ const char *name;
+ int flags;
+#define HTML_INPHRASE (1 << 0) /* Can appear in phrasing context. */
+#define HTML_TOPHRASE (1 << 1) /* Establishes phrasing context. */
+#define HTML_NOSTACK (1 << 2) /* Does not have an end tag. */
+#define HTML_NLBEFORE (1 << 3) /* Output line break before opening. */
+#define HTML_NLBEGIN (1 << 4) /* Output line break after opening. */
+#define HTML_NLEND (1 << 5) /* Output line break before closing. */
+#define HTML_NLAFTER (1 << 6) /* Output line break after closing. */
+#define HTML_NLAROUND (HTML_NLBEFORE | HTML_NLAFTER)
+#define HTML_NLINSIDE (HTML_NLBEGIN | HTML_NLEND)
+#define HTML_NLALL (HTML_NLAROUND | HTML_NLINSIDE)
+#define HTML_INDENT (1 << 7) /* Indent content by two spaces. */
+#define HTML_NOINDENT (1 << 8) /* Exception: never indent content. */
+};
+
+static const struct htmldata htmltags[TAG_MAX] = {
+ {"html", HTML_NLALL},
+ {"head", HTML_NLALL | HTML_INDENT},
+ {"meta", HTML_NOSTACK | HTML_NLALL},
+ {"link", HTML_NOSTACK | HTML_NLALL},
+ {"style", HTML_NLALL | HTML_INDENT},
+ {"title", HTML_NLAROUND},
+ {"body", HTML_NLALL},
+ {"div", HTML_NLAROUND},
+ {"section", HTML_NLALL},
+ {"table", HTML_NLALL | HTML_INDENT},
+ {"tr", HTML_NLALL | HTML_INDENT},
+ {"td", HTML_NLAROUND},
+ {"li", HTML_NLAROUND | HTML_INDENT},
+ {"ul", HTML_NLALL | HTML_INDENT},
+ {"ol", HTML_NLALL | HTML_INDENT},
+ {"dl", HTML_NLALL | HTML_INDENT},
+ {"dt", HTML_NLAROUND},
+ {"dd", HTML_NLAROUND | HTML_INDENT},
+ {"h1", HTML_TOPHRASE | HTML_NLAROUND},
+ {"h2", HTML_TOPHRASE | HTML_NLAROUND},
+ {"p", HTML_TOPHRASE | HTML_NLAROUND | HTML_INDENT},
+ {"pre", HTML_TOPHRASE | HTML_NLALL | HTML_NOINDENT},
+ {"a", HTML_INPHRASE | HTML_TOPHRASE},
+ {"b", HTML_INPHRASE | HTML_TOPHRASE},
+ {"cite", HTML_INPHRASE | HTML_TOPHRASE},
+ {"code", HTML_INPHRASE | HTML_TOPHRASE},
+ {"i", HTML_INPHRASE | HTML_TOPHRASE},
+ {"small", HTML_INPHRASE | HTML_TOPHRASE},
+ {"span", HTML_INPHRASE | HTML_TOPHRASE},
+ {"var", HTML_INPHRASE | HTML_TOPHRASE},
+ {"br", HTML_INPHRASE | HTML_NOSTACK | HTML_NLALL},
+ {"math", HTML_INPHRASE | HTML_NLALL | HTML_INDENT},
+ {"mrow", 0},
+ {"mi", 0},
+ {"mn", 0},
+ {"mo", 0},
+ {"msup", 0},
+ {"msub", 0},
+ {"msubsup", 0},
+ {"mfrac", 0},
+ {"msqrt", 0},
+ {"mfenced", 0},
+ {"mtable", 0},
+ {"mtr", 0},
+ {"mtd", 0},
+ {"munderover", 0},
+ {"munder", 0},
+ {"mover", 0},
+};
+
+/* Avoid duplicate HTML id= attributes. */
+static struct ohash id_unique;
+
+static void html_reset_internal(struct html *);
+static void print_byte(struct html *, char);
+static void print_endword(struct html *);
+static void print_indent(struct html *);
+static void print_word(struct html *, const char *);
+
+static void print_ctag(struct html *, struct tag *);
+static int print_escape(struct html *, char);
+static int print_encode(struct html *, const char *, const char *, int);
+static void print_href(struct html *, const char *, const char *, int);
+static void print_metaf(struct html *);