2015-03-02 16:45:41 +00:00
|
|
|
/* $Id: tbl_html.c,v 1.16 2015/01/30 17:32:16 schwarze Exp $ */
|
2012-10-18 09:55:16 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
#include "config.h"
|
2014-12-02 07:34:06 +00:00
|
|
|
|
|
|
|
#include <sys/types.h>
|
2012-10-18 09:55:16 +00:00
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "mandoc.h"
|
|
|
|
#include "out.h"
|
|
|
|
#include "html.h"
|
|
|
|
|
|
|
|
static void html_tblopen(struct html *, const struct tbl_span *);
|
|
|
|
static size_t html_tbl_len(size_t, void *);
|
|
|
|
static size_t html_tbl_strlen(const char *, void *);
|
|
|
|
|
2014-11-22 18:08:25 +00:00
|
|
|
|
2012-10-18 09:55:16 +00:00
|
|
|
static size_t
|
|
|
|
html_tbl_len(size_t sz, void *arg)
|
|
|
|
{
|
2014-11-22 18:08:25 +00:00
|
|
|
|
2012-10-18 09:55:16 +00:00
|
|
|
return(sz);
|
|
|
|
}
|
|
|
|
|
|
|
|
static size_t
|
|
|
|
html_tbl_strlen(const char *p, void *arg)
|
|
|
|
{
|
|
|
|
|
|
|
|
return(strlen(p));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
html_tblopen(struct html *h, const struct tbl_span *sp)
|
|
|
|
{
|
|
|
|
struct htmlpair tag;
|
|
|
|
struct roffsu su;
|
|
|
|
struct roffcol *col;
|
2015-03-02 16:45:41 +00:00
|
|
|
int ic;
|
2012-10-18 09:55:16 +00:00
|
|
|
|
2015-03-02 16:45:41 +00:00
|
|
|
if (h->tbl.cols == NULL) {
|
2012-10-18 09:55:16 +00:00
|
|
|
h->tbl.len = html_tbl_len;
|
|
|
|
h->tbl.slen = html_tbl_strlen;
|
2014-12-02 07:34:06 +00:00
|
|
|
tblcalc(&h->tbl, sp, 0);
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
assert(NULL == h->tblt);
|
|
|
|
PAIR_CLASS_INIT(&tag, "tbl");
|
|
|
|
h->tblt = print_otag(h, TAG_TABLE, 1, &tag);
|
|
|
|
|
2015-03-02 16:45:41 +00:00
|
|
|
for (ic = 0; ic < sp->opts->cols; ic++) {
|
2012-10-18 09:55:16 +00:00
|
|
|
bufinit(h);
|
2015-03-02 16:45:41 +00:00
|
|
|
col = h->tbl.cols + ic;
|
2012-10-18 09:55:16 +00:00
|
|
|
SCALE_HS_INIT(&su, col->width);
|
|
|
|
bufcat_su(h, "width", &su);
|
|
|
|
PAIR_STYLE_INIT(&tag, h);
|
|
|
|
print_otag(h, TAG_COL, 1, &tag);
|
|
|
|
}
|
|
|
|
|
|
|
|
print_otag(h, TAG_TBODY, 0, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
print_tblclose(struct html *h)
|
|
|
|
{
|
|
|
|
|
|
|
|
assert(h->tblt);
|
|
|
|
print_tagq(h, h->tblt);
|
|
|
|
h->tblt = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
print_tbl(struct html *h, const struct tbl_span *sp)
|
|
|
|
{
|
|
|
|
const struct tbl_dat *dp;
|
|
|
|
struct htmlpair tag;
|
|
|
|
struct tag *tt;
|
2015-03-02 16:45:41 +00:00
|
|
|
int ic;
|
2012-10-18 09:55:16 +00:00
|
|
|
|
|
|
|
/* Inhibit printing of spaces: we do padding ourselves. */
|
|
|
|
|
2015-03-02 16:45:41 +00:00
|
|
|
if (h->tblt == NULL)
|
2012-10-18 09:55:16 +00:00
|
|
|
html_tblopen(h, sp);
|
|
|
|
|
|
|
|
assert(h->tblt);
|
|
|
|
|
|
|
|
h->flags |= HTML_NONOSPACE;
|
|
|
|
h->flags |= HTML_NOSPACE;
|
|
|
|
|
|
|
|
tt = print_otag(h, TAG_TR, 0, NULL);
|
|
|
|
|
|
|
|
switch (sp->pos) {
|
2014-11-22 18:08:25 +00:00
|
|
|
case TBL_SPAN_HORIZ:
|
2012-10-18 09:55:16 +00:00
|
|
|
/* FALLTHROUGH */
|
2014-11-22 18:08:25 +00:00
|
|
|
case TBL_SPAN_DHORIZ:
|
2012-10-18 09:55:16 +00:00
|
|
|
PAIR_INIT(&tag, ATTR_COLSPAN, "0");
|
|
|
|
print_otag(h, TAG_TD, 1, &tag);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
dp = sp->first;
|
2015-03-02 16:45:41 +00:00
|
|
|
for (ic = 0; ic < sp->opts->cols; ic++) {
|
2012-10-18 09:55:16 +00:00
|
|
|
print_stagq(h, tt);
|
|
|
|
print_otag(h, TAG_TD, 0, NULL);
|
|
|
|
|
2015-03-02 16:45:41 +00:00
|
|
|
if (dp == NULL || dp->layout->col > ic)
|
|
|
|
continue;
|
|
|
|
if (dp->layout->pos != TBL_CELL_DOWN)
|
|
|
|
if (dp->string != NULL)
|
2014-01-31 19:59:03 +00:00
|
|
|
print_text(h, dp->string);
|
|
|
|
dp = dp->next;
|
2012-10-18 09:55:16 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
print_tagq(h, tt);
|
|
|
|
|
|
|
|
h->flags &= ~HTML_NONOSPACE;
|
|
|
|
|
2015-03-02 16:45:41 +00:00
|
|
|
if (sp->next == NULL) {
|
2012-10-18 09:55:16 +00:00
|
|
|
assert(h->tbl.cols);
|
|
|
|
free(h->tbl.cols);
|
|
|
|
h->tbl.cols = NULL;
|
|
|
|
print_tblclose(h);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|