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