Text::Markdown::Discount
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

218 lines
6.5 KiB

  1. #ifndef _MARKDOWN_D
  2. #define _MARKDOWN_D
  3. #include "cstring.h"
  4. /* reference-style links (and images) are stored in an array
  5. * of footnotes.
  6. */
  7. typedef struct footnote {
  8. Cstring tag; /* the tag for the reference link */
  9. Cstring link; /* what this footnote points to */
  10. Cstring title; /* what it's called (TITLE= attribute) */
  11. int height, width; /* dimensions (for image link) */
  12. int dealloc; /* deallocation needed? */
  13. int refnumber;
  14. int flags;
  15. #define EXTRA_BOOKMARK 0x01
  16. #define REFERENCED 0x02
  17. } Footnote;
  18. /* each input line is read into a Line, which contains the line,
  19. * the offset of the first non-space character [this assumes
  20. * that all tabs will be expanded to spaces!], and a pointer to
  21. * the next line.
  22. */
  23. typedef enum { chk_text, chk_code,
  24. chk_hr, chk_dash,
  25. chk_tilde, chk_backtick,
  26. chk_equal } line_type;
  27. typedef struct line {
  28. Cstring text;
  29. struct line *next;
  30. int dle; /* leading indent on the line */
  31. int flags; /* special attributes for this line */
  32. #define PIPECHAR 0x01 /* line contains a | */
  33. #define CHECKED 0x02
  34. line_type kind;
  35. int count;
  36. } Line;
  37. /* a paragraph is a collection of Lines, with links to the next paragraph
  38. * and (if it's a QUOTE, UL, or OL) to the reparsed contents of this
  39. * paragraph.
  40. */
  41. typedef struct paragraph {
  42. struct paragraph *next; /* next paragraph */
  43. struct paragraph *down; /* recompiled contents of this paragraph */
  44. struct line *text; /* all the text in this paragraph */
  45. char *ident; /* %id% tag for QUOTE */
  46. enum { WHITESPACE=0, CODE, QUOTE, MARKUP,
  47. HTML, STYLE, DL, UL, OL, AL, LISTITEM,
  48. HDR, HR, TABLE, SOURCE } typ;
  49. enum { IMPLICIT=0, PARA, CENTER} align;
  50. int hnumber; /* <Hn> for typ == HDR */
  51. } Paragraph;
  52. enum { ETX, SETEXT }; /* header types */
  53. typedef struct block {
  54. enum { bTEXT, bSTAR, bUNDER } b_type;
  55. int b_count;
  56. char b_char;
  57. Cstring b_text;
  58. Cstring b_post;
  59. } block;
  60. typedef STRING(block) Qblock;
  61. typedef char* (*mkd_callback_t)(const char*, const int, void*);
  62. typedef void (*mkd_free_t)(char*, void*);
  63. typedef struct callback_data {
  64. void *e_data; /* private data for callbacks */
  65. mkd_callback_t e_url; /* url edit callback */
  66. mkd_callback_t e_flags; /* extra href flags callback */
  67. mkd_free_t e_free; /* edit/flags callback memory deallocator */
  68. } Callback_data;
  69. struct escaped {
  70. char *text;
  71. struct escaped *up;
  72. } ;
  73. /* a magic markdown io thing holds all the data structures needed to
  74. * do the backend processing of a markdown document
  75. */
  76. typedef struct mmiot {
  77. Cstring out;
  78. Cstring in;
  79. Qblock Q;
  80. int isp;
  81. int reference;
  82. struct escaped *esc;
  83. char *ref_prefix;
  84. STRING(Footnote) *footnotes;
  85. DWORD flags;
  86. #define MKD_NOLINKS 0x00000001
  87. #define MKD_NOIMAGE 0x00000002
  88. #define MKD_NOPANTS 0x00000004
  89. #define MKD_NOHTML 0x00000008
  90. #define MKD_STRICT 0x00000010
  91. #define MKD_TAGTEXT 0x00000020
  92. #define MKD_NO_EXT 0x00000040
  93. #define MKD_CDATA 0x00000080
  94. #define MKD_NOSUPERSCRIPT 0x00000100
  95. #define MKD_NORELAXED 0x00000200
  96. #define MKD_NOTABLES 0x00000400
  97. #define MKD_NOSTRIKETHROUGH 0x00000800
  98. #define MKD_TOC 0x00001000
  99. #define MKD_1_COMPAT 0x00002000
  100. #define MKD_AUTOLINK 0x00004000
  101. #define MKD_SAFELINK 0x00008000
  102. #define MKD_NOHEADER 0x00010000
  103. #define MKD_TABSTOP 0x00020000
  104. #define MKD_NODIVQUOTE 0x00040000
  105. #define MKD_NOALPHALIST 0x00080000
  106. #define MKD_NODLIST 0x00100000
  107. #define MKD_EXTRA_FOOTNOTE 0x00200000
  108. #define MKD_NOSTYLE 0x00400000
  109. #define IS_LABEL 0x08000000
  110. #define USER_FLAGS 0x0FFFFFFF
  111. #define INPUT_MASK (MKD_NOHEADER|MKD_TABSTOP)
  112. Callback_data *cb;
  113. } MMIOT;
  114. /*
  115. * the mkdio text input functions return a document structure,
  116. * which contains a header (retrieved from the document if
  117. * markdown was configured * with the * --enable-pandoc-header
  118. * and the document begins with a pandoc-style header) and the
  119. * root of the linked list of Lines.
  120. */
  121. typedef struct document {
  122. int magic; /* "I AM VALID" magic number */
  123. #define VALID_DOCUMENT 0x19600731
  124. Line *title;
  125. Line *author;
  126. Line *date;
  127. ANCHOR(Line) content; /* uncompiled text, not valid after compile() */
  128. Paragraph *code; /* intermediate code generated by compile() */
  129. int compiled; /* set after mkd_compile() */
  130. int html; /* set after (internal) htmlify() */
  131. int tabstop; /* for properly expanding tabs (ick) */
  132. char *ref_prefix;
  133. MMIOT *ctx; /* backend buffers, flags, and structures */
  134. Callback_data cb; /* callback functions & private data */
  135. } Document;
  136. /*
  137. * economy FILE-type structure for pulling characters out of a
  138. * fixed-length string.
  139. */
  140. struct string_stream {
  141. const char *data; /* the unread data */
  142. int size; /* and how much is there? */
  143. } ;
  144. extern int mkd_firstnonblank(Line *);
  145. extern int mkd_compile(Document *, DWORD);
  146. extern int mkd_document(Document *, char **);
  147. extern int mkd_generatehtml(Document *, FILE *);
  148. extern int mkd_css(Document *, char **);
  149. extern int mkd_generatecss(Document *, FILE *);
  150. #define mkd_style mkd_generatecss
  151. extern int mkd_xml(char *, int , char **);
  152. extern int mkd_generatexml(char *, int, FILE *);
  153. extern void mkd_cleanup(Document *);
  154. extern int mkd_line(char *, int, char **, DWORD);
  155. extern int mkd_generateline(char *, int, FILE*, DWORD);
  156. #define mkd_text mkd_generateline
  157. extern void mkd_basename(Document*, char *);
  158. typedef int (*mkd_sta_function_t)(const int,const void*);
  159. extern void mkd_string_to_anchor(char*,int, mkd_sta_function_t, void*, int);
  160. extern Document *mkd_in(FILE *, DWORD);
  161. extern Document *mkd_string(const char*,int, DWORD);
  162. extern Document *gfm_in(FILE *, DWORD);
  163. extern Document *gfm_string(const char*,int, DWORD);
  164. extern void mkd_initialize();
  165. extern void mkd_shlib_destructor();
  166. extern void mkd_ref_prefix(Document*, char*);
  167. /* internal resource handling functions.
  168. */
  169. extern void ___mkd_freeLine(Line *);
  170. extern void ___mkd_freeLines(Line *);
  171. extern void ___mkd_freeParagraph(Paragraph *);
  172. extern void ___mkd_freefootnote(Footnote *);
  173. extern void ___mkd_freefootnotes(MMIOT *);
  174. extern void ___mkd_initmmiot(MMIOT *, void *);
  175. extern void ___mkd_freemmiot(MMIOT *, void *);
  176. extern void ___mkd_freeLineRange(Line *, Line *);
  177. extern void ___mkd_xml(char *, int, FILE *);
  178. extern void ___mkd_reparse(char *, int, int, MMIOT*, char*);
  179. extern void ___mkd_emblock(MMIOT*);
  180. extern void ___mkd_tidy(Cstring *);
  181. extern Document *__mkd_new_Document();
  182. extern void __mkd_enqueue(Document*, Cstring *);
  183. extern void __mkd_header_dle(Line *);
  184. extern int __mkd_io_strget(struct string_stream *);
  185. #endif/*_MARKDOWN_D*/