php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
before_html.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2018-2020 Alexander Borisov
3 *
4 * Author: Alexander Borisov <borisov@lexbor.com>
5 */
6
10
11
12static bool
13lxb_html_tree_insertion_mode_before_html_open(lxb_html_tree_t *tree,
14 lxb_html_token_t *token);
15
16static bool
17lxb_html_tree_insertion_mode_before_html_closed(lxb_html_tree_t *tree,
18 lxb_html_token_t *token);
19
20lxb_inline bool
22
25 lxb_dom_node_t *node_html);
26
27
28bool
30 lxb_html_token_t *token)
31{
32 if (token->type & LXB_HTML_TOKEN_TYPE_CLOSE) {
33 return lxb_html_tree_insertion_mode_before_html_closed(tree, token);;
34 }
35
36 return lxb_html_tree_insertion_mode_before_html_open(tree, token);
37}
38
39static bool
40lxb_html_tree_insertion_mode_before_html_open(lxb_html_tree_t *tree,
41 lxb_html_token_t *token)
42{
43 switch (token->tag_id) {
45 lxb_html_tree_parse_error(tree, token,
47 break;
48
50 lxb_dom_comment_t *comment;
51
52 comment = lxb_html_tree_insert_comment(tree, token,
54 if (comment == NULL) {
55 return lxb_html_tree_process_abort(tree);
56 }
57
58 break;
59 }
60
61 case LXB_TAG_HTML: {
62 lxb_dom_node_t *node_html;
63 lxb_html_element_t *element;
64
65 element = lxb_html_tree_create_element_for_token(tree, token,
67 if (element == NULL) {
69
70 return lxb_html_tree_process_abort(tree);
71 }
72
73 node_html = lxb_dom_interface_node(element);
74
76 node_html);
77 if (tree->status != LXB_STATUS_OK) {
78 return lxb_html_tree_process_abort(tree);
79 }
80
81 tree->has_explicit_html_tag = true;
82
84
85 break;
86 }
87
88 case LXB_TAG__TEXT:
90 if (tree->status != LXB_STATUS_OK) {
91 return lxb_html_tree_process_abort(tree);
92 }
93
94 if (token->text_start == token->text_end) {
95 return true;
96 }
97 /* fall through */
98
99 default:
101 }
102
103 return true;
104}
105
106static bool
107lxb_html_tree_insertion_mode_before_html_closed(lxb_html_tree_t *tree,
108 lxb_html_token_t *token)
109{
110 switch (token->tag_id) {
111 case LXB_TAG_HEAD:
112 case LXB_TAG_BODY:
113 case LXB_TAG_HTML:
114 case LXB_TAG_BR:
116
117 default:
118 lxb_html_tree_parse_error(tree, token,
120 break;
121 }
122
123 return true;
124}
125
126lxb_inline bool
128{
129 lxb_dom_node_t *node_html;
130
132 if (node_html == NULL) {
134 return lxb_html_tree_process_abort(tree);
135 }
136
138 node_html);
139 if (tree->status != LXB_STATUS_OK) {
140 return lxb_html_tree_process_abort(tree);
141 }
142
144
145 return false;
146}
147
bool lxb_html_tree_insertion_mode_before_html(lxb_html_tree_t *tree, lxb_html_token_t *token)
Definition before_html.c:29
lxb_inline lxb_status_t lxb_html_tree_insertion_mode_before_html_html(lxb_html_tree_t *tree, lxb_dom_node_t *node_html)
lxb_inline bool lxb_html_tree_insertion_mode_before_html_anything_else(lxb_html_tree_t *tree)
@ LXB_STATUS_ERROR_MEMORY_ALLOCATION
Definition base.h:51
@ LXB_STATUS_OK
Definition base.h:49
DNS_STATUS status
Definition dns_win32.c:49
#define lxb_dom_interface_element(obj)
Definition interface.h:28
#define lxb_dom_interface_node(obj)
Definition interface.h:31
struct lxb_dom_comment lxb_dom_comment_t
Definition interface.h:49
struct lxb_dom_node lxb_dom_node_t
Definition interface.h:38
#define NULL
Definition gdcache.h:45
struct lxb_html_tree lxb_html_tree_t
Definition base.h:28
struct lxb_html_element lxb_html_element_t
Definition interface.h:111
lxb_status_t lxb_html_token_data_skip_ws_begin(lxb_html_token_t *token)
Definition token.c:179
@ LXB_HTML_TOKEN_TYPE_CLOSE
Definition token.h:27
@ LXB_HTML_RULES_ERROR_DOTOINBEHTMO
Definition error.h:34
@ LXB_HTML_RULES_ERROR_UNCLTOINBEHTMO
Definition error.h:36
LXB_API bool lxb_html_tree_insertion_mode_before_head(lxb_html_tree_t *tree, lxb_html_token_t *token)
Definition before_head.c:27
void lxb_dom_document_attach_element(lxb_dom_document_t *document, lxb_dom_element_t *element)
Definition document.c:231
bool lxb_html_tree_process_abort(lxb_html_tree_t *tree)
Definition tree.c:224
lxb_dom_comment_t * lxb_html_tree_insert_comment(lxb_html_tree_t *tree, lxb_html_token_t *token, lxb_dom_node_t *pos)
Definition tree.c:790
lxb_html_element_t * lxb_html_tree_create_element_for_token(lxb_html_tree_t *tree, lxb_html_token_t *token, lxb_ns_id_t ns)
Definition tree.c:422
void lxb_html_tree_parse_error(lxb_html_tree_t *tree, lxb_html_token_t *token, lxb_html_tree_error_id_t id)
Definition tree.c:237
@ LXB_NS_HTML
Definition const.h:26
lxb_inline lxb_status_t lxb_html_tree_open_elements_push(lxb_html_tree_t *tree, lxb_dom_node_t *node)
lxb_dom_document_t dom_document
Definition document.h:58
lxb_html_token_type_t type
Definition token.h:49
const lxb_char_t * text_end
Definition token.h:40
lxb_tag_id_t tag_id
Definition token.h:48
const lxb_char_t * text_start
Definition token.h:39
bool has_explicit_html_tag
Definition tree.h:58
lxb_status_t status
Definition tree.h:66
lxb_html_tree_insertion_mode_f mode
Definition tree.h:62
lxb_html_document_t * document
Definition tree.h:42
@ LXB_TAG__EM_DOCTYPE
Definition const.h:29
@ LXB_TAG_HEAD
Definition const.h:121
@ LXB_TAG_HTML
Definition const.h:125
@ LXB_TAG__EM_COMMENT
Definition const.h:28
@ LXB_TAG_BODY
Definition const.h:55
@ LXB_TAG_BR
Definition const.h:56
@ LXB_TAG__TEXT
Definition const.h:26
@ LXB_HTML_TREE_INSERTION_POSITION_CHILD
Definition tree.h:72
lxb_inline void lxb_html_tree_insert_node(lxb_dom_node_t *to, lxb_dom_node_t *node, lxb_html_tree_insertion_position_t ipos)
Definition tree.h:314
lxb_inline lxb_dom_node_t * lxb_html_tree_create_node(lxb_html_tree_t *tree, lxb_tag_id_t tag_id, lxb_ns_id_t ns)
Definition tree.h:272
unsigned int lxb_status_t
Definition types.h:28
#define lxb_inline
Definition types.h:21