commit c9dd4d28a0e39c87c8678f59638637d486366e1a
parent a5a4dcc8d5c607c66641225167f6bf73ce5dc275
Author: Robin <kroekerrobin@gmail.com>
Date: Sun, 13 Aug 2023 16:25:48 +0200
Print rootTag if no findPattern is provided
Diffstat:
| M | html.c | | | 35 | +++++++++++++++++++++++++++++++++-- |
1 file changed, 33 insertions(+), 2 deletions(-)
diff --git a/html.c b/html.c
@@ -780,15 +780,46 @@ void printResult
}
}
+void printEverything(struct tag *t, enum output_type out)
+{
+ switch (out)
+ {
+ case OUT_INNER_HTML:
+ break;
+ case OUT_OUTER_HTML:
+ break;
+ case OUT_INNER_TEXT:
+ break;
+ }
+}
+
+bool existFindPattern(struct filter_opts *opts)
+{
+ if (strlen(opts->tag) > 0)
+ return true;
+ if (strlen(opts->attr) > 0)
+ return true;
+ if (strlen(opts->key) > 0)
+ return true;
+ return false;
+}
+
void filterHtml(char *text, struct filter_opts *opts)
{
struct tag_list *tagList = initTagList();
struct tag_list *foundTags = initTagList();
size_t len = parseDoctype(text);
if (len)
- text = text + len;
+ text += len;
struct tag *rootTag = parseTag(text, 0, STATE_INNER_TEXT, tagList);
- findTag(rootTag, opts, foundTags);
+ if (!existFindPattern(opts))
+ {
+ foundTags->tags = realloc(foundTags->tags, sizeof(struct tag));
+ foundTags->tags[0] = rootTag;
+ foundTags->len = 1;
+ }
+ else
+ findTag(rootTag, opts, foundTags);
printResult(text, rootTag, opts, foundTags);
freeTag(rootTag);
freeTagList(tagList);