2020
2121#define G_LOG_DOMAIN "BAZAAR::APPSTREAM-DESCRIPTION-RENDER"
2222
23+ #include "config.h"
24+
2325#include <xmlb.h>
2426
2527#include "bz-appstream-description-render.h"
5860
5961static GParamSpec * props [LAST_PROP ] = { 0 };
6062
63+ static void
64+ setup_text_tags (GtkTextBuffer * buffer );
65+
6166static void
6267regenerate (BzAppstreamDescriptionRender * self );
6368
69+ static void
70+ insert (GtkTextBuffer * buffer ,
71+ GtkTextIter * iter ,
72+ const char * text );
73+
6474static void
6575compile (BzAppstreamDescriptionRender * self ,
6676 XbNode * node ,
@@ -264,6 +274,35 @@ regenerate (BzAppstreamDescriptionRender *self)
264274 }
265275}
266276
277+ static void
278+ insert (GtkTextBuffer * buffer ,
279+ GtkTextIter * iter ,
280+ const char * text )
281+ {
282+ g_auto (GStrv ) parts = NULL ;
283+
284+ parts = g_strsplit (text , "**" , -1 );
285+
286+ for (int j = 0 ; parts [j ] != NULL ; j ++ )
287+ {
288+ if (j % 2 == 0 )
289+ {
290+ gtk_text_buffer_insert (buffer , iter , parts [j ], -1 );
291+ }
292+ else
293+ {
294+ GtkTextMark * m = NULL ;
295+ GtkTextIter si = { 0 };
296+
297+ m = gtk_text_buffer_create_mark (buffer , NULL , iter , TRUE);
298+ gtk_text_buffer_insert (buffer , iter , parts [j ], -1 );
299+ gtk_text_buffer_get_iter_at_mark (buffer , & si , m );
300+ gtk_text_buffer_apply_tag_by_name (buffer , "emphasis" , & si , iter );
301+ gtk_text_buffer_delete_mark (buffer , m );
302+ }
303+ }
304+ }
305+
267306static void
268307compile (BzAppstreamDescriptionRender * self ,
269308 XbNode * node ,
@@ -336,7 +375,7 @@ compile (BzAppstreamDescriptionRender *self,
336375
337376 normalized = normalize_whitespace (text );
338377 if (normalized != NULL && * normalized != '\0' )
339- gtk_text_buffer_insert (buffer , iter , normalized , -1 );
378+ insert (buffer , iter , normalized );
340379 }
341380
342381 for (int i = 0 ; child != NULL ; i ++ )
@@ -354,7 +393,7 @@ compile (BzAppstreamDescriptionRender *self,
354393
355394 normalized = normalize_whitespace (tail );
356395 if (normalized != NULL && * normalized != '\0' )
357- gtk_text_buffer_insert (buffer , iter , normalized , -1 );
396+ insert (buffer , iter , normalized );
358397 }
359398
360399 g_object_unref (child );
0 commit comments