Coder Social home page Coder Social logo

dumbo's Introduction

dumbo

A planned C library for executing CSS selectors on HTML trees from a variety of libraries, including gumbo.

Goals

  • Portable: Uses C99 and autotools
  • Small: Focussed feature-set only for retrieving elements from HTML trees
  • Customisable: Allows compile-time toggling of HTML library support
  • Support CSS 3 (including the deprecated :contains() and non-standard ::attr(name))
  • Support selections on streaming HTML parsers (e.g., SAX parsers)

Implementation notes

As much as possible, dumbo shouldn't do any allocations. So, the API for executing selectors should be an iterator interface, and take void ** since client code should know what kind of tree they have (and thus, node type or te). Upon match, the library should just modify the out parameter to point to the element.

Example code:

#include <dumbo.h>
// ...
char *html = ...;
char *selector = ...;

MyTree *tree = mytree_parse(html);
MyTree *root = mytree_getroot(tree);

// Wrapped to store the tree, the library's tag (some internal enum), and
// library-specific context data for the current execution of the css selection.
dumbo_ctx ctx = DUMBO_CTX_WRAP_MYTREE(root);
dumbo_css *css = dumbo_css_parse(selector);

MyTree *node;
while (dumbo_css_exec(css, &ctx, &node) == 0) {
	// ...
}

// ...

// Execute again on different css selector (with the same tree).
dumbo_css_free(css);
selector = ...;
css = dumbo_css_parse(selector);
// Reuse the current context.
DUMBO_CTX_RESET_MYTREE(ctx);
while (dumbo_css_exec(css, &ctx, &node) == 0) {
	// ...
}

// ...

// Execute with different *tree* but the same selector.
mytree_free(tree);
html = ...;
tree = mytree_parse(html);
root = mytree_getroot(tree);
ctx = DUMBO_CTX_WRAP_MYTREE(root);
while (dumbo_css_exec(css, &ctx, &node) == 0) {
	// ...
}

// ...

dumbo_css_free(css);
mytree_free(tree);

dumbo's People

Contributors

hoboneer avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.