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