Debian Codegraph @

ext/markdown.h

raw symbols SCIP
1 #ifndef _MARKDOWN_D
2 #define _MARKDOWN_D
3
4 #include "config.h"
5 #include "cstring.h"
6
7 #ifdef HAVE_INTTYPES_H
8 # include <inttypes.h>
9 #elif HAVE_STDINT_H
10 # include <stdint.h>
11 #endif
12
13 /* flags, captured into a named type
14 */
15 typedef DWORD mkd_flag_t;
16
17 #define is_flag_set(flags, item) ((flags) & (item))
18 #define set_flag(flags, item) ((flags) |= (item))
19 #define clear_flag(flags, item) ((flags) &= ~(item))
20
21 /* each input line is read into a Line, which contains the line,
22 * the offset of the first non-space character [this assumes
23 * that all tabs will be expanded to spaces!], and a pointer to
24 * the next line.
25 */
26 typedef enum { chk_text, chk_code,
27 chk_hr, chk_dash,
28 chk_tilde, chk_backtick,
29 chk_equal } line_type;
30 typedef struct line {
31 Cstring text;
32 struct line *next;
33 int dle; /* leading indent on the line */
34 int flags; /* special attributes for this line */
35 #define PIPECHAR 0x01 /* line contains a | */
36 #define CHECKED 0x02
37
38 line_type kind;
39 int count;
40 } Line;
41
42
43 /* a paragraph is a collection of Lines, with links to the next paragraph
44 * and (if it's a QUOTE, UL, or OL) to the reparsed contents of this
45 * paragraph.
46 */
47 typedef struct paragraph {
48 struct paragraph *next; /* next paragraph */
49 struct paragraph *down; /* recompiled contents of this paragraph */
50 struct line *text; /* all the text in this paragraph */
51 char *ident; /* %id% tag for QUOTE */
52 char *lang; /* lang attribute for CODE */
53 enum { WHITESPACE=0, CODE, QUOTE, MARKUP,
54 HTML, STYLE, DL, UL, OL, AL, LISTITEM,
55 HDR, HR, TABLE, SOURCE } typ;
56 enum { IMPLICIT=0, PARA, CENTER} align;
57 int hnumber; /* <Hn> for typ == HDR */
58 #if GITHUB_CHECKBOX
59 int flags;
60 #define GITHUB_CHECK 0x01
61 #define IS_CHECKED 0x02
62 #endif
63 } Paragraph;
64
65 enum { ETX, SETEXT }; /* header types */
66
67 /* reference-style links (and images) are stored in an array
68 * of footnotes.
69 */
70 typedef struct footnote {
71 Cstring tag; /* the tag for the reference link */
72 Cstring link; /* what this footnote points to */
73 Cstring title; /* what it's called (TITLE= attribute) */
74 Paragraph *text; /* EXTRA_FOOTNOTE content */
75
76 int height, width; /* dimensions (for image link) */
77 int dealloc; /* deallocation needed? */
78 int refnumber;
79 int flags;
80 #define EXTRA_FOOTNOTE 0x01
81 #define REFERENCED 0x02
82 } Footnote;
83
84
85 typedef struct block {
86 enum { bTEXT, bSTAR, bUNDER } b_type;
87 int b_count;
88 char b_char;
89 Cstring b_text;
90 Cstring b_post;
91 } block;
92
93 typedef STRING(block) Qblock;
94
95
96 typedef char* (*mkd_callback_t)(const char*, const int, void*);
97 typedef void (*mkd_free_t)(char*, void*);
98
99 typedef struct callback_data {
100 void *e_data; /* private data for callbacks */
101 mkd_callback_t e_url; /* url edit callback */
102 mkd_callback_t e_flags; /* extra href flags callback */
103 mkd_callback_t e_anchor; /* callback for anchor types */
104 mkd_free_t e_free; /* edit/flags callback memory deallocator */
105 mkd_callback_t e_codefmt; /* codeblock formatter (for highlighting) */
106 } Callback_data;
107
108
109 struct escaped {
110 char *text;
111 struct escaped *up;
112 } ;
113
114
115 struct footnote_list {
116 int reference;
117 STRING(Footnote) note;
118 } ;
119
120
121 /* a magic markdown io thing holds all the data structures needed to
122 * do the backend processing of a markdown document
123 */
124 typedef struct mmiot {
125 Cstring out;
126 Cstring in;
127 Qblock Q;
128 char last; /* last text character added to out */
129 int isp;
130 struct escaped *esc;
131 char *ref_prefix;
132 struct footnote_list *footnotes;
133 mkd_flag_t flags;
134 #define MKD_NOLINKS 0x00000001
135 #define MKD_NOIMAGE 0x00000002
136 #define MKD_NOPANTS 0x00000004
137 #define MKD_NOHTML 0x00000008
138 #define MKD_STRICT 0x00000010
139 #define MKD_TAGTEXT 0x00000020
140 #define MKD_NO_EXT 0x00000040
141 #define MKD_CDATA 0x00000080
142 #define MKD_NOSUPERSCRIPT 0x00000100
143 #define MKD_NORELAXED 0x00000200
144 #define MKD_NOTABLES 0x00000400
145 #define MKD_NOSTRIKETHROUGH 0x00000800
146 #define MKD_TOC 0x00001000
147 #define MKD_1_COMPAT 0x00002000
148 #define MKD_AUTOLINK 0x00004000
149 #define MKD_SAFELINK 0x00008000
150 #define MKD_NOHEADER 0x00010000
151 #define MKD_TABSTOP 0x00020000
152 #define MKD_NODIVQUOTE 0x00040000
153 #define MKD_NOALPHALIST 0x00080000
154 #define MKD_NODLIST 0x00100000
155 #define MKD_EXTRA_FOOTNOTE 0x00200000
156 #define MKD_NOSTYLE 0x00400000
157 #define MKD_NODLDISCOUNT 0x00800000
158 #define MKD_DLEXTRA 0x01000000
159 #define MKD_FENCEDCODE 0x02000000
160 #define MKD_IDANCHOR 0x04000000
161 #define MKD_GITHUBTAGS 0x08000000
162 #define MKD_URLENCODEDANCHOR 0x10000000
163 #define IS_LABEL 0x20000000
164 #define MKD_LATEX 0x40000000
165 #define MKD_EXPLICITLIST 0x80000000
166 #define USER_FLAGS 0xFFFFFFFF
167 #define INPUT_MASK (MKD_NOHEADER|MKD_TABSTOP)
168
169 Callback_data *cb;
170 } MMIOT;
171
172
173 #define MKD_EOLN '\r'
174
175
176 /*
177 * the mkdio text input functions return a document structure,
178 * which contains a header (retrieved from the document if
179 * markdown was configured * with the * --enable-pandoc-header
180 * and the document begins with a pandoc-style header) and the
181 * root of the linked list of Lines.
182 */
183 typedef struct document {
184 int magic; /* "I AM VALID" magic number */
185 #define VALID_DOCUMENT 0x19600731
186 Line *title;
187 Line *author;
188 Line *date;
189 ANCHOR(Line) content; /* uncompiled text, not valid after compile() */
190 Paragraph *code; /* intermediate code generated by compile() */
191 int compiled; /* set after mkd_compile() */
192 int dirty; /* flags or callbacks changed */
193 int html; /* set after (internal) htmlify() */
194 int tabstop; /* for properly expanding tabs (ick) */
195 char *ref_prefix;
196 MMIOT *ctx; /* backend buffers, flags, and structures */
197 Callback_data cb; /* callback functions & private data */
198 } Document;
199
200
201 /*
202 * economy FILE-type structure for pulling characters out of a
203 * fixed-length string.
204 */
205 struct string_stream {
206 const char *data; /* the unread data */
207 int size; /* and how much is there? */
208 } ;
209
210
211 extern int mkd_firstnonblank(Line *);
212 extern int mkd_compile(Document *, mkd_flag_t);
213 extern int mkd_document(Document *, char **);
214 extern int mkd_generatehtml(Document *, FILE *);
215 extern int mkd_css(Document *, char **);
216 extern int mkd_generatecss(Document *, FILE *);
217 #define mkd_style mkd_generatecss
218 extern int mkd_xml(char *, int , char **);
219 extern int mkd_generatexml(char *, int, FILE *);
220 extern void mkd_cleanup(Document *);
221 extern int mkd_line(char *, int, char **, mkd_flag_t);
222 extern int mkd_generateline(char *, int, FILE*, mkd_flag_t);
223 #define mkd_text mkd_generateline
224 extern void mkd_basename(Document*, char *);
225
226 typedef int (*mkd_sta_function_t)(const int,const void*);
227 extern void mkd_string_to_anchor(char*,int, mkd_sta_function_t, void*, int, MMIOT *);
228
229 extern Document *mkd_in(FILE *, mkd_flag_t);
230 extern Document *mkd_string(const char*, int, mkd_flag_t);
231
232 extern Document *gfm_in(FILE *, mkd_flag_t);
233 extern Document *gfm_string(const char*,int, mkd_flag_t);
234
235 extern void mkd_initialize();
236 extern void mkd_shlib_destructor();
237
238 extern void mkd_ref_prefix(Document*, char*);
239
240 /* internal resource handling functions.
241 */
242 extern void ___mkd_freeLine(Line *);
243 extern void ___mkd_freeLines(Line *);
244 extern void ___mkd_freeParagraph(Paragraph *);
245 extern void ___mkd_freefootnote(Footnote *);
246 extern void ___mkd_freefootnotes(MMIOT *);
247 extern void ___mkd_initmmiot(MMIOT *, void *);
248 extern void ___mkd_freemmiot(MMIOT *, void *);
249 extern void ___mkd_freeLineRange(Line *, Line *);
250 extern void ___mkd_xml(char *, int, FILE *);
251 extern void ___mkd_reparse(char *, int, mkd_flag_t, MMIOT*, char*);
252 extern void ___mkd_emblock(MMIOT*);
253 extern void ___mkd_tidy(Cstring *);
254
255 extern Document *__mkd_new_Document();
256 extern void __mkd_enqueue(Document*, Cstring *);
257 extern void __mkd_trim_line(Line *, int);
258
259 extern int __mkd_io_strget(struct string_stream *);
260
261 /* utility function to do some operation and exit the current function
262 * if it fails
263 */
264 #define DO_OR_DIE(op) if ( (op) == EOF ) return EOF; else 1
265
266 #endif/*_MARKDOWN_D*/