Skip to content
This repository was archived by the owner on Feb 15, 2023. It is now read-only.

Commit b6dcb36

Browse files
committed
parser: Export create_node
The `create_mode` helper is very useful when building tooling on top of Gumbo, so don't keep it static.
1 parent 62fd3e2 commit b6dcb36

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/gumbo.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,6 +638,9 @@ GumboOutput* gumbo_parse_fragment(
638638
/** Release the memory used for the parse tree & parse errors. */
639639
void gumbo_destroy_output(GumboOutput* output);
640640

641+
/** Create a new node object, unatached to any documents */
642+
GumboNode* gumbo_create_node(GumboNodeType type);
643+
641644
/** Release the memory used by a single node */
642645
void gumbo_destroy_node(GumboNode* node);
643646

src/parser.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ static void set_frameset_not_ok(GumboParser* parser) {
449449
parser->_parser_state->_frameset_ok = false;
450450
}
451451

452-
static GumboNode* create_node(GumboNodeType type) {
452+
GumboNode* gumbo_create_node(GumboNodeType type) {
453453
GumboNode* node = gumbo_malloc(sizeof(GumboNode));
454454
node->parent = NULL;
455455
node->index_within_parent = -1;
@@ -459,7 +459,7 @@ static GumboNode* create_node(GumboNodeType type) {
459459
}
460460

461461
static GumboNode* new_document_node(void) {
462-
GumboNode* document_node = create_node(GUMBO_NODE_DOCUMENT);
462+
GumboNode* document_node = gumbo_create_node(GUMBO_NODE_DOCUMENT);
463463
document_node->parse_flags = GUMBO_INSERTION_BY_PARSER;
464464
gumbo_vector_init(1, &document_node->v.document.children);
465465

@@ -881,7 +881,7 @@ static void maybe_flush_text_node_buffer(GumboParser* parser) {
881881
assert(buffer_state->_type == GUMBO_NODE_WHITESPACE ||
882882
buffer_state->_type == GUMBO_NODE_TEXT ||
883883
buffer_state->_type == GUMBO_NODE_CDATA);
884-
GumboNode* text_node = create_node(buffer_state->_type);
884+
GumboNode* text_node = gumbo_create_node(buffer_state->_type);
885885
GumboText* text_node_data = &text_node->v.text;
886886
text_node_data->text = gumbo_string_buffer_to_string(&buffer_state->_buffer);
887887
text_node_data->original_text.data = buffer_state->_start_original_text;
@@ -948,7 +948,7 @@ static GumboNode* pop_current_node(GumboParser* parser) {
948948
static void append_comment_node(
949949
GumboParser* parser, GumboNode* node, const GumboToken* token) {
950950
maybe_flush_text_node_buffer(parser);
951-
GumboNode* comment = create_node(GUMBO_NODE_COMMENT);
951+
GumboNode* comment = gumbo_create_node(GUMBO_NODE_COMMENT);
952952
comment->type = GUMBO_NODE_COMMENT;
953953
comment->parse_flags = GUMBO_INSERTION_NORMAL;
954954
comment->v.text.text = token->v.text;
@@ -981,7 +981,7 @@ void clear_stack_to_table_body_context(GumboParser* parser) {
981981

982982
// Creates a parser-inserted element in the HTML namespace and returns it.
983983
static GumboNode* create_element(GumboParser* parser, GumboTag tag) {
984-
GumboNode* node = create_node(GUMBO_NODE_ELEMENT);
984+
GumboNode* node = gumbo_create_node(GUMBO_NODE_ELEMENT);
985985
GumboElement* element = &node->v.element;
986986
gumbo_vector_init(1, &element->children);
987987
gumbo_vector_init(0, &element->attributes);
@@ -1006,7 +1006,7 @@ static GumboNode* create_element_from_token(
10061006
start_tag->tag == GUMBO_TAG_TEMPLATE)
10071007
? GUMBO_NODE_TEMPLATE : GUMBO_NODE_ELEMENT;
10081008

1009-
GumboNode* node = create_node(type);
1009+
GumboNode* node = gumbo_create_node(type);
10101010
GumboElement* element = &node->v.element;
10111011
gumbo_vector_init(1, &element->children);
10121012
element->attributes = start_tag->attributes;

0 commit comments

Comments
 (0)