From fbfd8c7d027f054eacb7384787cf665e4822eda6 Mon Sep 17 00:00:00 2001 From: Přemysl Eric Janouch Date: Sun, 10 Oct 2021 01:51:15 +0200 Subject: tabfile: add support for writing Pango markup Enabling this option will ensure the field would parse. --- src/tabfile.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/tabfile.c b/src/tabfile.c index b2ceefa..053748c 100644 --- a/src/tabfile.c +++ b/src/tabfile.c @@ -24,6 +24,7 @@ #include #include +#include #include @@ -93,6 +94,11 @@ import_line (Generator *generator, gchar *line, gsize len, GError **error) || !inplace_unescape (separator, error)) return FALSE; + if (generator->info->same_type_sequence + && *generator->info->same_type_sequence == STARDICT_FIELD_PANGO + && !pango_parse_markup (separator, -1, 0, NULL, NULL, NULL, error)) + return FALSE; + generator_begin_entry (generator); return generator_write_string (generator, separator, TRUE, error) && generator_finish_entry (generator, line, error); @@ -145,12 +151,13 @@ main (int argc, char *argv[]) g_option_context_set_summary (ctx, "Create a StarDict dictionary from plaintext."); - StardictInfo template = - { - .same_type_sequence = "m", - }; + gboolean pango_markup = FALSE; + StardictInfo template = {}; GOptionEntry entries[] = { + { "pango", 'p', 0, G_OPTION_ARG_NONE, &pango_markup, + "Entries use Pango markup", NULL }, + { "book-name", 'b', 0, G_OPTION_ARG_STRING, &template.book_name, "Set the book name field", "TEXT" }, { "author", 'a', 0, G_OPTION_ARG_STRING, &template.author, @@ -175,6 +182,10 @@ main (int argc, char *argv[]) fatal ("%s", g_option_context_get_help (ctx, TRUE, FALSE)); g_option_context_free (ctx); + template.same_type_sequence = pango_markup + ? (char[]) { STARDICT_FIELD_PANGO, 0 } + : (char[]) { STARDICT_FIELD_MEANING, 0 }; + if (!template.book_name) template.book_name = argv[1]; if (template.description) -- cgit v1.2.3-70-g09d2