forked from Orc/discount
-
Notifications
You must be signed in to change notification settings - Fork 0
/
markdown.h
219 lines (186 loc) · 6.44 KB
/
markdown.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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#ifndef _MARKDOWN_D
#define _MARKDOWN_D
#include "cstring.h"
/* reference-style links (and images) are stored in an array
* of footnotes.
*/
typedef struct footnote {
Cstring tag; /* the tag for the reference link */
Cstring link; /* what this footnote points to */
Cstring title; /* what it's called (TITLE= attribute) */
int height, width; /* dimensions (for image link) */
int dealloc; /* deallocation needed? */
int refnumber;
int flags;
#define EXTRA_BOOKMARK 0x01
#define REFERENCED 0x02
} Footnote;
/* each input line is read into a Line, which contains the line,
* the offset of the first non-space character [this assumes
* that all tabs will be expanded to spaces!], and a pointer to
* the next line.
*/
typedef enum { chk_text, chk_code,
chk_hr, chk_dash,
chk_tilde, chk_backtick,
chk_equal, chk_dollar } line_type;
typedef struct line {
Cstring text;
struct line *next;
int dle; /* leading indent on the line */
int flags; /* special attributes for this line */
#define PIPECHAR 0x01 /* line contains a | */
#define CHECKED 0x02
line_type kind;
int count;
} Line;
/* a paragraph is a collection of Lines, with links to the next paragraph
* and (if it's a QUOTE, UL, or OL) to the reparsed contents of this
* paragraph.
*/
typedef struct paragraph {
struct paragraph *next; /* next paragraph */
struct paragraph *down; /* recompiled contents of this paragraph */
struct line *text; /* all the text in this paragraph */
char *ident; /* %id% tag for QUOTE */
enum { WHITESPACE=0, CODE, LATEX, QUOTE, MARKUP,
HTML, STYLE, DL, UL, OL, AL, OL_i, OL_I, OL_a, OL_A, LISTITEM,
HDR, HR, TABLE, SOURCE } typ;
enum { IMPLICIT=0, PARA, CENTER} align;
int hnumber; /* <Hn> for typ == HDR */
} Paragraph;
enum { ETX, SETEXT }; /* header types */
typedef struct block {
enum { bTEXT, bSTAR, bUNDER } b_type;
int b_count;
char b_char;
Cstring b_text;
Cstring b_post;
} block;
typedef STRING(block) Qblock;
typedef char* (*mkd_callback_t)(const char*, const int, void*);
typedef void (*mkd_free_t)(char*, void*);
typedef struct callback_data {
void *e_data; /* private data for callbacks */
mkd_callback_t e_url; /* url edit callback */
mkd_callback_t e_flags; /* extra href flags callback */
mkd_free_t e_free; /* edit/flags callback memory deallocator */
} Callback_data;
struct escaped {
char *text;
struct escaped *up;
} ;
/* a magic markdown io thing holds all the data structures needed to
* do the backend processing of a markdown document
*/
typedef struct mmiot {
Cstring out;
Cstring in;
Qblock Q;
int isp;
int reference;
struct escaped *esc;
char *ref_prefix;
STRING(Footnote) *footnotes;
DWORD flags;
#define MKD_NOLINKS 0x00000001
#define MKD_NOIMAGE 0x00000002
#define MKD_NOPANTS 0x00000004
#define MKD_NOHTML 0x00000008
#define MKD_STRICT 0x00000010
#define MKD_TAGTEXT 0x00000020
#define MKD_NO_EXT 0x00000040
#define MKD_CDATA 0x00000080
#define MKD_NOSUPERSCRIPT 0x00000100
#define MKD_NORELAXED 0x00000200
#define MKD_NOTABLES 0x00000400
#define MKD_NOSTRIKETHROUGH 0x00000800
#define MKD_TOC 0x00001000
#define MKD_1_COMPAT 0x00002000
#define MKD_AUTOLINK 0x00004000
#define MKD_SAFELINK 0x00008000
#define MKD_NOHEADER 0x00010000
#define MKD_TABSTOP 0x00020000
#define MKD_NODIVQUOTE 0x00040000
#define MKD_NOALPHALIST 0x00080000
#define MKD_NODLIST 0x00100000
#define MKD_EXTRA_FOOTNOTE 0x00200000
#define MKD_NOSTYLE 0x00400000
#define IS_LABEL 0x08000000
#define USER_FLAGS 0x0FFFFFFF
#define INPUT_MASK (MKD_NOHEADER|MKD_TABSTOP)
Callback_data *cb;
int hasLaTeX;
} MMIOT;
/*
* the mkdio text input functions return a document structure,
* which contains a header (retrieved from the document if
* markdown was configured * with the * --enable-pandoc-header
* and the document begins with a pandoc-style header) and the
* root of the linked list of Lines.
*/
typedef struct document {
int magic; /* "I AM VALID" magic number */
#define VALID_DOCUMENT 0x19600731
Line *title;
Line *author;
Line *date;
ANCHOR(Line) content; /* uncompiled text, not valid after compile() */
Paragraph *code; /* intermediate code generated by compile() */
int compiled; /* set after mkd_compile() */
int html; /* set after (internal) htmlify() */
int tabstop; /* for properly expanding tabs (ick) */
char *ref_prefix;
MMIOT *ctx; /* backend buffers, flags, and structures */
Callback_data cb; /* callback functions & private data */
} Document;
/*
* economy FILE-type structure for pulling characters out of a
* fixed-length string.
*/
struct string_stream {
const char *data; /* the unread data */
int size; /* and how much is there? */
} ;
extern int mkd_firstnonblank(Line *);
extern int mkd_compile(Document *, DWORD);
extern int mkd_document(Document *, char **);
extern int mkd_generatehtml(Document *, FILE *);
extern int mkd_css(Document *, char **);
extern int mkd_generatecss(Document *, FILE *);
#define mkd_style mkd_generatecss
extern int mkd_xml(char *, int , char **);
extern int mkd_generatexml(char *, int, FILE *);
extern void mkd_cleanup(Document *);
extern int mkd_line(char *, int, char **, DWORD);
extern int mkd_generateline(char *, int, FILE*, DWORD);
#define mkd_text mkd_generateline
extern void mkd_basename(Document*, char *);
typedef int (*mkd_sta_function_t)(const int,const void*);
extern void mkd_string_to_anchor(char*,int, mkd_sta_function_t, void*, int);
extern Document *mkd_in(FILE *, DWORD);
extern Document *mkd_string(const char*,int, DWORD);
extern Document *gfm_in(FILE *, DWORD);
extern Document *gfm_string(const char*,int, DWORD);
extern void mkd_initialize();
extern void mkd_shlib_destructor();
extern void mkd_ref_prefix(Document*, char*);
/* internal resource handling functions.
*/
extern void ___mkd_freeLine(Line *);
extern void ___mkd_freeLines(Line *);
extern void ___mkd_freeParagraph(Paragraph *);
extern void ___mkd_freefootnote(Footnote *);
extern void ___mkd_freefootnotes(MMIOT *);
extern void ___mkd_initmmiot(MMIOT *, void *);
extern void ___mkd_freemmiot(MMIOT *, void *);
extern void ___mkd_freeLineRange(Line *, Line *);
extern void ___mkd_xml(char *, int, FILE *);
extern void ___mkd_reparse(char *, int, int, MMIOT*, char*);
extern void ___mkd_emblock(MMIOT*);
extern void ___mkd_tidy(Cstring *);
extern Document *__mkd_new_Document();
extern void __mkd_enqueue(Document*, Cstring *);
extern void __mkd_header_dle(Line *);
extern int __mkd_io_strget(struct string_stream *);
#endif/*_MARKDOWN_D*/