aboutsummaryrefslogtreecommitdiff
path: root/src/stmd.h
blob: eb1b9891e3bb75462641f689b220ae8ea0889ebd (plain)
  1. #include <stdbool.h>
  2. #include "buffer.h"
  3. #include "uthash.h"
  4. #define VERSION "0.1"
  5. #define CODE_INDENT 4
  6. typedef struct {
  7. const unsigned char *data;
  8. int len;
  9. int alloc;
  10. } chunk;
  11. typedef struct Inline {
  12. enum { str, softbreak, linebreak, code, raw_html, entity,
  13. emph, strong, link, image } tag;
  14. union {
  15. chunk literal;
  16. struct Inline *inlines;
  17. struct {
  18. struct Inline *label;
  19. unsigned char *url;
  20. unsigned char *title;
  21. } linkable;
  22. } content;
  23. struct Inline *next;
  24. } inl;
  25. typedef struct Reference {
  26. unsigned char *label;
  27. unsigned char *url;
  28. unsigned char *title;
  29. UT_hash_handle hh; // used by uthash
  30. } reference;
  31. // Types for blocks
  32. struct ListData {
  33. enum { bullet,
  34. ordered } list_type;
  35. int marker_offset;
  36. int padding;
  37. int start;
  38. enum { period,
  39. parens } delimiter;
  40. unsigned char bullet_char;
  41. bool tight;
  42. };
  43. struct FencedCodeData {
  44. int fence_length;
  45. int fence_offset;
  46. char fence_char;
  47. gh_buf info;
  48. };
  49. typedef struct Block {
  50. enum { document,
  51. block_quote,
  52. list,
  53. list_item,
  54. fenced_code,
  55. indented_code,
  56. html_block,
  57. paragraph,
  58. atx_header,
  59. setext_header,
  60. hrule,
  61. reference_def
  62. } tag;
  63. int start_line;
  64. int start_column;
  65. int end_line;
  66. bool open;
  67. bool last_line_blank;
  68. struct Block* children;
  69. struct Block* last_child;
  70. struct Block* parent;
  71. struct Block* top;
  72. gh_buf string_content;
  73. int string_pos;
  74. inl* inline_content;
  75. union {
  76. struct ListData list_data;
  77. struct FencedCodeData fenced_code_data;
  78. int header_level;
  79. reference** refmap;
  80. } attributes;
  81. struct Block * next;
  82. struct Block * prev;
  83. } block;
  84. inl* parse_inlines(gh_buf *input, int input_pos, reference** refmap);
  85. void free_inlines(inl* e);
  86. int parse_reference(gh_buf *input, int input_pos, reference** refmap);
  87. void free_reference(reference *ref);
  88. void free_reference_map(reference **refmap);
  89. void add_reference(reference** refmap, reference* ref);
  90. void unescape_buffer(gh_buf *buf);
  91. extern block* make_document();
  92. extern block* add_child(block* parent,
  93. int block_type, int start_line, int start_column);
  94. void free_blocks(block* e);
  95. block *stmd_parse_document(const char *buffer, size_t len);
  96. // FOR NOW:
  97. void process_inlines(block* cur, reference** refmap);
  98. void incorporate_line(gh_buf *ln, int line_number, block** curptr);
  99. void finalize(block* b, int line_number);
  100. void print_inlines(inl* ils, int indent);
  101. void print_blocks(block* blk, int indent);
  102. /* TODO */
  103. // int blocks_to_html(block* b, bstring* result, bool tight);
  104. // int inlines_to_html(inl* b, bstring* result);
  105. void utf8proc_case_fold(gh_buf *dest, const unsigned char *str, int len);