75internal_emit(
char* out,
size_t cap,
size_t* pos,
const char* src,
size_t len)
77 if (len > (cap - *pos)) {
80 (void)
memcpy(&out[*pos], src, len);
160 for (
const char* p = str; *p !=
'\0'; ++p) {
216 static const char*
const k_void[] = {
232 for (
size_t i = 0U; i < (
sizeof(k_void) /
sizeof(k_void[0])); ++i) {
233 if (
strcmp(name, k_void[i]) == 0) {
277 for (uint16_t i = 0U; i < node->
attr_count; ++i) {
413 while ((sp > 0U) && ok && (guard < max_iter)) {
439 return ok && (guard < max_iter);
472 static const char*
const k_block[] = {
473 "p",
"h1",
"h2",
"h3",
"h4",
"h5",
"h6",
"li",
474 "ul",
"ol",
"div",
"br",
"hr",
"section",
"tr",
"pre",
475 "header",
"blockquote",
"article",
"aside",
"footer",
"figure",
"figcaption",
477 for (
size_t i = 0U; i < (
sizeof(k_block) /
sizeof(k_block[0])); ++i) {
478 if (
strcmp(name, k_block[i]) == 0) {
528 for (
const char* p = str; *p !=
'\0'; ++p) {
530 const bool ws = (c ==
' ') || (c ==
'\t') || (c ==
'\n') || (c ==
'\r');
585 while ((*pos > 0U) && (out[*pos - 1U] ==
' ')) {
589 if ((*pos > 0U) && (out[*pos - 1U] ==
'\n')) {
645 uint32_t* stack = s_text_stack;
648 bool at_break =
true;
654 while ((sp > 0U) && ok && (guard < max_iter)) {
657 const uint32_t n = stack[sp];
679 return ok && (guard < max_iter);
683book_chapter_text(
const void* base, uint32_t chapter_idx,
char* out,
size_t cap,
size_t* out_len)
703 uint32_t chapter_idx,
Flat, execute-in-place container for a build-time "compiled" e-book.
@ k_book_node_text
A text run: carries a string, no children.
@ k_book_nil
Absent index / "applies to all chapters".
static const book_chapter_t * book_chapters(const void *base)
Base of the chapter table.
static const book_header_t * book_header(const void *base)
View the blob base as its header.
static const book_node_t * book_nodes(const void *base)
Base of the DOM node table.
static const book_attr_t * book_attrs(const void *base)
Base of the attribute table.
static const char * book_string(const void *base, uint32_t off)
Resolve a string-pool offset to a NUL-terminated UTF-8 string.
book DOM-walk helpers shared across the library's translation units.
@ k_book_xhtml_stack
Max pending open/close walk entries.
@ k_book_xhtml_iter_x
Iteration-guard multiplier over node_count.
Paged (demand-fetched) accessor mode for book over ra8_vmem (#163).
ra8_err_t book_chapter_text(const void *base, uint32_t chapter_idx, char *out, size_t cap, size_t *out_len)
Extract one chapter's readable plain text from the DOM.
bool priv_book_is_block(const char *name)
Test whether an element name is a block-level HTML element.
static bool internal_emit_cstr(char *out, size_t cap, size_t *pos, const char *str)
Append a NUL-terminated string to the output buffer.
static bool internal_emit_attrs(const void *base, const book_node_t *node, char *out, size_t cap, size_t *pos)
Append all attributes of a DOM node to the output buffer.
static const char *const s_tag_xhtml
Log tag for serializer diagnostics.
bool priv_book_emit_break(char *out, size_t cap, size_t *pos, bool *at_break)
Append a paragraph break, collapsing consecutive block-level breaks.
static bool internal_open_element(const void *base, const book_node_t *node, char *out, size_t cap, size_t *pos, book_walk_entry_t *stack, uint32_t *sp)
Emit an element open tag and schedule its close and children on the walk stack.
ra8_err_t book_chapter_to_xhtml(const void *base, uint32_t chapter_idx, char *out, size_t cap, size_t *out_len)
Serialize one chapter's DOM subtree back to XHTML for the renderer.
bool priv_book_emit_text(char *out, size_t cap, size_t *pos, const char *str, bool *at_break)
Append a whitespace-collapsed text run to the output buffer.
static bool internal_is_void(const char *name)
Test whether an element name is an HTML void element.
static bool internal_walk_text(const void *base, uint32_t root, uint32_t node_count, char *out, size_t cap, size_t *pos)
Bounded pre-order walk that extracts plain text from a DOM subtree.
static bool internal_emit(char *out, size_t cap, size_t *pos, const char *src, size_t len)
Append a raw byte span to the output buffer.
static bool internal_emit_escaped(char *out, size_t cap, size_t *pos, const char *str, bool in_attr)
Append entity-escaped text to the output buffer.
static bool internal_walk_to_xhtml(const void *base, uint32_t root, uint32_t node_count, char *out, size_t cap, size_t *pos)
Iterative, bounded DOM walk that serialises a subtree to XHTML.
Annotation-attribute framework macros for ra8-firmware.
#define RA8_PRIV
Module-private helper: shared across TUs but only inside one library.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
Validation and Error-Checking Macros for ra8-firmware.
#define RA8_CHECK_NULL_PTR(ptr, tag, message)
Reject nullptr pointer, returning k_ra8_err_null_ptr.
@ k_ra8_err_invalid_arg
Invalid function argument.
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
@ k_ra8_err_invalid_size
Invalid size parameter (too large, too small, or misaligned).
ra8_err_codes_t ra8_err_t
Canonical error-return type used by every ra8-firmware API.
int strcmp(const char *s1, const char *s2)
Compare two null-terminated strings.
size_t strlen(const char *s)
Calculate string length.
void * memcpy(void *dst, const void *src, size_t n)
Copy memory area between non-overlapping regions.
One name="value" attribute on an element.
uint32_t value_off
String-pool offset of the attribute value.
uint32_t name_off
String-pool offset of the attribute name.
uint32_t root_node
Node-table index of this chapter's root element.
uint8_t kind
book_node_kind_t.
uint32_t text_off
Text: string-pool offset of the run (element: 0).
uint16_t attr_count
Element: number of attributes (text: 0).
uint32_t next_sibling
Index of next sibling node, or nil.
uint32_t name_off
Element: string-pool offset of tag name (text: 0).
uint32_t first_child
Index of first child node, or nil.
uint32_t first_attr
Index of first attribute, or nil.
One deferred unit of work on the serializer stack.
bool is_close
true: emit </name>; false: open node value.
uint32_t value
Close: tag-name string offset.