aboutsummaryrefslogtreecommitdiff
path: root/src/stmd.h
blob: c6473a6b1ee746d4ae7e5d380245a3ed74077a7e (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 "references.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_EMPH,
  18. INL_STRONG,
  19. INL_LINK,
  20. INL_IMAGE
  21. } tag;
  22. union {
  23. chunk literal;
  24. struct node_inl *inlines;
  25. struct {
  26. struct node_inl *label;
  27. unsigned char *url;
  28. unsigned char *title;
  29. } linkable;
  30. } content;
  31. struct node_inl *next;
  32. };
  33. typedef struct node_inl node_inl;
  34. // Types for blocks
  35. struct ListData {
  36. enum {
  37. bullet,
  38. ordered
  39. } list_type;
  40. int marker_offset;
  41. int padding;
  42. int start;
  43. enum {
  44. period,
  45. parens
  46. } delimiter;
  47. unsigned char bullet_char;
  48. bool tight;
  49. };
  50. struct FencedCodeData {
  51. int fence_length;
  52. int fence_offset;
  53. char fence_char;
  54. strbuf info;
  55. };
  56. struct node_block {
  57. enum {
  58. BLOCK_DOCUMENT,
  59. BLOCK_BQUOTE,
  60. BLOCK_LIST,
  61. BLOCK_LIST_ITEM,
  62. BLOCK_FENCED_CODE,
  63. BLOCK_INDENTED_CODE,
  64. BLOCK_HTML,
  65. BLOCK_PARAGRAPH,
  66. BLOCK_ATX_HEADER,
  67. BLOCK_SETEXT_HEADER,
  68. BLOCK_HRULE,
  69. BLOCK_REFERENCE_DEF
  70. } tag;
  71. int start_line;
  72. int start_column;
  73. int end_line;
  74. bool open;
  75. bool last_line_blank;
  76. struct node_block* children;
  77. struct node_block* last_child;
  78. struct node_block* parent;
  79. struct node_block* top;
  80. strbuf string_content;
  81. node_inl* inline_content;
  82. union {
  83. struct ListData list;
  84. struct FencedCodeData code;
  85. struct {
  86. int level;
  87. } header;
  88. struct {
  89. reference_map *refmap;
  90. } document;
  91. } as;
  92. struct node_block *next;
  93. struct node_block *prev;
  94. };
  95. typedef struct node_block node_block;
  96. node_block *stmd_parse_document(const unsigned char *buffer, size_t len);
  97. node_block *stmd_parse_file(FILE *f);
  98. void stmd_free_nodes(node_block *e);
  99. void stmd_debug_print(node_block *root);
  100. void stmd_render_html(strbuf *html, node_block *root);
  101. #endif