From f12d5332a8fa6e2a65e750326adf875c78e4bd5f Mon Sep 17 00:00:00 2001 From: Sascha Kruse Date: Fri, 22 Feb 2013 19:38:42 +0000 Subject: [PATCH] fail more gracefully on broken markup Strip markup and display plain text. Also print error message why markup couldn't be parsed. --- x.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/x.c b/x.c index 480ef8c..21265a6 100644 --- a/x.c +++ b/x.c @@ -184,16 +184,20 @@ colored_layout *r_create_layout_from_notification(cairo_t *c, notification *n) r_setup_pango_layout(cl->l, width); /* markup */ - bool success = pango_parse_markup(n->text_to_render, -1, 0, &(cl->attr), &(cl->text), NULL, NULL); + GError *err = NULL; + pango_parse_markup(n->text_to_render, -1, 0, &(cl->attr), &(cl->text), NULL, &err); - if (success) { + if (!err) { pango_layout_set_text(cl->l, cl->text, -1); pango_layout_set_attributes(cl->l, cl->attr); } else { + /* remove markup and display plain message instead */ + n->text_to_render = notification_fix_markup(n->text_to_render); cl->text = NULL; cl->attr = NULL; pango_layout_set_text(cl->l, n->text_to_render, -1); - printf("Error parsing markup\n"); + printf("Error parsing markup: %s\n", err->message); + g_error_free(err); } pango_layout_get_pixel_size(cl->l, NULL, &(n->displayed_height));