1 xtk_markdown
liquibyte edited this page 2026-11-19 16:23:20 -06:00
This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

xtk_markdown.h

A CommonMark parser that reports a document's blocks, spans and text through callbacks.

xtk_markdown_parse() reads a Markdown document and, as it goes, calls the program's functions: one when a block (a paragraph, a heading, a list item, a table cell) starts and one when it ends, the same for each span (emphasis, a link, code), and one for each run of text. The program builds what it needs from those calls: formatted text on the screen, HTML, or a model of its own. XtkRichText reads Markdown this way. The parser draws nothing and keeps nothing after the call returns. It is derived from md4c by Martin Mitáš (MIT licence; the notice is at the top of this file, see also CREDITS.md).

The calls. Blocks nest, and the calls come in document order: enter_block(XTK_MARKDOWN_BLOCK_DOCUMENT) first, then each block's enter, its contents (child blocks, or spans and text), and its leave. Spans nest inside a block the same way. Every block and span that is entered is left. Text arrives in pieces through text, each with a type: normal text, a line break, an entity, code and so on. Strings given to the callbacks are not NUL-terminated: use the size given with them. They point into the input or into the parser's own memory and are valid only during the call. A callback that returns non-zero stops the parse, and xtk_markdown_parse() returns that value.

Dialect. With flags 0 the parser follows CommonMark. Each XTK_MARKDOWN_FLAG_* turns on one extension or change; XTK_MARKDOWN_DIALECT_GITHUB is the set closest to GitHub's Markdown. The extensions and their syntax:

Example. Print the headings of a document:

static int in_heading;

static int enter_block(XtkMarkdownBlockType type, void *detail, void *user_data) {
    (void)user_data;
    if (type == XTK_MARKDOWN_BLOCK_H) {
        in_heading = 1;
        printf("%u: ", ((XtkMarkdownBlockHDetail *)detail)->level);
    }
    return 0;
}
static int leave_block(XtkMarkdownBlockType type, void *detail, void *user_data) {
    (void)detail; (void)user_data;
    if (type == XTK_MARKDOWN_BLOCK_H) { in_heading = 0; putchar('\n'); }
    return 0;
}
static int span(XtkMarkdownSpanType type, void *detail, void *user_data) {
    (void)type; (void)detail; (void)user_data;
    return 0;
}
static int text(XtkMarkdownTextType type, const XtkMarkdownChar *text, XtkMarkdownSize size, void *user_data) {
    (void)type; (void)user_data;
    if (in_heading) fwrite(text, 1, size, stdout);
    return 0;
}

XtkMarkdownParser parser = {
    .flags = XTK_MARKDOWN_DIALECT_GITHUB,
    .enter_block = enter_block, .leave_block = leave_block,
    .enter_span = span, .leave_span = span,
    .text = text,
};
const char *source = "# Title\n\nSome *text*.\n\n## Part\n";
if (xtk_markdown_parse(source, (XtkMarkdownSize)strlen(source), &parser, NULL) != 0)
    fprintf(stderr, "parse failed\n");
 * 

Limitations.

  • There is no list of named entities: anything of the form &name; is reported as an entity, and the program decodes it.
  • Raw HTML is passed through as text; it is not parsed.
  • A table header has exactly one row.
#include "xtk_markdown.h"

Types: XtkMarkdownChar, XtkMarkdownSize, XtkMarkdownOffset, XtkMarkdownBlockType, XtkMarkdownSpanType, XtkMarkdownTextType, XtkMarkdownAlign, XtkMarkdownAttribute, XtkMarkdownBlockUlDetail, XtkMarkdownBlockOlDetail, XtkMarkdownBlockLiDetail, XtkMarkdownBlockHDetail, XtkMarkdownBlockCodeDetail, XtkMarkdownBlockTableDetail, XtkMarkdownBlockTdDetail, XtkMarkdownBlockAdmonitionDetail, XtkMarkdownSpanADetail, XtkMarkdownSpanImgDetail, XtkMarkdownSpanWikilinkDetail, XtkMarkdownSpanFootnoteReferenceDetail, XtkMarkdownBlockFootnoteDefinitionDetail, XtkMarkdownBlockBlankDetail, XtkMarkdownParser

