google / gumbo-parser

An HTML5 parsing library in pure C99
Apache License 2.0
5.16k stars 660 forks source link

Getting style properties of gumbo nodes #404

Closed msclecram closed 1 year ago

msclecram commented 6 years ago

Hi,

I'm trying to get some style properties of each node, mainly color and background color.

I'm using gumbo-query and katana-parser together with gumbo-parser. I parse the css files, inline and style selectors with katana and I do queries with gumbo query. However doing a query to get which nodes affect a selector is very slow with big css files and also it seems I'm applying wrong the css priority rules.

Is there another solution to get the style properties of a node using gumbo-parser or libraries for gumbo parser?

Thanks.

XxXStu commented 6 years ago
GumboNode* node = current_node;
if ( node->type == GUMBO_NODE_ELEMENT )
{
    //get-all-attr
    for (unsigned int i = 0; i < node->v.element.attributes.length; ++i)
    {
        GumboAttribute * attr = node->v.element.attributes.data[i];
        ...
    }

    //get-one-attr
    GumboAttribute * href = gumbo_get_attribute(&node->v.element.attributes, "style");
   ...
}

Hope it can help you.