1 /* SGML node handling */
2 /* $Id: html.c,v 1.3 2004/12/20 00:08:07 jonas Exp $ */
13 #include "document/dom/navigator.h"
14 #include "document/dom/node.h"
15 #include "document/sgml/html/html.h"
16 #include "document/sgml/parser.h"
17 #include "document/sgml/scanner.h"
18 #include "document/sgml/sgml.h"
19 #include "util/error.h"
20 #include "util/memory.h"
21 #include "util/string.h"
24 #define HTML_NODE_INFO(node, name, id) SGML_NODE_INFO(HTML, node, name, id)
25 #define HTML_NODE_INF2(node, name, str, id) SGML_NODE_INF2(HTML, node, name, str, id)
28 static struct sgml_node_info html_attributes
[HTML_ATTRIBUTES
] = {
29 SGML_NODE_HEAD(HTML
, ATTRIBUTE
),
31 #include "document/sgml/html/attribute.inc"
34 static struct sgml_node_info html_elements
[HTML_ELEMENTS
] = {
35 SGML_NODE_HEAD(HTML
, ELEMENT
),
37 #include "document/sgml/html/element.inc"
41 static struct dom_node
*
42 add_html_element_end_node(struct dom_navigator
*navigator
, struct dom_node
*node
, void *data
)
44 struct sgml_parser
*parser
= navigator
->data
;
45 struct dom_node
*parent
;
46 struct scanner_token
*token
;
48 assert(navigator
&& parser
&& node
);
49 assert(dom_navigator_has_parents(navigator
));
51 /* Are we the actual node being popped? */
52 if (node
!= get_dom_navigator_top(navigator
)->node
)
55 parent
= get_dom_navigator_parent(navigator
)->node
;
56 token
= get_scanner_token(&parser
->scanner
);
58 assertm(token
, "No token found in callback");
59 assertm(token
->type
== SGML_TOKEN_ELEMENT_END
, "Bad token found in callback");
61 if (!token
->length
) return NULL
;
63 return add_dom_element(parent
, token
->string
, token
->length
);
66 /* TODO: We need to handle ascending of <br> and "<p>text1<p>text2" using data
67 * from sgml_node_info. */
68 static struct dom_node
*
69 add_html_element_node(struct dom_navigator
*navigator
, struct dom_node
*node
, void *data
)
71 struct sgml_parser
*parser
= navigator
->data
;
73 assert(navigator
&& node
);
74 assert(dom_navigator_has_parents(navigator
));
76 /* TODO: Move to SGML parser main loop and disguise these element ends
77 * in some internal processing instruction. */
78 if (parser
->flags
& SGML_PARSER_ADD_ELEMENT_ENDS
)
79 get_dom_navigator_top(navigator
)->callback
= add_html_element_end_node
;
85 struct sgml_info sgml_html_info
= {
90 /* DOM_NODE_ELEMENT */ add_html_element_node
,
91 /* DOM_NODE_ATTRIBUTE */ NULL
,
92 /* DOM_NODE_TEXT */ NULL
,
93 /* DOM_NODE_CDATA_SECTION */ NULL
,
94 /* DOM_NODE_ENTITY_REFERENCE */ NULL
,
95 /* DOM_NODE_ENTITY */ NULL
,
96 /* DOM_NODE_PROC_INSTRUCTION */ NULL
,
97 /* DOM_NODE_COMMENT */ NULL
,
98 /* DOM_NODE_DOCUMENT */ NULL
,
99 /* DOM_NODE_DOCUMENT_TYPE */ NULL
,
100 /* DOM_NODE_DOCUMENT_FRAGMENT */ NULL
,
101 /* DOM_NODE_NOTATION */ NULL
,