aboutsummaryrefslogtreecommitdiff
path: root/src/HtmlTree.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/HtmlTree.c')
-rw-r--r--src/HtmlTree.c41
1 files changed, 40 insertions, 1 deletions
diff --git a/src/HtmlTree.c b/src/HtmlTree.c
index faef08a..4c1628c 100644
--- a/src/HtmlTree.c
+++ b/src/HtmlTree.c
@@ -1,5 +1,6 @@
#include "../include/HtmlTree.h"
#include <stdlib.h>
+#include <string.h>
#include <assert.h>
static void html_node_deinit(HtmlNode *self);
@@ -123,7 +124,11 @@ static int parse_callback(HtmlParser *html_parser, HtmlParseType parse_type, voi
}
case HTML_PARSE_TEXT:
case HTML_PARSE_JAVASCRIPT_CODE: {
- HtmlNode *new_node = html_node_create(html_parser->text_stripped, parse_userdata->current_node, parse_type == HTML_PARSE_TEXT ? HTML_NODE_TEXT : HTML_NODE_JS);
+ HtmlNode *new_node;
+ if(html_parser->text_stripped.size == 0)
+ return 0;
+
+ new_node = html_node_create(html_parser->text_stripped, parse_userdata->current_node, parse_type == HTML_PARSE_TEXT ? HTML_NODE_TEXT : HTML_NODE_JS);
if(!new_node)
return 1;
@@ -162,3 +167,37 @@ HtmlAttribute* html_node_get_attribute_by_name(HtmlNode *self, HtmlStringView na
}
return NULL;
}
+
+HtmlNode* html_node_find_child(HtmlNode *self, const char *tag_name, const char *attribute_name, const char *attribute_value) {
+ HtmlStringView tag;
+ HtmlStringView attr_name;
+ HtmlStringView attr_value;
+ HtmlNodeChild *child;
+
+ tag.data = tag_name;
+ tag.size = strlen(tag_name);
+
+ attr_name.data = attribute_name;
+ attr_name.size = strlen(attribute_name);
+
+ attr_value.data = attribute_value;
+ attr_value.size = strlen(attribute_value);
+
+ for(child = self->first_child; child; child = child->next) {
+ HtmlAttribute *attr;
+ if(child->node.node_type != HTML_NODE_NODE)
+ continue;
+
+ if(!html_string_view_equals_case_insensitive(&child->node.name_or_value, &tag))
+ continue;
+
+ attr = html_node_get_attribute_by_name(&child->node, attr_name);
+ if(!attr)
+ continue;
+
+ if(html_string_view_equals_case_insensitive(&attr->value, &attr_value))
+ return &child->node;
+ }
+
+ return NULL;
+}