HTML5-DOM

 view release on metacpan or  search on metacpan

third_party/modest/source/myhtml/myhtml.c  view on Meta::CPAN

void myhtml_node_namespace_set(myhtml_tree_node_t *node, myhtml_namespace_t ns)
{
    node->ns = ns;
}

myhtml_tag_id_t myhtml_node_tag_id(myhtml_tree_node_t *node)
{
    return node->tag_id;
}

const char * myhtml_tag_name_by_id(myhtml_tree_t* tree, myhtml_tag_id_t tag_id, size_t *length)
{
    if(length)
        *length = 0;
    
    if(tree == NULL || tree->tags == NULL)
        return NULL;
    
    const myhtml_tag_context_t *tag_ctx = myhtml_tag_get_by_id(tree->tags, tag_id);
    
    if(tag_ctx == NULL)
        return NULL;
    
    if(length)
        *length = tag_ctx->name_length;
    
    return tag_ctx->name;
}

myhtml_tag_id_t myhtml_tag_id_by_name(myhtml_tree_t* tree, const char *tag_name, size_t length)
{
    if(tree == NULL || tree->tags == NULL)
        return MyHTML_TAG__UNDEF;
    
    const myhtml_tag_context_t *ctx = myhtml_tag_get_by_name(tree->tags, tag_name, length);
    
    if(ctx == NULL)
        return MyHTML_TAG__UNDEF;
    
    return ctx->id;
}

bool myhtml_node_is_close_self(myhtml_tree_node_t *node)
{
    if(node->token)
        return (node->token->type & MyHTML_TOKEN_TYPE_CLOSE_SELF);
    
    return false;
}

bool myhtml_node_is_void_element(myhtml_tree_node_t *node)
{
    // http://w3c.github.io/html-reference/syntax.html#void-elements
    switch (node->tag_id)
    {
        case MyHTML_TAG_AREA:
        case MyHTML_TAG_BASE:
        case MyHTML_TAG_BR:
        case MyHTML_TAG_COL:
        case MyHTML_TAG_COMMAND:
        case MyHTML_TAG_EMBED:
        case MyHTML_TAG_HR:
        case MyHTML_TAG_IMG:
        case MyHTML_TAG_INPUT:
        case MyHTML_TAG_KEYGEN:
        case MyHTML_TAG_LINK:
        case MyHTML_TAG_META:
        case MyHTML_TAG_PARAM:
        case MyHTML_TAG_SOURCE:
        case MyHTML_TAG_TRACK:
        case MyHTML_TAG_WBR:
        {
            return true;
        }
        default:
        {
            return false;
        }
    }
}

myhtml_tree_attr_t * myhtml_node_attribute_first(myhtml_tree_node_t *node)
{
    if(node->token)
        return node->token->attr_first;
    
    return NULL;
}

myhtml_tree_attr_t * myhtml_node_attribute_last(myhtml_tree_node_t *node)
{
    if(node->token)
        return node->token->attr_last;
    
    return NULL;
}

const char * myhtml_node_text(myhtml_tree_node_t *node, size_t *length)
{
    if(node->token && node->token->str.length && node->token->str.data)
    {
        if(length)
            *length = node->token->str.length;
        
        return node->token->str.data;
    }
    
    if(length)
        *length = 0;
    
    return NULL;
}

mycore_string_t * myhtml_node_string(myhtml_tree_node_t *node)
{
    if(node && node->token)
        return &node->token->str;
    
    return NULL;
}



( run in 0.577 second using v1.01-cache-2.11-cpan-71847e10f99 )