Constants: XTK_MARKDOWN_FLAG_COLLAPSEWHITESPACE, XTK_MARKDOWN_FLAG_PERMISSIVEATXHEADERS, XTK_MARKDOWN_FLAG_PERMISSIVEURLAUTOLINKS, XTK_MARKDOWN_FLAG_PERMISSIVEEMAILAUTOLINKS, XTK_MARKDOWN_FLAG_NOINDENTEDCODEBLOCKS, XTK_MARKDOWN_FLAG_NOHTMLBLOCKS, XTK_MARKDOWN_FLAG_NOHTMLSPANS, XTK_MARKDOWN_FLAG_TABLES, XTK_MARKDOWN_FLAG_STRIKETHROUGH, XTK_MARKDOWN_FLAG_PERMISSIVEWWWAUTOLINKS, XTK_MARKDOWN_FLAG_TASKLISTS, XTK_MARKDOWN_FLAG_LATEXMATHSPANS, XTK_MARKDOWN_FLAG_WIKILINKS, XTK_MARKDOWN_FLAG_UNDERLINE, XTK_MARKDOWN_FLAG_HARD_SOFT_BREAKS, XTK_MARKDOWN_FLAG_SPOILERS, XTK_MARKDOWN_FLAG_SUPERSCRIPTS, XTK_MARKDOWN_FLAG_SUBSCRIPTS, XTK_MARKDOWN_FLAG_ADMONITIONS, XTK_MARKDOWN_FLAG_FOOTNOTES, XTK_MARKDOWN_FLAG_HIGHLIGHT, XTK_MARKDOWN_FLAG_PRESERVEBLANKLINES, XTK_MARKDOWN_FLAG_PERMISSIVEAUTOLINKS, XTK_MARKDOWN_FLAG_NOHTML, XTK_MARKDOWN_DIALECT_COMMONMARK, XTK_MARKDOWN_DIALECT_GITHUB

Functions: xtk_markdown_parse

Types

XtkMarkdownChar

typedef char XtkMarkdownChar;

One unit of the input text: a byte of UTF-8.

XtkMarkdownSize

typedef unsigned XtkMarkdownSize;

A length, in XtkMarkdownChar units (bytes).

XtkMarkdownOffset

typedef unsigned XtkMarkdownOffset;

A position in the input, in XtkMarkdownChar units (bytes) from its start.

XtkMarkdownBlockType

The kinds of block: the parts of the document's structure, such as paragraphs and list items.

Blocks are reported with enter_block and leave_block. For some kinds the detail argument points to a structure named below; for the others it is NULL.

