forked from fletcher/peg-multimarkdown
-
Notifications
You must be signed in to change notification settings - Fork 1
/
markdown_peg.h
143 lines (126 loc) · 6.42 KB
/
markdown_peg.h
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#ifndef __MARKDOWN_PEG_H__
#define __MARKDOWN_PEG_H__
/* markdown_peg.h */
#include "markdown_lib.h"
#include "glib.h"
#ifndef WIN32
extern char *strdup(const char *string);
#endif
/* Information (label, URL and title) for a link. */
struct Link {
struct Element *label;
char *url;
char *title;
struct Element *attr;
char *identifier;
};
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. */
#define ELEMENT_LIST(V) \
V(LIST) \
V(RAW) \
V(SPACE) \
V(LINEBREAK) \
V(ELLIPSIS) \
V(EMDASH) \
V(ENDASH) \
V(APOSTROPHE) \
V(SINGLEQUOTED) \
V(DOUBLEQUOTED) \
V(STR) \
V(LINK) \
V(IMAGE) \
V(IMAGEBLOCK) \
V(CODE) \
V(HTML) \
V(EMPH) \
V(STRONG) \
V(PLAIN) \
V(PARA) \
V(LISTITEM) \
V(BULLETLIST) \
V(ORDEREDLIST) \
V(H1) V(H2) V(H3) V(H4) V(H5) V(H6) V(H7) \
V(BLOCKQUOTE) \
V(VERBATIM) \
V(HTMLBLOCK) \
V(HRULE) \
V(REFERENCE) \
V(NOTE) \
V(CITATION) \
V(NOCITATION) \
V(LOCATOR) \
V(NOTELABEL) \
V(DEFLIST) \
V(TERM) \
V(DEFINITION) \
V(FOOTER) \
V(LABEL) \
V(HEADINGSECTION) \
V(ENDHTML) \
V(TABLE) \
V(TABLEHEAD) \
V(TABLEBODY) \
V(TABLEROW) \
V(TABLECELL) \
V(CELLSPAN) \
V(TABLECAPTION) \
V(TABLELABEL) \
V(TABLESEPARATOR) \
V(AUTOLABEL) \
V(ATTRIBUTE) \
V(ATTRKEY) \
V(ATTRVALUE) \
V(GLOSSARY) \
V(GLOSSARYTERM) \
V(GLOSSARYSORTKEY) \
V(MATHSPAN) \
enum keys {
#define KEY_DECLARATION(name) name,
ELEMENT_LIST(KEY_DECLARATION)
#undef KEY_DECLARATION
};
/* constants for managing Smart Typography */
enum smartelements {
LSQUOTE,
RSQUOTE,
LDQUOTE,
RDQUOTE,
NDASH,
MDASH,
ELLIP,
APOS,
};
enum smartoutput {
HTMLOUT,
LATEXOUT,
};
enum language {
DUTCH,
ENGLISH,
FRENCH,
GERMAN,
SWEDISH,
GERMANGUILL,
};
/* Semantic value of a parsing action. */
struct Element {
int key;
union Contents contents;
struct Element *children;
struct Element *next;
};
typedef struct Element element;
element * parse_references(char *string, int extensions);
element * parse_notes(char *string, int extensions, element *reference_list);
element * parse_labels(char *string, int extensions, element *reference_list, element *note_list);
element * parse_markdown(char *string, int extensions, element *reference_list, element *note_list, element *label_list);
void free_element_list(element * elt);
void free_element(element *elt);
void print_element_list(GString *out, element *elt, int exts);
#endif /* __MARKDOWN_PEG_H__ */