summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--html.c95
-rw-r--r--html.h10
-rw-r--r--main.c9
-rw-r--r--main.h1
-rw-r--r--man_html.c2
-rw-r--r--mandoc.129
-rw-r--r--mdoc_html.c2
8 files changed, 127 insertions, 23 deletions
diff --git a/Makefile b/Makefile
index 4af9009c..18a60ddd 100644
--- a/Makefile
+++ b/Makefile
@@ -127,6 +127,8 @@ uninstall:
$(OBJS): config.h
+$(LNS): config.h
+
man_macro.ln: man_macro.c libman.h
man_macro.o: man_macro.c libman.h
diff --git a/html.c b/html.c
index c1ae9eea..1b15069d 100644
--- a/html.c
+++ b/html.c
@@ -36,38 +36,34 @@
#define UNCONST(a) ((void *)(uintptr_t)(const void *)(a))
-#define DOCTYPE "-//W3C//DTD HTML 4.01//EN"
-#define DTD "http://www.w3.org/TR/html4/strict.dtd"
-
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}, /* TAG_META */
+ {"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 */
- {"p", HTML_CLRLINE}, /* TAG_P */
{"span", 0}, /* TAG_SPAN */
{"link", HTML_CLRLINE | HTML_NOSTACK}, /* TAG_LINK */
- {"br", HTML_CLRLINE | HTML_NOSTACK}, /* TAG_LINK */
+ {"br", HTML_CLRLINE | HTML_NOSTACK | HTML_AUTOCLOSE}, /* TAG_BR */
{"a", 0}, /* TAG_A */
{"table", HTML_CLRLINE}, /* TAG_TABLE */
- {"col", HTML_CLRLINE | HTML_NOSTACK}, /* TAG_COL */
+ {"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 */
- {"base", HTML_CLRLINE | HTML_NOSTACK}, /* TAG_BASE */
};
static const char *const htmlfonts[HTMLFONT_MAX] = {
@@ -96,12 +92,15 @@ static const char *const htmlattrs[ATTR_MAX] = {
static void print_spec(struct html *, const char *, size_t);
static void print_res(struct html *, const char *, size_t);
static void print_ctag(struct html *, enum htmltag);
+static void print_doctype(struct html *);
+static void print_xmltype(struct html *);
static int print_encode(struct html *, const char *, int);
static void print_metaf(struct html *, enum roffdeco);
+static void *ml_alloc(char *, enum htmltype);
-void *
-html_alloc(char *outopts)
+static void *
+ml_alloc(char *outopts, enum htmltype type)
{
struct html *h;
const char *toks[4];
@@ -118,6 +117,7 @@ html_alloc(char *outopts)
exit(EXIT_FAILURE);
}
+ h->type = type;
h->tags.head = NULL;
h->ords.head = NULL;
h->symtab = chars_init(CHARS_HTML);
@@ -140,6 +140,21 @@ html_alloc(char *outopts)
return(h);
}
+void *
+html_alloc(char *outopts)
+{
+
+ return(ml_alloc(outopts, HTML_HTML_4_01_STRICT));
+}
+
+
+void *
+xhtml_alloc(char *outopts)
+{
+
+ return(ml_alloc(outopts, HTML_XHTML_1_0_STRICT));
+}
+
void
html_free(void *p)
@@ -366,6 +381,16 @@ print_otag(struct html *h, enum htmltag tag,
(void)print_encode(h, p[i].val, 1);
putchar('\"');
}
+
+ if (HTML_AUTOCLOSE & htmltags[tag].flags)
+ switch (h->type) {
+ case (HTML_XHTML_1_0_STRICT):
+ putchar('/');
+ break;
+ default:
+ break;
+ }
+
putchar('>');
h->flags |= HTML_NOSPACE;
@@ -385,12 +410,54 @@ print_ctag(struct html *h, enum htmltag tag)
}
-/* ARGSUSED */
void
-print_gen_doctype(struct html *h)
+print_gen_decls(struct html *h)
{
-
- printf("<!DOCTYPE HTML PUBLIC \"%s\" \"%s\">", DOCTYPE, DTD);
+
+ print_xmltype(h);
+ print_doctype(h);
+}
+
+
+static void
+print_xmltype(struct html *h)
+{
+ const char *decl;
+
+ switch (h->type) {
+ case (HTML_XHTML_1_0_STRICT):
+ decl = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
+ break;
+ default:
+ decl = NULL;
+ break;
+ }
+
+ if (NULL == decl)
+ return;
+
+ printf("%s\n", decl);
+}
+
+
+static void
+print_doctype(struct html *h)
+{
+ const char *doctype;
+ const char *dtd;
+
+ switch (h->type) {
+ case (HTML_HTML_4_01_STRICT):
+ doctype = "-//W3C//DTD HTML 4.01//EN";
+ dtd = "http://www.w3.org/TR/html4/strict.dtd";
+ break;
+ default:
+ doctype = "-//W3C//DTD XHTML 1.0 Strict//EN";
+ dtd = "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";
+ break;
+ }
+
+ printf("<!DOCTYPE HTML PUBLIC \"%s\" \"%s\">\n", doctype, dtd);
}
diff --git a/html.h b/html.h
index 7c401de6..41755bbc 100644
--- a/html.h
+++ b/html.h
@@ -28,7 +28,6 @@ enum htmltag {
TAG_DIV,
TAG_H1,
TAG_H2,
- TAG_P,
TAG_SPAN,
TAG_LINK,
TAG_BR,
@@ -40,7 +39,6 @@ enum htmltag {
TAG_LI,
TAG_UL,
TAG_OL,
- TAG_BASE,
TAG_MAX
};
@@ -105,6 +103,11 @@ struct htmlpair {
do { (p)->key = ATTR_SUMMARY; \
(p)->val = (v); } while (/* CONSTCOND */ 0)
+enum htmltype {
+ HTML_HTML_4_01_STRICT,
+ HTML_XHTML_1_0_STRICT
+};
+
struct html {
int flags;
#define HTML_NOSPACE (1 << 0)
@@ -121,11 +124,12 @@ struct html {
struct tag *metaf;
enum htmlfont metal;
enum htmlfont metac;
+ enum htmltype type;
};
struct roffsu;
-void print_gen_doctype(struct html *);
+void print_gen_decls(struct html *);
void print_gen_head(struct html *);
struct tag *print_ofont(struct html *, enum htmlfont);
struct tag *print_otag(struct html *, enum htmltag,
diff --git a/main.c b/main.c
index 20fe0cce..a07c3273 100644
--- a/main.c
+++ b/main.c
@@ -61,6 +61,7 @@ enum outt {
OUTT_ASCII = 0,
OUTT_TREE,
OUTT_HTML,
+ OUTT_XHTML,
OUTT_LINT
};
@@ -428,6 +429,12 @@ fdesc(struct buf *blk, struct buf *ln, struct curparse *curp)
if ( ! (curp->outman && curp->outmdoc)) {
switch (curp->outtype) {
+ case (OUTT_XHTML):
+ curp->outdata = xhtml_alloc(curp->outopts);
+ curp->outman = html_man;
+ curp->outmdoc = html_mdoc;
+ curp->outfree = html_free;
+ break;
case (OUTT_HTML):
curp->outdata = html_alloc(curp->outopts);
curp->outman = html_man;
@@ -550,6 +557,8 @@ toptions(enum outt *tflags, char *arg)
*tflags = OUTT_TREE;
else if (0 == strcmp(arg, "html"))
*tflags = OUTT_HTML;
+ else if (0 == strcmp(arg, "xhtml"))
+ *tflags = OUTT_XHTML;
else {
fprintf(stderr, "%s: Bad argument\n", arg);
return(0);
diff --git a/main.h b/main.h
index 589344d7..63bc2b67 100644
--- a/main.h
+++ b/main.h
@@ -30,6 +30,7 @@ struct man;
*/
void *html_alloc(char *);
+void *xhtml_alloc(char *);
void html_mdoc(void *, const struct mdoc *);
void html_man(void *, const struct man *);
void html_free(void *);
diff --git a/man_html.c b/man_html.c
index 32406eff..93ee8120 100644
--- a/man_html.c
+++ b/man_html.c
@@ -114,7 +114,7 @@ html_man(void *arg, const struct man *m)
h = (struct html *)arg;
- print_gen_doctype(h);
+ print_gen_decls(h);
t = print_otag(h, TAG_HTML, 0, NULL);
print_man(man_meta(m), man_node(m), h);
diff --git a/mandoc.1 b/mandoc.1
index e1875b6f..c81bf0bc 100644
--- a/mandoc.1
+++ b/mandoc.1
@@ -167,6 +167,10 @@ styles. This is the default. See
Produce strict HTML-4.01 output, with a sane default style. See
.Sx HTML Output .
.
+.It Fl T Ns Ar xhtml
+Produce strict XHTML-1.0 output, with a sane default style. See
+.Sx XHTML Output .
+.
.It Fl T Ns Ar tree
Produce an indented parse tree.
.
@@ -333,7 +337,7 @@ exceed this limit.
.Ss HTML Output
Output produced by
.Fl T Ns Ar html
-comforms to HTML-4.01 strict.
+conforms to HTML-4.01 strict.
.Pp
Font styles and page structure are applied using CSS2. By default, no
font style is applied to any text, although CSS2 is hard-coded to format
@@ -348,6 +352,17 @@ cause rendered documents to appear as they do in
Special characters are rendered in decimal-encoded UTF-8.
.
.
+.Ss XHTML Output
+Output produced by
+.Fl T Ns Ar xhtml
+conforms to XHTML-1.0 strict.
+.Pp
+See
+.Sx HTML Output
+for details; beyond generating XHTML tags instead of HTML tags, these
+output modes are identical.
+.
+.
.Sh EXAMPLES
To page manuals to the terminal:
.
@@ -437,7 +452,7 @@ Sentences are unilaterally monospaced.
.El
.
.
-.Ss HTML Compatibility
+.Ss HTML/XHTML Compatibility
.Bl -bullet -compact
.It
The
@@ -483,13 +498,17 @@ utility was written by
.Sh CAVEATS
The
.Fl T Ns Ar html
+and
+.Fl T Ns Ar xhtml
CSS2 styling used for
.Fl m Ns Ar doc
input lists does not render properly in brain-dead browsers, such as
Internet Explorer 6 and earlier.
.Pp
In
-.Fl T Ns Ar html ,
+.Fl T Ns Ar html
+and
+.Fl T Ns Ar xhtml ,
the maximum size of an element attribute is determined by
.Dv BUFSIZ ,
which is usually 1024 bytes. Be aware of this when setting long link
@@ -498,7 +517,9 @@ formats, e.g.,
.Pp
The
.Fl T Ns Ar html
-output mode doesn't render the
+and
+.Fl T Ns Ar xhtml
+output modes don't render the
.Sq \es
font size escape documented in
.Xr mdoc 7
diff --git a/mdoc_html.c b/mdoc_html.c
index c9766217..86e8b800 100644
--- a/mdoc_html.c
+++ b/mdoc_html.c
@@ -266,7 +266,7 @@ html_mdoc(void *arg, const struct mdoc *m)
h = (struct html *)arg;
- print_gen_doctype(h);
+ print_gen_decls(h);
t = print_otag(h, TAG_HTML, 0, NULL);
print_mdoc(mdoc_meta(m), mdoc_node(m), h);
print_tagq(h, t);