diff options
author | Přemysl Eric Janouch <p@janouch.name> | 2021-10-11 01:40:02 +0200 |
---|---|---|
committer | Přemysl Eric Janouch <p@janouch.name> | 2021-10-11 02:43:30 +0200 |
commit | 4d6cd247cb226eff6c302748474534c23459cbec (patch) | |
tree | 373a3975f2e6df9d61831a7c4135cb0164653820 | |
parent | b9ba894cc94a5b883ea4b30f6aeeede0a8b5f9de (diff) | |
download | tdv-4d6cd247cb226eff6c302748474534c23459cbec.tar.gz tdv-4d6cd247cb226eff6c302748474534c23459cbec.tar.xz tdv-4d6cd247cb226eff6c302748474534c23459cbec.zip |
sdtui: implement elementary XDXF display
We're lacking word wrapping, but it's more or less usable.
-rw-r--r-- | src/sdtui.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/sdtui.c b/src/sdtui.c index d823f43..04d7ddb 100644 --- a/src/sdtui.c +++ b/src/sdtui.c @@ -344,6 +344,25 @@ view_entry_split_add_pango (ViewEntry *ve, const gchar *markup) g_free (text); } +static void +view_entry_split_add_xdxf (ViewEntry *ve, const gchar *xml) +{ + // Trivially filter out all tags we can't quite handle, + // then parse the reduced XML as Pango markup--this seems to work well. + GString *filtered = g_string_new (""); + while (*xml) + { + const gchar *p = NULL; + if (*xml != '<' || !*(p = xml + 1 + (xml[1] == '/')) + || (strchr ("biu", *p) && p[1] == '>') || !(p = strchr (p, '>'))) + g_string_append_c (filtered, *xml++); + else + xml = ++p; + } + view_entry_split_add_pango (ve, filtered->str); + g_string_free (filtered, TRUE); +} + /// Decomposes a dictionary entry into the format we want. static ViewEntry * view_entry_new (StardictIterator *iterator) @@ -372,6 +391,10 @@ view_entry_new (StardictIterator *iterator) view_entry_split_add_pango (ve, field->data); found_anything_displayable = TRUE; break; + case STARDICT_FIELD_XDXF: + view_entry_split_add_xdxf (ve, field->data); + found_anything_displayable = TRUE; + break; case STARDICT_FIELD_PHONETIC: g_string_append_printf (word, " /%s/", (const gchar *) field->data); break; |