In HTML output, in cells with an "n" (number) layout, pad numbers
authorschwarze <schwarze@openbsd.org>
Thu, 9 Sep 2021 16:50:57 +0000 (16:50 +0000)
committerschwarze <schwarze@openbsd.org>
Thu, 9 Sep 2021 16:50:57 +0000 (16:50 +0000)
on the right side with UTF-8 punctuation and figure spaces such
that numbers in different tbl(7) rows align at the decimal point.

The exact HTML output format was suggested
by <Oliver dot Corff at email dot de>;
the implementation in C is mine.

usr.bin/mandoc/tbl_html.c

index acad113..77b6a8c 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: tbl_html.c,v 1.32 2021/09/09 14:45:18 schwarze Exp $ */
+/*     $OpenBSD: tbl_html.c,v 1.33 2021/09/09 16:50:57 schwarze Exp $ */
 /*
  * Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
  * Copyright (c) 2014,2015,2017,2018,2021 Ingo Schwarze <schwarze@openbsd.org>
@@ -113,10 +113,13 @@ print_tbl(struct html *h, const struct tbl_span *sp)
        const struct tbl_dat    *dp;
        const struct tbl_cell   *cp;
        const struct tbl_span   *psp;
+       const struct roffcol    *col;
        struct tag              *tt;
        const char              *hspans, *vspans, *halign, *valign;
        const char              *bborder, *lborder, *rborder;
+       const char              *ccp;
        char                     hbuf[4], vbuf[4];
+       size_t                   sz;
        enum mandoc_esc          save_font;
        int                      i;
 
@@ -250,6 +253,27 @@ print_tbl(struct html *h, const struct tbl_span *sp)
                        if (dp->layout->pos == TBL_CELL_LONG)
                                print_text(h, "\\[u2003]");  /* em space */
                        print_text(h, dp->string);
+                       if (dp->layout->pos == TBL_CELL_NUMBER) {
+                               col = h->tbl.cols + dp->layout->col;
+                               if (col->decimal < col->nwidth) {
+                                       if ((ccp = strrchr(dp->string,
+                                           sp->opts->decimal)) == NULL) {
+                                               /* Punctuation space. */
+                                               print_text(h, "\\[u2008]");
+                                               ccp = strchr(dp->string, '\0');
+                                       } else
+                                               ccp++;
+                                       sz = col->nwidth - col->decimal;
+                                       while (--sz > 0) {
+                                               if (*ccp == '\0')
+                                                       /* Figure space. */
+                                                       print_text(h,
+                                                           "\\[u2007]");
+                                               else
+                                                       ccp++;
+                                       }
+                               }
+                       }
                        html_setfont(h, save_font);
                }
        }