---
name: "soldout_markdown"
section: "3"
platform: "linux"
package: "libsoldout-dev"
version: "1.4-7+b1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/soldout_markdown"
---

# soldout\_markdown(3)

parse markdown document

## NAME

**soldout\_markdown**, **markdown** – parse markdown document

## SYNOPSIS

**#include \<markdown.h\>**

**#define MKD\_CELL\_ALIGN\_DEFAULT**

**#define MKD\_CELL\_ALIGN\_LEFT**

**#define MKD\_CELL\_ALIGN\_RIGHT**

**#define MKD\_CELL\_ALIGN\_CENTER**

**#define MKD\_CELL\_ALIGN\_MASK**

**#define MKD\_CELL\_HEAD**

**#define MKD\_LIST\_ORDERED**

**#define MKD\_LI\_BLOCK**

*void*\

**markdown**(*struct buf \*ob*, *struct buf \*ib*, *const struct mkd\_renderer \*rndr*);

## DESCRIPTION

The **markdown**() function parses the input buffer *ib* and renders it into the output buffer *ob*; *rndr* is a pointer to the renderer structure.

Function pointers in *struct mkd\_renderer* can be NULL. A null block-level callback will make the corresponding block disappear from the output, as if the callback was an empty function. A null span-level callback will cause the corresponding element to be treated as normal characters, copied verbatim to the output. Moreover, span-level callbacks return an integer, which tells whether the renderer accepts to render the item (non-zero return value) or whether it should be copied verbatim (zero return value).

The first argument of a renderer function is always the output buffer, where the function is supposed to write its output. The last argument of a renderer function is always a private pointer, which is *opaque* member of *struct* *mkd\_renderer*. libsoldout itself never does nothing with this data.

*emph\_chars* is a zero-terminated string which contains the set of characters that trigger emphasis. In regular markdown, emphasis is only triggered by ‘\_’ and ‘\*’, but in some extensions it might be useful to add other characters to this list. The character that triggered the emphasis is then passed to *emphasis*, *double\_emphasis* and *triple\_emphasis* function callbacks through the parameter *c*.

The *normal\_text* callback should perform whatever escape is needed to have the output looking like the input data.

libsoldout supports PHP-Markdown-like tables. It uses the following flags: MKD\_CELL\_ALIGN\_DEFAULT, MKD\_CELL\_ALIGN\_LEFT, MKD\_CELL\_ALIGN\_RIGHT, MKD\_CELL\_ALIGN\_CENTER, MKD\_CELL\_ALIGN\_MASK, MKD\_CELL\_HEAD in these function callbacks: *table\_cell* and *table\_row*.

MKD\_LIST\_ORDERED, MKD\_LI\_BLOCK are used as flags in these function callbacks: *list* and *listitem*.

### Types

- *enum mkd\_autolink*

  type of autolink:

  - MKDA\_NOT\_AUTOLINK

    used internally when it is not an autolink.

  - MKDA\_NORMAL

    normal http/https/ftp link.

  - MKDA\_EXPLICIT\_EMAIL

    e-mail link with explicit mailto.

  - MKDA\_IMPLICIT\_EMAIL

    e-mail link without mailto.

- *struct mkd\_renderer*

  consists of the following fields:

  - Document level callbacks

    - *prolog*

      a pointer to a *void* **function**(*struct buf \*ob*, *void \*opaque*)

    - *epilog*

      a pointer to a *void* **function**(*struct buf \*ob*, *void \*opaque*)

      - Block level callbacks (NULL skips the block)

        - *blockcode*

          a pointer to a *void* **function**(*struct buf \*ob*, *struct buf \*text*, *void \*opaque*)

        - *blockquote*

          a pointer to a *void* **function**(*struct buf \*ob*, *struct buf \*text*, *void \*opaque*)

        - *blockhtml*

          a pointer to a *void* **function**(*struct buf \*ob*, *struct buf \*text*, *void \*opaque*)

        - *header*

          a pointer to a *void* **function**(*struct buf \*ob*, *struct buf \*text*, *int level*, *void \*opaque*)

        - *hrule*

          a pointer to a *void* **function**(*struct buf \*ob*, *void \*opaque*)

        - *list*

          a pointer to a *void* **function**(*struct buf \*ob*, *struct buf \*text*, *int flags*, *void \*opaque*)

        - *listitem*

          a pointer to a *void* **function**(*struct buf \*ob*, *struct buf \*text*, *int flags*, *void \*opaque*)

        - *paragraph*

          a pointer to a *void* **function**(*struct buf \*ob*, *struct buf \*text*, *void \*opaque*)

        - *table*

          a pointer to a *void* **function**(*struct buf \*ob*, *struct buf \*head\_row*, *struct buf \*rows*, *void \*opaque*)

        - *table\_cell*

          a pointer to a *void* **function**(*struct buf \*ob*, *struct buf \*text*, *int flags*, *void \*opaque*)

        - *table\_row*

          a pointer to a *void* **function**(*struct buf \*ob*, *struct buf \*cells*, *int flags*, *void \*opaque*)

      - Span level callbacks (NULL or return 0 prints the span verbatim)

        - *autolink*

          a pointer to a *int* **function**(*struct buf \*ob*, *struct buf \*link*, *enum mkd\_autolink type*, *void \*opaque*)

        - *codespan*

          a pointer to a *int* **function**(*struct buf \*ob*, *struct buf \*text*, *void \*opaque*)

        - *emphasis*

          a pointer to a *int* **function**(*struct buf \*ob*, *struct buf \*text*, *char c*, *void \*opaque*)

        - *double\_emphasis*

          a pointer to a *int* **function**(*struct buf \*ob*, *struct buf \*text*, *char c*, *void \*opaque*)

        - *triple\_emphasis*

          a pointer to a *int* **function**(*struct buf \*ob*, *struct buf \*text*, *char c*, *void \*opaque*)

        - *image*

          a pointer to a *int* **function**(*struct buf \*ob*, *struct buf \*link*, *struct buf \*title*, *struct buf \*alt*, *void \*opaque*)

        - *linebreak*

          a pointer to a *int* **function**(*struct buf \*ob*, *void \*opaque*)

        - *link*

          a pointer to a *int* **function**(*struct buf \*ob*, *struct buf \*link*, *struct buf \*title*, *struct buf \*content*, *void \*opaque*)

        - *raw\_html\_tag*

          a pointer to a *int* **function**(*struct buf \*ob*, *struct buf \*tag*, *void \*opaque*)

      - Low level callbacks (NULL copies input directly into the output)

        - *entity*

          a pointer to a *void* **function**(*struct buf \*ob*, *struct buf \*entity*, *void \*opaque*)

        - *normal\_text*

          a pointer to a *void* **function**(*struct buf \*ob*, *struct buf \*text*, *void \*opaque*)

      - Renderer data

        - *int* *max\_work\_stack*

          prevent arbitrary deep recursion.

        - *const char \** *emph\_chars*

          chars that trigger emphasis rendering.

        - *void \** *opaque*

          opaque data send to every rendering callback.

## RETURN VALUES

The **markdown**() function does not return a value.

## SEE ALSO

[soldout(3)](/soldout/3.md), [soldout\_buffer(3)](/soldout_buffer/3.md), [soldout\_renderers(3)](/soldout_renderers/3.md)

## AUTHORS

The **soldout** library was written by Natasha "Kerensikova" Porte ⟨*natacha@instinctive.eu*⟩. Manual page was originally written by Massimo Manghi ⟨*mxmanghi@apache.org*⟩, and rewritten to mdoc format by Svyatoslav Mishyn ⟨*juef@openmailbox.org*⟩.
