Code Monkey home page Code Monkey logo

modest_html's Introduction

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.

modest_html's People

Contributors

f34nk avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

modest_html's Issues

Failes to handle html with input tag

ModestEx fails target tests related to html containing input tag.
f34nk/modest_ex#27

Tested on Apple OSX 10.12.

Error could be reproduced:
d55b5c7

test/html_append_test

[LOG]	append_text_node_to_single_input_node_test()
html_select()
	div
html_select_scope()
	-text
-> <input type="radio">Radio Button
[ERROR]	append_text_node_to_single_input_node_test()
	XXX/modest_html/test/html_append_test.c:97

test/html_prepend_test

[LOG]	prepend_text_node_to_single_input_node_test()
html_select()
	div
html_select_scope()
	-text
html_prepend_collection() - Empty collection
html_serialize_collection() - Empty collection
-> (null)
Segmentation fault: 11

test/html_select_test

[LOG]	select_single_input_node_test()
html_select()
	html
-> <input type="radio">

OK

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.