aboutsummaryrefslogtreecommitdiff
path: root/src/cmark.h
blob: 8b299342e6a4fd90c928bef8d755e36fd0fe04b2 (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. cmark_node_block *cmark_parse_document(const unsigned char *buffer, size_t len);
  101. cmark_node_block *cmark_parse_file(FILE *f);
  102. void cmark_free_nodes(cmark_node_block *e);
  103. void cmark_debug_print(cmark_node_block *root);
  104. void cmark_render_html(cmark_strbuf *html, cmark_node_block *root);
  105. unsigned char *cmark_markdown_to_html(unsigned char *text, int len);
  106. #ifndef CMARK_NO_SHORT_NAMES
  107. #define VERSION CMARK_VERSION
  108. #define CODE_INDENT CMARK_CODE_INDENT
  109. #define MAX_LINK_LABEL_LENGTH CMARK_MAX_LINK_LABEL_LENGTH
  110. #define node_inl cmark_node_inl
  111. #define INL_STRING CMARK_INL_STRING
  112. #define INL_SOFTBREAK CMARK_INL_SOFTBREAK
  113. #define INL_LINEBREAK CMARK_INL_LINEBREAK
  114. #define INL_CODE CMARK_INL_CODE
  115. #define INL_RAW_HTML CMARK_INL_RAW_HTML
  116. #define INL_EMPH CMARK_INL_EMPH
  117. #define INL_STRONG CMARK_INL_STRONG
  118. #define INL_LINK CMARK_INL_LINK
  119. #define INL_IMAGE CMARK_INL_IMAGE
  120. #define ListData cmark_ListData
  121. #define FencedCodeData cmark_FencedCodeData
  122. #define node_block cmark_node_block
  123. #define BLOCK_DOCUMENT CMARK_BLOCK_DOCUMENT
  124. #define BLOCK_BQUOTE CMARK_BLOCK_BQUOTE
  125. #define BLOCK_LIST CMARK_BLOCK_LIST
  126. #define BLOCK_LIST_ITEM CMARK_BLOCK_LIST_ITEM
  127. #define BLOCK_FENCED_CODE CMARK_BLOCK_FENCED_CODE
  128. #define BLOCK_INDENTED_CODE CMARK_BLOCK_INDENTED_CODE
  129. #define BLOCK_HTML CMARK_BLOCK_HTML
  130. #define BLOCK_PARAGRAPH CMARK_BLOCK_PARAGRAPH
  131. #define BLOCK_ATX_HEADER CMARK_BLOCK_ATX_HEADER
  132. #define BLOCK_SETEXT_HEADER CMARK_BLOCK_SETEXT_HEADER
  133. #define BLOCK_HRULE CMARK_BLOCK_HRULE
  134. #define BLOCK_REFERENCE_DEF CMARK_BLOCK_REFERENCE_DEF
  135. #endif
  136. #ifdef __cplusplus
  137. }
  138. #endif
  139. #endif