php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
before_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
8
9
10static bool
11lxb_html_tree_insertion_mode_before_head_open(lxb_html_tree_t *tree,
12 lxb_html_token_t *token);
13
14static bool
15lxb_html_tree_insertion_mode_before_head_closed(lxb_html_tree_t *tree,
16 lxb_html_token_t *token);
17
18lxb_inline bool
20
23 lxb_html_token_t *token);
24
25
26bool
28 lxb_html_token_t *token)
29{
30 if (token->type & LXB_HTML_TOKEN_TYPE_CLOSE) {
31 return lxb_html_tree_insertion_mode_before_head_closed(tree, token);
32 }
33
34 return lxb_html_tree_insertion_mode_before_head_open(tree, token);
35}
36
37static bool
38lxb_html_tree_insertion_mode_before_head_open(lxb_html_tree_t *tree,
39 lxb_html_token_t *token)
40{
41 switch (token->tag_id) {
43 lxb_dom_comment_t *comment;
44
45 comment = lxb_html_tree_insert_comment(tree, token, NULL);
46 if (comment == NULL) {
48
49 return lxb_html_tree_process_abort(tree);
50 }
51
52 break;
53 }
54
56 lxb_html_tree_parse_error(tree, token,
58 break;
59
60 case LXB_TAG_HTML:
61 return lxb_html_tree_insertion_mode_in_body(tree, token);
62
63 case LXB_TAG_HEAD:
65 token);
66 if (tree->status != LXB_STATUS_OK) {
67 return lxb_html_tree_process_abort(tree);
68 }
69
70 tree->has_explicit_head_tag = true;
71
73
74 break;
75
76 case LXB_TAG__TEXT:
78 if (tree->status != LXB_STATUS_OK) {
79 return lxb_html_tree_process_abort(tree);
80 }
81
82 if (token->text_start == token->text_end) {
83 return true;
84 }
85 /* fall through */
86
87 default:
89 }
90
91 return true;
92}
93
94static bool
95lxb_html_tree_insertion_mode_before_head_closed(lxb_html_tree_t *tree,
96 lxb_html_token_t *token)
97{
98 switch (token->tag_id) {
99 case LXB_TAG_HEAD:
100 case LXB_TAG_BODY:
101 case LXB_TAG_HTML:
102 case LXB_TAG_BR:
104
105 default:
106 lxb_html_tree_parse_error(tree, token,
108 break;
109 }
110
111 return true;
112}
113
114lxb_inline bool
116{
117 lxb_html_token_t fake_token = {0};
118
119 fake_token.tag_id = LXB_TAG_HEAD;
120
122 &fake_token);
123 if (tree->status != LXB_STATUS_OK) {
124 return lxb_html_tree_process_abort(tree);
125 }
126
128
129 return false;
130}
131
134 lxb_html_token_t *token)
135{
136 lxb_html_element_t *element;
137
138 element = lxb_html_tree_insert_html_element(tree, token);
139 if (element == NULL) {
141 }
142
143 tree->document->head = lxb_html_interface_head(element);
144
145 return LXB_STATUS_OK;
146}
lxb_inline bool lxb_html_tree_insertion_mode_before_head_anything_else(lxb_html_tree_t *tree)
bool lxb_html_tree_insertion_mode_before_head(lxb_html_tree_t *tree, lxb_html_token_t *token)
Definition before_head.c:27
lxb_inline lxb_status_t lxb_html_tree_insertion_mode_before_head_head(lxb_html_tree_t *tree, lxb_html_token_t *token)
@ LXB_STATUS_ERROR_MEMORY_ALLOCATION
Definition base.h:51
@ LXB_STATUS_OK
Definition base.h:49
struct lxb_dom_comment lxb_dom_comment_t
Definition interface.h:49
#define NULL
Definition gdcache.h:45
struct lxb_html_tree lxb_html_tree_t
Definition base.h:28
#define lxb_html_interface_head(obj)
Definition interface.h:44
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_DOTOINBEHEMO
Definition error.h:38
@ LXB_HTML_RULES_ERROR_UNCLTOINBEHEMO
Definition error.h:40
LXB_API bool lxb_html_tree_insertion_mode_in_head(lxb_html_tree_t *tree, lxb_html_token_t *token)
Definition in_head.c:41
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
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
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_html_head_element_t * head
Definition document.h:62
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_head_tag
Definition tree.h:59
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_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
unsigned int lxb_status_t
Definition types.h:28
#define lxb_inline
Definition types.h:21