Skip to content
pi-c Artifact [c8653159ee]
Login

Artifact [c8653159ee]

Artifact c8653159eedf7f06f81241d21f366a7e35a111dfd8426c3937dff45c729a9fd7:


/* HTML to readable text (htmltext.c), for the web_fetch tool: a forgiving single pass, not a
 * browser. Headings, links, lists, code blocks, quotes and tables stay, as markdown; script,
 * style, navigation and the rest of the page's machinery go. */
#ifndef PIC_HTMLTEXT_H
#define PIC_HTMLTEXT_H

#include <stddef.h>

/* The page's links and images, made absolute by the caller: HREF is as written in the page;
 * the result is malloc'd, or NULL to keep HREF as it is. NULL resolve_fn: kept as written. */
typedef char *(*pic_html_resolve_fn)(void *ctx, const char *href);

/* The text of the LEN bytes of HTML (UTF-8), malloc'd and NUL-terminated; NULL when out of
 * memory. A <title> becomes a first line "Title: ..." when there is one. */
char *pic_html_to_text(const char *html, size_t len, pic_html_resolve_fn resolve_fn, void *ctx);

/* The words of the LEN bytes of HTML (a snippet with <strong> in it, say) as plain text: markup
 * and entities resolved, no markdown marks, links or images. Malloc'd, or NULL. */
char *pic_html_plain(const char *html, size_t len);

#endif