aboutsummaryrefslogtreecommitdiff
path: root/src/cmark.h
blob: 1331e760f77354f90609f3e19998e8de36884a37 (plain)
  1. #ifndef _CMARK_H_
  2. #define _CMARK_H_
  3. #include <stdbool.h>
  4. #include <stdio.h>
  5. #include "buffer.h"
  6. #include "chunk.h"
  7. #include "references.h"
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. #define CMARK_VERSION "0.1"
  12. #define CMARK_CODE_INDENT 4
  13. #define CMARK_MAX_LINK_LABEL_LENGTH 1000
  14. struct cmark_node_inl {
  15. enum {
  16. CMARK_INL_STRING,
  17. CMARK_INL_SOFTBREAK,
  18. CMARK_INL_LINEBREAK,
  19. CMARK_INL_CODE,
  20. CMARK_INL_RAW_HTML,
  21. CMARK_INL_EMPH,
  22. CMARK_INL_STRONG,
  23. CMARK_INL_LINK,
  24. CMARK_INL_IMAGE
  25. } tag;
  26. union {
  27. cmark_chunk literal;
  28. struct cmark_node_inl *inlines;
  29. struct {
  30. struct cmark_node_inl *label;
  31. unsigned char *url;
  32. unsigned char *title;
  33. } linkable;
  34. } content;
  35. struct cmark_node_inl *next;
  36. };
  37. typedef struct cmark_node_inl cmark_node_inl;
  38. // Types for blocks
  39. struct cmark_ListData {
  40. enum {
  41. bullet,
  42. ordered
  43. } list_type;
  44. int marker_offset;
  45. int padding;
  46. int start;
  47. enum {
  48. period,
  49. parens
  50. } delimiter;
  51. unsigned char bullet_char;
  52. bool tight;
  53. };
  54. struct cmark_FencedCodeData {
  55. int fence_length;
  56. int fence_offset;
  57. unsigned char fence_char;
  58. cmark_strbuf info;
  59. };
  60. struct cmark_node_block {
  61. enum {
  62. CMARK_BLOCK_DOCUMENT,
  63. CMARK_BLOCK_BQUOTE,
  64. CMARK_BLOCK_LIST,
  65. CMARK_BLOCK_LIST_ITEM,
  66. CMARK_BLOCK_FENCED_CODE,
  67. CMARK_BLOCK_INDENTED_CODE,
  68. CMARK_BLOCK_HTML,
  69. CMARK_BLOCK_PARAGRAPH,
  70. CMARK_BLOCK_ATX_HEADER,
  71. CMARK_BLOCK_SETEXT_HEADER,
  72. CMARK_BLOCK_HRULE,
  73. CMARK_BLOCK_REFERENCE_DEF
  74. } tag;
  75. int start_line;
  76. int start_column;
  77. int end_line;
  78. bool open;
  79. bool last_line_blank;
  80. struct cmark_node_block* children;
  81. struct cmark_node_block* last_child;
  82. struct cmark_node_block* parent;
  83. struct cmark_node_block* top;
  84. cmark_strbuf string_content;
  85. cmark_node_inl* inline_content;
  86. union {
  87. struct cmark_ListData list;
  88. struct cmark_FencedCodeData code;
  89. struct {
  90. int level;
  91. } header;
  92. struct {
  93. cmark_reference_map *refmap;
  94. } document;
  95. } as;
  96. struct cmark_node_block *next;
  97. struct cmark_node_block *prev;
  98. };
  99. typedef struct cmark_node_block cmark_node_block;
  100. __attribute__((visibility("default")))
  101. void cmark_free_blocks(cmark_node_block *e);
  102. __attribute__((visibility("default")))
  103. void cmark_free_inlines(cmark_node_inl* e);
  104. __attribute__((visibility("default")))
  105. cmark_node_inl* cmark_append_inlines(cmark_node_inl* a, cmark_node_inl* b);
  106. __attribute__((visibility("default")))
  107. cmark_node_block* cmark_append_blocks(cmark_node_block* a, cmark_node_block* b);
  108. __attribute__((visibility("default")))
  109. cmark_node_inl *cmark_make_link(cmark_node_inl *label, unsigned char *url, unsigned char *title);
  110. __attribute__((visibility("default")))
  111. cmark_node_inl* cmark_make_autolink(cmark_node_inl* label, cmark_chunk url, int is_email);
  112. __attribute__((visibility("default")))
  113. cmark_node_inl* cmark_make_inlines(int t, cmark_node_inl* contents);
  114. __attribute__((visibility("default")))
  115. cmark_node_inl* cmark_make_literal(int t, cmark_chunk s);
  116. __attribute__((visibility("default")))
  117. cmark_node_inl* cmark_make_simple(int t);
  118. // Macros for creating various kinds of simple.
  119. #define cmark_make_str(s) cmark_make_literal(INL_STRING, s)
  120. #define cmark_make_code(s) cmark_make_literal(INL_CODE, s)
  121. #define cmark_make_raw_html(s) cmark_make_literal(INL_RAW_HTML, s)
  122. #define cmark_make_linebreak() cmark_make_simple(INL_LINEBREAK)
  123. #define cmark_make_softbreak() cmark_make_simple(INL_SOFTBREAK)
  124. #define cmark_make_emph(contents) cmark_make_inlines(INL_EMPH, contents)
  125. #define cmark_make_strong(contents) cmark_make_inlines(INL_STRONG, contents)
  126. __attribute__((visibility("default")))
  127. cmark_node_block *cmark_parse_document(const unsigned char *buffer, size_t len);
  128. __attribute__((visibility("default")))
  129. cmark_node_block *cmark_parse_file(FILE *f);
  130. __attribute__((visibility("default")))
  131. void cmark_debug_print(cmark_node_block *root);
  132. __attribute__((visibility("default")))
  133. void cmark_render_html(cmark_strbuf *html, cmark_node_block *root);
  134. __attribute__((visibility("default")))
  135. unsigned char *cmark_markdown_to_html(unsigned char *text, int len);
  136. #ifndef CMARK_NO_SHORT_NAMES
  137. #define VERSION CMARK_VERSION
  138. #define CODE_INDENT CMARK_CODE_INDENT
  139. #define MAX_LINK_LABEL_LENGTH CMARK_MAX_LINK_LABEL_LENGTH
  140. #define node_inl cmark_node_inl
  141. #define INL_STRING CMARK_INL_STRING
  142. #define INL_SOFTBREAK CMARK_INL_SOFTBREAK
  143. #define INL_LINEBREAK CMARK_INL_LINEBREAK
  144. #define INL_CODE CMARK_INL_CODE
  145. #define INL_RAW_HTML CMARK_INL_RAW_HTML
  146. #define INL_EMPH CMARK_INL_EMPH
  147. #define INL_STRONG CMARK_INL_STRONG
  148. #define INL_LINK CMARK_INL_LINK
  149. #define INL_IMAGE CMARK_INL_IMAGE
  150. #define ListData cmark_ListData
  151. #define FencedCodeData cmark_FencedCodeData
  152. #define node_block cmark_node_block
  153. #define BLOCK_DOCUMENT CMARK_BLOCK_DOCUMENT
  154. #define BLOCK_BQUOTE CMARK_BLOCK_BQUOTE
  155. #define BLOCK_LIST CMARK_BLOCK_LIST
  156. #define BLOCK_LIST_ITEM CMARK_BLOCK_LIST_ITEM
  157. #define BLOCK_FENCED_CODE CMARK_BLOCK_FENCED_CODE
  158. #define BLOCK_INDENTED_CODE CMARK_BLOCK_INDENTED_CODE
  159. #define BLOCK_HTML CMARK_BLOCK_HTML
  160. #define BLOCK_PARAGRAPH CMARK_BLOCK_PARAGRAPH
  161. #define BLOCK_ATX_HEADER CMARK_BLOCK_ATX_HEADER
  162. #define BLOCK_SETEXT_HEADER CMARK_BLOCK_SETEXT_HEADER
  163. #define BLOCK_HRULE CMARK_BLOCK_HRULE
  164. #define BLOCK_REFERENCE_DEF CMARK_BLOCK_REFERENCE_DEF
  165. #define free_simple cmark_free_simple
  166. #define free_blocks cmark_free_blocks
  167. #define append_simple cmark_append_simple
  168. #define make_link cmark_make_link
  169. #define make_autolink cmark_make_autolink
  170. #define make_str cmark_make_str
  171. #define make_code cmark_make_code
  172. #define make_raw_html cmark_make_raw_html
  173. #define make_linebreak cmark_make_linebreak
  174. #define make_softbreak cmark_make_softbreak
  175. #define make_emph cmark_make_emph
  176. #define make_strong cmark_make_strong
  177. #define make_simple cmark_make_simple
  178. #define make_simple cmark_make_simple
  179. #define make_simple cmark_make_simple
  180. #endif
  181. #ifdef __cplusplus
  182. }
  183. #endif
  184. #endif