Improve handling of feeds with missing data
Previously the description was used in the treeview if the title was not present, however this is not possible in some cases, as it may contain markup. The the RSS code is changed so now if there is no title, the description is used as the title, but with the html stripped from it. We also have to consider that some description elements may simply contain an html tag (and therefore no text). In that case the URI is used as the title.
This commit is contained in:
parent
ff2abf1fd4
commit
20d03e43aa
3 changed files with 49 additions and 17 deletions
|
@ -33,35 +33,36 @@ feed_get_element_string (FeedParser* fparser)
|
||||||
return (gchar*)xmlNodeListGetString (fparser->doc, node->children, 1);
|
return (gchar*)xmlNodeListGetString (fparser->doc, node->children, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
handle_markup_chars (void* user_data,
|
handle_markup_chars (void* user_data,
|
||||||
const xmlChar* ch,
|
const xmlChar* ch,
|
||||||
int len)
|
int len)
|
||||||
{
|
{
|
||||||
gchar** markup;
|
if (len > 0)
|
||||||
gchar* temp;
|
{
|
||||||
|
gchar** markup;
|
||||||
|
gchar* temp;
|
||||||
|
|
||||||
markup = (gchar**)user_data;
|
markup = (gchar**)user_data;
|
||||||
temp = g_strndup ((gchar*)ch, len);
|
temp = g_strndup ((gchar*)ch, len);
|
||||||
*markup = (*markup) ? g_strconcat (*markup, temp, NULL) : g_strdup (temp);
|
*markup = (*markup) ? g_strconcat (*markup, temp, NULL) : g_strdup (temp);
|
||||||
g_free (temp);
|
g_free (temp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gchar*
|
gchar*
|
||||||
feed_get_element_markup (FeedParser* fparser)
|
feed_remove_markup (gchar* markup)
|
||||||
{
|
{
|
||||||
gchar* markup;
|
|
||||||
const xmlChar* stag;
|
const xmlChar* stag;
|
||||||
|
if (((stag = xmlStrchr (BAD_CAST markup, '<')) && xmlStrchr (stag, '>')) ||
|
||||||
markup = feed_get_element_string (fparser);
|
xmlStrchr (BAD_CAST markup, '&'))
|
||||||
if ((stag = xmlStrchr (BAD_CAST markup, '<')) && xmlStrchr (stag, '>'))
|
|
||||||
{
|
{
|
||||||
gchar* text = NULL;
|
gchar* text = NULL;
|
||||||
htmlSAXHandlerPtr psax;
|
htmlSAXHandlerPtr psax;
|
||||||
|
|
||||||
psax = g_new0 (htmlSAXHandler, 1);
|
psax = g_new0 (htmlSAXHandler, 1);
|
||||||
psax->characters = handle_markup_chars;
|
psax->characters = handle_markup_chars;
|
||||||
htmlSAXParseDoc (BAD_CAST markup, NULL, psax, &text);
|
htmlSAXParseDoc (BAD_CAST markup, "UTF-8", psax, &text);
|
||||||
g_free (psax);
|
g_free (psax);
|
||||||
g_free (markup);
|
g_free (markup);
|
||||||
return text;
|
return text;
|
||||||
|
@ -69,6 +70,15 @@ feed_get_element_markup (FeedParser* fparser)
|
||||||
return markup;
|
return markup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gchar*
|
||||||
|
feed_get_element_markup (FeedParser* fparser)
|
||||||
|
{
|
||||||
|
gchar* markup;
|
||||||
|
|
||||||
|
markup = feed_get_element_string (fparser);
|
||||||
|
return feed_remove_markup (markup);
|
||||||
|
}
|
||||||
|
|
||||||
gint64
|
gint64
|
||||||
feed_get_element_date (FeedParser* fparser)
|
feed_get_element_date (FeedParser* fparser)
|
||||||
{
|
{
|
||||||
|
|
|
@ -57,6 +57,9 @@ typedef struct _FeedParser
|
||||||
gchar*
|
gchar*
|
||||||
feed_get_element_string (FeedParser* fparser);
|
feed_get_element_string (FeedParser* fparser);
|
||||||
|
|
||||||
|
gchar*
|
||||||
|
feed_remove_markup (gchar* markup);
|
||||||
|
|
||||||
gchar*
|
gchar*
|
||||||
feed_get_element_markup (FeedParser* fparser);
|
feed_get_element_markup (FeedParser* fparser);
|
||||||
|
|
||||||
|
|
|
@ -137,11 +137,30 @@ rss_postparse_item (FeedParser* fparser)
|
||||||
* Verify that the required RSS elements are added
|
* Verify that the required RSS elements are added
|
||||||
* (as per the spec)
|
* (as per the spec)
|
||||||
*/
|
*/
|
||||||
if (!katze_item_get_name (fparser->item) &&
|
if (!katze_item_get_name (fparser->item))
|
||||||
!katze_item_get_text (fparser->item))
|
|
||||||
{
|
{
|
||||||
feed_parser_set_error (fparser, FEED_PARSE_ERROR_MISSING_ELEMENT,
|
gchar* desc;
|
||||||
_("Failed to find required RSS \"item\" elements in XML data."));
|
|
||||||
|
desc = (gchar*)katze_item_get_text (fparser->item);
|
||||||
|
if (!desc)
|
||||||
|
{
|
||||||
|
feed_parser_set_error (fparser, FEED_PARSE_ERROR_MISSING_ELEMENT,
|
||||||
|
_("Failed to find required RSS \"item\" elements in XML data."));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
desc = feed_remove_markup (g_strdup (desc));
|
||||||
|
if (desc)
|
||||||
|
{
|
||||||
|
katze_item_set_name (fparser->item, desc);
|
||||||
|
g_free (desc);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ((desc = (gchar*)katze_item_get_uri (fparser->item)))
|
||||||
|
katze_item_set_name (fparser->item, desc);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue