mirror of
https://github.com/rkd77/elinks.git
synced 2025-02-02 15:09:23 -05:00
[libdom] document.write works for test cases
This commit is contained in:
parent
9e32406e29
commit
b17f051f59
@ -13,6 +13,7 @@
|
||||
#include "config/options.h"
|
||||
#include "dialogs/status.h"
|
||||
#include "document/document.h"
|
||||
#include "document/libdom/mapa.h"
|
||||
#include "document/renderer.h"
|
||||
#include "document/view.h"
|
||||
#include "document/xml/renderer.h"
|
||||
@ -338,48 +339,19 @@ check_for_rerender(struct ecmascript_interpreter *interpreter, const char* text)
|
||||
|
||||
foreach(item, interpreter->writecode) {
|
||||
if (item->string.length) {
|
||||
// TODO
|
||||
#if 0
|
||||
std::map<int, xmlpp::Element *> *mapa = (std::map<int, xmlpp::Element *> *)document->element_map;
|
||||
void *mapa = (void *)document->element_map;
|
||||
|
||||
if (mapa) {
|
||||
auto element = (*mapa).find(item->element_offset);
|
||||
void *el = find_in_map(mapa, item->element_offset);
|
||||
|
||||
if (element != (*mapa).end()) {
|
||||
xmlpp::Element *el = element->second;
|
||||
|
||||
const xmlpp::Element *parent = el->get_parent();
|
||||
|
||||
if (!parent) goto fromstart;
|
||||
|
||||
xmlpp::ustring text = "<root>";
|
||||
text += item->string.source;
|
||||
text += "</root>";
|
||||
|
||||
xmlDoc* doc = htmlReadDoc((xmlChar*)text.c_str(), NULL, "utf-8", HTML_PARSE_RECOVER | HTML_PARSE_NOERROR | HTML_PARSE_NOWARNING);
|
||||
// Encapsulate raw libxml document in a libxml++ wrapper
|
||||
xmlpp::Document doc1(doc);
|
||||
|
||||
auto root = doc1.get_root_node();
|
||||
auto root1 = root->find("//root")[0];
|
||||
auto children2 = root1->get_children();
|
||||
auto it2 = children2.begin();
|
||||
auto end2 = children2.end();
|
||||
for (; it2 != end2; ++it2) {
|
||||
auto n = xmlAddPrevSibling(el->cobj(), (*it2)->cobj());
|
||||
xmlpp::Node::create_wrapper(n);
|
||||
}
|
||||
xmlpp::Node::remove_node(el);
|
||||
if (el) {
|
||||
el_insert_before(document, el, &item->string);
|
||||
} else {
|
||||
fromstart:
|
||||
#endif
|
||||
add_fragment(cached, 0, item->string.source, item->string.length);
|
||||
document->ecmascript_counter++;
|
||||
break;
|
||||
#if 0
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -200,6 +200,7 @@ void *document_parse_text(char *text, size_t length);
|
||||
void free_document(void *doc);
|
||||
void location_goto(struct document_view *doc_view, char *url);
|
||||
void location_goto_const(struct document_view *doc_view, const char *url);
|
||||
void el_insert_before(struct document *document, void *element, struct string *source);
|
||||
|
||||
extern char *console_error_filename;
|
||||
extern char *console_log_filename;
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
#include "cache/cache.h"
|
||||
#include "document/document.h"
|
||||
#include "util/string.h"
|
||||
|
||||
void *
|
||||
document_parse_text(char *data, size_t length)
|
||||
@ -62,7 +63,6 @@ document_parse_text(char *data, size_t length)
|
||||
return doc;
|
||||
}
|
||||
|
||||
|
||||
void *
|
||||
document_parse(struct document *document)
|
||||
{
|
||||
@ -78,3 +78,41 @@ document_parse(struct document *document)
|
||||
|
||||
return document_parse_text(f->data, f->length);
|
||||
}
|
||||
|
||||
void
|
||||
el_insert_before(struct document *document, void *element, struct string *source)
|
||||
{
|
||||
dom_document *doc = (dom_document *)document->dom;
|
||||
dom_node *node = (dom_node *)element;
|
||||
dom_string *text = NULL;
|
||||
dom_exception exc = dom_string_create(source->source, source->length, &text);
|
||||
|
||||
if (exc != DOM_NO_ERR || !text) {
|
||||
return;
|
||||
}
|
||||
dom_text *frag = NULL;
|
||||
exc = dom_document_create_text_node(doc, text, &frag);
|
||||
|
||||
if (exc != DOM_NO_ERR || !frag) {
|
||||
goto ret2;
|
||||
}
|
||||
dom_node *parent = NULL;
|
||||
exc = dom_node_get_parent_node(node, &parent);
|
||||
|
||||
if (exc != DOM_NO_ERR || !parent) {
|
||||
goto ret3;
|
||||
}
|
||||
dom_node *result = NULL;
|
||||
exc = dom_node_replace_child(parent, frag, node, &result);
|
||||
|
||||
if (exc != DOM_NO_ERR || !result) {
|
||||
goto ret4;
|
||||
}
|
||||
dom_node_unref(result);
|
||||
ret4:
|
||||
dom_node_unref(parent);
|
||||
ret3:
|
||||
dom_node_unref(frag);
|
||||
ret2:
|
||||
dom_string_unref(text);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user