aboutsummaryrefslogtreecommitdiff
path: root/src/cmark.h
blob: a135fa91b85990e7cbeea20555edac5861958e04 (plain)
  1. #ifndef _STDMD_H_
  2. #define _STDMD_H_
  3. #include <stdbool.h>
  4. #include <stdio.h>
  5. #include "buffer.h"
  6. #include "chunk.h"
  7. #include "references.h"
  8. #define VERSION "0.1"
  9. #define CODE_INDENT 4
  10. #define MAX_LINK_LABEL_LENGTH 1000
  11. struct node_inl {
  12. enum {
  13. INL_STRING,
  14. INL_SOFTBREAK,
  15. INL_LINEBREAK,
  16. INL_CODE,
  17. INL_RAW_HTML,
  18. INL_EMPH,
  19. INL_STRONG,
  20. INL_LINK,
  21. INL_IMAGE
  22. } tag;
  23. union {
  24. chunk literal;
  25. struct node_inl *inlines;
  26. struct {
  27. struct node_inl *label;
  28. unsigned char *url;
  29. unsigned char *title;
  30. } linkable;
  31. } content;
  32. struct node_inl *next;
  33. };
  34. typedef struct node_inl node_inl;
  35. // Types for blocks
  36. struct ListData {
  37. enum {
  38. bullet,
  39. ordered
  40. } list_type;
  41. int marker_offset;
  42. int padding;
  43. int start;
  44. enum {
  45. period,
  46. parens
  47. } delimiter;
  48. unsigned char bullet_char;
  49. bool tight;
  50. };
  51. struct FencedCodeData {
  52. int fence_length;
  53. int fence_offset;
  54. unsigned char fence_char;
  55. strbuf info;
  56. };
  57. struct node_block {
  58. enum {
  59. BLOCK_DOCUMENT,
  60. BLOCK_BQUOTE,
  61. BLOCK_LIST,
  62. BLOCK_LIST_ITEM,
  63. BLOCK_FENCED_CODE,
  64. BLOCK_INDENTED_CODE,
  65. BLOCK_HTML,
  66. BLOCK_PARAGRAPH,
  67. BLOCK_ATX_HEADER,
  68. BLOCK_SETEXT_HEADER,
  69. BLOCK_HRULE,
  70. BLOCK_REFERENCE_DEF
  71. } tag;
  72. int start_line;
  73. int start_column;
  74. int end_line;
  75. bool open;
  76. bool last_line_blank;
  77. struct node_block* children;
  78. struct node_block* last_child;
  79. struct node_block* parent;
  80. struct node_block* top;
  81. strbuf string_content;
  82. node_inl* inline_content;
  83. union {
  84. struct ListData list;
  85. struct FencedCodeData code;
  86. struct {
  87. int level;
  88. } header;
  89. struct {
  90. reference_map *refmap;
  91. } document;
  92. } as;
  93. struct node_block *next;
  94. struct node_block *prev;
  95. };
  96. typedef struct node_block node_block;
  97. node_block *cmark_parse_document(const unsigned char *buffer, size_t len);
  98. node_block *cmark_parse_file(FILE *f);
  99. void cmark_free_nodes(node_block *e);
  100. void cmark_debug_print(node_block *root);
  101. void cmark_render_html(strbuf *html, node_block *root);
  102. #endif