sdtui: implement elementary XDXF display
We're lacking word wrapping, but it's more or less usable.
This commit is contained in:
parent
b9ba894cc9
commit
4d6cd247cb
23
src/sdtui.c
23
src/sdtui.c
|
@ -344,6 +344,25 @@ view_entry_split_add_pango (ViewEntry *ve, const gchar *markup)
|
||||||
g_free (text);
|
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.
|
/// Decomposes a dictionary entry into the format we want.
|
||||||
static ViewEntry *
|
static ViewEntry *
|
||||||
view_entry_new (StardictIterator *iterator)
|
view_entry_new (StardictIterator *iterator)
|
||||||
|
@ -372,6 +391,10 @@ view_entry_new (StardictIterator *iterator)
|
||||||
view_entry_split_add_pango (ve, field->data);
|
view_entry_split_add_pango (ve, field->data);
|
||||||
found_anything_displayable = TRUE;
|
found_anything_displayable = TRUE;
|
||||||
break;
|
break;
|
||||||
|
case STARDICT_FIELD_XDXF:
|
||||||
|
view_entry_split_add_xdxf (ve, field->data);
|
||||||
|
found_anything_displayable = TRUE;
|
||||||
|
break;
|
||||||
case STARDICT_FIELD_PHONETIC:
|
case STARDICT_FIELD_PHONETIC:
|
||||||
g_string_append_printf (word, " /%s/", (const gchar *) field->data);
|
g_string_append_printf (word, " /%s/", (const gchar *) field->data);
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue