github-markdown 0.3.2 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +1 -0
- data/ext/markdown/gh-markdown.c +17 -1
- data/ext/markdown/plaintext.c +193 -0
- data/ext/markdown/plaintext.h +36 -0
- data/github-markdown.gemspec +4 -2
- metadata +7 -5
data/Rakefile
CHANGED
@@ -74,6 +74,7 @@ task :gather => 'sundown/src/markdown.h' do |t|
|
|
74
74
|
'sundown/src/{markdown,buffer,stack,autolink}.c',
|
75
75
|
'sundown/html/{html,houdini_html_e,houdini_href_e}.c',
|
76
76
|
'sundown/html/{html,houdini}.h',
|
77
|
+
'sundown/plaintext/plaintext.{c,h}',
|
77
78
|
]
|
78
79
|
cp files, 'ext/markdown/',
|
79
80
|
:preserve => true,
|
data/ext/markdown/gh-markdown.c
CHANGED
@@ -25,11 +25,12 @@
|
|
25
25
|
|
26
26
|
#include "markdown.h"
|
27
27
|
#include "html.h"
|
28
|
+
#include "plaintext.h"
|
28
29
|
|
29
30
|
static struct {
|
30
31
|
struct sd_markdown *md;
|
31
32
|
struct html_renderopt render_opts;
|
32
|
-
} g_markdown, g_GFM;
|
33
|
+
} g_markdown, g_GFM, g_plaintext;
|
33
34
|
|
34
35
|
static void
|
35
36
|
rndr_blockcode_github(
|
@@ -104,6 +105,8 @@ static VALUE rb_ghmd_to_html(VALUE self, VALUE rb_text, VALUE rb_mode)
|
|
104
105
|
md = g_markdown.md;
|
105
106
|
} else if (mode == rb_intern("gfm")) {
|
106
107
|
md = g_GFM.md;
|
108
|
+
} else if (mode == rb_intern("plaintext")) {
|
109
|
+
md = g_plaintext.md;
|
107
110
|
} else {
|
108
111
|
rb_raise(rb_eTypeError, "Invalid render mode");
|
109
112
|
}
|
@@ -194,6 +197,18 @@ static void rb_ghmd__init_gfm(void)
|
|
194
197
|
);
|
195
198
|
}
|
196
199
|
|
200
|
+
static void rb_ghmd__init_plaintext(void)
|
201
|
+
{
|
202
|
+
struct sd_callbacks callbacks;
|
203
|
+
|
204
|
+
sdtext_renderer(&callbacks);
|
205
|
+
g_GFM.md = sd_markdown_new(
|
206
|
+
GITHUB_MD_FLAGS,
|
207
|
+
GITHUB_MD_NESTING,
|
208
|
+
&callbacks, NULL
|
209
|
+
);
|
210
|
+
}
|
211
|
+
|
197
212
|
void Init_markdown()
|
198
213
|
{
|
199
214
|
VALUE rb_mGitHub = rb_const_get(rb_cObject, rb_intern("GitHub"));
|
@@ -203,5 +218,6 @@ void Init_markdown()
|
|
203
218
|
|
204
219
|
rb_ghmd__init_md();
|
205
220
|
rb_ghmd__init_gfm();
|
221
|
+
rb_ghmd__init_plaintext();
|
206
222
|
}
|
207
223
|
|
@@ -0,0 +1,193 @@
|
|
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_raw_block(struct buf *ob, const struct buf *text, void *opaque)
|
114
|
+
{
|
115
|
+
/* NO OP */
|
116
|
+
}
|
117
|
+
|
118
|
+
static void
|
119
|
+
rndr_hrule(struct buf *ob, void *opaque)
|
120
|
+
{
|
121
|
+
/* NO OP */
|
122
|
+
}
|
123
|
+
|
124
|
+
static int
|
125
|
+
rndr_image(struct buf *ob, const struct buf *link, const struct buf *title, const struct buf *alt, void *opaque)
|
126
|
+
{
|
127
|
+
/* NO OP */
|
128
|
+
return 1;
|
129
|
+
}
|
130
|
+
|
131
|
+
static int
|
132
|
+
rndr_raw_html(struct buf *ob, const struct buf *text, void *opaque)
|
133
|
+
{
|
134
|
+
/* NO OP */
|
135
|
+
return 1;
|
136
|
+
}
|
137
|
+
|
138
|
+
static void
|
139
|
+
rndr_table(struct buf *ob, const struct buf *header, const struct buf *body, void *opaque)
|
140
|
+
{
|
141
|
+
plaintext_block(ob, body);
|
142
|
+
}
|
143
|
+
|
144
|
+
static void
|
145
|
+
rndr_tablerow(struct buf *ob, const struct buf *text, void *opaque)
|
146
|
+
{
|
147
|
+
plaintext_block(ob, text);
|
148
|
+
}
|
149
|
+
|
150
|
+
static void
|
151
|
+
rndr_tablecell(struct buf *ob, const struct buf *text, int flags, void *opaque)
|
152
|
+
{
|
153
|
+
plaintext_block(ob, text);
|
154
|
+
}
|
155
|
+
|
156
|
+
void
|
157
|
+
sdtext_renderer(struct sd_callbacks *callbacks)
|
158
|
+
{
|
159
|
+
static const struct sd_callbacks cb_default = {
|
160
|
+
rndr_blockcode,
|
161
|
+
rndr_blockquote,
|
162
|
+
rndr_raw_block,
|
163
|
+
rndr_header,
|
164
|
+
rndr_hrule,
|
165
|
+
rndr_list,
|
166
|
+
rndr_listitem,
|
167
|
+
rndr_paragraph,
|
168
|
+
rndr_table,
|
169
|
+
rndr_tablerow,
|
170
|
+
rndr_tablecell,
|
171
|
+
|
172
|
+
rndr_autolink,
|
173
|
+
rndr_span_element,
|
174
|
+
rndr_span_element,
|
175
|
+
rndr_span_element,
|
176
|
+
rndr_image,
|
177
|
+
rndr_linebreak,
|
178
|
+
rndr_link,
|
179
|
+
rndr_raw_html,
|
180
|
+
rndr_span_element,
|
181
|
+
rndr_span_element,
|
182
|
+
rndr_span_element,
|
183
|
+
|
184
|
+
NULL,
|
185
|
+
NULL,
|
186
|
+
|
187
|
+
NULL,
|
188
|
+
NULL,
|
189
|
+
};
|
190
|
+
|
191
|
+
/* Prepare the callbacks */
|
192
|
+
memcpy(callbacks, &cb_default, sizeof(struct sd_callbacks));
|
193
|
+
}
|
@@ -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
|
+
|
data/github-markdown.gemspec
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
Gem::Specification.new do |s|
|
3
3
|
s.name = 'github-markdown'
|
4
|
-
s.version = '0.
|
4
|
+
s.version = '0.4.0'
|
5
5
|
s.summary = 'The Markdown parser for GitHub.com'
|
6
6
|
s.description = 'Self-contained Markdown parser for GitHub, with all our custom extensions'
|
7
|
-
s.date = '2012-
|
7
|
+
s.date = '2012-05-03'
|
8
8
|
s.email = 'vicent@github.com'
|
9
9
|
s.homepage = 'http://github.github.com/github-flavored-markdown/'
|
10
10
|
s.authors = ['GitHub, Inc']
|
@@ -26,6 +26,8 @@ Gem::Specification.new do |s|
|
|
26
26
|
ext/markdown/html_blocks.h
|
27
27
|
ext/markdown/markdown.c
|
28
28
|
ext/markdown/markdown.h
|
29
|
+
ext/markdown/plaintext.c
|
30
|
+
ext/markdown/plaintext.h
|
29
31
|
ext/markdown/stack.c
|
30
32
|
ext/markdown/stack.h
|
31
33
|
github-markdown.gemspec
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: github-markdown
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 4
|
9
|
+
- 0
|
10
|
+
version: 0.4.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- GitHub, Inc
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-
|
18
|
+
date: 2012-05-03 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -57,6 +57,8 @@ files:
|
|
57
57
|
- ext/markdown/html_blocks.h
|
58
58
|
- ext/markdown/markdown.c
|
59
59
|
- ext/markdown/markdown.h
|
60
|
+
- ext/markdown/plaintext.c
|
61
|
+
- ext/markdown/plaintext.h
|
60
62
|
- ext/markdown/stack.c
|
61
63
|
- ext/markdown/stack.h
|
62
64
|
- github-markdown.gemspec
|