SLWEB_HTML(7)

NAME
slweb_html - slweb HTML serializer

SYNOPSIS

#include <slweb/html.h>

DESCRIPTION
This component allows library users to serialize HTML text from a tree structure composed by one or more struct html_node objects. slweb_html(7) provides the following functions:

•   html_node_alloc(3) allocates a struct html_node object, consumed by other functions from this component.

•   html_node_free(3) frees the memory from a struct html_node object previously allocated by a call to html_node_alloc(3), plus all of the memory allocated by its children.

•   html_node_set_value(3) sets the HTML value for a struct html_node object, escaping characters that could case syntax errors, such as < (LESS-THAN SIGN).

•   html_node_set_value_unescaped(3) sets the HTML value for a struct html_node object. As opposed to html_node_set_value(3), no escaping is performed.

•   html_node_add_attr(3) adds an attribute to a struct html_node object.

•   html_node_add_child(3) allocates a children struct html_node object to another struct html_node object.

•   html_node_add_sibling(3) adds a sibling struct html_node object to another struct html_node object.

•   html_serialize(3) serializes a struct html_node object and all of its children into a null-terminated string with the HTML-serialized data. Typically, a root struct html_node object is allocated via html_node_alloc(3), and child nodes are appended to it via html_node_add_child(3). Optionally, values and/or attributes can be added to nodes via html_node_set_value(3) and html_node_add_attr(3), respectively. Finally, html_node_free(3) shall free the memory used by the root node and all of its children.

EXAMPLE
The example below is a minimal showcase of some of the features provided by slweb_html(7), which prints a minimal HTML file to standard output:

    #include <slweb/html.h>
    #include <dynstr.h>
    #include <stdlib.h>
    #include <stdio.h>
    int main()
    {
        int ret = EXIT_FAILURE;
        struct dynstr d;
        struct html_node *const html = html_node_alloc("html"), *body;
        static const char text[] = "testing slweb";
        dynstr_init(&d);
        if (!html)
        {
            fprintf(stderr, "html_node_alloc_failed\n");
            goto end;
        }
        else if (!(body = html_node_add_child(html, "body")))
        {
            fprintf(stderr, "html_node_add_child failed\n");
            goto end;
        }
        else if (html_node_set_value(body, text))
        {
            fprintf(stderr, "html_node_set_value failed\n");
            goto end;
        }
        else if (html_serialize(html, &d))
        {
            fprintf(stderr, "html_serialize failed\n");
            goto end;
        }
        printf("%s", d.str);
        ret = EXIT_SUCCESS;
    end:
        dynstr_free(&d);
        return ret;
    }

This program should write the following data over standard output:

    <html>
            <body>testing slweb</body>
    </html>

SEE ALSO
html_node_alloc(3), html_node_free(3), html_node_set_value(3), html_node_set_value_unescaped(3), html_node_add_attr(3), html_node_add_child(3), html_node_add_sibling(3), html_serialize(3), slweb_html(7).

COPYRIGHT
Copyright (C) 2023 Xavier Del Campo Romero.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.