aboutsummaryrefslogtreecommitdiff
path: root/src/stmd.h
blob: be653717e964f0efb96be4d76f180e8e17f7b00b (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 "uthash.h"
  8. #define VERSION "0.1"
  9. #define CODE_INDENT 4
  10. struct node_inl {
  11. enum {
  12. INL_STRING,
  13. INL_SOFTBREAK,
  14. INL_LINEBREAK,
  15. INL_CODE,
  16. INL_RAW_HTML,
  17. INL_ENTITY,
  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. struct reference {
  36. unsigned char *label;
  37. unsigned char *url;
  38. unsigned char *title;
  39. UT_hash_handle hh; // used by uthash
  40. };
  41. typedef struct reference reference;
  42. // Types for blocks
  43. struct ListData {
  44. enum {
  45. bullet,
  46. ordered
  47. } list_type;
  48. int marker_offset;
  49. int padding;
  50. int start;
  51. enum {
  52. period,
  53. parens
  54. } delimiter;
  55. unsigned char bullet_char;
  56. bool tight;
  57. };
  58. struct FencedCodeData {
  59. int fence_length;
  60. int fence_offset;
  61. char fence_char;
  62. strbuf info;
  63. };
  64. struct node_block {
  65. enum {
  66. BLOCK_DOCUMENT,
  67. BLOCK_BQUOTE,
  68. BLOCK_LIST,
  69. BLOCK_LIST_ITEM,
  70. BLOCK_FENCED_CODE,
  71. BLOCK_INDENTED_CODE,
  72. BLOCK_HTML,
  73. BLOCK_PARAGRAPH,
  74. BLOCK_ATX_HEADER,
  75. BLOCK_SETEXT_HEADER,
  76. BLOCK_HRULE,
  77. BLOCK_REFERENCE_DEF
  78. } tag;
  79. int start_line;
  80. int start_column;
  81. int end_line;
  82. bool open;
  83. bool last_line_blank;
  84. struct node_block* children;
  85. struct node_block* last_child;
  86. struct node_block* parent;
  87. struct node_block* top;
  88. strbuf string_content;
  89. node_inl* inline_content;
  90. union {
  91. struct ListData list_data;
  92. struct FencedCodeData fenced_code_data;
  93. int header_level;
  94. reference** refmap;
  95. } attributes;
  96. struct node_block * next;
  97. struct node_block * prev;
  98. };
  99. typedef struct node_block node_block;
  100. node_inl* parse_inlines(strbuf *input, reference** refmap);
  101. void free_inlines(node_inl* e);
  102. int parse_reference(strbuf *input, reference** refmap);
  103. void free_reference(reference *ref);
  104. void free_reference_map(reference **refmap);
  105. void add_reference(reference** refmap, reference* ref);
  106. void unescape_buffer(strbuf *buf);
  107. extern node_block* make_document();
  108. extern node_block* add_child(node_block* parent,
  109. int block_type, int start_line, int start_column);
  110. void free_blocks(node_block* e);
  111. extern node_block *stmd_parse_document(const unsigned char *buffer, size_t len);
  112. extern node_block *stmd_parse_file(FILE *f);
  113. void print_inlines(node_inl* ils, int indent);
  114. void print_blocks(node_block* blk, int indent);
  115. void blocks_to_html(strbuf *html, node_block *b, bool tight);
  116. void inlines_to_html(strbuf *html, node_inl *b);
  117. void utf8proc_case_fold(strbuf *dest, const unsigned char *str, int len);
  118. #endif