Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve body parsing #76

Merged
merged 2 commits into from
Oct 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions notification.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pango/pangocairo.h>
#include <wayland-client.h>
#ifdef __linux__
#include <linux/input-event-codes.h>
Expand Down Expand Up @@ -186,7 +187,7 @@ char *format_notif_text(char variable, bool *markup, void *data) {
case 's':
return strdup(notif->summary);
case 'b':
*markup = true;
*markup = notif->style.markup;
return strdup(notif->body);
}
return NULL;
Expand Down Expand Up @@ -226,7 +227,7 @@ size_t format_text(const char *format, char *buf, mako_format_func_t format_func
}

size_t value_len;
if (!markup) {
if (!markup || !pango_parse_markup(value, -1, 0, NULL, NULL, NULL, NULL)) {
char *escaped = NULL;
if (buf != NULL) {
escaped = buf + len;
Expand Down
20 changes: 8 additions & 12 deletions render.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,15 @@ static int render_notification(cairo_t *cairo, struct mako_state *state,
pango_font_description_free(desc);

PangoAttrList *attrs = NULL;
if (style->markup) {
GError *error = NULL;
char *buf = NULL;
if (pango_parse_markup(text, -1, 0, &attrs, &buf, NULL, &error)) {
pango_layout_set_text(layout, buf, -1);
free(buf);
} else {
fprintf(stderr, "cannot parse pango markup: %s\n", error->message);
g_error_free(error);
// fallback to plain text
pango_layout_set_text(layout, text, -1);
}
GError *error = NULL;
char *buf = NULL;
if (pango_parse_markup(text, -1, 0, &attrs, &buf, NULL, &error)) {
pango_layout_set_text(layout, buf, -1);
free(buf);
} else {
fprintf(stderr, "cannot parse pango markup: %s\n", error->message);
g_error_free(error);
// fallback to plain text
pango_layout_set_text(layout, text, -1);
}

Expand Down