diff options
-rw-r--r-- | src/html.c | 43 | ||||
-rw-r--r-- | src/html.h | 3 |
2 files changed, 46 insertions, 0 deletions
@@ -23,10 +23,53 @@ #include <string.h> #include <glib.h> +#include <gtk/gtk.h> #include "html.h" gchar * +mq_html_document(const gchar *title, ...) +{ + gsize len; + va_list ap; + gchar *child; + gchar *document; + gchar *ptr; + + /* Calculate length. */ + len = strlen("<!doctype html>\n<html dir=\""); + len += 3; /* "ltr" or "rtl" */ + len += strlen("\">\n<head>\n<meta charset=\"utf-8\">\n<title>"); + len += strlen(title); + len += strlen("</title>\n</head>\n<body>\n"); + va_start(ap, title); + while ((child = va_arg(ap, gchar *))) { + len += strlen(child); + } + va_end(ap); + len += strlen("</body>\n</html>\n"); + ++len; /* NUL byte */ + + /* Build string. */ + document = g_new(gchar, len); + ptr = g_stpcpy(document, "<!doctype html>\n<html dir=\""); + ptr = g_stpcpy(ptr, gtk_widget_get_default_direction() == + GTK_TEXT_DIR_RTL ? "rtl" : "ltr"); + ptr = g_stpcpy(ptr, "\">\n<head>\n<meta charset=\"utf-8\">\n<title>"); + ptr = g_stpcpy(ptr, title); + ptr = g_stpcpy(ptr, "</title>\n</head>\n<body>\n"); + va_start(ap, title); + while ((child = va_arg(ap, gchar *))) { + ptr = g_stpcpy(ptr, child); + g_free(child); + } + va_end(ap); + ptr = g_stpcpy(ptr, "</body>\n</html>\n"); /* g_stpcpy() adds NUL. */ + + return document; +} + +gchar * mq_html_container(const gchar *element, ...) { gsize len; @@ -25,6 +25,9 @@ #include <glib.h> gchar * +mq_html_document(const gchar *title, ...); + +gchar * mq_html_container(const gchar *element, ...); gchar * |