Esempio n. 1
0
// Creates an template node and returns it.
GumboNode* gumbo_create_template_node() {
  GumboNode* node = gumbo_create_node(GUMBO_NODE_TEMPLATE);
  GumboElement* element = &node->v.element;
  gumbo_vector_init(1, &element->children);
  gumbo_vector_init(0, &element->attributes);
  element->tag = GUMBO_TAG_TEMPLATE;
  element->tag_namespace = GUMBO_NAMESPACE_HTML;
  element->original_tag = kGumboEmptyString;
  element->original_end_tag = kGumboEmptyString;
  element->start_pos = kGumboEmptySourcePosition;
  element->end_pos = kGumboEmptySourcePosition;
  return node;
}
Esempio n. 2
0
// Creates an element node with the tag (enum) in the specified namespace and returns it.
// Since no original text exists, any created element tag must already exist in the tag_enum.h
// This is why we have expanded the set of recognized tags to include all svg and mathml tags 
GumboNode* gumbo_create_element_node(GumboTag tag, GumboNamespaceEnum gns) {
  GumboNode* node = gumbo_create_node(GUMBO_NODE_ELEMENT);
  GumboElement* element = &node->v.element;
  gumbo_vector_init(1, &element->children);
  gumbo_vector_init(0, &element->attributes);
  element->tag = tag;
  element->tag_namespace = gns;
  element->original_tag = kGumboEmptyString;
  element->original_end_tag = kGumboEmptyString;
  element->start_pos = kGumboEmptySourcePosition;
  element->end_pos = kGumboEmptySourcePosition;
  return node;
}
Esempio n. 3
0
// create and initialize a completely new tree output area
GumboOutput*  gumbo_new_output_init(void) {
  GumboOutput* output = gumbo_malloc(sizeof(GumboOutput));
  output->root = NULL;
  output->document = gumbo_new_document_node();
  gumbo_vector_init(0, &output->errors);
  return output;
}
Esempio n. 4
0
// used internally by gumbo_new_output init 
static GumboNode* gumbo_new_document_node(void) {
  GumboNode* document_node = gumbo_create_node(GUMBO_NODE_DOCUMENT);
  gumbo_vector_init(1, &document_node->v.document.children);
  GumboDocument* document = &document_node->v.document;
  document->has_doctype = false;
  document->name = NULL;
  document->public_identifier = NULL;
  document->system_identifier = NULL;
  return document_node;
}
Esempio n. 5
0
// Clones attributes, tags, etc. of a node, but does not copy the content (its children).  
// The clone shares no structure with the original node: all owned strings and
// values are fresh copies.
GumboNode* clone_element_node(const GumboNode* node) {
  assert(node->type == GUMBO_NODE_ELEMENT || node->type == GUMBO_NODE_TEMPLATE);
  GumboNode* new_node = gumbo_malloc(sizeof(GumboNode));
  *new_node = *node;
  new_node->parent = NULL;
  new_node->index_within_parent = -1;
  GumboElement* element = &new_node->v.element;
  gumbo_vector_init(1, &element->children);
  const GumboVector* old_attributes = &node->v.element.attributes;
  gumbo_vector_init(old_attributes->length, &element->attributes);
  for (int i = 0; i < old_attributes->length; ++i) {
    const GumboAttribute* old_attr = old_attributes->data[i];
    GumboAttribute* attr = gumbo_malloc(sizeof(GumboAttribute));
    *attr = *old_attr;
    attr->name = gumbo_strdup(old_attr->name);
    attr->value = gumbo_strdup(old_attr->value);
    gumbo_vector_add(attr, &element->attributes);
  }
  return new_node;
}
Esempio n. 6
0
void gumbo_init_errors(GumboParser* parser) {
  gumbo_vector_init(parser, 5, &parser->_output->errors);
}