summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--chars.in22
-rw-r--r--html.c270
-rw-r--r--mdoc_term.c3
3 files changed, 264 insertions, 31 deletions
diff --git a/chars.in b/chars.in
index a4d70c13..35ed72d6 100644
--- a/chars.in
+++ b/chars.in
@@ -1,4 +1,4 @@
-/* $Id: chars.in,v 1.4 2009/09/20 17:24:57 kristaps Exp $ */
+/* $Id: chars.in,v 1.5 2009/09/20 19:25:06 kristaps Exp $ */
/*
* Copyright (c) 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -32,14 +32,14 @@
STRING("Am", 2, "&", 1, "&amp;", 5)
STRING("Ba", 2, "|", 1, "|", 0)
-STRING("Ge", 2, ">=", 2, "", 0)
-STRING("Gt", 2, ">", 1, "", 0)
-STRING("If", 2, "infinity", 8, "", 0)
-STRING("Le", 2, "<=", 2, "", 0)
-STRING("Lq", 2, "``", 2, "", 0)
-STRING("Lt", 2, "<", 1, "", 0)
-STRING("Na", 2, "NaN", 3, "", 0)
-STRING("Ne", 2, "!=", 2, "", 0)
+STRING("Ge", 2, ">=", 2, "&#8804;", 7)
+STRING("Gt", 2, ">", 1, "&gt;", 4)
+STRING("If", 2, "infinity", 8, "infinity", 8)
+STRING("Le", 2, "<=", 2, "&#8804;", 7)
+STRING("Lq", 2, "``", 2, "&#8220;", 7)
+STRING("Lt", 2, "<", 1, "&lt;", 4)
+STRING("Na", 2, "NaN", 3, "NaN", 3)
+STRING("Ne", 2, "!=", 2, "&#8800;", 7)
STRING("Pi", 2, "pi", 2, "", 0)
STRING("Pm", 2, "+-", 2, "", 0)
STRING("R", 1, "(R)", 3, "", 0)
@@ -49,7 +49,7 @@ STRING("left-bracket", 12, "[", 1, "", 0)
STRING("left-parenthesis", 16, "(", 1, "", 0)
STRING("left-singlequote", 16, "`", 1, "", 0)
STRING("lp", 2, "(", 1, "", 0)
-STRING("q", 1, "\"", 1, "", 0)
+STRING("q", 1, "\"", 1, "&quot;", 6)
STRING("quote-left", 10, "`", 1, "", 0)
STRING("quote-right", 11, "\'", 1, "", 0)
STRING("right-bracket", 13, "]", 1, "", 0)
@@ -128,7 +128,7 @@ CHAR(",c", 2, "c", 1, "", 0)
CHAR("-", 1, "-", 1, "-", 1)
CHAR("->", 2, "->", 2, "", 0)
CHAR("-D", 2, "D", 1, "", 0)
-CHAR(".", 1, ".", 1, "", 0)
+CHAR(".", 1, ".", 1, ".", 1)
CHAR("/L", 2, "L", 1, "", 0)
CHAR("/O", 2, "O", 1, "", 0)
CHAR("/l", 2, "l", 1, "", 0)
diff --git a/html.c b/html.c
index fb34e9fe..df1e9c05 100644
--- a/html.c
+++ b/html.c
@@ -1,4 +1,4 @@
-/* $Id: html.c,v 1.38 2009/09/20 17:48:13 kristaps Exp $ */
+/* $Id: html.c,v 1.39 2009/09/20 19:25:06 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -162,6 +162,7 @@ static void print_mdoc(MDOC_ARGS);
static void print_mdoc_head(MDOC_ARGS);
static void print_mdoc_title(MDOC_ARGS);
static void print_mdoc_node(MDOC_ARGS);
+static void print_mdoc_nodelist(MDOC_ARGS);
static void print_man(MAN_ARGS);
static void print_man_head(MAN_ARGS);
static void print_man_body(MAN_ARGS);
@@ -180,6 +181,7 @@ static int a2width(const char *);
static int a2offs(const char *);
static int a2list(const struct mdoc_node *);
+static void mdoc_root_post(MDOC_ARGS);
static int mdoc_root_pre(MDOC_ARGS);
static int mdoc_tbl_pre(MDOC_ARGS, int);
static int mdoc_tbl_block_pre(MDOC_ARGS, int, int, int, int);
@@ -189,6 +191,7 @@ static int mdoc_tbl_head_pre(MDOC_ARGS, int, int);
static void mdoc_aq_post(MDOC_ARGS);
static int mdoc_aq_pre(MDOC_ARGS);
static int mdoc_ar_pre(MDOC_ARGS);
+static int mdoc_bd_pre(MDOC_ARGS);
static void mdoc_bl_post(MDOC_ARGS);
static int mdoc_bl_pre(MDOC_ARGS);
static int mdoc_d1_pre(MDOC_ARGS);
@@ -203,9 +206,12 @@ static int mdoc_nm_pre(MDOC_ARGS);
static int mdoc_ns_pre(MDOC_ARGS);
static void mdoc_op_post(MDOC_ARGS);
static int mdoc_op_pre(MDOC_ARGS);
+static int mdoc_pa_pre(MDOC_ARGS);
static int mdoc_pp_pre(MDOC_ARGS);
static void mdoc_pq_post(MDOC_ARGS);
static int mdoc_pq_pre(MDOC_ARGS);
+static void mdoc_qq_post(MDOC_ARGS);
+static int mdoc_qq_pre(MDOC_ARGS);
static int mdoc_sh_pre(MDOC_ARGS);
static void mdoc_sq_post(MDOC_ARGS);
static int mdoc_sq_pre(MDOC_ARGS);
@@ -220,7 +226,7 @@ extern size_t strlcat(char *, const char *, size_t);
#endif
static const struct htmlmdoc mdocs[MDOC_MAX] = {
- {NULL, NULL}, /* Ap */
+ {mdoc_pp_pre, NULL}, /* Ap */
{NULL, NULL}, /* Dd */
{NULL, NULL}, /* Dt */
{NULL, NULL}, /* Os */
@@ -229,7 +235,7 @@ static const struct htmlmdoc mdocs[MDOC_MAX] = {
{mdoc_pp_pre, NULL}, /* Pp */
{mdoc_d1_pre, NULL}, /* D1 */
{mdoc_d1_pre, NULL}, /* Dl */
- {NULL, NULL}, /* Bd */
+ {mdoc_bd_pre, NULL}, /* Bd */
{NULL, NULL}, /* Ed */
{mdoc_bl_pre, mdoc_bl_post}, /* Bl */
{NULL, NULL}, /* El */
@@ -255,7 +261,7 @@ static const struct htmlmdoc mdocs[MDOC_MAX] = {
{mdoc_nm_pre, NULL}, /* Nm */
{mdoc_op_pre, mdoc_op_post}, /* Op */
{NULL, NULL}, /* Ot */
- {NULL, NULL}, /* Pa */
+ {mdoc_pa_pre, NULL}, /* Pa */
{NULL, NULL}, /* Rv */
{NULL, NULL}, /* St */
{NULL, NULL}, /* Va */
@@ -302,8 +308,8 @@ static const struct htmlmdoc mdocs[MDOC_MAX] = {
{mdoc_pq_pre, mdoc_pq_post}, /* Pq */
{NULL, NULL}, /* Qc */
{NULL, NULL}, /* Ql */
- {NULL, NULL}, /* Qo */
- {NULL, NULL}, /* Qq */
+ {mdoc_qq_pre, mdoc_qq_post}, /* Qo */
+ {mdoc_qq_pre, mdoc_qq_post}, /* Qq */
{NULL, NULL}, /* Re */
{NULL, NULL}, /* Rs */
{NULL, NULL}, /* Sc */
@@ -439,7 +445,7 @@ print_mdoc(MDOC_ARGS)
t = print_otag(h, TAG_BODY, 0, NULL);
print_mdoc_title(m, n, h);
- print_mdoc_node(m, n, h);
+ print_mdoc_nodelist(m, n, h);
print_tagq(h, t);
}
@@ -497,6 +503,16 @@ print_mdoc_title(MDOC_ARGS)
static void
+print_mdoc_nodelist(MDOC_ARGS)
+{
+
+ print_mdoc_node(m, n, h);
+ if (n->next)
+ print_mdoc_nodelist(m, n->next, h);
+}
+
+
+static void
print_mdoc_node(MDOC_ARGS)
{
int child;
@@ -521,7 +537,7 @@ print_mdoc_node(MDOC_ARGS)
}
if (child && n->child)
- print_mdoc_node(m, n->child, h);
+ print_mdoc_nodelist(m, n->child, h);
print_stagq(h, t);
@@ -529,6 +545,7 @@ print_mdoc_node(MDOC_ARGS)
switch (n->type) {
case (MDOC_ROOT):
+ mdoc_root_post(m, n, h);
break;
case (MDOC_TEXT):
break;
@@ -537,9 +554,6 @@ print_mdoc_node(MDOC_ARGS)
(*mdocs[n->tok].post)(m, n, h);
break;
}
-
- if (n->next)
- print_mdoc_node(m, n->next, h);
}
@@ -974,18 +988,116 @@ a2width(const char *p)
}
+/* FIXME: parts should be in a utility file for front-ends. */
+/* ARGSUSED */
+static void
+mdoc_root_post(MDOC_ARGS)
+{
+ struct tm *tm;
+ struct htmlpair tag[2];
+ struct tag *t;
+ char b[BUFSIZ], os[BUFSIZ];
+
+ tm = localtime(&m->date);
+
+ if (0 == strftime(b, BUFSIZ - 1, "%B %e, %Y", tm))
+ err(EXIT_FAILURE, "strftime");
+ (void)strlcpy(os, m->os, BUFSIZ);
+ tag[0].key = ATTR_STYLE;
+ tag[0].val = "width: 100%; margin-top: 1em;";
+ tag[1].key = ATTR_CLASS;
+ tag[1].val = "foot";
+
+ t = print_otag(h, TAG_DIV, 2, tag);
+
+ bufinit();
+ bufcat("width: 50%;");
+ bufcat("text-align: left;");
+ bufcat("float: left;");
+ tag[0].key = ATTR_STYLE;
+ tag[0].val = buf;
+ print_otag(h, TAG_SPAN, 1, tag);
+ print_text(h, b);
+ print_stagq(h, t);
+
+ bufinit();
+ bufcat("width: 50%;");
+ bufcat("text-align: right;");
+ bufcat("float: left;");
+ tag[0].key = ATTR_STYLE;
+ tag[0].val = buf;
+ print_otag(h, TAG_SPAN, 1, tag);
+ print_text(h, os);
+ print_tagq(h, t);
+
+}
+
+
+/* FIXME: parts should be in a utility file for front-ends. */
/* ARGSUSED */
static int
mdoc_root_pre(MDOC_ARGS)
{
- struct htmlpair tag;
+ struct htmlpair tag[2];
+ struct tag *t, *tt;
+ char b[BUFSIZ], title[BUFSIZ];
- tag.key = ATTR_CLASS;
- tag.val = "body";
+ assert(m->vol);
+ (void)strlcpy(b, m->vol, BUFSIZ);
+
+ if (m->arch) {
+ (void)strlcat(b, " (", BUFSIZ);
+ (void)strlcat(b, m->arch, BUFSIZ);
+ (void)strlcat(b, ")", BUFSIZ);
+ }
+
+ (void)snprintf(title, BUFSIZ - 1, "%s(%d)", m->title, m->msec);
+
+ tag[0].key = ATTR_CLASS;
+ tag[0].val = "body";
+
+ t = print_otag(h, TAG_DIV, 1, tag);
+
+ tag[0].key = ATTR_CLASS;
+ tag[0].val = "head";
+ tag[1].key = ATTR_STYLE;
+ tag[1].val = "margin-bottom: 1em; clear: both;";
+
+ tt = print_otag(h, TAG_DIV, 2, tag);
+
+ bufinit();
+ bufcat("width: 30%;");
+ bufcat("text-align: left;");
+ bufcat("float: left;");
+ tag[0].key = ATTR_STYLE;
+ tag[0].val = buf;
+ print_otag(h, TAG_SPAN, 1, tag);
+ print_text(h, b);
+ print_stagq(h, tt);
+
+ bufinit();
+ bufcat("width: 30%;");
+ bufcat("text-align: center;");
+ bufcat("float: left;");
+ tag[0].key = ATTR_STYLE;
+ tag[0].val = buf;
+ print_otag(h, TAG_SPAN, 1, tag);
+ print_text(h, title);
+ print_stagq(h, tt);
+
+ bufinit();
+ bufcat("width: 30%;");
+ bufcat("text-align: right;");
+ bufcat("float: left;");
+ tag[0].key = ATTR_STYLE;
+ tag[0].val = buf;
+ print_otag(h, TAG_SPAN, 1, tag);
+ print_text(h, b);
+
+ print_stagq(h, t);
- print_otag(h, TAG_DIV, 1, &tag);
return(1);
}
@@ -1005,15 +1117,21 @@ mdoc_sh_pre(MDOC_ARGS)
} else if (MDOC_BLOCK == n->type) {
tag[0].key = ATTR_CLASS;
tag[0].val = "sec-block";
- print_otag(h, TAG_DIV, 1, tag);
+
+ if (n->prev && NULL == n->prev->body->child) {
+ print_otag(h, TAG_DIV, 1, tag);
+ return(1);
+ }
+
+ tag[1].key = ATTR_STYLE;
+ tag[1].val = "margin-top: 1em;";
+
+ print_otag(h, TAG_DIV, 2, tag);
return(1);
}
buffmt("margin-left: %dem;", INDENT);
- if (n->parent->next && n->child)
- bufcat("margin-bottom: 1em;");
-
tag[0].key = ATTR_CLASS;
tag[0].val = "sec-body";
tag[1].key = ATTR_STYLE;
@@ -1682,3 +1800,117 @@ mdoc_aq_post(MDOC_ARGS)
print_text(h, "\\(ra");
}
+
+/* ARGSUSED */
+static int
+mdoc_bd_pre(MDOC_ARGS)
+{
+ struct htmlpair tag[2];
+ int t, c, o, i;
+ const struct mdoc_node *bl;
+
+ /* FIXME: fmt_vspace() shit. */
+
+ if (MDOC_BLOCK == n->type)
+ bl = n;
+ else if (MDOC_HEAD == n->type)
+ return(0);
+ else
+ bl = n->parent;
+
+ t = o = c = 0;
+
+ for (i = 0; i < (int)bl->args->argc; i++)
+ switch (bl->args->argv[i].arg) {
+ case (MDOC_Offset):
+ assert(bl->args->argv[i].sz);
+ o = a2offs(bl->args->argv[i].value[0]);
+ break;
+ case (MDOC_Compact):
+ c = 1;
+ break;
+ case (MDOC_Ragged):
+ /* FALLTHROUGH */
+ case (MDOC_Filled):
+ /* FALLTHROUGH */
+ case (MDOC_Unfilled):
+ /* FALLTHROUGH */
+ case (MDOC_Literal):
+ t = bl->args->argv[i].arg;
+ break;
+ }
+
+ if (MDOC_BLOCK == n->type) {
+ if (o)
+ buffmt("margin-left: %dem;", o);
+ bufcat("margin-top: 1em;");
+ tag[0].key = ATTR_STYLE;
+ tag[0].val = buf;
+ print_otag(h, TAG_DIV, 1, tag);
+ return(1);
+ }
+
+ switch (t) {
+ case (MDOC_Unfilled):
+ case (MDOC_Literal):
+ break;
+ default:
+ return(1);
+ }
+
+ bufcat("white-space: pre;");
+ tag[0].key = ATTR_STYLE;
+ tag[0].val = buf;
+ tag[1].key = ATTR_CLASS;
+ tag[1].val = "lit-block";
+
+ print_otag(h, TAG_DIV, 2, tag);
+
+ for (n = n->child; n; n = n->next) {
+ h->flags |= HTML_NOSPACE;
+ print_mdoc_node(m, n, h);
+ if (n->next)
+ print_text(h, "\n");
+ }
+
+ return(0);
+}
+
+
+/* ARGSUSED */
+static int
+mdoc_pa_pre(MDOC_ARGS)
+{
+ struct htmlpair tag;
+
+ tag.key = ATTR_CLASS;
+ tag.val = "file";
+
+ print_otag(h, TAG_SPAN, 1, &tag);
+ return(1);
+}
+
+
+/* ARGSUSED */
+static int
+mdoc_qq_pre(MDOC_ARGS)
+{
+
+ if (MDOC_BODY != n->type)
+ return(1);
+ print_text(h, "\\*q");
+ h->flags |= HTML_NOSPACE;
+ return(1);
+}
+
+
+/* ARGSUSED */
+static void
+mdoc_qq_post(MDOC_ARGS)
+{
+
+ if (MDOC_BODY != n->type)
+ return;
+ h->flags |= HTML_NOSPACE;
+ print_text(h, "\\*q");
+}
diff --git a/mdoc_term.c b/mdoc_term.c
index de4b9258..53cc7e9a 100644
--- a/mdoc_term.c
+++ b/mdoc_term.c
@@ -1,4 +1,4 @@
-/* $Id: mdoc_term.c,v 1.74 2009/09/20 17:48:13 kristaps Exp $ */
+/* $Id: mdoc_term.c,v 1.75 2009/09/20 19:25:06 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -424,6 +424,7 @@ print_foot(DECL_ARGS)
}
+/* FIXME: put in utility library. */
/* ARGSUSED */
static void
print_head(DECL_ARGS)