From 8cc4c277b332718f3abaddbc0b7fa87235952688 Mon Sep 17 00:00:00 2001 From: Ben Wiley Sittler Date: Sat, 1 Nov 2008 06:03:36 +0000 Subject: [PATCH] output valid XHTML (it's valid HTML3 too); note that this drops the COLS=... attribute on the table, but that had previously been calculated incorrectly anyhow so i doubt it mattered --- caca/codec/export.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/caca/codec/export.c b/caca/codec/export.c index f1cab1d..3cf644b 100644 --- a/caca/codec/export.c +++ b/caca/codec/export.c @@ -461,15 +461,6 @@ static void *export_html3(caca_canvas_t const *cv, size_t *bytes) int x, y, len; int maxcols; - /* The HTML table markup: less than 1000 bytes - * A line: 10 chars for "\n" - * A glyph: 40 chars for "" - * up to 36 chars for "" - * up to 48 chars for "&#xxxxxx;", or "        " (\t); far less for pure ASCII - * 12 chars for "" */ - *bytes = 1000 + cv->height * (10 + cv->width * (40 + 36 + 48 + 12)); - cur = data = malloc(*bytes); - /* Table */ maxcols = 0; for(y = 0; y < cv->height; y++) @@ -488,8 +479,16 @@ static void *export_html3(caca_canvas_t const *cv, size_t *bytes) maxcols = cols; } - cur += sprintf(cur, "\n", - maxcols); + /* The HTML table markup: less than 1000 bytes + * A line: 10 chars for "\n" + * A glyph: up to 44 chars for "" */ + *bytes = 1000 + cv->height * (10 + maxcols * (44 + 45 + 9 + 12)); + cur = data = malloc(*bytes); + + cur += sprintf(cur, "
" + * up to 45 chars for "" + * up to 9 chars for "&#xxxxxx;" (far less for pure ASCII) + * 12 chars for "
\n"); for(y = 0; y < cv->height; y++) { @@ -518,20 +517,21 @@ static void *export_html3(caca_canvas_t const *cv, size_t *bytes) cur += sprintf(cur, " 1) - cur += sprintf(cur, " colspan=%d", len + thistab); + cur += sprintf(cur, " colspan=\"%d\"", len + thistab); cur += sprintf(cur, ">"); needfont = caca_attr_to_ansi_fg(lineattr[x]) < 0x10; if(needfont) - cur += sprintf(cur, "", (unsigned long int) + cur += sprintf(cur, "", (unsigned long int) _caca_attr_to_rgb24fg(lineattr[x])); + cur += sprintf(cur, ""); if(lineattr[x] & CACA_BOLD) cur += sprintf(cur, ""); if(lineattr[x] & CACA_ITALICS) @@ -581,6 +581,7 @@ static void *export_html3(caca_canvas_t const *cv, size_t *bytes) cur += sprintf(cur, ""); if(lineattr[x] & CACA_BOLD) cur += sprintf(cur, ""); + cur += sprintf(cur, ""); if(needfont) cur += sprintf(cur, "");