summaryrefslogtreecommitdiffstats
path: root/html.c
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2009-10-28 05:08:17 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2009-10-28 05:08:17 +0000
commite610e710af132c1cfeed06eb0da987c4ab7af35d (patch)
treee9cbd38d499e37af7b1048c22dde6a8d2c6efa1e /html.c
parentc6fa100a886693167f543f9b59fbc85e46faa49c (diff)
downloadmandoc-e610e710af132c1cfeed06eb0da987c4ab7af35d.tar.gz
Fixed un-reset buffer in `.In', -Thtml, -mdoc.
Added html_id[cat,cpy] for transforming id's into well-formed attribute strings (no %s, etc.).
Diffstat (limited to 'html.c')
-rw-r--r--html.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/html.c b/html.c
index 0a3c8a0d..7a087072 100644
--- a/html.c
+++ b/html.c
@@ -17,6 +17,7 @@
#include <sys/types.h>
#include <assert.h>
+#include <ctype.h>
#include <err.h>
#include <stdio.h>
#include <stdarg.h>
@@ -648,3 +649,50 @@ bufcat_su(struct html *h, const char *p, const struct roffsu *su)
buffmt(h, "%s: %d%s;", p, (int)v, u);
}
+
+void
+html_idcpy(char *dst, const char *src, int sz)
+{
+
+ assert(sz);
+ dst[0] = '\0';
+ html_idcat(dst, src, sz);
+}
+
+
+void
+html_idcat(char *dst, const char *src, int sz)
+{
+ int i;
+
+ /* Cf. <http://www.w3.org/TR/html4/types.html#h-6.2>. */
+
+ for (i = 0; *dst != '\0' && i < sz - 1; dst++, i++)
+ /* Jump to end. */ ;
+
+ for ( ; *src != '\0' && i < sz - 1; src++, i++) {
+ if (isalnum((u_char)*src)) {
+ *dst++ = *src;
+ continue;
+ }
+
+ switch (*src) {
+ case (';'):
+ *dst++ = ';';
+ break;
+ case ('-'):
+ *dst++ = '-';
+ break;
+ case (':'):
+ *dst++ = ':';
+ break;
+ case ('_'):
+ /* FALLTHROUGH */
+ default:
+ *dst++ = '_';
+ break;
+ }
+ }
+
+ *dst = '\0';
+}