mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
Make the parser stream mode work as intended
This makes the parser and renderer share the stack, most importantly the callbacks are now those of the renderer. Disable node attribute rendering code that worked around the attributes being visited in sorted order.
This commit is contained in:
parent
2dddf86acc
commit
7a912795e1
@ -589,25 +589,34 @@ render_dom_element_source(struct dom_stack *stack, struct dom_node *node, void *
|
|||||||
static struct dom_node *
|
static struct dom_node *
|
||||||
render_dom_attribute_source(struct dom_stack *stack, struct dom_node *node, void *data)
|
render_dom_attribute_source(struct dom_stack *stack, struct dom_node *node, void *data)
|
||||||
{
|
{
|
||||||
struct dom_stack_state *state = get_dom_stack_parent(stack);
|
|
||||||
struct dom_renderer *renderer = stack->renderer;
|
struct dom_renderer *renderer = stack->renderer;
|
||||||
struct screen_char *template = &renderer->styles[node->type];
|
struct screen_char *template = &renderer->styles[node->type];
|
||||||
struct dom_node *attribute = NULL;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
assert(node && renderer->document);
|
assert(node && renderer->document);
|
||||||
assert(state && state->list);
|
|
||||||
|
|
||||||
/* The attributes are sorted but we want them in the original order */
|
#if 0
|
||||||
foreach_dom_node(i, node, state->list) {
|
/* Disabled since the DOM source highlighter uses the stream parser and
|
||||||
if (node->string >= renderer->position
|
* therefore the attributes is pushed to it in order. However, if/when
|
||||||
&& (!attribute || node->string < attribute->string))
|
* we will support rendering (read saving) of loaded DOM trees this one
|
||||||
attribute = node;
|
* small hack is needed to get the attributes in the original order. */
|
||||||
|
{
|
||||||
|
struct dom_stack_state *state = get_dom_stack_parent(stack);
|
||||||
|
struct dom_node *attribute = NULL;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
assert(state && state->list);
|
||||||
|
|
||||||
|
/* The attributes are sorted but we want them in the original order */
|
||||||
|
foreach_dom_node(i, node, state->list) {
|
||||||
|
if (node->string >= renderer->position
|
||||||
|
&& (!attribute || node->string < attribute->string))
|
||||||
|
attribute = node;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert(attribute);
|
||||||
|
node = attribute;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
assert(attribute);
|
|
||||||
node = attribute;
|
|
||||||
|
|
||||||
render_dom_node_text(renderer, template, node);
|
render_dom_node_text(renderer, template, node);
|
||||||
|
|
||||||
if (node->data.attribute.value) {
|
if (node->data.attribute.value) {
|
||||||
@ -696,7 +705,6 @@ render_dom_document(struct cache_entry *cached, struct document *document,
|
|||||||
struct conv_table *convert_table;
|
struct conv_table *convert_table;
|
||||||
dom_stack_callback_T *callbacks = dom_source_renderer_callbacks;
|
dom_stack_callback_T *callbacks = dom_source_renderer_callbacks;
|
||||||
struct sgml_parser *parser;
|
struct sgml_parser *parser;
|
||||||
struct dom_stack stack;
|
|
||||||
|
|
||||||
assert(document->options.plain);
|
assert(document->options.plain);
|
||||||
|
|
||||||
@ -707,24 +715,17 @@ render_dom_document(struct cache_entry *cached, struct document *document,
|
|||||||
document->options.hard_assume);
|
document->options.hard_assume);
|
||||||
|
|
||||||
init_dom_renderer(&renderer, document, buffer, convert_table);
|
init_dom_renderer(&renderer, document, buffer, convert_table);
|
||||||
init_dom_stack(&stack, NULL, &renderer, callbacks, 0);
|
|
||||||
|
|
||||||
document->bgcolor = document->options.default_bg;
|
document->bgcolor = document->options.default_bg;
|
||||||
|
|
||||||
parser = init_sgml_parser(SGML_PARSER_STREAM, cached, document);
|
parser = init_sgml_parser(SGML_PARSER_STREAM, &renderer, cached,
|
||||||
if (!parser) {
|
document, callbacks);
|
||||||
done_dom_stack(&stack);
|
if (!parser) return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
root = parse_sgml(parser, buffer);
|
root = parse_sgml(parser, buffer);
|
||||||
done_sgml_parser(parser);
|
done_sgml_parser(parser);
|
||||||
if (!root) {
|
if (!root) return;
|
||||||
done_dom_stack(&stack);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
walk_dom_nodes(&stack, root);
|
|
||||||
/* If there are no non-element nodes after the last element node make
|
/* If there are no non-element nodes after the last element node make
|
||||||
* sure that we flush to the end of the cache entry source including
|
* sure that we flush to the end of the cache entry source including
|
||||||
* the '>' of the last element tag if it has one. (bug 519) */
|
* the '>' of the last element tag if it has one. (bug 519) */
|
||||||
@ -733,5 +734,4 @@ render_dom_document(struct cache_entry *cached, struct document *document,
|
|||||||
}
|
}
|
||||||
|
|
||||||
done_dom_node(root);
|
done_dom_node(root);
|
||||||
done_dom_stack(&stack);
|
|
||||||
}
|
}
|
||||||
|
@ -297,8 +297,9 @@ parse_sgml_document(struct dom_stack *stack, struct scanner *scanner)
|
|||||||
|
|
||||||
|
|
||||||
struct sgml_parser *
|
struct sgml_parser *
|
||||||
init_sgml_parser(enum sgml_parser_type type, struct cache_entry *cached,
|
init_sgml_parser(enum sgml_parser_type type, void *renderer,
|
||||||
struct document *document)
|
struct cache_entry *cached, struct document *document,
|
||||||
|
dom_stack_callback_T callbacks[DOM_NODES])
|
||||||
{
|
{
|
||||||
size_t obj_size = sizeof(struct sgml_parser_state);
|
size_t obj_size = sizeof(struct sgml_parser_state);
|
||||||
struct sgml_parser *parser;
|
struct sgml_parser *parser;
|
||||||
@ -311,7 +312,7 @@ init_sgml_parser(enum sgml_parser_type type, struct cache_entry *cached,
|
|||||||
parser->cache_entry = cached;
|
parser->cache_entry = cached;
|
||||||
parser->info = &sgml_html_info;
|
parser->info = &sgml_html_info;
|
||||||
|
|
||||||
init_dom_stack(&parser->stack, parser, NULL, NULL, obj_size);
|
init_dom_stack(&parser->stack, parser, renderer, callbacks, obj_size);
|
||||||
|
|
||||||
return parser;
|
return parser;
|
||||||
}
|
}
|
||||||
|
@ -41,8 +41,9 @@ struct sgml_parser_state {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct sgml_parser *
|
struct sgml_parser *
|
||||||
init_sgml_parser(enum sgml_parser_type type,
|
init_sgml_parser(enum sgml_parser_type type, void *renderer,
|
||||||
struct cache_entry *cached, struct document *document);
|
struct cache_entry *cached, struct document *document,
|
||||||
|
dom_stack_callback_T callbacks[DOM_NODES]);
|
||||||
|
|
||||||
void done_sgml_parser(struct sgml_parser *parser);
|
void done_sgml_parser(struct sgml_parser *parser);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user