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