1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00

[js] textContent

This commit is contained in:
Witold Filipczyk 2021-05-09 20:50:36 +02:00
parent 501a649068
commit d891cc503a

View File

@ -92,7 +92,7 @@ JSPropertySpec element_props[] = {
JS_PSGS("lang", element_get_property_lang, element_set_property_lang, JSPROP_ENUMERATE), JS_PSGS("lang", element_get_property_lang, element_set_property_lang, JSPROP_ENUMERATE),
// JS_PSGS("outerHTML", element_get_property_outerHtml, element_set_property_outerHtml, JSPROP_ENUMERATE), // JS_PSGS("outerHTML", element_get_property_outerHtml, element_set_property_outerHtml, JSPROP_ENUMERATE),
JS_PSG("tagName", element_get_property_tagName, JSPROP_ENUMERATE), JS_PSG("tagName", element_get_property_tagName, JSPROP_ENUMERATE),
// JS_PSGS("textContent", element_get_property_textContent, element_set_property_textContent, JSPROP_ENUMERATE), JS_PSGS("textContent", element_get_property_textContent, element_set_property_textContent, JSPROP_ENUMERATE),
JS_PSGS("title", element_get_property_title, element_set_property_title, JSPROP_ENUMERATE), JS_PSGS("title", element_get_property_title, element_set_property_title, JSPROP_ENUMERATE),
JS_PS_END JS_PS_END
}; };
@ -407,33 +407,23 @@ walk_tree(struct string *buf, tree<HTML::Node> const &dom, const unsigned int of
} }
static void static void
walk_tree_content(struct string *buf, tree<HTML::Node> const &dom, const unsigned int offset) walk_tree_content(struct string *buf, xmlpp::Node *node)
{ {
int local = 0; const auto nodeText = dynamic_cast<const xmlpp::TextNode*>(node);
tree<HTML::Node>::iterator it = dom.begin();
if (was_el && !it->isTag()) add_to_string(buf, it->text().c_str());
if (!was_el && it->isTag()) { if (nodeText) {
if (it->offset() == offset) { add_to_string(buf, nodeText->get_content().c_str());
was_el = 1;
local = 1;
}
} }
for (tree<HTML::Node>::sibling_iterator childIt = dom.begin(it); childIt != dom.end(it); ++childIt) auto childs = node->get_children();
{ auto it = childs.begin();
walk_tree_content(buf, childIt, offset); auto end = childs.end();
}
if (was_el) { for (; it != end; ++it) {
if (!local) { walk_tree_content(buf, *it);
//add_to_string(buf, it->closingText().c_str());
} else {
was_el = 0;
}
} }
} }
static void static void
walk_tree_outer(struct string *buf, tree<HTML::Node> const &dom, const unsigned int offset) walk_tree_outer(struct string *buf, tree<HTML::Node> const &dom, const unsigned int offset)
{ {
@ -580,13 +570,12 @@ element_get_property_textContent(JSContext *ctx, unsigned int argc, JS::Value *v
* such calls. */ * such calls. */
if (!JS_InstanceOf(ctx, hobj, &element_class, NULL)) if (!JS_InstanceOf(ctx, hobj, &element_class, NULL))
return false; return false;
vs = interpreter->vs; vs = interpreter->vs;
if (!vs) { if (!vs) {
return false; return false;
} }
xmlpp::Element *el = JS_GetPrivate(hobj);
tree<HTML::Node> *el = JS_GetPrivate(hobj);
if (!el) { if (!el) {
args.rval().setNull(); args.rval().setNull();
@ -599,9 +588,8 @@ element_get_property_textContent(JSContext *ctx, unsigned int argc, JS::Value *v
struct string buf; struct string buf;
init_string(&buf); init_string(&buf);
was_el = 0;
walk_tree_content(&buf, *dom, el->begin()->offset()); walk_tree_content(&buf, el);
args.rval().setString(JS_NewStringCopyZ(ctx, buf.source)); args.rval().setString(JS_NewStringCopyZ(ctx, buf.source));
done_string(&buf); done_string(&buf);
@ -609,8 +597,6 @@ element_get_property_textContent(JSContext *ctx, unsigned int argc, JS::Value *v
return true; return true;
} }
static bool static bool
element_set_property_className(JSContext *ctx, unsigned int argc, JS::Value *vp) element_set_property_className(JSContext *ctx, unsigned int argc, JS::Value *vp)
{ {