summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/html.c43
-rw-r--r--src/html.h3
2 files changed, 46 insertions, 0 deletions
diff --git a/src/html.c b/src/html.c
index bf4f18c..0a0bd40 100644
--- a/src/html.c
+++ b/src/html.c
@@ -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;
diff --git a/src/html.h b/src/html.h
index b31179d..d0bd8db 100644
--- a/src/html.h
+++ b/src/html.h
@@ -25,6 +25,9 @@
#include <glib.h>
gchar *
+mq_html_document(const gchar *title, ...);
+
+gchar *
mq_html_container(const gchar *element, ...);
gchar *