summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/utils/html.c40
-rw-r--r--src/utils/html.h3
2 files changed, 43 insertions, 0 deletions
diff --git a/src/utils/html.c b/src/utils/html.c
index 262be3b..fdaa96a 100644
--- a/src/utils/html.c
+++ b/src/utils/html.c
@@ -300,6 +300,46 @@ mq_html_document(const gchar *title, ...)
return document;
}
+gchar *
+mq_html_document_v(const gchar *title, gchar **children)
+{
+ gsize len;
+ gsize i;
+ 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<style>\n");
+ len += strlen(styles);
+ len += strlen("</style>\n</head>\n<body>\n");
+ for (i = 0; children && children[i]; ++i) {
+ len += strlen(children[i]);
+ }
+ 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<style>\n");
+ ptr = g_stpcpy(ptr, styles);
+ ptr = g_stpcpy(ptr, "</style>\n</head>\n<body>\n");
+ for (i = 0; children && children[i]; ++i) {
+ ptr = g_stpcpy(ptr, children[i]);
+ }
+ ptr = g_stpcpy(ptr, "</body>\n</html>\n"); /* g_stpcpy() adds NUL. */
+
+ return document;
+}
+
#define TEXT_ELEMENT(ELEM) \
gchar * \
mq_html_##ELEM(const gchar *text) \
diff --git a/src/utils/html.h b/src/utils/html.h
index 27e0cfe..10588f7 100644
--- a/src/utils/html.h
+++ b/src/utils/html.h
@@ -29,6 +29,9 @@ G_BEGIN_DECLS
gchar *
mq_html_document(const gchar *title, ...) G_GNUC_NULL_TERMINATED;
+gchar *
+mq_html_document_v(const gchar *title, gchar **children);
+
#define TEXT_ELEMENT(ELEM) \
gchar * \
mq_html_##ELEM(const gchar *text); \