1 #ifndef CMARK_NODE_H
2 #define CMARK_NODE_H
3 
4 #ifdef __cplusplus
5 extern "C" {
6 #endif
7 
8 #include <stdio.h>
9 #include <stdint.h>
10 
11 #include "cmark-gfm.h"
12 #include "cmark-gfm-extension_api.h"
13 #include "buffer.h"
14 #include "chunk.h"
15 
16 typedef struct {
17   cmark_list_type list_type;
18   int marker_offset;
19   int padding;
20   int start;
21   cmark_delim_type delimiter;
22   unsigned char bullet_char;
23   bool tight;
24 } cmark_list;
25 
26 typedef struct {
27   cmark_chunk info;
28   cmark_chunk literal;
29   uint8_t fence_length;
30   uint8_t fence_offset;
31   unsigned char fence_char;
32   int8_t fenced;
33 } cmark_code;
34 
35 typedef struct {
36   int level;
37   bool setext;
38 } cmark_heading;
39 
40 typedef struct {
41   cmark_chunk url;
42   cmark_chunk title;
43 } cmark_link;
44 
45 typedef struct {
46   cmark_chunk on_enter;
47   cmark_chunk on_exit;
48 } cmark_custom;
49 
50 enum cmark_node__internal_flags {
51   CMARK_NODE__OPEN = (1 << 0),
52   CMARK_NODE__LAST_LINE_BLANK = (1 << 1),
53   CMARK_NODE__LAST_LINE_CHECKED = (1 << 2),
54 };
55 
56 struct cmark_node {
57   cmark_strbuf content;
58 
59   struct cmark_node *next;
60   struct cmark_node *prev;
61   struct cmark_node *parent;
62   struct cmark_node *first_child;
63   struct cmark_node *last_child;
64 
65   void *user_data;
66   cmark_free_func user_data_free_func;
67 
68   int start_line;
69   int start_column;
70   int end_line;
71   int end_column;
72   int internal_offset;
73   uint16_t type;
74   uint16_t flags;
75 
76   cmark_syntax_extension *extension;
77 
78   union {
79     cmark_chunk literal;
80     cmark_list list;
81     cmark_code code;
82     cmark_heading heading;
83     cmark_link link;
84     cmark_custom custom;
85     int html_block_type;
86     void *opaque;
87   } as;
88 };
89 
cmark_node_mem(cmark_node * node)90 static CMARK_INLINE cmark_mem *cmark_node_mem(cmark_node *node) {
91   return node->content.mem;
92 }
93 CMARK_GFM_EXPORT int cmark_node_check(cmark_node *node, FILE *out);
94 
CMARK_NODE_TYPE_BLOCK_P(cmark_node_type node_type)95 static CMARK_INLINE bool CMARK_NODE_TYPE_BLOCK_P(cmark_node_type node_type) {
96 	return (node_type & CMARK_NODE_TYPE_MASK) == CMARK_NODE_TYPE_BLOCK;
97 }
98 
CMARK_NODE_BLOCK_P(cmark_node * node)99 static CMARK_INLINE bool CMARK_NODE_BLOCK_P(cmark_node *node) {
100 	return node != NULL && CMARK_NODE_TYPE_BLOCK_P((cmark_node_type) node->type);
101 }
102 
CMARK_NODE_TYPE_INLINE_P(cmark_node_type node_type)103 static CMARK_INLINE bool CMARK_NODE_TYPE_INLINE_P(cmark_node_type node_type) {
104 	return (node_type & CMARK_NODE_TYPE_MASK) == CMARK_NODE_TYPE_INLINE;
105 }
106 
CMARK_NODE_INLINE_P(cmark_node * node)107 static CMARK_INLINE bool CMARK_NODE_INLINE_P(cmark_node *node) {
108 	return node != NULL && CMARK_NODE_TYPE_INLINE_P((cmark_node_type) node->type);
109 }
110 
111 CMARK_GFM_EXPORT bool cmark_node_can_contain_type(cmark_node *node, cmark_node_type child_type);
112 
113 #ifdef __cplusplus
114 }
115 #endif
116 
117 #endif
118