1LOWDOWN_DIFF(3)          BSD Library Functions Manual          LOWDOWN_DIFF(3)
2

NAME

4     lowdown_diff — compute difference between parsed Markdown trees
5

LIBRARY

7     library “liblowdown”
8

SYNOPSIS

10     #include <sys/queue.h>
11     #include <stdio.h>
12     #include <lowdown.h>
13
14     struct lowdown_node *
15     lowdown_diff(const struct lowdown_node *nold,
16         const struct lowdown_node *nnew, size_t *maxn);
17

DESCRIPTION

19     Computes the difference between two Markdown trees, the source nold and
20     destination nnew, parsed by lowdown_doc_parse(3).  It uses the enum
21     lowdown_chng type in the return tree's nodes to dictate insertions into
22     and deletions from nold.  The maxn argument, if not NULL, is set to one
23     greater than the highest node identifier of the returned tree.
24

RETURN VALUES

26     Returns a pointer to the difference tree or NULL on memory exhaution.
27     The pointer must be freed with lowdown_node_free(3).
28

EXAMPLES

30     The following parses and compares old of length osz and new of length
31     nsz.  It first allocates the parser, then the document, then the renderer
32     (HTML is used in this case).  Then it passes output to the renderer,
33     prints it, and cleans up resources.  On any memory errors, it exits with
34     err(3).
35
36           struct lowdown_doc *doc;
37           struct lowdown_node *no, *nn, *diff;
38           struct lowdown_buf *ob;
39           void *rndr;
40
41           if ((doc = lowdown_doc_new(NULL)) == NULL)
42                   err(1, NULL);
43           if ((no = lowdown_doc_parse(doc, NULL, old, osz, NULL)) == NULL)
44                   err(1, NULL);
45           if ((nn = lowdown_doc_parse(doc, NULL, new, nsz, NULL)) == NULL)
46                   err(1, NULL);
47           if ((diff = lowdown_diff(no, nn, NULL)) == NULL)
48                   err(1, NULL);
49           if ((rndr = lowdown_html_new(NULL)) == NULL)
50                   err(1, NULL);
51           if ((ob = lowdown_buf_new(1024)) == NULL)
52                   err(1, NULL);
53           if (!lowdown_html_rndr(ob, rndr, diff))
54                   err(1, NULL);
55
56           fwrite(stdout, 1, ob->size, ob->data);
57
58           lowdown_buf_free(ob);
59           lowdown_html_rndr_free(rndr);
60           lowdown_node_free(no);
61           lowdown_node_free(nn);
62           lowdown_node_free(diff);
63           lowdown_doc_free(doc);
64

SEE ALSO

66     lowdown(3)
67
68     Gregory Cobena, Serge Abiteboul, and Amelie Marian, Detecting Changes in
69     XML Documents, https://www.cs.rutgers.edu/~amelie/papers/2002/diff.pdf,
70     2002.
71
72     Wu Sun, Manber Udi, and Myers Gene, “An O(NP) sequence comparison
73     algorithm”, Issue 6, Information Processing Letters, Volume 35, 1990.
74
75BSD                            December 17, 2023                           BSD
Impressum