Skip to content
Merged
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
43 changes: 41 additions & 2 deletions src/bz-appstream-description-render.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

#define G_LOG_DOMAIN "BAZAAR::APPSTREAM-DESCRIPTION-RENDER"

#include "config.h"

#include <xmlb.h>

#include "bz-appstream-description-render.h"
Expand Down Expand Up @@ -58,9 +60,17 @@ enum

static GParamSpec *props[LAST_PROP] = { 0 };

static void
setup_text_tags (GtkTextBuffer *buffer);

static void
regenerate (BzAppstreamDescriptionRender *self);

static void
insert (GtkTextBuffer *buffer,
GtkTextIter *iter,
const char *text);

static void
compile (BzAppstreamDescriptionRender *self,
XbNode *node,
Expand Down Expand Up @@ -264,6 +274,35 @@ regenerate (BzAppstreamDescriptionRender *self)
}
}

static void
insert (GtkTextBuffer *buffer,
GtkTextIter *iter,
const char *text)
{
g_auto (GStrv) parts = NULL;

parts = g_strsplit (text, "**", -1);

for (int j = 0; parts[j] != NULL; j++)
{
if (j % 2 == 0)
{
gtk_text_buffer_insert (buffer, iter, parts[j], -1);
}
else
{
GtkTextMark *m = NULL;
GtkTextIter si = { 0 };

m = gtk_text_buffer_create_mark (buffer, NULL, iter, TRUE);
gtk_text_buffer_insert (buffer, iter, parts[j], -1);
gtk_text_buffer_get_iter_at_mark (buffer, &si, m);
gtk_text_buffer_apply_tag_by_name (buffer, "emphasis", &si, iter);
gtk_text_buffer_delete_mark (buffer, m);
}
}
}

static void
compile (BzAppstreamDescriptionRender *self,
XbNode *node,
Expand Down Expand Up @@ -336,7 +375,7 @@ compile (BzAppstreamDescriptionRender *self,

normalized = normalize_whitespace (text);
if (normalized != NULL && *normalized != '\0')
gtk_text_buffer_insert (buffer, iter, normalized, -1);
insert (buffer, iter, normalized);
}

for (int i = 0; child != NULL; i++)
Expand All @@ -354,7 +393,7 @@ compile (BzAppstreamDescriptionRender *self,

normalized = normalize_whitespace (tail);
if (normalized != NULL && *normalized != '\0')
gtk_text_buffer_insert (buffer, iter, normalized, -1);
insert (buffer, iter, normalized);
}

g_object_unref (child);
Expand Down