public
Description: An implementation of markdown in C, using a PEG grammar
Clone URL: git://github.com/jgm/peg-markdown.git
jgm (author)
Tue May 06 20:53:36 -0700 2008
commit  8a59c5dee96c51a4099a63f84e70fbf347a38827
tree    1e0bf05fbb8e4e1a45cdfd95b903ec5e870e06b8
parent  2a3daabc3b5f87fde7098c9049dd8885d203ca56
peg-markdown / markdown_peg.h
100644 74 lines (58 sloc) 1.726 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/* markdown_peg.h */
 
extern char *strdup(const char *string);
 
/**********************************************************************
 
  Data Structures
 
 ***********************************************************************/
 
/* Information (label, URL and title) for a link. */
struct Link {
    struct ElementListItem *label;
    char *url;
    char *title;
};
 
typedef struct Link link;
 
/* Union for contents of an Element (string, list, or link). */
union Contents {
    char *str;
    struct ElementListItem *list;
    struct Link link;
};
 
/* Types of semantic values returned by parsers. */
enum keys { LIST, /* A generic list of values. For ordered and bullet lists, see below. */
            SPACE,
            LINEBREAK,
            STR,
            LINK,
            IMAGE,
            CODE,
            HTML,
            EMPH,
            STRONG,
            PLAIN,
            PARA,
            LISTITEM,
            BULLETLIST,
            ORDEREDLIST,
            H1, H2, H3, H4, H5, H6, /* Code assumes that these are in order. */
            BLOCKQUOTE,
            VERBATIM,
            HTMLBLOCK,
            HRULE,
            REFERENCE
          };
 
/* Semantic value of a parsing action. */
struct Element {
    int key;
    union Contents contents;
};
 
typedef struct Element element;
 
/* Node in linked list of Elements. */
struct ElementListItem {
    element val;
    struct ElementListItem *next;
};
 
typedef struct ElementListItem item;
 
enum markdown_extensions {
    EXT_SMART_QUOTES = 1,
    EXT_SMART_DASHES = 2
};
 
element markdown(int extensions, char *string);