sdtui: implement elementary XDXF display

We're lacking word wrapping, but it's more or less usable.
This commit is contained in:
Přemysl Eric Janouch 2021-10-11 01:40:02 +02:00
parent b9ba894cc9
commit 4d6cd247cb
Signed by: p
GPG Key ID: A0420B94F92B9493
1 changed files with 23 additions and 0 deletions

View File

@ -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;