public
Description: An implementation of markdown in C, using a PEG grammar
Clone URL: git://github.com/jgm/peg-markdown.git
Search Repo:
jgm (author)
Thu May 15 22:48:59 -0700 2008
commit  a2e3e304e279d7e63b645ee0ab07af0c81d5a88e
tree    3ee83fd0399fa2a10e3fe53b00753f267cdc218f
parent  0f7d17cb4d21585897b6246fe519657d5b9bb44a
peg-markdown / markdown_peg.h
100644 96 lines (80 sloc) 2.532 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/* markdown_peg.h */
 
extern char *strdup(const char *string);
 
/**********************************************************************
 
  Data Structures
 
 ***********************************************************************/
 
/* Information (label, URL and title) for a link. */
struct Link {
    struct Element *label;
    char *url;
    char *title;
};
 
typedef struct Link link;
 
/* Union for contents of an Element (string, list, or link). */
union Contents {
    char *str;
    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. */
            RAW, /* Raw markdown to be processed further */
            SPACE,
            LINEBREAK,
            ELLIPSIS,
            EMDASH,
            ENDASH,
            APOSTROPHE,
            SINGLEQUOTED,
            DOUBLEQUOTED,
            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,
            NOTE,
          };
 
/* Semantic value of a parsing action. */
struct Element {
    int key;
    union Contents contents;
    struct Element *children;
    struct Element *next;
};
 
typedef struct Element element;
 
enum markdown_extensions {
    EXT_SMART = 1,
    EXT_NOTES = 2
};
 
element *cons(element new, element *list);
element *reverse(element *list);
element markdown(char *string, int extensions);
 
/* Output formats. */
enum formats { HTML_FORMAT,
               LATEX_FORMAT,
               GROFF_MM_FORMAT
             };
 
void print_html_string(char *str, bool obfuscate);
void print_html_element(element elt, bool obfuscate);
void print_html_element_list(element *list, bool obfuscate);
void print_latex_string(char *str);
void print_latex_element(element elt);
void print_latex_element_list(element *list);
void print_latex_element(element elt);
void print_groff_string(char *str);
void print_groff_mm_element(element elt, int count);
void print_groff_mm_element_list(element *list);
void print_groff_mm_element(element elt, int count);
void print_element(element elt, int format);