---
name: "lowdown_doc_parse"
section: "3"
platform: "linux"
package: "lowdown"
version: "3.2.1-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/lowdown_doc_parse"
---

# lowdown\_doc\_parse(3)

parse a Markdown document into an AST

## NAME

**lowdown\_doc\_parse** – parse a Markdown document into an AST

## LIBRARY

library “liblowdown”

## SYNOPSIS

**#include \<sys/queue.h\>**

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

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

*struct lowdown\_node \**\

**lowdown\_doc\_parse**(*struct lowdown\_doc \*doc*, *size\_t \*maxn*, *const char \*input*, *size\_t inputsz*, *struct lowdown\_metaq \*metaq*);

## DESCRIPTION

Parse a [lowdown(5)](/lowdown/5.md) document *input* of length *inputsz* into an AST with the parser *doc*. The *maxn* argument, if not NULL, is set to one greater than the highest node identifier. Its value is undefined if the function returns NULL.

If *metaq* is not NULL, it is filled in with document metadata (if any). Metadata key names are canonicalised and duplicate names are ignored. The results should be freed with [lowdown\_metaq\_free(3)](/lowdown_metaq_free/3.md).

This function may be invoked multiple times with a single *doc* and different input.

## RETURN VALUES

Returns the root of the parse tree or NULL on memory allocation failure. If not NULL, the returned node is always of type LOWDOWN\_ROOT.

## EXAMPLES

The following parses *b* of length *bsz*. It first allocates the parser, then the document, then the renderer (HTML is used in this case). Then it passes output to the renderer, prints it, and cleans up resources. On any memory errors, it exits with [err(3)](/err/3.md).

```
struct lowdown_doc *doc;
struct lowdown_node *n;
struct lowdown_buf *ob;
void *rndr;
if ((doc = lowdown_doc_new(NULL)) == NULL)
	err(1, NULL);
if ((n = lowdown_doc_parse(doc, NULL, b, bsz, NULL)) == NULL)
	err(1, NULL);
if ((rndr = lowdown_html_new(NULL)) == NULL)
	err(1, NULL);
if ((ob = lowdown_buf_new(1024)) == NULL)
	err(1, NULL);
if (!lowdown_html_rndr(ob, rndr, n))
	err(1, NULL);
fwrite(stdout, 1, ob->size, ob->data);
lowdown_buf_free(ob);
lowdown_html_rndr_free(rndr);
lowdown_node_free(n);
lowdown_doc_free(doc);
```

## SEE ALSO

[lowdown(3)](/lowdown/3.md)
