summaryrefslogtreecommitdiffstats
path: root/wv_dom.h
blob: b5bf57618335ad77778bdc842aae6439e2b1dacc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#ifndef WV_DOM_H
#define WV_DOM_H

#include "wv_mem.h"

typedef enum {
	WV_TAG_UNKNOWN = 0,
	WV_TAG_DOCUMENT,
	WV_TAG_HTML,
	WV_TAG_HEAD,
	WV_TAG_META,
	WV_TAG_TITLE,
	WV_TAG_LINK,
	WV_TAG_BODY,
	WV_TAG_HEADER,
	WV_TAG_DIV,
	WV_TAG_H1,
	WV_TAG_A,
	WV_TAG_ARTICLE,
	WV_TAG_UL,
	WV_TAG_LI,
	WV_TAG_TIME,
	WV_TAG_FOOTER,
	WV_TAG_P
} wv_tag_id;

typedef enum {
	WV_NODE_DOCUMENT,
	WV_NODE_ELEMENT,
	WV_NODE_TEXT
} wv_node_type;

struct wv_attr {
	wv_ref key;   /* E.g., "href" */
	wv_ref val;   /* E.g., "/log/vcs-1/" */
	wv_ref next;  /* Next attribute in the list */
};

struct wv_node {
	wv_node_type type;

	wv_ref parent;
	wv_ref first_child;
	wv_ref last_child;
	wv_ref prev_sibling;
	wv_ref next_sibling;

	union {
		struct {
			wv_tag_id tag_id;
			wv_ref attr_head;
		} element;

		struct {
			wv_ref str;
			size_t len;
		} text;
	} u;
};

/* DOM operations */
wv_ref wv_node_new(struct wv_arena *arena, wv_node_type type);
void wv_node_append(struct wv_arena *arena, wv_ref parent, 
	wv_ref child);

/* Attribute operations */
wv_ref wv_attr_get(struct wv_arena *arena, wv_ref node_ref, 
	const char *key_name);
void wv_attr_set(struct wv_arena *arena, wv_ref node_ref, 
	wv_ref key_str, wv_ref val_str);

#endif /* WV_DOM_H */