1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
/*
* blogc: A blog compiler.
* Copyright (C) 2015-2016 Rafael G. Martins <rafael@rafaelmartins.eng.br>
*
* This program can be distributed under the terms of the BSD License.
* See the file LICENSE.
*/
#ifndef _CONTENT_PARSER_H
#define _CONTENT_PARSER_H
#include <stddef.h>
#include <stdbool.h>
#include "utils.h"
/*
* Raw node
*
* +-----+
* | RAW | -> ...
* +-----+
*
*/
/*
* Header node
*
* +--------+
* | HEADER | -> ...
* +--------+
* |
* +-----+ +------+ +-----+
* | raw | -> | bold | -> | raw | -> ...
* +-----+ +------+ +-----+
*
*/
/*
* Blockquote node
*
* +------------+
* | BLOCKQUOTE | -> ...
* +------------+
* |
* +-----------+ +--------+ +-----------+
* | PARAGRAPH | -> | HEADER | -> | PARAGRAPH | -> ...
* +-----------+ +--------+ +-----------+
* |
* +-----+
* | raw | -> ...
* +-----+
*
*/
/*
* Code node
*
* +------+
* | CODE | -> ...
* +------+
*
*/
/*
* Horizontal rule node
*
* +-----------------+
* | HORIZONTAL_RULE | -> ...
* +-----------------+
*
*/
/*
* Unordered list node
*
* +----------------+
* | UNORDERED_LIST | -> ...
* +----------------+
* |
* +-----------+ +-----------+
* | LIST_ITEM | -> | LIST_ITEM | -> ...
* +-----------+ +-----------+
* |
* +-----+ +------+
* | raw | -> | bold | -> ...
* +-----+ +------+
*
*/
/*
* Ordered list node
*
* +--------------+
* | ORDERED_LIST | -> ...
* +--------------+
* |
* +-----------+ +-----------+
* | LIST_ITEM | -> | LIST_ITEM | -> ...
* +-----------+ +-----------+
* |
* +-----+ +------+
* | raw | -> | bold | -> ...
* +-----+ +------+
*
*/
/*
* Paragraph node
*
* +-----------+
* | PARAGRAPH | -> ...
* +-----------+
* |
* +-----+ +------+ +-----+
* | raw | -> | bold | -> | raw |
* +-----+ +------+ +-----+
*
*/
typedef enum {
BLOGC_CONTENT_BLOCK = 1,
BLOGC_CONTENT_INLINE,
} blogc_content_node_type_t;
typedef enum {
BLOGC_CONTENT_BLOCK_RAW = 1,
BLOGC_CONTENT_BLOCK_HEADER,
BLOGC_CONTENT_BLOCK_BLOCKQUOTE,
BLOGC_CONTENT_BLOCK_CODE,
BLOGC_CONTENT_BLOCK_HORIZONTAL_RULE,
BLOGC_CONTENT_BLOCK_UNORDERED_LIST,
BLOGC_CONTENT_BLOCK_ORDERED_LIST,
BLOGC_CONTENT_BLOCK_LIST_ITEM,
BLOGC_CONTENT_BLOCK_PARAGRAPH,
BLOGC_CONTENT_BLOCK_EXCERPT,
} blogc_content_block_type_t;
typedef enum {
BLOGC_CONTENT_INLINE_RAW = 1,
BLOGC_CONTENT_INLINE_LINK,
BLOGC_CONTENT_INLINE_IMAGE,
BLOGC_CONTENT_INLINE_BOLD,
BLOGC_CONTENT_INLINE_ITALIC,
BLOGC_CONTENT_INLINE_CODE,
BLOGC_CONTENT_INLINE_BREAK_LINE,
} blogc_content_inline_type_t;
typedef struct _blogc_content_node_t {
blogc_content_node_type_t node_type;
union {
blogc_content_block_type_t block_type;
blogc_content_inline_type_t inline_type;
} type;
char *content;
struct _blogc_content_node_t *child;
struct _blogc_content_node_t *next;
sb_trie_t *parameters;
} blogc_content_node_t;
char* blogc_slugify(const char *str);
char* blogc_htmlentities(const char *str);
char* blogc_fix_description(const char *paragraph);
char* blogc_content_parse_inline(const char *src);
bool blogc_is_ordered_list_item(const char *str, size_t prefix_len);
blogc_content_node_t* blogc_content_parse_ast(const char *src, char **nl);
void blogc_content_free_ast(blogc_content_node_t *ast);
char* blogc_content_parse(const char *src, char **excerpt, char **description);
char* blogc_content_render_html(blogc_content_node_t *ast, char *nl, char **excerpt,
char **description);
void blogc_content_debug(blogc_content_node_t *ast);
#endif /* _CONTENT_PARSER_H */
|