mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
rss: simplify rendering to be done while parsing
This commit is contained in:
parent
0a5ee2d3de
commit
86ffd94237
@ -31,8 +31,6 @@ enum rss_style {
|
|||||||
struct rss_renderer {
|
struct rss_renderer {
|
||||||
struct screen_char styles[RSS_STYLES];
|
struct screen_char styles[RSS_STYLES];
|
||||||
|
|
||||||
struct dom_node *channel;
|
|
||||||
struct dom_node_list *items;
|
|
||||||
struct dom_node *item;
|
struct dom_node *item;
|
||||||
struct dom_node *node;
|
struct dom_node *node;
|
||||||
struct dom_string text;
|
struct dom_string text;
|
||||||
@ -60,8 +58,13 @@ render_rss_item(struct dom_renderer *renderer, struct dom_node *item)
|
|||||||
struct dom_string *author = get_rss_text(item, RSS_ELEMENT_AUTHOR);
|
struct dom_string *author = get_rss_text(item, RSS_ELEMENT_AUTHOR);
|
||||||
struct dom_string *date = get_rss_text(item, RSS_ELEMENT_PUBDATE);
|
struct dom_string *date = get_rss_text(item, RSS_ELEMENT_PUBDATE);
|
||||||
|
|
||||||
|
if (item->data.element.type == RSS_ELEMENT_ITEM) {
|
||||||
|
Y(renderer)++;
|
||||||
|
X(renderer) = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (title && is_dom_string_set(title)) {
|
if (title && is_dom_string_set(title)) {
|
||||||
if (item == rss->channel) {
|
if (item->data.element.type == RSS_ELEMENT_CHANNEL) {
|
||||||
unsigned char *str;
|
unsigned char *str;
|
||||||
|
|
||||||
str = convert_string(renderer->convert_table,
|
str = convert_string(renderer->convert_table,
|
||||||
@ -107,6 +110,15 @@ render_rss_item(struct dom_renderer *renderer, struct dom_node *item)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
flush_rss_item(struct dom_renderer *renderer, struct rss_renderer *rss)
|
||||||
|
{
|
||||||
|
if (rss->item) {
|
||||||
|
render_rss_item(renderer, rss->item);
|
||||||
|
rss->item = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static enum dom_code
|
static enum dom_code
|
||||||
dom_rss_push_element(struct dom_stack *stack, struct dom_node *node, void *xxx)
|
dom_rss_push_element(struct dom_stack *stack, struct dom_node *node, void *xxx)
|
||||||
@ -119,22 +131,13 @@ dom_rss_push_element(struct dom_stack *stack, struct dom_node *node, void *xxx)
|
|||||||
switch (node->data.element.type) {
|
switch (node->data.element.type) {
|
||||||
case RSS_ELEMENT_CHANNEL:
|
case RSS_ELEMENT_CHANNEL:
|
||||||
/* The stack should have: #document * channel */
|
/* The stack should have: #document * channel */
|
||||||
if (stack->depth == 3 && !rss->channel)
|
if (stack->depth == 3)
|
||||||
rss->channel = node;
|
rss->item = node;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RSS_ELEMENT_ITEM:
|
case RSS_ELEMENT_ITEM:
|
||||||
/* The stack should have: #document * channel item */
|
flush_rss_item(renderer, rss);
|
||||||
#if 0
|
|
||||||
/* Don't be so strict ... */
|
|
||||||
if (stack->depth != 4)
|
|
||||||
break;
|
|
||||||
#endif
|
|
||||||
/* ... but be exclusive. */
|
|
||||||
if (!rss->item) {
|
|
||||||
add_to_dom_node_list(&rss->items, node, -1);
|
|
||||||
rss->item = node;
|
rss->item = node;
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RSS_ELEMENT_LINK:
|
case RSS_ELEMENT_LINK:
|
||||||
@ -159,10 +162,13 @@ dom_rss_pop_element(struct dom_stack *stack, struct dom_node *node, void *xxx)
|
|||||||
assert(node && node->parent && renderer && renderer->document);
|
assert(node && node->parent && renderer && renderer->document);
|
||||||
|
|
||||||
switch (node->data.element.type) {
|
switch (node->data.element.type) {
|
||||||
|
case RSS_ELEMENT_CHANNEL:
|
||||||
|
flush_rss_item(renderer, rss);
|
||||||
|
break;
|
||||||
|
|
||||||
case RSS_ELEMENT_ITEM:
|
case RSS_ELEMENT_ITEM:
|
||||||
if (is_dom_string_set(&rss->text))
|
if (is_dom_string_set(&rss->text))
|
||||||
done_dom_string(&rss->text);
|
done_dom_string(&rss->text);
|
||||||
rss->item = NULL;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RSS_ELEMENT_LINK:
|
case RSS_ELEMENT_LINK:
|
||||||
@ -243,25 +249,8 @@ dom_rss_pop_document(struct dom_stack *stack, struct dom_node *root, void *xxx)
|
|||||||
struct dom_renderer *renderer = stack->current->data;
|
struct dom_renderer *renderer = stack->current->data;
|
||||||
struct rss_renderer *rss = renderer->data;
|
struct rss_renderer *rss = renderer->data;
|
||||||
|
|
||||||
if (!rss->channel)
|
|
||||||
return DOM_CODE_OK;
|
|
||||||
|
|
||||||
render_rss_item(renderer, rss->channel);
|
|
||||||
|
|
||||||
if (rss->items) {
|
|
||||||
struct dom_node *node;
|
|
||||||
int index;
|
|
||||||
|
|
||||||
foreach_dom_node (rss->items, node, index) {
|
|
||||||
Y(renderer)++;
|
|
||||||
X(renderer) = 0;
|
|
||||||
render_rss_item(renderer, node);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (is_dom_string_set(&rss->text))
|
if (is_dom_string_set(&rss->text))
|
||||||
done_dom_string(&rss->text);
|
done_dom_string(&rss->text);
|
||||||
mem_free_if(rss->items);
|
|
||||||
|
|
||||||
done_dom_node(root);
|
done_dom_node(root);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user