Name Value Description
XTK_MARKDOWN_BLOCK_DOCUMENT 0 The whole document; always the outermost block.
XTK_MARKDOWN_BLOCK_QUOTE A block quote (> ...).
XTK_MARKDOWN_BLOCK_UL A bulleted list. Detail: XtkMarkdownBlockUlDetail.
XTK_MARKDOWN_BLOCK_OL A numbered list. Detail: XtkMarkdownBlockOlDetail.
XTK_MARKDOWN_BLOCK_LI A list item. Detail: XtkMarkdownBlockLiDetail.
XTK_MARKDOWN_BLOCK_HR A horizontal rule (---); it has no contents.
XTK_MARKDOWN_BLOCK_H A heading, level 1 to 6. Detail: XtkMarkdownBlockHDetail.
XTK_MARKDOWN_BLOCK_CODE A code block, fenced or indented. Detail: XtkMarkdownBlockCodeDetail. Its text arrives as XTK_MARKDOWN_TEXT_CODE, with each line ended by ‘’ '` in the text, not by a line break text.
XTK_MARKDOWN_BLOCK_HTML A block of raw HTML. Its contents arrive as XTK_MARKDOWN_TEXT_HTML, verbatim, with ‘’ '` in the text for line ends.
XTK_MARKDOWN_BLOCK_P A paragraph.
XTK_MARKDOWN_BLOCK_TABLE A table. Detail: XtkMarkdownBlockTableDetail. Only with XTK_MARKDOWN_FLAG_TABLES.
XTK_MARKDOWN_BLOCK_THEAD The table's header row group, inside TABLE.
XTK_MARKDOWN_BLOCK_TBODY The table's body row group, inside TABLE (only when it has body rows).
XTK_MARKDOWN_BLOCK_TR A table row, inside THEAD or TBODY.
XTK_MARKDOWN_BLOCK_TH A header cell, inside a TR of THEAD. Detail: XtkMarkdownBlockTdDetail.
XTK_MARKDOWN_BLOCK_TD A body cell, inside a TR of TBODY. Detail: XtkMarkdownBlockTdDetail.
XTK_MARKDOWN_BLOCK_FOOTNOTE_DEFINITION_SECTION The section that holds the footnote definitions, after the rest of the document. Detail: NULL. Only with XTK_MARKDOWN_FLAG_FOOTNOTES, and only when at least one footnote is referenced.
XTK_MARKDOWN_BLOCK_FOOTNOTE_DEFINITION One footnote definition, inside FOOTNOTE_DEFINITION_SECTION. Detail: XtkMarkdownBlockFootnoteDefinitionDetail. Only with XTK_MARKDOWN_FLAG_FOOTNOTES; only the definitions that are referenced are reported, in the order of their first reference.
XTK_MARKDOWN_BLOCK_ADMONITION An admonition: a block quote that starts with [!NOTE] or one of the other tags. Detail: XtkMarkdownBlockAdmonitionDetail. Only with XTK_MARKDOWN_FLAG_ADMONITIONS.
XTK_MARKDOWN_BLOCK_BLANK A run of blank lines between two blocks; it has no contents. Detail: XtkMarkdownBlockBlankDetail. Only with XTK_MARKDOWN_FLAG_PRESERVEBLANKLINES.

XtkMarkdownSpanType

The kinds of span: inline runs inside a block that share a style, such as emphasis or a link.

Spans are reported with enter_span and leave_span, and can nest. For some kinds the detail argument points to a structure named below; for the others it is NULL.

Name Value Description
XTK_MARKDOWN_SPAN_EM Emphasis (*text* or _text_).
XTK_MARKDOWN_SPAN_STRONG Strong emphasis (**text**).
XTK_MARKDOWN_SPAN_A A link; its text is the span's contents. Detail: XtkMarkdownSpanADetail.
XTK_MARKDOWN_SPAN_IMG An image; its alternative text is the span's contents, which can hold spans and even other images (a program that wants plain alternative text flattens them). Detail: XtkMarkdownSpanImgDetail.
XTK_MARKDOWN_SPAN_CODE Inline code ('code'); its text arrives as XTK_MARKDOWN_TEXT_CODE.
XTK_MARKDOWN_SPAN_DEL Struck-through text (~~text~~). Only with XTK_MARKDOWN_FLAG_STRIKETHROUGH.
XTK_MARKDOWN_SPAN_LATEXMATH Inline LaTeX math ($...$); its text arrives as XTK_MARKDOWN_TEXT_LATEXMATH. Only with XTK_MARKDOWN_FLAG_LATEXMATHSPANS.
XTK_MARKDOWN_SPAN_LATEXMATH_DISPLAY Display LaTeX math ($$...$$); its text arrives as XTK_MARKDOWN_TEXT_LATEXMATH. Only with XTK_MARKDOWN_FLAG_LATEXMATHSPANS.
XTK_MARKDOWN_SPAN_WIKILINK A wiki link ([[target]] or [[target|label]]); its contents are the label, or the target when there is no label. Detail: XtkMarkdownSpanWikilinkDetail. Only with XTK_MARKDOWN_FLAG_WIKILINKS.
XTK_MARKDOWN_SPAN_U Underlined text (_text_). Only with XTK_MARKDOWN_FLAG_UNDERLINE.
XTK_MARKDOWN_SPAN_SPOILER A spoiler, text hidden until the reader asks (||text||). Only with XTK_MARKDOWN_FLAG_SPOILERS.
XTK_MARKDOWN_SPAN_SUPERSCRIPT Superscript (^text^). Only with XTK_MARKDOWN_FLAG_SUPERSCRIPTS.
XTK_MARKDOWN_SPAN_SUBSCRIPT Subscript (~text~). Only with XTK_MARKDOWN_FLAG_SUBSCRIPTS.
XTK_MARKDOWN_SPAN_FOOTNOTE_REFERENCE A footnote reference ([^label]). The span has no contents: no text callback comes between its enter and leave, and everything about it is in its detail, XtkMarkdownSpanFootnoteReferenceDetail. Only with XTK_MARKDOWN_FLAG_FOOTNOTES.
XTK_MARKDOWN_SPAN_MARK Highlighted text (==text==). Only with XTK_MARKDOWN_FLAG_HIGHLIGHT.

