aboutsummaryrefslogtreecommitdiff
path: root/src/stmd.h
blob: 5e34399cfea8d718e7906cf439d4dd4a2a2bb072 (plain)
  1. #include <stdbool.h>
  2. #include "bstrlib.h"
  3. #include "uthash.h"
  4. #define VERSION "0.1"
  5. #define CODE_INDENT 4
  6. typedef struct Inline {
  7. enum { str, softbreak, linebreak, code, raw_html, entity,
  8. emph, strong, link, image } tag;
  9. union {
  10. bstring literal;
  11. struct Inline* inlines;
  12. struct { struct Inline* label;
  13. bstring url;
  14. bstring title;
  15. } linkable;
  16. } content;
  17. struct Inline* next;
  18. } inl;
  19. typedef struct Reference {
  20. bstring label;
  21. bstring url;
  22. bstring title;
  23. UT_hash_handle hh; // used by uthash
  24. } reference;
  25. typedef struct Subject {
  26. bstring buffer;
  27. int pos;
  28. reference** reference_map;
  29. int label_nestlevel;
  30. } subject;
  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. bstring 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. bstring string_content;
  73. inl* inline_content;
  74. union {
  75. struct ListData list_data;
  76. struct FencedCodeData fenced_code_data;
  77. int header_level;
  78. reference** refmap;
  79. } attributes;
  80. struct Block * next;
  81. struct Block * prev;
  82. } block;
  83. int parse_inline(subject* subj, inl ** last);
  84. inl* parse_inlines(bstring input, reference** refmap);
  85. inl* parse_inlines_while(subject* subj, int (*f)(subject*));
  86. void free_inlines(inl* e);
  87. int parse_reference(bstring input, reference** refmap);
  88. void free_reference(reference *ref);
  89. void free_reference_map(reference **refmap);
  90. reference* make_reference(bstring label, bstring url, bstring title);
  91. reference* lookup_reference(reference** refmap, bstring label);
  92. void add_reference(reference** refmap, reference* ref);
  93. int unescape(bstring s);
  94. extern block* make_document();
  95. extern block* add_child(block* parent,
  96. int block_type, int start_line, int start_column);
  97. void free_blocks(block* e);
  98. // FOR NOW:
  99. int process_inlines(block* cur, reference** refmap);
  100. int incorporate_line(bstring ln, int line_number, block** curptr);
  101. int finalize(block* b, int line_number);
  102. void print_inlines(inl* ils, int indent);
  103. void print_blocks(block* blk, int indent);
  104. int blocks_to_html(block* b, bstring* result, bool tight);
  105. int inlines_to_html(inl* b, bstring* result);
  106. int bdetab(bstring s, int utf8);