aboutsummaryrefslogtreecommitdiff
path: root/src/cmark.h
blob: 5f0d5f7eb3c2cd5d2b6db31d46379fd6aae388c1 (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 VERSION "0.1"
  12. #define CODE_INDENT 4
  13. #define MAX_LINK_LABEL_LENGTH 1000
  14. struct node_inl {
  15. enum {
  16. INL_STRING,
  17. INL_SOFTBREAK,
  18. INL_LINEBREAK,
  19. INL_CODE,
  20. INL_RAW_HTML,
  21. INL_EMPH,
  22. INL_STRONG,
  23. INL_LINK,
  24. INL_IMAGE
  25. } tag;
  26. union {
  27. chunk literal;
  28. struct node_inl *inlines;
  29. struct {
  30. struct node_inl *label;
  31. unsigned char *url;
  32. unsigned char *title;
  33. } linkable;
  34. } content;
  35. struct node_inl *next;
  36. };
  37. typedef struct node_inl node_inl;
  38. // Types for blocks
  39. struct 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 FencedCodeData {
  55. int fence_length;
  56. int fence_offset;
  57. unsigned char fence_char;
  58. strbuf info;
  59. };
  60. struct node_block {
  61. enum {
  62. BLOCK_DOCUMENT,
  63. BLOCK_BQUOTE,
  64. BLOCK_LIST,
  65. BLOCK_LIST_ITEM,
  66. BLOCK_FENCED_CODE,
  67. BLOCK_INDENTED_CODE,
  68. BLOCK_HTML,
  69. BLOCK_PARAGRAPH,
  70. BLOCK_ATX_HEADER,
  71. BLOCK_SETEXT_HEADER,
  72. BLOCK_HRULE,
  73. 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 node_block* children;
  81. struct node_block* last_child;
  82. struct node_block* parent;
  83. struct node_block* top;
  84. strbuf string_content;
  85. node_inl* inline_content;
  86. union {
  87. struct ListData list;
  88. struct FencedCodeData code;
  89. struct {
  90. int level;
  91. } header;
  92. struct {
  93. reference_map *refmap;
  94. } document;
  95. } as;
  96. struct node_block *next;
  97. struct node_block *prev;
  98. };
  99. typedef struct node_block node_block;
  100. node_block *cmark_parse_document(const unsigned char *buffer, size_t len);
  101. node_block *cmark_parse_file(FILE *f);
  102. void cmark_free_nodes(node_block *e);
  103. void cmark_debug_print(node_block *root);
  104. void cmark_render_html(strbuf *html, node_block *root);
  105. unsigned char *cmark_markdown_to_html(unsigned char *text, int len);
  106. #ifdef __cplusplus
  107. }
  108. #endif
  109. #endif