Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
n_html.h File Reference

Lightweight HTML/XML extraction: links, forms, and sitemap URLs. More...

#include "nilorea/n_list.h"
#include "nilorea/n_str.h"
#include <stddef.h>
+ Include dependency graph for n_html.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  N_FORM_FIELD
 a single form field (input, select, textarea, button) More...
 
struct  N_HTML_FORM
 a parsed HTML form with its fields More...
 

Functions

LISTn_html_extract_forms (const char *html, size_t len)
 extract forms as a LIST of N_HTML_FORM*; free with n_html_forms_free
 
LISTn_html_extract_js_urls (const char *js, size_t len)
 extract URL/path tokens from JavaScript source (quoted string literals that look like an http(s) URL, a protocol-relative "//host" URL, or a "/" / "./" / "../" path; a "${...}" template is truncated to its static prefix), deduped, as a LIST of N_STR*; free with n_html_links_free.
 
LISTn_html_extract_links (const char *html, size_t len)
 extract link URLs (a/href, form/action, img/src, script/src, link/href, iframe/src) as a LIST of N_STR*; free with n_html_links_free
 
LISTn_html_extract_scripts (const char *html, size_t len)
 extract the inline <script> bodies (those without a src attribute) from an HTML document as a LIST of N_STR*; free with n_html_links_free.
 
void n_html_forms_free (LIST **forms)
 free a list returned by n_html_extract_forms
 
void n_html_links_free (LIST **links)
 free a list returned by n_html_extract_links or n_sitemap_extract_urls
 
N_STRn_html_to_text (const char *html, size_t len)
 render HTML to readable plain text: drop tags, skip script/style, decode common entities, collapse whitespace, and line-break block elements; returns a new N_STR (free with free_nstr) or NULL
 
LISTn_sitemap_extract_urls (const char *xml, size_t len)
 extract <loc> URLs from a sitemap.xml as a LIST of N_STR*; free with n_html_links_free
 

Detailed Description

Lightweight HTML/XML extraction: links, forms, and sitemap URLs.

Author
Castagnier Mickael
Version
1.0
Date
2026

A small, dependency-free tag scanner (not a full HTML parser) that pulls the link, form, and sitemap surface out of a document for a web crawler. It is tolerant of malformed markup and never executes anything.

Definition in file n_html.h.


Data Structure Documentation

◆ N_FORM_FIELD

struct N_FORM_FIELD

a single form field (input, select, textarea, button)

Examples
ex_html.c.

Definition at line 45 of file n_html.h.

+ Collaboration diagram for N_FORM_FIELD:
Data Fields
char * name field name attribute, or ""
int required 1 when the required attribute is present
char * type field type (lowercased), default "text"
char * value default value attribute, or ""

◆ N_HTML_FORM

struct N_HTML_FORM

a parsed HTML form with its fields

Examples
ex_html.c.

Definition at line 53 of file n_html.h.

+ Collaboration diagram for N_HTML_FORM:
Data Fields
char * action action attribute (may be "" for self)
char * enctype lower-case enctype, default "application/x-www-form-urlencoded"
LIST * fields list of N_FORM_FIELD*
char * method upper-case method, default "GET"

Function Documentation

◆ n_html_extract_forms()

LIST * n_html_extract_forms ( const char *  html,
size_t  len 
)

◆ n_html_extract_js_urls()

LIST * n_html_extract_js_urls ( const char *  js,
size_t  len 
)

extract URL/path tokens from JavaScript source (quoted string literals that look like an http(s) URL, a protocol-relative "//host" URL, or a "/" / "./" / "../" path; a "${...}" template is truncated to its static prefix), deduped, as a LIST of N_STR*; free with n_html_links_free.

Recovers fetch()/XHR/route endpoints a static link scan misses.

Definition at line 915 of file n_html.c.

References _n_html_push_js_url(), MAX_LIST_ITEMS, and new_generic_list().

Referenced by test_js_urls(), and test_scripts().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ n_html_extract_links()

LIST * n_html_extract_links ( const char *  html,
size_t  len 
)

extract link URLs (a/href, form/action, img/src, script/src, link/href, iframe/src) as a LIST of N_STR*; free with n_html_links_free

Definition at line 360 of file n_html.c.

References _n_html_attr_lookup(), _n_html_push_link(), _n_html_scan_tags(), N_HTML_TAG_::closing, list_destroy(), list_foreach, MAX_LIST_ITEMS, N_HTML_TAG_::name, and new_generic_list().

Referenced by test_empty_and_null(), and test_links().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ n_html_extract_scripts()

LIST * n_html_extract_scripts ( const char *  html,
size_t  len 
)

extract the inline <script> bodies (those without a src attribute) from an HTML document as a LIST of N_STR*; free with n_html_links_free.

Feed each to n_html_extract_js_urls to mine inline endpoints.

Definition at line 941 of file n_html.c.

References _n_html_find_ci(), char_to_nstr_ex(), free_nstr_ptr(), list_push(), MAX_LIST_ITEMS, and new_generic_list().

Referenced by test_scripts().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ n_html_forms_free()

void n_html_forms_free ( LIST **  forms)

free a list returned by n_html_extract_forms

Definition at line 984 of file n_html.c.

References list_destroy().

Referenced by test_empty_and_null(), test_enctype(), and test_forms().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ n_html_links_free()

void n_html_links_free ( LIST **  links)

free a list returned by n_html_extract_links or n_sitemap_extract_urls

Definition at line 979 of file n_html.c.

References list_destroy().

Referenced by test_empty_and_null(), test_js_urls(), test_links(), test_scripts(), and test_sitemap().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ n_html_to_text()

N_STR * n_html_to_text ( const char *  html,
size_t  len 
)

render HTML to readable plain text: drop tags, skip script/style, decode common entities, collapse whitespace, and line-break block elements; returns a new N_STR (free with free_nstr) or NULL

Definition at line 627 of file n_html.c.

References _n_html_block_kind(), _n_html_entities, _n_html_flush(), _n_html_lc(), _n_html_put_cp(), _n_html_put_str(), char_to_nstr_ex(), Free, LOG_ERR, Malloc, and n_log.

Referenced by test_to_text().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ n_sitemap_extract_urls()

LIST * n_sitemap_extract_urls ( const char *  xml,
size_t  len 
)

extract <loc> URLs from a sitemap.xml as a LIST of N_STR*; free with n_html_links_free

Definition at line 456 of file n_html.c.

References _n_html_strndup(), char_to_nstr(), Free, free_nstr_ptr(), list_push(), MAX_LIST_ITEMS, and new_generic_list().

Referenced by test_empty_and_null(), and test_sitemap().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: