github-markdown-jekyll 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,138 @@
1
+ /* markdown.h - generic markdown parser */
2
+
3
+ /*
4
+ * Copyright (c) 2009, Natacha Porté
5
+ *
6
+ * Permission to use, copy, modify, and distribute this software for any
7
+ * purpose with or without fee is hereby granted, provided that the above
8
+ * copyright notice and this permission notice appear in all copies.
9
+ *
10
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17
+ */
18
+
19
+ #ifndef UPSKIRT_MARKDOWN_H
20
+ #define UPSKIRT_MARKDOWN_H
21
+
22
+ #include "buffer.h"
23
+ #include "autolink.h"
24
+
25
+ #ifdef __cplusplus
26
+ extern "C" {
27
+ #endif
28
+
29
+ #define SUNDOWN_VERSION "1.16.0"
30
+ #define SUNDOWN_VER_MAJOR 1
31
+ #define SUNDOWN_VER_MINOR 16
32
+ #define SUNDOWN_VER_REVISION 0
33
+
34
+ /********************
35
+ * TYPE DEFINITIONS *
36
+ ********************/
37
+
38
+ /* mkd_autolink - type of autolink */
39
+ enum mkd_autolink {
40
+ MKDA_NOT_AUTOLINK, /* used internally when it is not an autolink*/
41
+ MKDA_NORMAL, /* normal http/http/ftp/mailto/etc link */
42
+ MKDA_EMAIL, /* e-mail link without explit mailto: */
43
+ };
44
+
45
+ enum mkd_tableflags {
46
+ MKD_TABLE_ALIGN_L = 1,
47
+ MKD_TABLE_ALIGN_R = 2,
48
+ MKD_TABLE_ALIGN_CENTER = 3,
49
+ MKD_TABLE_ALIGNMASK = 3,
50
+ MKD_TABLE_HEADER = 4
51
+ };
52
+
53
+ enum mkd_extensions {
54
+ MKDEXT_NO_INTRA_EMPHASIS = (1 << 0),
55
+ MKDEXT_TABLES = (1 << 1),
56
+ MKDEXT_FENCED_CODE = (1 << 2),
57
+ MKDEXT_AUTOLINK = (1 << 3),
58
+ MKDEXT_STRIKETHROUGH = (1 << 4),
59
+ MKDEXT_SPACE_HEADERS = (1 << 6),
60
+ MKDEXT_SUPERSCRIPT = (1 << 7),
61
+ MKDEXT_LAX_SPACING = (1 << 8),
62
+ };
63
+
64
+ /* sd_callbacks - functions for rendering parsed data */
65
+ struct sd_callbacks {
66
+ /* block level callbacks - NULL skips the block */
67
+ void (*blockcode)(struct buf *ob, const struct buf *text, const struct buf *lang, void *opaque);
68
+ void (*blockquote)(struct buf *ob, const struct buf *text, void *opaque);
69
+ void (*blockhtml)(struct buf *ob,const struct buf *text, void *opaque);
70
+ void (*header)(struct buf *ob, const struct buf *text, int level, void *opaque);
71
+ void (*hrule)(struct buf *ob, void *opaque);
72
+ void (*list)(struct buf *ob, const struct buf *text, int flags, void *opaque);
73
+ void (*listitem)(struct buf *ob, const struct buf *text, int flags, void *opaque);
74
+ void (*paragraph)(struct buf *ob, const struct buf *text, void *opaque);
75
+ void (*table)(struct buf *ob, const struct buf *header, const struct buf *body, void *opaque);
76
+ void (*table_row)(struct buf *ob, const struct buf *text, void *opaque);
77
+ void (*table_cell)(struct buf *ob, const struct buf *text, int flags, void *opaque);
78
+
79
+
80
+ /* span level callbacks - NULL or return 0 prints the span verbatim */
81
+ int (*autolink)(struct buf *ob, const struct buf *link, enum mkd_autolink type, void *opaque);
82
+ int (*codespan)(struct buf *ob, const struct buf *text, void *opaque);
83
+ int (*double_emphasis)(struct buf *ob, const struct buf *text, void *opaque);
84
+ int (*emphasis)(struct buf *ob, const struct buf *text, void *opaque);
85
+ int (*image)(struct buf *ob, const struct buf *link, const struct buf *title, const struct buf *alt, void *opaque);
86
+ int (*linebreak)(struct buf *ob, void *opaque);
87
+ int (*link)(struct buf *ob, const struct buf *link, const struct buf *title, const struct buf *content, void *opaque);
88
+ int (*raw_html_tag)(struct buf *ob, const struct buf *tag, void *opaque);
89
+ int (*triple_emphasis)(struct buf *ob, const struct buf *text, void *opaque);
90
+ int (*strikethrough)(struct buf *ob, const struct buf *text, void *opaque);
91
+ int (*superscript)(struct buf *ob, const struct buf *text, void *opaque);
92
+
93
+ /* low level callbacks - NULL copies input directly into the output */
94
+ void (*entity)(struct buf *ob, const struct buf *entity, void *opaque);
95
+ void (*normal_text)(struct buf *ob, const struct buf *text, void *opaque);
96
+
97
+ /* header and footer */
98
+ void (*doc_header)(struct buf *ob, void *opaque);
99
+ void (*doc_footer)(struct buf *ob, void *opaque);
100
+ };
101
+
102
+ struct sd_markdown;
103
+
104
+ /*********
105
+ * FLAGS *
106
+ *********/
107
+
108
+ /* list/listitem flags */
109
+ #define MKD_LIST_ORDERED 1
110
+ #define MKD_LI_BLOCK 2 /* <li> containing block data */
111
+
112
+ /**********************
113
+ * EXPORTED FUNCTIONS *
114
+ **********************/
115
+
116
+ extern struct sd_markdown *
117
+ sd_markdown_new(
118
+ unsigned int extensions,
119
+ size_t max_nesting,
120
+ const struct sd_callbacks *callbacks,
121
+ void *opaque);
122
+
123
+ extern void
124
+ sd_markdown_render(struct buf *ob, const uint8_t *document, size_t doc_size, struct sd_markdown *md);
125
+
126
+ extern void
127
+ sd_markdown_free(struct sd_markdown *md);
128
+
129
+ extern void
130
+ sd_version(int *major, int *minor, int *revision);
131
+
132
+ #ifdef __cplusplus
133
+ }
134
+ #endif
135
+
136
+ #endif
137
+
138
+ /* vim: set filetype=c: */
@@ -0,0 +1,187 @@
1
+ /*
2
+ * Copyright (c) 2012, Vicent Marti
3
+ *
4
+ * Permission to use, copy, modify, and distribute this software for any
5
+ * purpose with or without fee is hereby granted, provided that the above
6
+ * copyright notice and this permission notice appear in all copies.
7
+ *
8
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
+ */
16
+
17
+ #include "markdown.h"
18
+ #include "plaintext.h"
19
+ #include "buffer.h"
20
+
21
+ #include <string.h>
22
+ #include <stdlib.h>
23
+ #include <stdio.h>
24
+ #include <ctype.h>
25
+
26
+ static void plaintext(struct buf *ob, const struct buf *text)
27
+ {
28
+ if (!text || !text->size)
29
+ return;
30
+
31
+ bufput(ob, text->data, text->size);
32
+ }
33
+
34
+ static void plaintext_block(struct buf *ob, const struct buf *text)
35
+ {
36
+ if (ob->size)
37
+ bufputc(ob, '\n');
38
+
39
+ plaintext(ob, text);
40
+ bufputc(ob, '\n');
41
+ }
42
+
43
+ /********************
44
+ * GENERIC RENDERER *
45
+ ********************/
46
+ static int
47
+ rndr_autolink(struct buf *ob, const struct buf *link, enum mkd_autolink type, void *opaque)
48
+ {
49
+ plaintext(ob, link);
50
+ return 1;
51
+ }
52
+
53
+ static void
54
+ rndr_blockcode(struct buf *ob, const struct buf *text, const struct buf *lang, void *opaque)
55
+ {
56
+ plaintext_block(ob, text);
57
+ }
58
+
59
+ static void
60
+ rndr_blockquote(struct buf *ob, const struct buf *text, void *opaque)
61
+ {
62
+ plaintext_block(ob, text);
63
+ }
64
+
65
+ static int
66
+ rndr_span_element(struct buf *ob, const struct buf *text, void *opaque)
67
+ {
68
+ plaintext(ob, text);
69
+ return 1;
70
+ }
71
+
72
+ static int
73
+ rndr_linebreak(struct buf *ob, void *opaque)
74
+ {
75
+ bufputc(ob, '\n');
76
+ return 1;
77
+ }
78
+
79
+ static void
80
+ rndr_header(struct buf *ob, const struct buf *text, int level, void *opaque)
81
+ {
82
+ plaintext_block(ob, text);
83
+ }
84
+
85
+ static int
86
+ rndr_link(struct buf *ob, const struct buf *link, const struct buf *title, const struct buf *content, void *opaque)
87
+ {
88
+ plaintext(ob, content);
89
+ return 1;
90
+ }
91
+
92
+ static void
93
+ rndr_list(struct buf *ob, const struct buf *text, int flags, void *opaque)
94
+ {
95
+ plaintext_block(ob, text);
96
+ }
97
+
98
+ static void
99
+ rndr_listitem(struct buf *ob, const struct buf *text, int flags, void *opaque)
100
+ {
101
+ BUFPUTSL(ob, "- ");
102
+ plaintext(ob, text);
103
+ bufputc(ob, '\n');
104
+ }
105
+
106
+ static void
107
+ rndr_paragraph(struct buf *ob, const struct buf *text, void *opaque)
108
+ {
109
+ plaintext_block(ob, text);
110
+ }
111
+
112
+ static void
113
+ rndr_hrule(struct buf *ob, void *opaque)
114
+ {
115
+ /* NO OP */
116
+ }
117
+
118
+ static int
119
+ rndr_image(struct buf *ob, const struct buf *link, const struct buf *title, const struct buf *alt, void *opaque)
120
+ {
121
+ /* NO OP */
122
+ return 1;
123
+ }
124
+
125
+ static int
126
+ rndr_raw_html(struct buf *ob, const struct buf *text, void *opaque)
127
+ {
128
+ /* NO OP */
129
+ return 1;
130
+ }
131
+
132
+ static void
133
+ rndr_table(struct buf *ob, const struct buf *header, const struct buf *body, void *opaque)
134
+ {
135
+ plaintext_block(ob, body);
136
+ }
137
+
138
+ static void
139
+ rndr_tablerow(struct buf *ob, const struct buf *text, void *opaque)
140
+ {
141
+ plaintext_block(ob, text);
142
+ }
143
+
144
+ static void
145
+ rndr_tablecell(struct buf *ob, const struct buf *text, int flags, void *opaque)
146
+ {
147
+ plaintext_block(ob, text);
148
+ }
149
+
150
+ void
151
+ sdtext_renderer(struct sd_callbacks *callbacks)
152
+ {
153
+ static const struct sd_callbacks cb_default = {
154
+ rndr_blockcode,
155
+ rndr_blockquote,
156
+ NULL,
157
+ rndr_header,
158
+ rndr_hrule,
159
+ rndr_list,
160
+ rndr_listitem,
161
+ rndr_paragraph,
162
+ rndr_table,
163
+ rndr_tablerow,
164
+ rndr_tablecell,
165
+
166
+ rndr_autolink,
167
+ rndr_span_element,
168
+ rndr_span_element,
169
+ rndr_span_element,
170
+ rndr_image,
171
+ rndr_linebreak,
172
+ rndr_link,
173
+ rndr_raw_html,
174
+ rndr_span_element,
175
+ rndr_span_element,
176
+ rndr_span_element,
177
+
178
+ NULL,
179
+ NULL,
180
+
181
+ NULL,
182
+ NULL,
183
+ };
184
+
185
+ /* Prepare the callbacks */
186
+ memcpy(callbacks, &cb_default, sizeof(struct sd_callbacks));
187
+ }
@@ -0,0 +1,36 @@
1
+ /*
2
+ * Copyright (c) 2011, Vicent Marti
3
+ *
4
+ * Permission to use, copy, modify, and distribute this software for any
5
+ * purpose with or without fee is hereby granted, provided that the above
6
+ * copyright notice and this permission notice appear in all copies.
7
+ *
8
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
+ */
16
+
17
+ #ifndef SUNDOWN_PLAINTEXT_H
18
+ #define SUNDOWN_PLAINTEXT_H
19
+
20
+ #include "markdown.h"
21
+ #include "buffer.h"
22
+ #include <stdlib.h>
23
+
24
+ #ifdef __cplusplus
25
+ extern "C" {
26
+ #endif
27
+
28
+ extern void
29
+ sdtext_renderer(struct sd_callbacks *callbacks);
30
+
31
+ #ifdef __cplusplus
32
+ }
33
+ #endif
34
+
35
+ #endif
36
+
@@ -0,0 +1,81 @@
1
+ #include "stack.h"
2
+ #include <string.h>
3
+
4
+ int
5
+ stack_grow(struct stack *st, size_t new_size)
6
+ {
7
+ void **new_st;
8
+
9
+ if (st->asize >= new_size)
10
+ return 0;
11
+
12
+ new_st = realloc(st->item, new_size * sizeof(void *));
13
+ if (new_st == NULL)
14
+ return -1;
15
+
16
+ memset(new_st + st->asize, 0x0,
17
+ (new_size - st->asize) * sizeof(void *));
18
+
19
+ st->item = new_st;
20
+ st->asize = new_size;
21
+
22
+ if (st->size > new_size)
23
+ st->size = new_size;
24
+
25
+ return 0;
26
+ }
27
+
28
+ void
29
+ stack_free(struct stack *st)
30
+ {
31
+ if (!st)
32
+ return;
33
+
34
+ free(st->item);
35
+
36
+ st->item = NULL;
37
+ st->size = 0;
38
+ st->asize = 0;
39
+ }
40
+
41
+ int
42
+ stack_init(struct stack *st, size_t initial_size)
43
+ {
44
+ st->item = NULL;
45
+ st->size = 0;
46
+ st->asize = 0;
47
+
48
+ if (!initial_size)
49
+ initial_size = 8;
50
+
51
+ return stack_grow(st, initial_size);
52
+ }
53
+
54
+ void *
55
+ stack_pop(struct stack *st)
56
+ {
57
+ if (!st->size)
58
+ return NULL;
59
+
60
+ return st->item[--st->size];
61
+ }
62
+
63
+ int
64
+ stack_push(struct stack *st, void *item)
65
+ {
66
+ if (stack_grow(st, st->size * 2) < 0)
67
+ return -1;
68
+
69
+ st->item[st->size++] = item;
70
+ return 0;
71
+ }
72
+
73
+ void *
74
+ stack_top(struct stack *st)
75
+ {
76
+ if (!st->size)
77
+ return NULL;
78
+
79
+ return st->item[st->size - 1];
80
+ }
81
+
@@ -0,0 +1,29 @@
1
+ #ifndef STACK_H__
2
+ #define STACK_H__
3
+
4
+ #include <stdlib.h>
5
+
6
+ #ifdef __cplusplus
7
+ extern "C" {
8
+ #endif
9
+
10
+ struct stack {
11
+ void **item;
12
+ size_t size;
13
+ size_t asize;
14
+ };
15
+
16
+ void stack_free(struct stack *);
17
+ int stack_grow(struct stack *, size_t);
18
+ int stack_init(struct stack *, size_t);
19
+
20
+ int stack_push(struct stack *, void *);
21
+
22
+ void *stack_pop(struct stack *);
23
+ void *stack_top(struct stack *);
24
+
25
+ #ifdef __cplusplus
26
+ }
27
+ #endif
28
+
29
+ #endif