]> git.cameronkatri.com Git - mandoc.git/blobdiff - mdoc_html.c
Fixed `Bd' prior vertical space (was ignoring -compact).
[mandoc.git] / mdoc_html.c
index 03c3c50468c8c4f4177494c8f977cf9e10ee9cac..f28e5e2cbaaa754aae6774f3c69f5648e6890f41 100644 (file)
@@ -1,4 +1,4 @@
-/*     $Id: mdoc_html.c,v 1.6 2009/09/24 11:05:45 kristaps Exp $ */
+/*     $Id: mdoc_html.c,v 1.13 2009/09/26 17:35:49 kristaps Exp $ */
 /*
  * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
  *
@@ -15,6 +15,7 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 #include <sys/types.h>
+#include <sys/param.h>
 #include <sys/queue.h>
 
 #include <assert.h>
@@ -59,6 +60,8 @@ static        int               mdoc_tbl_block_pre(MDOC_ARGS, int, int, int, int);
 static int               mdoc_tbl_body_pre(MDOC_ARGS, int, int);
 static int               mdoc_tbl_head_pre(MDOC_ARGS, int, int);
 
+static void              mdoc__x_post(MDOC_ARGS);
+static int               mdoc__x_pre(MDOC_ARGS);
 static int               mdoc_ad_pre(MDOC_ARGS);
 static int               mdoc_an_pre(MDOC_ARGS);
 static int               mdoc_ap_pre(MDOC_ARGS);
@@ -171,17 +174,17 @@ static    const struct htmlmdoc mdocs[MDOC_MAX] = {
        {mdoc_va_pre, NULL}, /* Va */
        {mdoc_vt_pre, NULL}, /* Vt */ 
        {mdoc_xr_pre, NULL}, /* Xr */
-       {NULL, NULL}, /* %A */
-       {NULL, NULL}, /* %B */
-       {NULL, NULL}, /* %D */
-       {NULL, NULL}, /* %I */
-       {NULL, NULL}, /* %J */
-       {NULL, NULL}, /* %N */
-       {NULL, NULL}, /* %O */
-       {NULL, NULL}, /* %P */
-       {NULL, NULL}, /* %R */
-       {NULL, NULL}, /* %T */
-       {NULL, NULL}, /* %V */
+       {mdoc__x_pre, mdoc__x_post}, /* %A */
+       {mdoc__x_pre, mdoc__x_post}, /* %B */
+       {mdoc__x_pre, mdoc__x_post}, /* %D */
+       {mdoc__x_pre, mdoc__x_post}, /* %I */
+       {mdoc__x_pre, mdoc__x_post}, /* %J */
+       {mdoc__x_pre, mdoc__x_post}, /* %N */
+       {mdoc__x_pre, mdoc__x_post}, /* %O */
+       {mdoc__x_pre, mdoc__x_post}, /* %P */
+       {mdoc__x_pre, mdoc__x_post}, /* %R */
+       {mdoc__x_pre, mdoc__x_post}, /* %T */
+       {mdoc__x_pre, mdoc__x_post}, /* %V */
        {NULL, NULL}, /* Ac */
        {mdoc_aq_pre, mdoc_aq_post}, /* Ao */
        {mdoc_aq_pre, mdoc_aq_post}, /* Aq */
@@ -243,11 +246,11 @@ static    const struct htmlmdoc mdocs[MDOC_MAX] = {
        {mdoc_brq_pre, mdoc_brq_post}, /* Brq */ 
        {mdoc_brq_pre, mdoc_brq_post}, /* Bro */ 
        {NULL, NULL}, /* Brc */ 
-       {NULL, NULL}, /* %C */ 
+       {mdoc__x_pre, mdoc__x_post}, /* %C */ 
        {NULL, NULL}, /* Es */  /* TODO */
        {NULL, NULL}, /* En */  /* TODO */
        {mdoc_xx_pre, NULL}, /* Dx */ 
-       {NULL, NULL}, /* %Q */ 
+       {mdoc__x_pre, mdoc__x_post}, /* %Q */ 
        {mdoc_sp_pre, NULL}, /* br */
        {mdoc_sp_pre, NULL}, /* sp */ 
 };
@@ -522,19 +525,19 @@ mdoc_root_pre(MDOC_ARGS)
        tt = print_otag(h, TAG_TR, 0, NULL);
 
        tag[0].key = ATTR_STYLE;
-       tag[0].val = "width: 33%;";
+       tag[0].val = "width: 10%;";
        print_otag(h, TAG_TD, 1, tag);
        print_text(h, title);
        print_stagq(h, tt);
 
        tag[0].key = ATTR_STYLE;
-       tag[0].val = "width: 33%; text-align: center;";
+       tag[0].val = "width: 80%; white-space: nowrap; text-align: center;";
        print_otag(h, TAG_TD, 1, tag);
        print_text(h, b);
        print_stagq(h, tt);
 
        tag[0].key = ATTR_STYLE;
-       tag[0].val = "width: 33%; text-align: right;";
+       tag[0].val = "width: 10%; text-align: right;";
        print_otag(h, TAG_TD, 1, tag);
        print_text(h, title);
        print_tagq(h, t);
@@ -1324,7 +1327,7 @@ mdoc_bd_pre(MDOC_ARGS)
                switch (bl->args->argv[i].arg) {
                case (MDOC_Offset):
                        assert(bl->args->argv[i].sz);
-                       o = a2offs (bl->args->argv[i].value[0]);
+                       o = a2offs(bl->args->argv[i].value[0]);
                        break;
                case (MDOC_Compact):
                        c = 1;
@@ -1560,7 +1563,7 @@ mdoc_ft_pre(MDOC_ARGS)
        }
 
        tag.key = ATTR_CLASS;
-       tag.val = "type";
+       tag.val = "ftype";
        print_otag(h, TAG_SPAN, 1, &tag);
        return(1);
 }
@@ -1573,6 +1576,9 @@ mdoc_fn_pre(MDOC_ARGS)
        struct tag              *t;
        struct htmlpair          tag;
        const struct mdoc_node  *nn;
+       char                     nbuf[BUFSIZ];
+       const char              *sp, *ep;
+       int                      sz;
 
        if (SEC_SYNOPSIS == n->sec) {
                if (n->next) {
@@ -1583,13 +1589,33 @@ mdoc_fn_pre(MDOC_ARGS)
                        print_otag(h, TAG_DIV, 0, NULL);
        }
 
+       /* Split apart into type and name. */
+
        tag.key = ATTR_CLASS;
-       tag.val = "type";
+       tag.val = "ftype";
+       t = print_otag(h, TAG_SPAN, 1, &tag);
 
-       /* FIXME: can be "type funcname" "type varname"... */
+       assert(n->child->string);
+       sp = n->child->string;
+       while (NULL != (ep = strchr(sp, ' '))) {
+               sz = MIN((int)(ep - sp), BUFSIZ - 1);
+               (void)memcpy(nbuf, sp, (size_t)sz);
+               nbuf[sz] = '\0';
+               print_text(h, nbuf);
+               sp = ++ep;
+       }
+
+       print_tagq(h, t);
 
+       tag.key = ATTR_CLASS;
+       tag.val = "fname";
        t = print_otag(h, TAG_SPAN, 1, &tag);
-       print_text(h, n->child->string);
+
+       if (sp) {
+               (void)strlcpy(nbuf, sp, BUFSIZ);
+               print_text(h, nbuf);
+       }
+
        print_tagq(h, t);
 
        h->flags |= HTML_NOSPACE;
@@ -1991,26 +2017,20 @@ mdoc_pf_post(MDOC_ARGS)
 static int
 mdoc_rs_pre(MDOC_ARGS)
 {
-       struct htmlpair tag[2];
-       int             i;
+       struct htmlpair tag;
 
        if (MDOC_BLOCK != n->type)
                return(1);
 
-       tag[i = 0].key = ATTR_CLASS;
-       tag[i++].val = "ref";
-
-       if (n->prev && SEC_SYNOPSIS == n->sec) {
-               tag[i].key = ATTR_STYLE;
-               tag[i++].val = "margin-top: 1em;";
-       } else if (SEC_SYNOPSIS != n->sec) {
-               tag[i].key = ATTR_STYLE;
-               tag[i++].val = "display: inline; margin-right: 1em";
+       if (n->prev && SEC_SEE_ALSO == n->sec) {
+               tag.key = ATTR_STYLE;
+               tag.val = "margin-top: 1em;";
+               print_otag(h, TAG_DIV, 1, &tag);
        }
 
-       /* FIXME: div's have spaces stripped--we want them. */
-
-       print_otag(h, TAG_DIV, i, tag);
+       tag.key = ATTR_CLASS;
+       tag.val = "ref";
+       print_otag(h, TAG_SPAN, 1, &tag);
        return(1);
 }
 
@@ -2079,3 +2099,81 @@ mdoc_lb_pre(MDOC_ARGS)
        print_otag(h, TAG_SPAN, 1, &tag);
        return(1);
 }
+
+
+/* ARGSUSED */
+static int
+mdoc__x_pre(MDOC_ARGS)
+{
+       struct htmlpair tag;
+
+       tag.key = ATTR_CLASS;
+
+       switch (n->tok) {
+       case(MDOC__A):
+               tag.val = "ref-auth";
+               break;
+       case(MDOC__B):
+               tag.val = "ref-book";
+               break;
+       case(MDOC__C):
+               tag.val = "ref-city";
+               break;
+       case(MDOC__D):
+               tag.val = "ref-date";
+               break;
+       case(MDOC__I):
+               tag.val = "ref-issue";
+               break;
+       case(MDOC__J):
+               tag.val = "ref-jrnl";
+               break;
+       case(MDOC__N):
+               tag.val = "ref-num";
+               break;
+       case(MDOC__O):
+               tag.val = "ref-opt";
+               break;
+       case(MDOC__P):
+               tag.val = "ref-page";
+               break;
+       case(MDOC__Q):
+               tag.val = "ref-corp";
+               break;
+       case(MDOC__R):
+               tag.val = "ref-rep";
+               break;
+       case(MDOC__T):
+               print_text(h, "\\(lq");
+               h->flags |= HTML_NOSPACE;
+               tag.val = "ref-title";
+               break;
+       case(MDOC__V):
+               tag.val = "ref-vol";
+               break;
+       default:
+               abort();
+               /* NOTREACHED */
+       }
+
+       print_otag(h, TAG_SPAN, 1, &tag);
+       return(1);
+}
+
+
+/* ARGSUSED */
+static void
+mdoc__x_post(MDOC_ARGS)
+{
+
+       h->flags |= HTML_NOSPACE;
+       switch (n->tok) {
+       case (MDOC__T):
+               print_text(h, "\\(rq");
+               h->flags |= HTML_NOSPACE;
+               break;
+       default:
+               break;
+       }
+       print_text(h, n->next ? "," : ".");
+}