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 };
54 
55 struct cmark_node {
56   cmark_strbuf content;
57 
58   struct cmark_node *next;
59   struct cmark_node *prev;
60   struct cmark_node *parent;
61   struct cmark_node *first_child;
62   struct cmark_node *last_child;
63 
64   void *user_data;
65   cmark_free_func user_data_free_func;
66 
67   int start_line;
68   int start_column;
69   int end_line;
70   int end_column;
71   int internal_offset;
72   uint16_t type;
73   uint16_t flags;
74 
75   cmark_syntax_extension *extension;
76 
77   union {
78     cmark_chunk literal;
79     cmark_list list;
80     cmark_code code;
81     cmark_heading heading;
82     cmark_link link;
83     cmark_custom custom;
84     int html_block_type;
85     void *opaque;
86   } as;
87 };
88 
cmark_node_mem(cmark_node * node)89 static CMARK_INLINE cmark_mem *cmark_node_mem(cmark_node *node) {
90   return node->content.mem;
91 }
92 CMARK_GFM_EXPORT int cmark_node_check(cmark_node *node, FILE *out);
93 
CMARK_NODE_TYPE_BLOCK_P(cmark_node_type node_type)94 static CMARK_INLINE bool CMARK_NODE_TYPE_BLOCK_P(cmark_node_type node_type) {
95 	return (node_type & CMARK_NODE_TYPE_MASK) == CMARK_NODE_TYPE_BLOCK;
96 }
97 
CMARK_NODE_BLOCK_P(cmark_node * node)98 static CMARK_INLINE bool CMARK_NODE_BLOCK_P(cmark_node *node) {
99 	return node != NULL && CMARK_NODE_TYPE_BLOCK_P((cmark_node_type) node->type);
100 }
101 
CMARK_NODE_TYPE_INLINE_P(cmark_node_type node_type)102 static CMARK_INLINE bool CMARK_NODE_TYPE_INLINE_P(cmark_node_type node_type) {
103 	return (node_type & CMARK_NODE_TYPE_MASK) == CMARK_NODE_TYPE_INLINE;
104 }
105 
CMARK_NODE_INLINE_P(cmark_node * node)106 static CMARK_INLINE bool CMARK_NODE_INLINE_P(cmark_node *node) {
107 	return node != NULL && CMARK_NODE_TYPE_INLINE_P((cmark_node_type) node->type);
108 }
109 
110 CMARK_GFM_EXPORT bool cmark_node_can_contain_type(cmark_node *node, cmark_node_type child_type);
111 
112 #ifdef __cplusplus
113 }
114 #endif
115 
116 #endif
117