aboutsummaryrefslogtreecommitdiff
path: root/src/stmd.h
blob: 9ed33ecbc2cdc296280871498c2626990f312db7 (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 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 inl *inlines;
  26. struct {
  27. struct inl *label;
  28. unsigned char *url;
  29. unsigned char *title;
  30. } linkable;
  31. } content;
  32. struct inl *next;
  33. };
  34. typedef struct Reference {
  35. unsigned char *label;
  36. unsigned char *url;
  37. unsigned char *title;
  38. UT_hash_handle hh; // used by uthash
  39. } reference;
  40. // Types for blocks
  41. struct ListData {
  42. enum { bullet,
  43. ordered } list_type;
  44. int marker_offset;
  45. int padding;
  46. int start;
  47. enum { period,
  48. parens } delimiter;
  49. unsigned char bullet_char;
  50. bool tight;
  51. };
  52. struct FencedCodeData {
  53. int fence_length;
  54. int fence_offset;
  55. char fence_char;
  56. strbuf info;
  57. };
  58. typedef struct Block {
  59. enum { document,
  60. block_quote,
  61. list,
  62. list_item,
  63. fenced_code,
  64. indented_code,
  65. html_block,
  66. paragraph,
  67. atx_header,
  68. setext_header,
  69. hrule,
  70. 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 Block* children;
  78. struct Block* last_child;
  79. struct Block* parent;
  80. struct Block* top;
  81. strbuf string_content;
  82. struct inl* inline_content;
  83. union {
  84. struct ListData list_data;
  85. struct FencedCodeData fenced_code_data;
  86. int header_level;
  87. reference** refmap;
  88. } attributes;
  89. struct Block * next;
  90. struct Block * prev;
  91. } block;
  92. struct inl* parse_inlines(strbuf *input, reference** refmap);
  93. void free_inlines(struct inl* e);
  94. int parse_reference(strbuf *input, reference** refmap);
  95. void free_reference(reference *ref);
  96. void free_reference_map(reference **refmap);
  97. void add_reference(reference** refmap, reference* ref);
  98. void unescape_buffer(strbuf *buf);
  99. extern block* make_document();
  100. extern block* add_child(block* parent,
  101. int block_type, int start_line, int start_column);
  102. void free_blocks(block* e);
  103. extern block *stmd_parse_document(const unsigned char *buffer, size_t len);
  104. extern block *stmd_parse_file(FILE *f);
  105. void print_inlines(struct inl* ils, int indent);
  106. void print_blocks(block* blk, int indent);
  107. void blocks_to_html(strbuf *html, block *b, bool tight);
  108. void inlines_to_html(strbuf *html, struct inl *b);
  109. void utf8proc_case_fold(strbuf *dest, const unsigned char *str, int len);
  110. #endif