forked from fletcher/MultiMarkdown-4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
libMultiMarkdown.h
181 lines (163 loc) · 5.02 KB
/
libMultiMarkdown.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*
libMultiMarkdown.h -- MultiMarkdown library header
(c) 2013-2015 Fletcher T. Penney (http://fletcherpenney.net/).
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License or the MIT
license. See LICENSE for details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
//#include "parser.h"
/* Main API commands */
char * markdown_to_string(const char * source, unsigned long extensions, int format);
bool has_metadata(const char *source, unsigned long extensions);
char * extract_metadata_keys(const char *source, unsigned long extensions);
char * extract_metadata_value(const char *source, unsigned long extensions, char *key);
char * mmd_version(void);
/* These are the basic extensions */
enum parser_extensions {
EXT_COMPATIBILITY = 1 << 0, /* Markdown compatibility mode */
EXT_COMPLETE = 1 << 1, /* Create complete document */
EXT_SNIPPET = 1 << 2, /* Create snippet only */
EXT_HEAD_CLOSED = 1 << 3, /* for use by parser */
EXT_SMART = 1 << 4, /* Enable Smart quotes */
EXT_NOTES = 1 << 5, /* Enable Footnotes */
EXT_NO_LABELS = 1 << 6, /* Don't add anchors to headers, etc. */
EXT_FILTER_STYLES = 1 << 7, /* Filter out style blocks */
EXT_FILTER_HTML = 1 << 8, /* Filter out raw HTML */
EXT_PROCESS_HTML = 1 << 9, /* Process Markdown inside HTML */
EXT_NO_METADATA = 1 << 10, /* Don't parse Metadata */
EXT_OBFUSCATE = 1 << 11, /* Mask email addresses */
EXT_CRITIC = 1 << 12, /* Critic Markup Support */
EXT_CRITIC_ACCEPT = 1 << 13, /* Accept all proposed changes */
EXT_CRITIC_REJECT = 1 << 14, /* Reject all proposed changes */
EXT_RANDOM_FOOT = 1 << 15, /* Use random numbers for footnote links */
EXT_HEADINGSECTION = 1 << 16, /* Group blocks under parent heading */
EXT_ESCAPED_LINE_BREAKS = 1 << 17, /* Escaped line break */
EXT_NO_STRONG = 1 << 18, /* Don't allow nested <strong>'s */
EXT_NO_EMPH = 1 << 19, /* Don't allow nested <emph>'s */
EXT_FAKE = 1 << 31, /* 31 is highest number allowed */
};
/* Define output formats we support -- first in list is default. As a rule, */
/* formats with no comment should be treated with suspicion and care. Use of */
/* some export formats may cause crashing or undefined behavior. */
enum export_formats {
ORIGINAL_FORMAT, /* Transclusion happens, but no parsing */
HTML_FORMAT, /* Well supported */
TEXT_FORMAT, /* Not currently used, may exit host process */
LATEX_FORMAT,
MEMOIR_FORMAT,
BEAMER_FORMAT,
OPML_FORMAT,
ODF_FORMAT,
RTF_FORMAT, /* Not recommended for production code, may crash */
CRITIC_ACCEPT_FORMAT,
CRITIC_REJECT_FORMAT,
CRITIC_HTML_HIGHLIGHT_FORMAT,
LYX_FORMAT, /* Not actively developed */
TOC_FORMAT,
};
/* These are the identifiers for node types */
enum keys {
NO_TYPE,
LIST,
STR,
APOSTROPHE,
FOOTER,
PARA,
PLAIN,
LINEBREAK,
SPACE,
HEADINGSECTION,
H1, H2, H3, H4, H5, H6, H7, /* Keep these in order */
METADATA,
METAKEY,
METAVALUE,
MATHSPAN,
STRONG,
EMPH,
LINK,
SOURCE,
TITLE,
REFNAME,
AUTOLABEL,
IMAGE,
IMAGEBLOCK,
NOTEREFERENCE,
CODE,
HTML,
ELLIPSIS,
ENDASH,
EMDASH,
SINGLEQUOTED,
DOUBLEQUOTED,
BLOCKQUOTE,
BLOCKQUOTEMARKER,
RAW,
VERBATIM,
VERBATIMTYPE,
VERBATIMFENCE,
DEFLIST,
TERM,
DEFINITION,
HRULE,
ORDEREDLIST,
BULLETLIST,
LISTITEM,
HTMLBLOCK,
TABLE,
TABLECAPTION,
TABLELABEL,
TABLESEPARATOR,
TABLECELL,
CELLSPAN,
TABLEROW,
TABLEBODY,
TABLEHEAD,
LINKREFERENCE,
NOTESOURCE,
CITATIONSOURCE,
SOURCEBRANCH,
NOTELABEL,
GLOSSARYLABEL,
ATTRVALUE,
ATTRKEY,
GLOSSARYSOURCE,
GLOSSARYSORTKEY,
GLOSSARYTERM,
CITATION,
NOCITATION,
CRITICADDITION,
CRITICDELETION,
CRITICSUBSTITUTION,
CRITICHIGHLIGHT,
CRITICCOMMENT,
SUPERSCRIPT,
SUBSCRIPT,
VARIABLE,
ABBREVIATION,
ABBR,
ABBRSTART,
ABBRSTOP,
TOC,
KEY_COUNTER /* This *MUST* be the last item in the list */
};
/* This is the element used in the resulting parse tree */
struct node {
short key; /* what type of element are we? */
char *str; /* relevant string from source for element */
struct link_data *link_data; /* store link info when relevant */
struct node *children; /* child elements */
struct node *next; /* next element */
};
typedef struct node node;
/* Define a structure to simplify handling of links */
struct link_data {
char *label; /* if this is a reference link */
char *source; /* source URL */
char *title; /* title string */
node *attr; /* attribute tree */
};
typedef struct link_data link_data;