aboutsummaryrefslogtreecommitdiff
path: root/src/stmd.h
blob: 957ab03a0c4b5beba4d23eb64ff26ba36588e653 (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. struct node_block {
  61. enum {
  62. document,
  63. block_quote,
  64. list,
  65. list_item,
  66. fenced_code,
  67. indented_code,
  68. html_block,
  69. paragraph,
  70. atx_header,
  71. setext_header,
  72. hrule,
  73. reference_def
  74. } tag;
  75. int start_line;
  76. int start_column;
  77. int end_line;
  78. bool open;
  79. bool last_line_blank;
  80. struct node_block* children;
  81. struct node_block* last_child;
  82. struct node_block* parent;
  83. struct node_block* top;
  84. strbuf string_content;
  85. node_inl* inline_content;
  86. union {
  87. struct ListData list_data;
  88. struct FencedCodeData fenced_code_data;
  89. int header_level;
  90. reference** refmap;
  91. } attributes;
  92. struct node_block * next;
  93. struct node_block * prev;
  94. };
  95. typedef struct node_block node_block;
  96. node_inl* parse_inlines(strbuf *input, reference** refmap);
  97. void free_inlines(node_inl* e);
  98. int parse_reference(strbuf *input, reference** refmap);
  99. void free_reference(reference *ref);
  100. void free_reference_map(reference **refmap);
  101. void add_reference(reference** refmap, reference* ref);
  102. void unescape_buffer(strbuf *buf);
  103. extern node_block* make_document();
  104. extern node_block* add_child(node_block* parent,
  105. int block_type, int start_line, int start_column);
  106. void free_blocks(node_block* e);
  107. extern node_block *stmd_parse_document(const unsigned char *buffer, size_t len);
  108. extern node_block *stmd_parse_file(FILE *f);
  109. void print_inlines(node_inl* ils, int indent);
  110. void print_blocks(node_block* blk, int indent);
  111. void blocks_to_html(strbuf *html, node_block *b, bool tight);
  112. void inlines_to_html(strbuf *html, node_inl *b);
  113. void utf8proc_case_fold(strbuf *dest, const unsigned char *str, int len);
  114. #endif