php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
in_head.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
14
15
16static bool
17lxb_html_tree_insertion_mode_in_head_open(lxb_html_tree_t *tree,
18 lxb_html_token_t *token);
19
20static bool
21lxb_html_tree_insertion_mode_in_head_closed(lxb_html_tree_t *tree,
22 lxb_html_token_t *token);
23
24lxb_inline bool
26 lxb_html_token_t *token);
27
28lxb_inline bool
30 lxb_html_token_t *token);
31
32lxb_inline bool
34 lxb_html_token_t *token);
35
36lxb_inline bool
38
39
40bool
42 lxb_html_token_t *token)
43{
44 if (token->type & LXB_HTML_TOKEN_TYPE_CLOSE) {
45 return lxb_html_tree_insertion_mode_in_head_closed(tree, token);;
46 }
47
48 return lxb_html_tree_insertion_mode_in_head_open(tree, token);
49}
50
51static bool
52lxb_html_tree_insertion_mode_in_head_open(lxb_html_tree_t *tree,
53 lxb_html_token_t *token)
54{
55 switch (token->tag_id) {
57 lxb_dom_comment_t *comment;
58
59 comment = lxb_html_tree_insert_comment(tree, token, NULL);
60 if (comment == NULL) {
62
63 return lxb_html_tree_process_abort(tree);
64 }
65
66 break;
67 }
68
70 lxb_html_tree_parse_error(tree, token,
72 break;
73
74 case LXB_TAG_HTML:
75 return lxb_html_tree_insertion_mode_in_body(tree, token);
76
77 case LXB_TAG_BASE:
79 case LXB_TAG_BGSOUND:
80 case LXB_TAG_LINK: {
81 lxb_html_element_t *element;
82
83 element = lxb_html_tree_insert_html_element(tree, token);
84 if (element == NULL) {
86
87 return lxb_html_tree_process_abort(tree);
88 }
89
92
93 break;
94 }
95
96 case LXB_TAG_META: {
97 lxb_html_element_t *element;
98
99 element = lxb_html_tree_insert_html_element(tree, token);
100 if (element == NULL) {
102
103 return lxb_html_tree_process_abort(tree);
104 }
105
108
109 /*
110 * TODO: Check encoding: charset attribute or http-equiv attribute.
111 */
112
113 break;
114 }
115
116 case LXB_TAG_TITLE: {
117 lxb_html_element_t *element;
118
119 element = lxb_html_tree_generic_rcdata_parsing(tree, token);
120 if (element == NULL) {
122
123 return lxb_html_tree_process_abort(tree);
124 }
125
126 break;
127 }
128
129 case LXB_TAG_NOSCRIPT: {
130 lxb_html_element_t *element;
131
132 if (tree->document->dom_document.scripting) {
133 element = lxb_html_tree_generic_rawtext_parsing(tree, token);
134 }
135 else {
136 element = lxb_html_tree_insert_html_element(tree, token);
138 }
139
140 if (element == NULL) {
142
143 return lxb_html_tree_process_abort(tree);
144 }
145
146 break;
147 }
148
149 case LXB_TAG_NOFRAMES:
150 case LXB_TAG_STYLE: {
151 lxb_html_element_t *element;
152
153 element = lxb_html_tree_generic_rawtext_parsing(tree, token);
154 if (element == NULL) {
156
157 return lxb_html_tree_process_abort(tree);
158 }
159
160 break;
161 }
162
163 case LXB_TAG_SCRIPT:
165
166 case LXB_TAG_TEMPLATE:
168
169 case LXB_TAG_HEAD:
170 lxb_html_tree_parse_error(tree, token,
172 break;
173
174 /*
175 * We can create function for this, but...
176 *
177 * The "in head noscript" insertion mode use this
178 * is you change this code, please, change it in head noscript" mode
179 */
180 case LXB_TAG__TEXT: {
181 lxb_html_token_t ws_token = {0};
182
183 tree->status = lxb_html_token_data_split_ws_begin(token, &ws_token);
184 if (tree->status != LXB_STATUS_OK) {
185 return lxb_html_tree_process_abort(tree);
186 }
187
188 if (ws_token.text_start != ws_token.text_end) {
189 tree->status = lxb_html_tree_insert_character(tree, &ws_token,
190 NULL);
191 if (tree->status != LXB_STATUS_OK) {
192 return lxb_html_tree_process_abort(tree);
193 }
194 }
195
196 if (token->text_start == token->text_end) {
197 return true;
198 }
199 }
200 /* fall through */
201
202 default:
204 }
205
206 return true;
207}
208
209static bool
210lxb_html_tree_insertion_mode_in_head_closed(lxb_html_tree_t *tree,
211 lxb_html_token_t *token)
212{
213 switch (token->tag_id) {
214 case LXB_TAG_HEAD:
216
218
219 break;
220
221 case LXB_TAG_BODY:
222 case LXB_TAG_HTML:
223 case LXB_TAG_BR:
225
226 case LXB_TAG_TEMPLATE:
228 token);
229
230 default:
231 lxb_html_tree_parse_error(tree, token,
233 break;
234
235 }
236
237 return true;
238}
239
240lxb_inline bool
242 lxb_html_token_t *token)
243{
244 lxb_dom_node_t *ap_node;
245 lxb_html_element_t *element;
247
249 if (ap_node == NULL) {
250 tree->status = LXB_STATUS_ERROR;
251
252 return lxb_html_tree_process_abort(tree);
253 }
254
256 if (element == NULL) {
258
259 return lxb_html_tree_process_abort(tree);
260 }
261
262 /* TODO: Need code for set flags for Script Element */
263
265 lxb_dom_interface_node(element));
266 if (tree->status != LXB_HTML_STATUS_OK) {
268
269 return lxb_html_tree_process_abort(tree);
270 }
271
272 lxb_html_tree_insert_node(ap_node, lxb_dom_interface_node(element), ipos);
273
274 /*
275 * Need for tokenizer state Script
276 * See description for
277 * 'lxb_html_tokenizer_state_script_data_before' function
278 */
282
283 tree->original_mode = tree->mode;
285
286 return true;
287}
288
289lxb_inline bool
322
323lxb_inline bool
356
357lxb_inline bool
void lxb_html_tree_active_formatting_up_to_last_marker(lxb_html_tree_t *tree)
lxb_inline lxb_status_t lxb_html_tree_active_formatting_push_marker(lxb_html_tree_t *tree)
@ LXB_STATUS_ERROR_MEMORY_ALLOCATION
Definition base.h:51
@ LXB_STATUS_OK
Definition base.h:49
@ LXB_STATUS_ERROR
Definition base.h:50
#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
@ LXB_HTML_STATUS_OK
Definition base.h:34
#define lxb_html_interface_script(obj)
Definition interface.h:72
struct lxb_html_element lxb_html_element_t
Definition interface.h:111
#define lxb_html_interface_template(obj)
Definition interface.h:84
lxb_status_t lxb_html_token_data_split_ws_begin(lxb_html_token_t *token, lxb_html_token_t *ws_token)
Definition token.c:232
@ LXB_HTML_TOKEN_TYPE_CLOSE
Definition token.h:27
lxb_inline void lxb_html_tokenizer_state_set(lxb_html_tokenizer_t *tkz, lxb_html_tokenizer_state_f state)
Definition tokenizer.h:222
lxb_inline void lxb_html_tokenizer_tmp_tag_id_set(lxb_html_tokenizer_t *tkz, lxb_tag_id_t tag_id)
Definition tokenizer.h:229
@ LXB_HTML_RULES_ERROR_TECLTOWIOPINHEMO
Definition error.h:50
@ LXB_HTML_RULES_ERROR_TEELISNOCUINHEMO
Definition error.h:52
@ LXB_HTML_RULES_ERROR_DOTOINHEMO
Definition error.h:42
@ LXB_HTML_RULES_ERROR_HETOINHEMO
Definition error.h:46
@ LXB_HTML_RULES_ERROR_UNCLTOINHEMO
Definition error.h:48
lxb_inline bool lxb_html_tree_insertion_mode_in_head_template_closed(lxb_html_tree_t *tree, lxb_html_token_t *token)
Definition in_head.c:324
lxb_inline bool lxb_html_tree_insertion_mode_in_head_anything_else(lxb_html_tree_t *tree)
Definition in_head.c:358
bool lxb_html_tree_insertion_mode_in_head(lxb_html_tree_t *tree, lxb_html_token_t *token)
Definition in_head.c:41
lxb_inline bool lxb_html_tree_insertion_mode_in_head_template(lxb_html_tree_t *tree, lxb_html_token_t *token)
Definition in_head.c:290
lxb_inline bool lxb_html_tree_insertion_mode_in_head_script(lxb_html_tree_t *tree, lxb_html_token_t *token)
Definition in_head.c:241
LXB_API bool lxb_html_tree_insertion_mode_after_head(lxb_html_tree_t *tree, lxb_html_token_t *token)
Definition after_head.c:27
LXB_API bool lxb_html_tree_insertion_mode_text(lxb_html_tree_t *tree, lxb_html_token_t *token)
Definition text.c:14
LXB_API bool lxb_html_tree_insertion_mode_in_head_noscript(lxb_html_tree_t *tree, lxb_html_token_t *token)
LXB_API bool lxb_html_tree_insertion_mode_in_template(lxb_html_tree_t *tree, lxb_html_token_t *token)
LXB_API bool lxb_html_tree_insertion_mode_in_body(lxb_html_tree_t *tree, lxb_html_token_t *token)
Definition in_body.c:1685
bool lxb_html_tree_process_abort(lxb_html_tree_t *tree)
Definition tree.c:224
void lxb_html_tree_generate_all_implied_end_tags_thoroughly(lxb_html_tree_t *tree, lxb_tag_id_t ex_tag, lxb_ns_id_t ex_ns)
Definition tree.c:952
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_generic_rawtext_parsing(lxb_html_tree_t *tree, lxb_html_token_t *token)
Definition tree.c:863
lxb_dom_node_t * lxb_html_tree_appropriate_place_inserting_node(lxb_html_tree_t *tree, lxb_dom_node_t *override_target, lxb_html_tree_insertion_position_t *ipos)
Definition tree.c:304
lxb_status_t lxb_html_tree_insert_character(lxb_html_tree_t *tree, lxb_html_token_t *token, lxb_dom_node_t **ret_node)
Definition tree.c:669
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
lxb_html_element_t * lxb_html_tree_generic_rcdata_parsing(lxb_html_tree_t *tree, lxb_html_token_t *token)
Definition tree.c:889
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
void lxb_html_tree_reset_insertion_mode_appropriately(lxb_html_tree_t *tree)
Definition tree.c:999
@ LXB_NS__UNDEF
Definition const.h:24
@ LXB_NS_HTML
Definition const.h:26
lxb_dom_node_t * lxb_html_tree_open_elements_find_reverse(lxb_html_tree_t *tree, lxb_tag_id_t tag_id, lxb_ns_id_t ns, size_t *return_index)
void lxb_html_tree_open_elements_pop_until_tag_id(lxb_html_tree_t *tree, lxb_tag_id_t tag_id, lxb_ns_id_t ns, bool exclude)
lxb_inline lxb_status_t lxb_html_tree_open_elements_push(lxb_html_tree_t *tree, lxb_dom_node_t *node)
lxb_inline lxb_dom_node_t * lxb_html_tree_open_elements_pop(lxb_html_tree_t *tree)
lxb_html_script_element_t * lxb_html_script_element_interface_destroy(lxb_html_script_element_t *script_element)
const lxb_char_t * lxb_html_tokenizer_state_script_data_before(lxb_html_tokenizer_t *tkz, const lxb_char_t *data, const lxb_char_t *end)
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 frameset_ok
Definition tree.h:56
lxb_html_tree_insertion_mode_f original_mode
Definition tree.h:63
lxb_html_tokenizer_t * tkz_ref
Definition tree.h:40
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_TEMPLATE
Definition const.h:203
@ LXB_TAG_TITLE
Definition const.h:210
@ LXB_TAG_NOSCRIPT
Definition const.h:163
@ LXB_TAG_HEAD
Definition const.h:121
@ LXB_TAG_HTML
Definition const.h:125
@ LXB_TAG_BGSOUND
Definition const.h:51
@ LXB_TAG__EM_COMMENT
Definition const.h:28
@ LXB_TAG_BODY
Definition const.h:55
@ LXB_TAG_BASEFONT
Definition const.h:48
@ LXB_TAG_META
Definition const.h:148
@ LXB_TAG_BASE
Definition const.h:47
@ LXB_TAG_SCRIPT
Definition const.h:185
@ LXB_TAG_LINK
Definition const.h:139
@ LXB_TAG_BR
Definition const.h:56
@ LXB_TAG_STYLE
Definition const.h:195
@ LXB_TAG_NOFRAMES
Definition const.h:162
@ LXB_TAG__TEXT
Definition const.h:26
@ LXB_TAG__UNDEF
Definition const.h:24
lxb_html_template_element_t * lxb_html_template_element_interface_destroy(lxb_html_template_element_t *template_element)
lxb_inline lxb_status_t lxb_html_tree_template_insertion_push(lxb_html_tree_t *tree, lxb_html_tree_insertion_mode_f mode)
lxb_inline lxb_html_tree_insertion_mode_f lxb_html_tree_template_insertion_pop(lxb_html_tree_t *tree)
lxb_html_tree_insertion_position_t
Definition tree.h:71
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_current_node(lxb_html_tree_t *tree)
Definition tree.h:286
lxb_inline void lxb_html_tree_acknowledge_token_self_closing(lxb_html_tree_t *tree, lxb_html_token_t *token)
Definition tree.h:327
lxb_inline bool lxb_html_tree_node_is(lxb_dom_node_t *node, lxb_tag_id_t tag_id)
Definition tree.h:280
lxb_inline lxb_html_element_t * lxb_html_tree_insert_html_element(lxb_html_tree_t *tree, lxb_html_token_t *token)
Definition tree.h:307
#define lxb_inline
Definition types.h:21