Skip to content

Latest commit

 

History

History
130 lines (103 loc) · 3.32 KB

README.md

File metadata and controls

130 lines (103 loc) · 3.32 KB

This project is not maintained anymore.

Build status

modest_html

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.

  • Modest

    • HTML5 parsing library in pure C99
    • fully conformant with the HTML5 spec
  • vec

    • A type-safe dynamic array implementation for C
  • map

    • A type-safe generic hashmap implementation for C.
  • dmt

    • Dynamic Memory Tracker (DMT) Library

Current Version

2.0.1

Example

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;

Dependencies

cmake 3.x

Compile and test

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

Cloning

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

Roadmap

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

License

modest_html is under LGPL license. Check the LICENSE file for more details.