XtkMarkdownTextType

The kinds of text given to the text callback.

Name Value Description
XTK_MARKDOWN_TEXT_NORMAL 0 Ordinary text.
XTK_MARKDOWN_TEXT_NULLCHAR A NUL character in the input. CommonMark says to show it as U+FFFD, the replacement character, which this type lets the program do.
XTK_MARKDOWN_TEXT_BR A hard line break (two spaces or a backslash at the end of a line). Line breaks are not reported inside code blocks or HTML blocks, where ‘’ '` is part of the text.
XTK_MARKDOWN_TEXT_SOFTBR A soft line break: a line end in the source that is not meaningful, usually shown as a space.
XTK_MARKDOWN_TEXT_ENTITY An entity, given as written: a named one such as   (anything of the form &name; counts, since the parser has no list of names), a decimal one such as Ӓ, or a hexadecimal one such as ካ. The program decodes it.
XTK_MARKDOWN_TEXT_CODE Text of a code block or of inline code. In a code block it holds the indentation spaces and a ‘’ '` for each line end.
XTK_MARKDOWN_TEXT_HTML Raw HTML, inline or a block's contents. In an HTML block it holds a ‘’ '` for each line end.
XTK_MARKDOWN_TEXT_LATEXMATH The LaTeX source of a math span, handled as inline code is.

XtkMarkdownAlign

A table column's alignment, from the colons of its delimiter row.

Name Value Description
XTK_MARKDOWN_ALIGN_DEFAULT 0 Not given (---)
XTK_MARKDOWN_ALIGN_LEFT Left (:---)
XTK_MARKDOWN_ALIGN_CENTER Centered (:---:)
XTK_MARKDOWN_ALIGN_RIGHT Right (---:)

XtkMarkdownAttribute

A string that is part of a detail structure, such as a link's target or title.

Such a string can hold pieces of different kinds, such as entities, so it is given with a table of its pieces. Take the image Its alternative text comes through the text callback, but its title is the XtkMarkdownAttribute XtkMarkdownSpanImgDetail::title, with three pieces:

![alt text](http://example.org/image.png 'foo " bar')

substring_offsets[0] is always 0, and the offset after the last piece is always the size. Only XTK_MARKDOWN_TEXT_NORMAL, XTK_MARKDOWN_TEXT_ENTITY and XTK_MARKDOWN_TEXT_NULLCHAR pieces occur. An empty attribute has size 0 and no pieces.

Field Type Description
text const XtkMarkdownChar * The string (not NUL-terminated); valid only during the callback.
size XtkMarkdownSize Its length.
substring_types const XtkMarkdownTextType * Each piece's type.
substring_offsets const XtkMarkdownOffset * Each piece's start in text, then one more equal to size.

XtkMarkdownBlockUlDetail

The detail of XTK_MARKDOWN_BLOCK_UL, a bulleted list.

Field Type Description
is_tight int Non-zero for a tight list (no blank lines between items), 0 for a loose one
mark XtkMarkdownChar The bullet character in the source: '-', '+' or '*'

XtkMarkdownBlockOlDetail

The detail of XTK_MARKDOWN_BLOCK_OL, a numbered list.

Field Type Description
start unsigned The number of the first item
is_tight int Non-zero for a tight list (no blank lines between items), 0 for a loose one
mark_delimiter XtkMarkdownChar The character after the numbers in the source: '.' or ')'

XtkMarkdownBlockLiDetail

The detail of XTK_MARKDOWN_BLOCK_LI, a list item.

Field Type Description
is_task int Non-zero for a task item (- [ ]); only with XTK_MARKDOWN_FLAG_TASKLISTS
task_mark XtkMarkdownChar For a task item, the character between the brackets: 'x', 'X' or ' '; otherwise not set
task_mark_offset XtkMarkdownOffset For a task item, the offset of that character in the input, so a program can toggle it

XtkMarkdownBlockHDetail

The detail of XTK_MARKDOWN_BLOCK_H, a heading.

Field Type Description
level unsigned The heading's level, 1 to 6

XtkMarkdownBlockCodeDetail

The detail of XTK_MARKDOWN_BLOCK_CODE, a code block.

Field Type Description
info XtkMarkdownAttribute The fence's whole info string, after the backticks; empty for an indented block.
language XtkMarkdownAttribute The first word of the info string, normally the language.
fence_char XtkMarkdownChar The fence character, '‘’ or '~'; 0 for an indented code block

XtkMarkdownBlockTableDetail

The detail of XTK_MARKDOWN_BLOCK_TABLE.

Field Type Description
column_count unsigned The number of columns
head_row_count unsigned The number of header rows (always 1)
body_row_count unsigned The number of body rows

XtkMarkdownBlockTdDetail

The detail of XTK_MARKDOWN_BLOCK_TH and XTK_MARKDOWN_BLOCK_TD, a table cell.

Field Type Description
align XtkMarkdownAlign The column's alignment.

XtkMarkdownBlockAdmonitionDetail

The detail of XTK_MARKDOWN_BLOCK_ADMONITION.

Field Type Description
type XtkMarkdownAttribute The kind, in lowercase: "note", "tip", "important", "warning" or "caution"

XtkMarkdownSpanADetail

The detail of XTK_MARKDOWN_SPAN_A, a link.

Field Type Description
href XtkMarkdownAttribute The link's target.
title XtkMarkdownAttribute Its title; empty when it has none.
is_autolink int Non-zero for an autolink (<https://...>, or a bare address with a permissive flag)

XtkMarkdownSpanImgDetail

The detail of XTK_MARKDOWN_SPAN_IMG, an image.

Field Type Description
source XtkMarkdownAttribute The image's location.
title XtkMarkdownAttribute Its title; empty when it has none.

XtkMarkdownSpanWikilinkDetail

The detail of XTK_MARKDOWN_SPAN_WIKILINK.

Field Type Description
target XtkMarkdownAttribute The page linked to: the part before the '|', or all of it.

XtkMarkdownSpanFootnoteReferenceDetail

The detail of XTK_MARKDOWN_SPAN_FOOTNOTE_REFERENCE.

Field Type Description
id unsigned int The footnote's number, from 1, in the order footnotes are first referenced
reference_id unsigned int This reference's number, from 1, among the references to the same footnote
label XtkMarkdownAttribute The label as written, for example "1" or "note"

XtkMarkdownBlockFootnoteDefinitionDetail

The detail of XTK_MARKDOWN_BLOCK_FOOTNOTE_DEFINITION.

Field Type Description
id unsigned int The footnote's number, from 1, as its references have it
reference_count unsigned int The number of references to it
label XtkMarkdownAttribute The label as written

XtkMarkdownBlockBlankDetail

The detail of XTK_MARKDOWN_BLOCK_BLANK.

Field Type Description
line_count unsigned The number of blank lines in the run

XtkMarkdownParser

What to parse and whom to tell: the dialect flags and the program's callbacks.

Zero the structure and fill in the fields. The five main callbacks must all be set. Each gets the user_data given to xtk_markdown_parse(), and returns 0 to go on or non-zero to stop the parse. For the block and span callbacks, detail points to the detail structure of the kind (see XtkMarkdownBlockType and XtkMarkdownSpanType) or is NULL; it is valid only during the call.

Field Type Description
abi_version unsigned Must be 0; any other value makes xtk_markdown_parse() return -1.
flags unsigned The dialect: an OR of XTK_MARKDOWN_FLAG_* values, or an XTK_MARKDOWN_DIALECT_* set.
enter_block int (*)(XtkMarkdownBlockType, void *, void *) Called when a block starts, with its kind and detail.
leave_block int (*)(XtkMarkdownBlockType, void *, void *) Called when a block ends, with its kind and detail.
enter_span int (*)(XtkMarkdownSpanType, void *, void *) Called when a span starts, with its kind and detail.
leave_span int (*)(XtkMarkdownSpanType, void *, void *) Called when a span ends, with its kind and detail.
text int (*)(XtkMarkdownTextType, const XtkMarkdownChar *, XtkMarkdownSize, void *) Called for each run of text inside the current block or span, with its kind, the text (not NUL-terminated) and its size.
debug_log void (*)(const char *, void *) Called with a message when something goes wrong (out of memory, a bad abi_version); may be NULL. For a programmer's diagnosis, not for showing to a user.
syntax void (*)(void) Not used; set it to NULL.

Constants

XTK_MARKDOWN_FLAG_COLLAPSEWHITESPACE

#define XTK_MARKDOWN_FLAG_COLLAPSEWHITESPACE 0x1

Collapse runs of white space in normal text into one space

XTK_MARKDOWN_FLAG_PERMISSIVEATXHEADERS

#define XTK_MARKDOWN_FLAG_PERMISSIVEATXHEADERS 0x2

Allow a heading with no space after the hashes (###heading)

#define XTK_MARKDOWN_FLAG_PERMISSIVEURLAUTOLINKS 0x4

Make bare URLs links, without < and >

#define XTK_MARKDOWN_FLAG_PERMISSIVEEMAILAUTOLINKS 0x8

Make bare e-mail addresses links, without <, > and mailto:

XTK_MARKDOWN_FLAG_NOINDENTEDCODEBLOCKS

#define XTK_MARKDOWN_FLAG_NOINDENTEDCODEBLOCKS 0x10

No indented code blocks; only fenced code blocks

XTK_MARKDOWN_FLAG_NOHTMLBLOCKS

#define XTK_MARKDOWN_FLAG_NOHTMLBLOCKS 0x20

No raw HTML blocks

XTK_MARKDOWN_FLAG_NOHTMLSPANS

#define XTK_MARKDOWN_FLAG_NOHTMLSPANS 0x40

No inline raw HTML

XTK_MARKDOWN_FLAG_TABLES

#define XTK_MARKDOWN_FLAG_TABLES 0x100

Pipe tables

XTK_MARKDOWN_FLAG_STRIKETHROUGH

#define XTK_MARKDOWN_FLAG_STRIKETHROUGH 0x200

Strikethrough, ~~text~~

#define XTK_MARKDOWN_FLAG_PERMISSIVEWWWAUTOLINKS 0x400

Make addresses that start with www. links, with no scheme

XTK_MARKDOWN_FLAG_TASKLISTS

#define XTK_MARKDOWN_FLAG_TASKLISTS 0x800

Task list items, - [ ] and - [x]

XTK_MARKDOWN_FLAG_LATEXMATHSPANS

#define XTK_MARKDOWN_FLAG_LATEXMATHSPANS 0x1000

LaTeX math, $...$ and $$...$$

#define XTK_MARKDOWN_FLAG_WIKILINKS 0x2000

Wiki links, [[target]] and [[target|label]]

XTK_MARKDOWN_FLAG_UNDERLINE

#define XTK_MARKDOWN_FLAG_UNDERLINE 0x4000

Underline, _text_ (then _ no longer makes emphasis)

XTK_MARKDOWN_FLAG_HARD_SOFT_BREAKS

#define XTK_MARKDOWN_FLAG_HARD_SOFT_BREAKS 0x8000

Report every soft line break as a hard one

XTK_MARKDOWN_FLAG_SPOILERS

#define XTK_MARKDOWN_FLAG_SPOILERS 0x10000

Spoilers, ||text||

XTK_MARKDOWN_FLAG_SUPERSCRIPTS

#define XTK_MARKDOWN_FLAG_SUPERSCRIPTS 0x20000

Superscript, ^text^

XTK_MARKDOWN_FLAG_SUBSCRIPTS

#define XTK_MARKDOWN_FLAG_SUBSCRIPTS 0x40000

Subscript, ~text~ (then one tilde no longer strikes through)

XTK_MARKDOWN_FLAG_ADMONITIONS

#define XTK_MARKDOWN_FLAG_ADMONITIONS 0x80000

Admonitions, a block quote that starts with [!NOTE] and the like

XTK_MARKDOWN_FLAG_FOOTNOTES

#define XTK_MARKDOWN_FLAG_FOOTNOTES 0x100000

Footnotes, [^label] and [^label]: text

XTK_MARKDOWN_FLAG_HIGHLIGHT

#define XTK_MARKDOWN_FLAG_HIGHLIGHT 0x200000

Highlight, ==text==

XTK_MARKDOWN_FLAG_PRESERVEBLANKLINES

#define XTK_MARKDOWN_FLAG_PRESERVEBLANKLINES 0x400000

Report runs of blank lines as XTK_MARKDOWN_BLOCK_BLANK

#define XTK_MARKDOWN_FLAG_PERMISSIVEAUTOLINKS (XTK_MARKDOWN_FLAG_PERMISSIVEEMAILAUTOLINKS | XTK_MARKDOWN_FLAG_PERMISSIVEURLAUTOLINKS | XTK_MARKDOWN_FLAG_PERMISSIVEWWWAUTOLINKS)

All three kinds of bare autolink: URLs, e-mail addresses and www. addresses.

XTK_MARKDOWN_FLAG_NOHTML

#define XTK_MARKDOWN_FLAG_NOHTML (XTK_MARKDOWN_FLAG_NOHTMLBLOCKS | XTK_MARKDOWN_FLAG_NOHTMLSPANS)

No raw HTML, neither blocks nor inline.

XTK_MARKDOWN_DIALECT_COMMONMARK

#define XTK_MARKDOWN_DIALECT_COMMONMARK 0

Plain CommonMark: no extensions.

XTK_MARKDOWN_DIALECT_GITHUB

#define XTK_MARKDOWN_DIALECT_GITHUB (XTK_MARKDOWN_FLAG_PERMISSIVEAUTOLINKS | XTK_MARKDOWN_FLAG_TABLES | XTK_MARKDOWN_FLAG_STRIKETHROUGH | XTK_MARKDOWN_FLAG_TASKLISTS | XTK_MARKDOWN_FLAG_ADMONITIONS | XTK_MARKDOWN_FLAG_FOOTNOTES)

The flags closest to GitHub's Markdown: bare autolinks, tables, strikethrough, task lists, admonitions and footnotes. The set can grow in later versions.

Functions

xtk_markdown_parse

int xtk_markdown_parse(
    const XtkMarkdownChar *text,
    XtkMarkdownSize size,
    const XtkMarkdownParser *parser,
    void *user_data);

Parse a Markdown document, calling the parser's callbacks as it goes.

The whole document is parsed in this call; the callbacks are called from inside it. The parser keeps no state between calls, so separate parses can run in separate threads.

Parameter Description
text The document; it need not be NUL-terminated
size The document's length in bytes
parser The dialect flags and the callbacks; copied at the start
user_data Passed to every callback

Returns: 0 when the whole document was parsed; -1 when memory runs out or abi_version is not 0; or the non-zero value a callback returned to stop the parse