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