0
0
mirror of https://github.com/rkd77/elinks.git synced 2025-06-30 22:19:29 -04:00

[document] text as struct string

This commit is contained in:
Witold Filipczyk 2023-09-28 11:54:46 +02:00
parent e80a2f7014
commit 98e72e99f3
7 changed files with 24 additions and 24 deletions

View File

@ -310,7 +310,9 @@ reset_document(struct document *document)
#if defined(CONFIG_ECMASCRIPT_SMJS) || defined(CONFIG_QUICKJS) || defined(CONFIG_MUJS)
free_ecmascript_string_list(&document->onload_snippets);
free_uri_list(&document->ecmascript_imports);
mem_free_set(&document->text, NULL);
if (document->text.length) {
done_string(&document->text);
}
mem_free_set(&document->body_onkeypress, NULL);
/// kill_timer(&document->timeout);
/// free_document(document->dom);
@ -401,7 +403,9 @@ done_document(struct document *document)
#endif
#ifdef CONFIG_LIBDOM
mem_free_if(document->text);
if (document->text.length) {
done_string(&document->text);
}
free_document(document->dom);
if (document->element_map) {

View File

@ -24,6 +24,7 @@ struct frameset_desc;
struct image;
struct module;
struct screen_char;
struct string;
/** Nodes are used for marking areas of text on the document canvas as
* searchable. */
@ -238,7 +239,7 @@ struct document {
void *dom;
void *element_map;
void *element_map_rev;
char *text;
struct string text;
void *forms_nodeset;
#endif

View File

@ -331,7 +331,7 @@ not_processed:
/* Create URL reference onload snippet. */
insert_in_string(&import_url, 0, "^", 1);
add_to_ecmascript_string_list(&html_context->part->document->onload_snippets,
import_url, -1, html_top->name - html_context->part->document->text);
import_url, -1, html_top->name - html_context->part->document->text.source);
imported:
/* Retreat. Do not permit nested scripts, tho'. */
@ -411,7 +411,7 @@ imported:
if (html_context->part->document && *html != '^') {
add_to_ecmascript_string_list(&html_context->part->document->onload_snippets,
html, *end - html, html_top->name - html_context->part->document->text);
html, *end - html, html_top->name - html_context->part->document->text.source);
}
#endif
}

View File

@ -1558,7 +1558,7 @@ new_link(struct html_context *html_context, const char *name, int namelen)
: elformat.color.clink;
#ifdef CONFIG_ECMASCRIPT
link->element_offset = elformat.top_name ? elformat.top_name - document->text : 0;
link->element_offset = (elformat.top_name && document->text.source) ? elformat.top_name - document->text.source : 0;
#endif
init_link_event_hooks(html_context, link);

View File

@ -2063,7 +2063,7 @@ select_css(struct html_context *html_context, struct html_element *html_element)
css_media media = {
.type = CSS_MEDIA_SCREEN,
};
int offset = html_element->name - html_context->document->text;
int offset = html_element->name - html_context->document->text.source;
dom_node *el = (dom_node *)find_in_map(html_context->document->element_map, offset);
if (!el) {
@ -2292,7 +2292,7 @@ parse_css_common(struct html_context *html_context, const char *text, int length
void
parse_css(struct html_context *html_context, char *name)
{
int offset = name - html_context->document->text;
int offset = name - html_context->document->text.source;
dom_node *el = (dom_node *)find_in_map(html_context->document->element_map, offset);
dom_node *n, *next;
dom_exception err;

View File

@ -266,10 +266,8 @@ render_source_document_cxx(struct cache_entry *cached, struct document *document
}
if (!buffer->length) {
struct string tt;
if (!init_string(&tt)) {
return;
if (document->text.length) {
done_string(&document->text);
}
mapa = document->element_map;
@ -280,14 +278,15 @@ render_source_document_cxx(struct cache_entry *cached, struct document *document
clear_map(mapa);
}
if (walk_tree(mapa, &tt, root, true, 0) == false) {
if (walk_tree(mapa, &document->text, root, true, 0) == false) {
fprintf(stderr, "Failed to complete DOM structure dump.\n");
dom_node_unref(root);
//dom_node_unref(doc);
return;
}
*buffer = tt;
document->text = tt.source;
dom_node_unref(root);
render_plain_document(cached, document, &document->text);
return;
}
dom_node_unref(root);
render_plain_document(cached, document, buffer);

View File

@ -317,10 +317,8 @@ dump_xhtml(struct cache_entry *cached, struct document *document, int parse)
}
if (1) {
struct string tt;
if (!init_string(&tt)) {
return;
if (document->text.length) {
done_string(&document->text);
}
mapa = document->element_map;
@ -339,7 +337,7 @@ dump_xhtml(struct cache_entry *cached, struct document *document, int parse)
clear_map(mapa_rev);
}
if (walk_tree(mapa, mapa_rev, &tt, root, true, 0) == false) {
if (walk_tree(mapa, mapa_rev, &document->text, root, true, 0) == false) {
fprintf(stderr, "Failed to complete DOM structure dump.\n");
dom_node_unref(root);
//dom_node_unref(doc);
@ -350,11 +348,9 @@ dump_xhtml(struct cache_entry *cached, struct document *document, int parse)
if (parse) {
free_document(document);
document->dom = NULL;
render_xhtml_document(cached, document, &tt);
done_string(&tt);
render_xhtml_document(cached, document, &document->text);
return;
}
document->text = tt.source;
render_html_document(cached, document, &tt);
render_html_document(cached, document, &document->text);
}
}