Warning, file /education/cantor/thirdparty/discount-2.2.6-patched/markdown.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 #ifndef _MARKDOWN_D 0002 #define _MARKDOWN_D 0003 0004 #include "config.h" 0005 #include "cstring.h" 0006 0007 #ifdef HAVE_INTTYPES_H 0008 # include <inttypes.h> 0009 #elif HAVE_STDINT_H 0010 # include <stdint.h> 0011 #endif 0012 0013 /* flags, captured into a named type 0014 */ 0015 typedef DWORD mkd_flag_t; 0016 0017 #define is_flag_set(flags, item) ((flags) & (item)) 0018 #define set_flag(flags, item) ((flags) |= (item)) 0019 #define clear_flag(flags, item) ((flags) &= ~(item)) 0020 0021 /* each input line is read into a Line, which contains the line, 0022 * the offset of the first non-space character [this assumes 0023 * that all tabs will be expanded to spaces!], and a pointer to 0024 * the next line. 0025 */ 0026 typedef enum { chk_text, chk_code, 0027 chk_hr, chk_dash, 0028 chk_tilde, chk_backtick, 0029 chk_equal } line_type; 0030 typedef struct line { 0031 Cstring text; 0032 struct line *next; 0033 int dle; /* leading indent on the line */ 0034 int flags; /* special attributes for this line */ 0035 #define PIPECHAR 0x01 /* line contains a | */ 0036 #define CHECKED 0x02 0037 0038 line_type kind; 0039 int count; 0040 } Line; 0041 0042 0043 /* a paragraph is a collection of Lines, with links to the next paragraph 0044 * and (if it's a QUOTE, UL, or OL) to the reparsed contents of this 0045 * paragraph. 0046 */ 0047 typedef struct paragraph { 0048 struct paragraph *next; /* next paragraph */ 0049 struct paragraph *down; /* recompiled contents of this paragraph */ 0050 struct line *text; /* all the text in this paragraph */ 0051 char *ident; /* %id% tag for QUOTE */ 0052 char *lang; /* lang attribute for CODE */ 0053 enum { WHITESPACE=0, CODE, QUOTE, MARKUP, 0054 HTML, STYLE, DL, UL, OL, AL, LISTITEM, 0055 HDR, HR, TABLE, SOURCE } typ; 0056 enum { IMPLICIT=0, PARA, CENTER} align; 0057 int hnumber; /* <Hn> for typ == HDR */ 0058 #if GITHUB_CHECKBOX 0059 int flags; 0060 #define GITHUB_CHECK 0x01 0061 #define IS_CHECKED 0x02 0062 #endif 0063 } Paragraph; 0064 0065 enum { ETX, SETEXT }; /* header types */ 0066 0067 /* reference-style links (and images) are stored in an array 0068 * of footnotes. 0069 */ 0070 typedef struct footnote { 0071 Cstring tag; /* the tag for the reference link */ 0072 Cstring link; /* what this footnote points to */ 0073 Cstring title; /* what it's called (TITLE= attribute) */ 0074 Paragraph *text; /* EXTRA_FOOTNOTE content */ 0075 0076 int height, width; /* dimensions (for image link) */ 0077 int dealloc; /* deallocation needed? */ 0078 int refnumber; 0079 int flags; 0080 #define EXTRA_FOOTNOTE 0x01 0081 #define REFERENCED 0x02 0082 } Footnote; 0083 0084 0085 typedef struct block { 0086 enum { bTEXT, bSTAR, bUNDER } b_type; 0087 int b_count; 0088 char b_char; 0089 Cstring b_text; 0090 Cstring b_post; 0091 } block; 0092 0093 typedef STRING(block) Qblock; 0094 0095 0096 typedef char* (*mkd_callback_t)(const char*, const int, void*); 0097 typedef void (*mkd_free_t)(char*, void*); 0098 0099 typedef struct callback_data { 0100 void *e_data; /* private data for callbacks */ 0101 mkd_callback_t e_url; /* url edit callback */ 0102 mkd_callback_t e_flags; /* extra href flags callback */ 0103 mkd_callback_t e_anchor; /* callback for anchor types */ 0104 mkd_free_t e_free; /* edit/flags callback memory deallocator */ 0105 mkd_callback_t e_codefmt; /* codeblock formatter (for highlighting) */ 0106 } Callback_data; 0107 0108 0109 struct escaped { 0110 char *text; 0111 struct escaped *up; 0112 } ; 0113 0114 0115 struct footnote_list { 0116 int reference; 0117 STRING(Footnote) note; 0118 } ; 0119 0120 0121 /* a magic markdown io thing holds all the data structures needed to 0122 * do the backend processing of a markdown document 0123 */ 0124 typedef struct mmiot { 0125 Cstring out; 0126 Cstring in; 0127 Qblock Q; 0128 char last; /* last text character added to out */ 0129 int isp; 0130 struct escaped *esc; 0131 char *ref_prefix; 0132 struct footnote_list *footnotes; 0133 Cstring latex; 0134 mkd_flag_t flags; 0135 #define MKD_NOLINKS 0x00000001 0136 #define MKD_NOIMAGE 0x00000002 0137 #define MKD_NOPANTS 0x00000004 0138 #define MKD_NOHTML 0x00000008 0139 #define MKD_STRICT 0x00000010 0140 #define MKD_TAGTEXT 0x00000020 0141 #define MKD_NO_EXT 0x00000040 0142 #define MKD_CDATA 0x00000080 0143 #define MKD_NOSUPERSCRIPT 0x00000100 0144 #define MKD_NORELAXED 0x00000200 0145 #define MKD_NOTABLES 0x00000400 0146 #define MKD_NOSTRIKETHROUGH 0x00000800 0147 #define MKD_TOC 0x00001000 0148 #define MKD_1_COMPAT 0x00002000 0149 #define MKD_AUTOLINK 0x00004000 0150 #define MKD_SAFELINK 0x00008000 0151 #define MKD_NOHEADER 0x00010000 0152 #define MKD_TABSTOP 0x00020000 0153 #define MKD_NODIVQUOTE 0x00040000 0154 #define MKD_NOALPHALIST 0x00080000 0155 #define MKD_NODLIST 0x00100000 0156 #define MKD_EXTRA_FOOTNOTE 0x00200000 0157 #define MKD_NOSTYLE 0x00400000 0158 #define MKD_NODLDISCOUNT 0x00800000 0159 #define MKD_DLEXTRA 0x01000000 0160 #define MKD_FENCEDCODE 0x02000000 0161 #define MKD_IDANCHOR 0x04000000 0162 #define MKD_GITHUBTAGS 0x08000000 0163 #define MKD_URLENCODEDANCHOR 0x10000000 0164 #define IS_LABEL 0x20000000 0165 #define MKD_LATEX 0x40000000 0166 #define MKD_EXPLICITLIST 0x80000000 0167 #define USER_FLAGS 0xFFFFFFFF 0168 #define INPUT_MASK (MKD_NOHEADER|MKD_TABSTOP) 0169 0170 Callback_data *cb; 0171 } MMIOT; 0172 0173 0174 #define MKD_EOLN '\r' 0175 0176 0177 /* 0178 * the mkdio text input functions return a document structure, 0179 * which contains a header (retrieved from the document if 0180 * markdown was configured * with the * --enable-pandoc-header 0181 * and the document begins with a pandoc-style header) and the 0182 * root of the linked list of Lines. 0183 */ 0184 typedef struct document { 0185 int magic; /* "I AM VALID" magic number */ 0186 #define VALID_DOCUMENT 0x19600731 0187 Line *title; 0188 Line *author; 0189 Line *date; 0190 ANCHOR(Line) content; /* uncompiled text, not valid after compile() */ 0191 Paragraph *code; /* intermediate code generated by compile() */ 0192 int compiled; /* set after mkd_compile() */ 0193 int dirty; /* flags or callbacks changed */ 0194 int html; /* set after (internal) htmlify() */ 0195 int tabstop; /* for properly expanding tabs (ick) */ 0196 char *ref_prefix; 0197 MMIOT *ctx; /* backend buffers, flags, and structures */ 0198 Callback_data cb; /* callback functions & private data */ 0199 } Document; 0200 0201 0202 /* 0203 * economy FILE-type structure for pulling characters out of a 0204 * fixed-length string. 0205 */ 0206 struct string_stream { 0207 const char *data; /* the unread data */ 0208 int size; /* and how much is there? */ 0209 } ; 0210 0211 0212 extern int mkd_firstnonblank(Line *); 0213 extern int mkd_compile(Document *, mkd_flag_t); 0214 extern int mkd_document(Document *, char **); 0215 extern int mkd_generatehtml(Document *, FILE *); 0216 extern int mkd_css(Document *, char **); 0217 extern int mkd_generatecss(Document *, FILE *); 0218 #define mkd_style mkd_generatecss 0219 extern int mkd_xml(char *, int , char **); 0220 extern int mkd_generatexml(char *, int, FILE *); 0221 extern void mkd_cleanup(Document *); 0222 extern int mkd_line(char *, int, char **, mkd_flag_t); 0223 extern int mkd_generateline(char *, int, FILE*, mkd_flag_t); 0224 #define mkd_text mkd_generateline 0225 extern void mkd_basename(Document*, char *); 0226 0227 typedef int (*mkd_sta_function_t)(const int,const void*); 0228 extern void mkd_string_to_anchor(char*,int, mkd_sta_function_t, void*, int, MMIOT *); 0229 0230 extern Document *mkd_in(FILE *, mkd_flag_t); 0231 extern Document *mkd_string(const char*, int, mkd_flag_t); 0232 0233 extern Document *gfm_in(FILE *, mkd_flag_t); 0234 extern Document *gfm_string(const char*,int, mkd_flag_t); 0235 0236 extern void mkd_initialize(); 0237 extern void mkd_shlib_destructor(); 0238 0239 extern void mkd_ref_prefix(Document*, char*); 0240 0241 // Cantor latex extention 0242 extern int mkd_latextext(Document*, char**); 0243 0244 /* internal resource handling functions. 0245 */ 0246 extern void ___mkd_freeLine(Line *); 0247 extern void ___mkd_freeLines(Line *); 0248 extern void ___mkd_freeParagraph(Paragraph *); 0249 extern void ___mkd_freefootnote(Footnote *); 0250 extern void ___mkd_freefootnotes(MMIOT *); 0251 extern void ___mkd_initmmiot(MMIOT *, void *); 0252 extern void ___mkd_freemmiot(MMIOT *, void *); 0253 extern void ___mkd_freeLineRange(Line *, Line *); 0254 extern void ___mkd_xml(char *, int, FILE *); 0255 extern void ___mkd_reparse(char *, int, mkd_flag_t, MMIOT*, char*); 0256 extern void ___mkd_emblock(MMIOT*); 0257 extern void ___mkd_tidy(Cstring *); 0258 0259 extern Document *__mkd_new_Document(); 0260 extern void __mkd_enqueue(Document*, Cstring *); 0261 extern void __mkd_trim_line(Line *, int); 0262 0263 extern int __mkd_io_strget(struct string_stream *); 0264 0265 /* utility function to do some operation and exit the current function 0266 * if it fails 0267 */ 0268 #define DO_OR_DIE(op) if ( (op) == EOF ) return EOF; else 1 0269 0270 #endif/*_MARKDOWN_D*/