aboutsummaryrefslogtreecommitdiff
path: root/src/cmark.h
blob: de62fe2d24f0d6cbb86eb277165e6e9b351136e0 (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_BQUOTE,
  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_ATX_HEADER,
  20. CMARK_NODE_SETEXT_HEADER,
  21. CMARK_NODE_HRULE,
  22. CMARK_NODE_REFERENCE_DEF,
  23. CMARK_NODE_FIRST_BLOCK = CMARK_NODE_DOCUMENT,
  24. CMARK_NODE_LAST_BLOCK = CMARK_NODE_REFERENCE_DEF,
  25. // Inline
  26. CMARK_NODE_STRING,
  27. CMARK_NODE_SOFTBREAK,
  28. CMARK_NODE_LINEBREAK,
  29. CMARK_NODE_INLINE_CODE,
  30. CMARK_NODE_INLINE_HTML,
  31. CMARK_NODE_EMPH,
  32. CMARK_NODE_STRONG,
  33. CMARK_NODE_LINK,
  34. CMARK_NODE_IMAGE,
  35. CMARK_NODE_FIRST_INLINE = CMARK_NODE_STRING,
  36. CMARK_NODE_LAST_INLINE = CMARK_NODE_IMAGE,
  37. // Other
  38. CMARK_NODE_LINK_LABEL
  39. } cmark_node_type;
  40. typedef enum {
  41. CMARK_BULLET_LIST,
  42. CMARK_ORDERED_LIST
  43. } cmark_list_type;
  44. typedef enum {
  45. CMARK_PERIOD_DELIM,
  46. CMARK_PAREN_DELIM
  47. } cmark_delim_type;
  48. typedef struct cmark_node cmark_node;
  49. typedef struct cmark_doc_parser cmark_doc_parser;
  50. CMARK_EXPORT cmark_node_type
  51. cmark_node_get_type(cmark_node *node);
  52. // Tree traversal
  53. CMARK_EXPORT cmark_node*
  54. cmark_node_next(cmark_node *node);
  55. CMARK_EXPORT cmark_node*
  56. cmark_node_previous(cmark_node *node);
  57. CMARK_EXPORT cmark_node*
  58. cmark_node_parent(cmark_node *node);
  59. CMARK_EXPORT cmark_node*
  60. cmark_node_first_child(cmark_node *node);
  61. CMARK_EXPORT cmark_node*
  62. cmark_node_last_child(cmark_node *node);
  63. // Tree manipulation
  64. CMARK_EXPORT void
  65. cmark_node_unlink(cmark_node *node);
  66. CMARK_EXPORT int
  67. cmark_node_insert_before(cmark_node *node, cmark_node *sibling);
  68. CMARK_EXPORT int
  69. cmark_node_insert_before(cmark_node *node, cmark_node *sibling);
  70. CMARK_EXPORT int
  71. cmark_node_prepend_child(cmark_node *node, cmark_node *child);
  72. CMARK_EXPORT int
  73. cmark_node_append_child(cmark_node *node, cmark_node *child);
  74. // Parser
  75. CMARK_EXPORT
  76. cmark_doc_parser *cmark_new_doc_parser();
  77. CMARK_EXPORT
  78. void cmark_free_doc_parser(cmark_doc_parser *parser);
  79. CMARK_EXPORT
  80. cmark_node *cmark_finish(cmark_doc_parser *parser);
  81. CMARK_EXPORT
  82. void cmark_process_line(cmark_doc_parser *parser, const unsigned char *buffer, size_t bytes);
  83. CMARK_EXPORT
  84. cmark_node *cmark_parse_document(const unsigned char *buffer, size_t len);
  85. CMARK_EXPORT
  86. cmark_node *cmark_parse_file(FILE *f);
  87. // Renderer
  88. CMARK_EXPORT
  89. void cmark_debug_print(cmark_node *root);
  90. CMARK_EXPORT
  91. unsigned char *cmark_render_html(cmark_node *root);
  92. CMARK_EXPORT
  93. unsigned char *cmark_markdown_to_html(unsigned char *text, int len);
  94. CMARK_EXPORT
  95. void cmark_free_nodes(cmark_node *e);
  96. #ifndef CMARK_NO_SHORT_NAMES
  97. #define NODE_DOCUMENT CMARK_NODE_DOCUMENT
  98. #define NODE_BQUOTE CMARK_NODE_BQUOTE
  99. #define NODE_LIST CMARK_NODE_LIST
  100. #define NODE_LIST_ITEM CMARK_NODE_LIST_ITEM
  101. #define NODE_FENCED_CODE CMARK_NODE_FENCED_CODE
  102. #define NODE_INDENTED_CODE CMARK_NODE_INDENTED_CODE
  103. #define NODE_HTML CMARK_NODE_HTML
  104. #define NODE_PARAGRAPH CMARK_NODE_PARAGRAPH
  105. #define NODE_ATX_HEADER CMARK_NODE_ATX_HEADER
  106. #define NODE_SETEXT_HEADER CMARK_NODE_SETEXT_HEADER
  107. #define NODE_HRULE CMARK_NODE_HRULE
  108. #define NODE_REFERENCE_DEF CMARK_NODE_REFERENCE_DEF
  109. #define NODE_STRING CMARK_NODE_STRING
  110. #define NODE_SOFTBREAK CMARK_NODE_SOFTBREAK
  111. #define NODE_LINEBREAK CMARK_NODE_LINEBREAK
  112. #define NODE_INLINE_CODE CMARK_NODE_INLINE_CODE
  113. #define NODE_INLINE_HTML CMARK_NODE_INLINE_HTML
  114. #define NODE_EMPH CMARK_NODE_EMPH
  115. #define NODE_STRONG CMARK_NODE_STRONG
  116. #define NODE_LINK CMARK_NODE_LINK
  117. #define NODE_IMAGE CMARK_NODE_IMAGE
  118. #define NODE_LINK_LABEL CMARK_NODE_LINK_LABEL
  119. #define BULLET_LIST CMARK_BULLET_LIST
  120. #define ORDERED_LIST CMARK_ORDERED_LIST
  121. #define PERIOD_DELIM CMARK_PERIOD_DELIM
  122. #define PAREN_DELIM CMARK_PAREN_DELIM
  123. #define free_simple cmark_free_simple
  124. #define free_blocks cmark_free_blocks
  125. #define doc_parser cmark_doc_parser
  126. #define new_doc_parser cmark_new_doc_parser
  127. #define free_doc_parser cmark_free_doc_parser
  128. #define process_line cmark_process_line
  129. #define finish cmark_finish
  130. #define block_next cmark_block_next
  131. #define block_previous cmark_block_previous
  132. #define block_parent cmark_block_parent
  133. #define block_children cmark_block_children
  134. #define block_delete cmark_block_delete
  135. #define block_insert_before cmark_block_insert_before
  136. #define block_insert_after cmark_block_insert_after
  137. #endif
  138. #ifdef __cplusplus
  139. }
  140. #endif
  141. #endif