1#ifndef MATCHA_HTMLCONV_H
2#define MATCHA_HTMLCONV_H
3
4#include <stddef.h>
5
6// Element types found during HTML parsing.
7enum {
8 HELEM_TEXT = 0, // Plain text segment
9 HELEM_H1 = 1, // <h1> text
10 HELEM_H2 = 2, // <h2> text
11 HELEM_LINK = 3, // <a href="...">text</a>
12 HELEM_IMAGE = 4, // <img src="..." alt="...">
13 HELEM_BLOCKQUOTE = 5, // <blockquote> content (with optional cite/prev)
14};
15
16// HTMLElement represents a parsed element from the HTML document.
17typedef struct {
18 int type;
19 char* text; // Text content (h1/h2 text, link text, blockquote content)
20 char* attr1; // href for links, src for images, cite for blockquotes
21 char* attr2; // alt for images, prev_text for blockquotes (On...wrote:)
22} HTMLElement;
23
24// HTMLConvertResult holds the output of html_to_elements.
25typedef struct {
26 HTMLElement* elements;
27 int count;
28 int cap;
29 int ok;
30} HTMLConvertResult;
31
32// html_to_elements parses an HTML string and returns an array of structured
33// elements. The caller processes these elements to apply terminal styling.
34// style/script content is stripped. Block elements get proper spacing.
35// Returns a result with ok=1 on success. Caller must free with free_html_result.
36HTMLConvertResult html_to_elements(const char* html, size_t len);
37
38// free_html_result frees all memory in an HTMLConvertResult.
39void free_html_result(HTMLConvertResult* r);
40
41#endif