---
name: "lowdown_diff"
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_diff"
---

# lowdown\_diff(3)

compute difference between parsed Markdown trees

## NAME

**lowdown\_diff** – compute difference between parsed Markdown trees

## LIBRARY

library “liblowdown”

## SYNOPSIS

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

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

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

*struct lowdown\_node \**\

**lowdown\_diff**(*const struct lowdown\_node \*nold*, *const struct lowdown\_node \*nnew*, *size\_t \*maxn*);

## DESCRIPTION

Computes the difference between two Markdown trees, the source *nold* and destination *nnew*, parsed by [lowdown\_doc\_parse(3)](/lowdown_doc_parse/3.md). It uses the *enum* *lowdown\_chng* type in the return tree's nodes to dictate insertions into and deletions from *nold*. The *maxn* argument, if not NULL, is set to one greater than the highest node identifier of the returned tree.

## RETURN VALUES

Returns a pointer to the difference tree or NULL on memory exhaustion. The pointer must be freed with [lowdown\_node\_free(3)](/lowdown_node_free/3.md).

## EXAMPLES

The following parses and compares *old* of length *osz* and *new* of length *nsz*. 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 *no, *nn, *diff;
struct lowdown_buf *ob;
void *rndr;
if ((doc = lowdown_doc_new(NULL)) == NULL)
	err(1, NULL);
if ((no = lowdown_doc_parse(doc, NULL, old, osz, NULL)) == NULL)
	err(1, NULL);
if ((nn = lowdown_doc_parse(doc, NULL, new, nsz, NULL)) == NULL)
	err(1, NULL);
if ((diff = lowdown_diff(no, nn, 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, diff))
	err(1, NULL);
fwrite(stdout, 1, ob->size, ob->data);
lowdown_buf_free(ob);
lowdown_html_rndr_free(rndr);
lowdown_node_free(no);
lowdown_node_free(nn);
lowdown_node_free(diff);
lowdown_doc_free(doc);
```

## SEE ALSO

[lowdown(3)](/lowdown/3.md) Gregory Cobena, Serge Abiteboul, and Amelie Marian, *Detecting Changes in XML Documents*, 2002, https://www.cs.rutgers.edu/~amelie/papers/2002/diff.pdf. Wu Sun, Manber Udi, and Myers Gene, “An O(NP) sequence comparison algorithm”, *Information Processing Letters*, Issue 6, Volume 35, 1990.
