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.

189 lines
5.8 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 struct line {
  24. Cstring text;
  25. struct line *next;
  26. int dle; /* leading indent on the line */
  27. int flags; /* special attributes for this line */
  28. #define PIPECHAR 0x01 /* line contains a | */
  29. #define CHECKED 0x02
  30. enum { chk_text, chk_code,
  31. chk_hr, chk_dash,
  32. chk_tilde, chk_equal } kind;
  33. int count;
  34. } Line;
  35. /* a paragraph is a collection of Lines, with links to the next paragraph
  36. * and (if it's a QUOTE, UL, or OL) to the reparsed contents of this
  37. * paragraph.
  38. */
  39. typedef struct paragraph {
  40. struct paragraph *next; /* next paragraph */
  41. struct paragraph *down; /* recompiled contents of this paragraph */
  42. struct line *text; /* all the text in this paragraph */
  43. char *ident; /* %id% tag for QUOTE */
  44. enum { WHITESPACE=0, CODE, QUOTE, MARKUP,
  45. HTML, STYLE, DL, UL, OL, AL, LISTITEM,
  46. HDR, HR, TABLE, SOURCE } typ;
  47. enum { IMPLICIT=0, PARA, CENTER} align;
  48. int hnumber; /* <Hn> for typ == HDR */
  49. } Paragraph;
  50. enum { ETX, SETEXT }; /* header types */
  51. typedef struct block {
  52. enum { bTEXT, bSTAR, bUNDER } b_type;
  53. int b_count;
  54. char b_char;
  55. Cstring b_text;
  56. Cstring b_post;
  57. } block;
  58. typedef STRING(block) Qblock;
  59. typedef char* (*mkd_callback_t)(const char*, const int, void*);
  60. typedef void (*mkd_free_t)(char*, void*);
  61. typedef struct callback_data {
  62. void *e_data; /* private data for callbacks */
  63. mkd_callback_t e_url; /* url edit callback */
  64. mkd_callback_t e_flags; /* extra href flags callback */
  65. mkd_free_t e_free; /* edit/flags callback memory deallocator */
  66. } Callback_data;
  67. /* a magic markdown io thing holds all the data structures needed to
  68. * do the backend processing of a markdown document
  69. */
  70. typedef struct mmiot {
  71. Cstring out;
  72. Cstring in;
  73. Qblock Q;
  74. int isp;
  75. int reference;
  76. char *ref_prefix;
  77. STRING(Footnote) *footnotes;
  78. DWORD flags;
  79. #define MKD_NOLINKS 0x00000001
  80. #define MKD_NOIMAGE 0x00000002
  81. #define MKD_NOPANTS 0x00000004
  82. #define MKD_NOHTML 0x00000008
  83. #define MKD_STRICT 0x00000010
  84. #define MKD_TAGTEXT 0x00000020
  85. #define MKD_NO_EXT 0x00000040
  86. #define MKD_CDATA 0x00000080
  87. #define MKD_NOSUPERSCRIPT 0x00000100
  88. #define MKD_NORELAXED 0x00000200
  89. #define MKD_NOTABLES 0x00000400
  90. #define MKD_NOSTRIKETHROUGH 0x00000800
  91. #define MKD_TOC 0x00001000
  92. #define MKD_1_COMPAT 0x00002000
  93. #define MKD_AUTOLINK 0x00004000
  94. #define MKD_SAFELINK 0x00008000
  95. #define MKD_NOHEADER 0x00010000
  96. #define MKD_TABSTOP 0x00020000
  97. #define MKD_NODIVQUOTE 0x00040000
  98. #define MKD_NOALPHALIST 0x00080000
  99. #define MKD_NODLIST 0x00100000
  100. #define MKD_EXTRA_FOOTNOTE 0x00200000
  101. #define IS_LABEL 0x08000000
  102. #define USER_FLAGS 0x0FFFFFFF
  103. #define INPUT_MASK (MKD_NOHEADER|MKD_TABSTOP)
  104. Callback_data *cb;
  105. } MMIOT;
  106. /*
  107. * the mkdio text input functions return a document structure,
  108. * which contains a header (retrieved from the document if
  109. * markdown was configured * with the * --enable-pandoc-header
  110. * and the document begins with a pandoc-style header) and the
  111. * root of the linked list of Lines.
  112. */
  113. typedef struct document {
  114. int magic; /* "I AM VALID" magic number */
  115. #define VALID_DOCUMENT 0x19600731
  116. Line *title;
  117. Line *author;
  118. Line *date;
  119. ANCHOR(Line) content; /* uncompiled text, not valid after compile() */
  120. Paragraph *code; /* intermediate code generated by compile() */
  121. int compiled; /* set after mkd_compile() */
  122. int html; /* set after (internal) htmlify() */
  123. int tabstop; /* for properly expanding tabs (ick) */
  124. char *ref_prefix;
  125. MMIOT *ctx; /* backend buffers, flags, and structures */
  126. Callback_data cb; /* callback functions & private data */
  127. } Document;
  128. extern int mkd_firstnonblank(Line *);
  129. extern int mkd_compile(Document *, DWORD);
  130. extern int mkd_document(Document *, char **);
  131. extern int mkd_generatehtml(Document *, FILE *);
  132. extern int mkd_css(Document *, char **);
  133. extern int mkd_generatecss(Document *, FILE *);
  134. #define mkd_style mkd_generatecss
  135. extern int mkd_xml(char *, int , char **);
  136. extern int mkd_generatexml(char *, int, FILE *);
  137. extern void mkd_cleanup(Document *);
  138. extern int mkd_line(char *, int, char **, DWORD);
  139. extern int mkd_generateline(char *, int, FILE*, DWORD);
  140. #define mkd_text mkd_generateline
  141. extern void mkd_basename(Document*, char *);
  142. typedef int (*mkd_sta_function_t)(const int,const void*);
  143. extern void mkd_string_to_anchor(char*,int, mkd_sta_function_t, void*, int);
  144. extern Document *mkd_in(FILE *, DWORD);
  145. extern Document *mkd_string(const char*,int, DWORD);
  146. extern void mkd_initialize();
  147. extern void mkd_shlib_destructor();
  148. extern void mkd_ref_prefix(Document*, char*);
  149. /* internal resource handling functions.
  150. */
  151. extern void ___mkd_freeLine(Line *);
  152. extern void ___mkd_freeLines(Line *);
  153. extern void ___mkd_freeParagraph(Paragraph *);
  154. extern void ___mkd_freefootnote(Footnote *);
  155. extern void ___mkd_freefootnotes(MMIOT *);
  156. extern void ___mkd_initmmiot(MMIOT *, void *);
  157. extern void ___mkd_freemmiot(MMIOT *, void *);
  158. extern void ___mkd_freeLineRange(Line *, Line *);
  159. extern void ___mkd_xml(char *, int, FILE *);
  160. extern void ___mkd_reparse(char *, int, int, MMIOT*);
  161. extern void ___mkd_emblock(MMIOT*);
  162. extern void ___mkd_tidy(Cstring *);
  163. #endif/*_MARKDOWN_D*/