/* Markdown as Pi's terminal UI draws it (markdown.c): headings, paragraphs
* with `code`, bold, italic, strikethrough and links, bulleted, numbered and
* nested lists, block quotes, fenced code with its language label, rules and
* tables. Pure functions: text in, styled and wrapped lines out. */
#ifndef PIC_TUI_MARKDOWN_H
#define PIC_TUI_MARKDOWN_H
#include <stddef.h>
#include "width.h"
typedef struct {
const char *base; /* SGR set again after every style change; NULL or "": none */
int links; /* link text is an OSC 8 hyperlink (and the url is not printed) */
int preserve; /* a user message: list markers and backslashes stay as typed */
} tui_md_opts;
/* text[0..len) as lines of at most cols columns, appended to out. Blocks are
* separated by one blank line; no trailing blank line. 0 or -1 (out of memory). */
int tui_markdown(const char *text, size_t len, size_t cols, const tui_md_opts *o, tui_lines *out);
/* A streamed reply is flushed block by block: the bytes of the first block of
* s that is finished (it ends in a blank line outside a code fence), blank
* line included; 0 when the first block is still open. */
size_t tui_markdown_block_len(const char *s);
/* One line of a block too long to wait for: inside a code fence (*fence) it is
* code; a fence line opens or closes it; otherwise it is rendered as text. */
int tui_markdown_line(const char *line, size_t len, int *fence, size_t cols, const tui_md_opts *o, tui_lines *out);
/* Pi's user message: the text rendered as markdown on the user-message
* background, one column of padding on each side and a blank row above and
* below, every row padded to cols. */
int tui_user_message_lines(const char *text, size_t cols, int links, tui_lines *out);
/* Whether the terminal is known to handle OSC 8 hyperlinks (Pi's list:
* kitty, ghostty, wezterm, iTerm2, Warp, VS Code, Alacritty...; not inside
* tmux or screen). */
int tui_hyperlinks_supported(void);
#endif