This library wraps functionality of lexborisovs Modest. It is written in in pure C99 and exposes a lot of useful features to parse and manipulate a html DOM. Internally it makes use of rxis excellent vec, map and dmt libraries.
Modest is a fast HTML renderer implemented as a pure C99 library with no outside dependencies.
-
- HTML5 parsing library in pure C99
- fully conformant with the HTML5 spec
-
- A type-safe dynamic array implementation for C
-
- A type-safe generic hashmap implementation for C.
-
- Dynamic Memory Tracker (DMT) Library
2.0.1
For more examples please checkout tests.
#include "modest_html.h"
/*
modest_html is build around a workspace struct.
The workspace holds all allocated memory and frees it in html_destroy().
*/
html_workspace_t *w = html_init();
// parse some html
const char *html = "<p>Hello</p><p>World</p>";
int tree_index = html_parse_tree(w, html, strlen(html));
// serialize the tree into a buffer
int buffer_index = html_serialize_tree(w, tree_index, "body");
// get buffer and join into a string
html_vec_str_t *buffer = html_get_buffer(w, buffer_index);
char* result = html_vec_str_join(buffer, "");
printf("%s\n", result);
// test result
if(result != NULL && strcmp(result, "<body><p>Hello</p><p>World</p></body>") != 0){
fprintf(stderr, "Failed\n");
html_free(result);
html_destroy(w);
return false;
}
// free result
html_free(result);
// destroy our workspace
html_destroy(w);
return true;
cmake 3.x
The script compiles Modest
and configures the library.
./configure
Build libmodest_html.a
into build/
.
cd build
make
Execute tests.
make test
Check for leaks.
valgrind --leak-check=yes test/example_test
git clone [email protected]:f34nk/modest_html.git
cd modest_html
All dependencies are added as submodules in the libs/
folder.
git submodule update --init --recursive --remote
See CHANGELOG.
- Features
- Find nodes using a CSS selector
- Serialize any string with valid or broken html
- Get attribute with optional CSS selector
- Set attribute with optional CSS selector
- Get text with optional CSS selector
- Set text with optional CSS selector
- Remove a node from html
- Append node to another node
- Prepend node to another node
- Insert node before another node
- Insert node after another node
- Replace node with another node
- Slice html to a subset of nodes
- Get position of node in relation to its parent
- Wrap node with another node
- Pretty print html
- Compare two html strings
- Documentation
modest_html is under LGPL license. Check the LICENSE file for more details.