1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-10-01 03:36:26 -04: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:
Jonas Fonseca 2005-12-05 19:25:13 +01:00 committed by Jonas Fonseca
parent 2dddf86acc
commit 7a912795e1
3 changed files with 33 additions and 31 deletions

View File

@ -589,25 +589,34 @@ render_dom_element_source(struct dom_stack *stack, struct dom_node *node, void *
static struct dom_node *
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 screen_char *template = &renderer->styles[node->type];
struct dom_node *attribute = NULL;
int i;
assert(node && renderer->document);
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;
#if 0
/* Disabled since the DOM source highlighter uses the stream parser and
* therefore the attributes is pushed to it in order. However, if/when
* we will support rendering (read saving) of loaded DOM trees this one
* 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;
}
assert(attribute);
node = attribute;
#endif
render_dom_node_text(renderer, template, node);
if (node->data.attribute.value) {
@ -696,7 +705,6 @@ render_dom_document(struct cache_entry *cached, struct document *document,
struct conv_table *convert_table;
dom_stack_callback_T *callbacks = dom_source_renderer_callbacks;
struct sgml_parser *parser;
struct dom_stack stack;
assert(document->options.plain);
@ -707,24 +715,17 @@ render_dom_document(struct cache_entry *cached, struct document *document,
document->options.hard_assume);
init_dom_renderer(&renderer, document, buffer, convert_table);
init_dom_stack(&stack, NULL, &renderer, callbacks, 0);
document->bgcolor = document->options.default_bg;
parser = init_sgml_parser(SGML_PARSER_STREAM, cached, document);
if (!parser) {
done_dom_stack(&stack);
return;
}
parser = init_sgml_parser(SGML_PARSER_STREAM, &renderer, cached,
document, callbacks);
if (!parser) return;
root = parse_sgml(parser, buffer);
done_sgml_parser(parser);
if (!root) {
done_dom_stack(&stack);
return;
}
if (!root) return;
walk_dom_nodes(&stack, root);
/* 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
* 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_stack(&stack);
}

View File

@ -297,8 +297,9 @@ parse_sgml_document(struct dom_stack *stack, struct scanner *scanner)
struct sgml_parser *
init_sgml_parser(enum sgml_parser_type type, struct cache_entry *cached,
struct document *document)
init_sgml_parser(enum sgml_parser_type type, void *renderer,
struct cache_entry *cached, struct document *document,
dom_stack_callback_T callbacks[DOM_NODES])
{
size_t obj_size = sizeof(struct sgml_parser_state);
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->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;
}

View File

@ -41,8 +41,9 @@ struct sgml_parser_state {
};
struct sgml_parser *
init_sgml_parser(enum sgml_parser_type type,
struct cache_entry *cached, struct document *document);
init_sgml_parser(enum sgml_parser_type type, void *renderer,
struct cache_entry *cached, struct document *document,
dom_stack_callback_T callbacks[DOM_NODES]);
void done_sgml_parser(struct sgml_parser *parser);