aboutsummaryrefslogtreecommitdiff
path: root/src/cmark.h
blob: 6e58f0b7937355b078aa442e0dc9cf9eb1859617 (plain)
  1. #ifndef CMARK_H
  2. #define CMARK_H
  3. #include <stdio.h>
  4. #include "cmark_export.h"
  5. #ifdef __cplusplus
  6. extern "C" {
  7. #endif
  8. #define CMARK_VERSION "0.1"
  9. typedef enum {
  10. // Block
  11. CMARK_NODE_DOCUMENT,
  12. CMARK_NODE_BLOCK_QUOTE,
  13. CMARK_NODE_LIST,
  14. CMARK_NODE_LIST_ITEM,
  15. CMARK_NODE_CODE_BLOCK,
  16. CMARK_NODE_HTML,
  17. CMARK_NODE_PARAGRAPH,
  18. CMARK_NODE_HEADER,
  19. CMARK_NODE_HRULE,
  20. CMARK_NODE_REFERENCE_DEF,
  21. CMARK_NODE_FIRST_BLOCK = CMARK_NODE_DOCUMENT,
  22. CMARK_NODE_LAST_BLOCK = CMARK_NODE_REFERENCE_DEF,
  23. // Inline
  24. CMARK_NODE_STRING,
  25. CMARK_NODE_SOFTBREAK,
  26. CMARK_NODE_LINEBREAK,
  27. CMARK_NODE_INLINE_CODE,
  28. CMARK_NODE_INLINE_HTML,
  29. CMARK_NODE_EMPH,
  30. CMARK_NODE_STRONG,
  31. CMARK_NODE_LINK,
  32. CMARK_NODE_IMAGE,
  33. CMARK_NODE_FIRST_INLINE = CMARK_NODE_STRING,
  34. CMARK_NODE_LAST_INLINE = CMARK_NODE_IMAGE,
  35. } cmark_node_type;
  36. typedef enum {
  37. CMARK_NO_LIST,
  38. CMARK_BULLET_LIST,
  39. CMARK_ORDERED_LIST
  40. } cmark_list_type;
  41. typedef enum {
  42. CMARK_PERIOD_DELIM,
  43. CMARK_PAREN_DELIM
  44. } cmark_delim_type;
  45. typedef struct cmark_node cmark_node;
  46. typedef struct cmark_doc_parser cmark_doc_parser;
  47. // Construction and destruction
  48. CMARK_EXPORT cmark_node*
  49. cmark_node_new(cmark_node_type type);
  50. CMARK_EXPORT void
  51. cmark_node_destroy(cmark_node *node);
  52. CMARK_EXPORT void
  53. cmark_free_nodes(cmark_node *e);
  54. // Tree traversal
  55. CMARK_EXPORT cmark_node*
  56. cmark_node_next(cmark_node *node);
  57. CMARK_EXPORT cmark_node*
  58. cmark_node_previous(cmark_node *node);
  59. CMARK_EXPORT cmark_node*
  60. cmark_node_parent(cmark_node *node);
  61. CMARK_EXPORT cmark_node*
  62. cmark_node_first_child(cmark_node *node);
  63. CMARK_EXPORT cmark_node*
  64. cmark_node_last_child(cmark_node *node);
  65. // Accessors
  66. CMARK_EXPORT cmark_node_type
  67. cmark_node_get_type(cmark_node *node);
  68. CMARK_EXPORT const char*
  69. cmark_node_get_string_content(cmark_node *node);
  70. CMARK_EXPORT int
  71. cmark_node_set_string_content(cmark_node *node, const char *content);
  72. CMARK_EXPORT int
  73. cmark_node_get_header_level(cmark_node *node);
  74. CMARK_EXPORT int
  75. cmark_node_set_header_level(cmark_node *node, int level);
  76. CMARK_EXPORT cmark_list_type
  77. cmark_node_get_list_type(cmark_node *node);
  78. CMARK_EXPORT int
  79. cmark_node_set_list_type(cmark_node *node, cmark_list_type type);
  80. CMARK_EXPORT int
  81. cmark_node_get_list_start(cmark_node *node);
  82. CMARK_EXPORT int
  83. cmark_node_set_list_start(cmark_node *node, int start);
  84. CMARK_EXPORT int
  85. cmark_node_get_list_tight(cmark_node *node);
  86. CMARK_EXPORT int
  87. cmark_node_set_list_tight(cmark_node *node, int tight);
  88. CMARK_EXPORT const char*
  89. cmark_node_get_fence_info(cmark_node *node);
  90. CMARK_EXPORT int
  91. cmark_node_set_fence_info(cmark_node *node, const char *info);
  92. CMARK_EXPORT const char*
  93. cmark_node_get_url(cmark_node *node);
  94. CMARK_EXPORT int
  95. cmark_node_set_url(cmark_node *node, const char *url);
  96. CMARK_EXPORT const char*
  97. cmark_node_get_title(cmark_node *node);
  98. CMARK_EXPORT int
  99. cmark_node_set_title(cmark_node *node, const char *title);
  100. CMARK_EXPORT int
  101. cmark_node_get_start_line(cmark_node *node);
  102. CMARK_EXPORT int
  103. cmark_node_get_start_column(cmark_node *node);
  104. CMARK_EXPORT int
  105. cmark_node_get_end_line(cmark_node *node);
  106. // Tree manipulation
  107. CMARK_EXPORT void
  108. cmark_node_unlink(cmark_node *node);
  109. CMARK_EXPORT int
  110. cmark_node_insert_before(cmark_node *node, cmark_node *sibling);
  111. CMARK_EXPORT int
  112. cmark_node_insert_after(cmark_node *node, cmark_node *sibling);
  113. CMARK_EXPORT int
  114. cmark_node_prepend_child(cmark_node *node, cmark_node *child);
  115. CMARK_EXPORT int
  116. cmark_node_append_child(cmark_node *node, cmark_node *child);
  117. // Parser
  118. CMARK_EXPORT
  119. cmark_doc_parser *cmark_new_doc_parser();
  120. CMARK_EXPORT
  121. void cmark_free_doc_parser(cmark_doc_parser *parser);
  122. CMARK_EXPORT
  123. cmark_node *cmark_finish(cmark_doc_parser *parser);
  124. CMARK_EXPORT
  125. void cmark_process_line(cmark_doc_parser *parser, const char *buffer, size_t bytes);
  126. CMARK_EXPORT
  127. cmark_node *cmark_parse_document(const char *buffer, size_t len);
  128. CMARK_EXPORT
  129. cmark_node *cmark_parse_file(FILE *f);
  130. // Renderer
  131. CMARK_EXPORT
  132. void cmark_debug_print(cmark_node *root);
  133. CMARK_EXPORT
  134. char *cmark_render_html(cmark_node *root);
  135. CMARK_EXPORT
  136. char *cmark_markdown_to_html(const char *text, int len);
  137. #ifndef CMARK_NO_SHORT_NAMES
  138. #define NODE_DOCUMENT CMARK_NODE_DOCUMENT
  139. #define NODE_BLOCK_QUOTE CMARK_NODE_BLOCK_QUOTE
  140. #define NODE_LIST CMARK_NODE_LIST
  141. #define NODE_LIST_ITEM CMARK_NODE_LIST_ITEM
  142. #define NODE_CODE_BLOCK CMARK_NODE_CODE_BLOCK
  143. #define NODE_HTML CMARK_NODE_HTML
  144. #define NODE_PARAGRAPH CMARK_NODE_PARAGRAPH
  145. #define NODE_HEADER CMARK_NODE_HEADER
  146. #define NODE_HRULE CMARK_NODE_HRULE
  147. #define NODE_REFERENCE_DEF CMARK_NODE_REFERENCE_DEF
  148. #define NODE_STRING CMARK_NODE_STRING
  149. #define NODE_SOFTBREAK CMARK_NODE_SOFTBREAK
  150. #define NODE_LINEBREAK CMARK_NODE_LINEBREAK
  151. #define NODE_INLINE_CODE CMARK_NODE_INLINE_CODE
  152. #define NODE_INLINE_HTML CMARK_NODE_INLINE_HTML
  153. #define NODE_EMPH CMARK_NODE_EMPH
  154. #define NODE_STRONG CMARK_NODE_STRONG
  155. #define NODE_LINK CMARK_NODE_LINK
  156. #define NODE_IMAGE CMARK_NODE_IMAGE
  157. #define NODE_LINK_LABEL CMARK_NODE_LINK_LABEL
  158. #define BULLET_LIST CMARK_BULLET_LIST
  159. #define ORDERED_LIST CMARK_ORDERED_LIST
  160. #define PERIOD_DELIM CMARK_PERIOD_DELIM
  161. #define PAREN_DELIM CMARK_PAREN_DELIM
  162. #define free_simple cmark_free_simple
  163. #define free_blocks cmark_free_blocks
  164. #define doc_parser cmark_doc_parser
  165. #define new_doc_parser cmark_new_doc_parser
  166. #define free_doc_parser cmark_free_doc_parser
  167. #define process_line cmark_process_line
  168. #define finish cmark_finish
  169. #define block_next cmark_block_next
  170. #define block_previous cmark_block_previous
  171. #define block_parent cmark_block_parent
  172. #define block_children cmark_block_children
  173. #define block_delete cmark_block_delete
  174. #define block_insert_before cmark_block_insert_before
  175. #define block_insert_after cmark_block_insert_after
  176. #endif
  177. #ifdef __cplusplus
  178. }
  179. #endif
  180. #endif