greenmat 3.2.2.1 → 3.5.1.1
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.
- checksums.yaml +5 -5
- data/.travis.yml +17 -4
- data/CHANGELOG.md +21 -0
- data/COPYING +17 -11
- data/Gemfile +2 -2
- data/README.md +19 -13
- data/bin/greenmat +4 -40
- data/ext/greenmat/autolink.c +29 -16
- data/ext/greenmat/buffer.c +24 -17
- data/ext/greenmat/buffer.h +18 -13
- data/ext/greenmat/gm_markdown.c +38 -14
- data/ext/greenmat/gm_render.c +60 -21
- data/ext/greenmat/greenmat.h +22 -0
- data/ext/greenmat/houdini.h +25 -0
- data/ext/greenmat/houdini_href_e.c +27 -11
- data/ext/greenmat/houdini_html_e.c +22 -1
- data/ext/greenmat/html.c +130 -48
- data/ext/greenmat/html.h +19 -14
- data/ext/greenmat/html_smartypants.c +47 -20
- data/ext/greenmat/markdown.c +42 -30
- data/ext/greenmat/markdown.h +17 -15
- data/ext/greenmat/stack.c +22 -0
- data/ext/greenmat/stack.h +22 -0
- data/greenmat.gemspec +4 -3
- data/lib/greenmat.rb +1 -1
- data/lib/greenmat/cli.rb +86 -0
- data/lib/greenmat/compat.rb +0 -5
- data/lib/greenmat/render_strip.rb +13 -1
- data/lib/greenmat/version.rb +1 -1
- data/spec/greenmat/markdown_spec.rb +123 -0
- data/test/custom_render_test.rb +41 -2
- data/test/greenmat_bin_test.rb +80 -0
- data/test/greenmat_compat_test.rb +6 -6
- data/test/html5_test.rb +60 -38
- data/test/html_render_test.rb +162 -128
- data/test/html_toc_render_test.rb +74 -11
- data/test/markdown_test.rb +261 -161
- data/test/safe_render_test.rb +5 -6
- data/test/smarty_html_test.rb +19 -13
- data/test/smarty_pants_test.rb +10 -0
- data/test/stripdown_render_test.rb +38 -9
- data/test/test_helper.rb +30 -9
- metadata +34 -19
- data/tasks/generate_xcode_project.rake +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5ebea41bf33e060dc7d4a5c28fbac9e49759062ac85dcbea55b14b1485cd18f1
|
4
|
+
data.tar.gz: 18cf03b8c7b166736b13326d3e601384b3776d6a65384f46dbf7d7d9545a5528
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e2eb93fbef73b7bb5853db8e107910bf3e7b8e89a649496040cdf665a9b97f54fd0031e0f042c1f6622764e51a85d87bada46d60b0ccbcb352e7743134daab3
|
7
|
+
data.tar.gz: 6da0421b78cf1b71fd92c080b62aeec8dc74726b999d5d4afb9dc10e465e15b0db28fef67d1d0343940bea56717ec94e944d47a6dfabbe8269dfd0d100fbd746
|
data/.travis.yml
CHANGED
@@ -1,14 +1,27 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
- sudo apt-get -qq install tidy
|
1
|
+
sudo: false
|
2
|
+
dist: trusty
|
4
3
|
|
5
|
-
|
4
|
+
addons:
|
5
|
+
apt:
|
6
|
+
packages:
|
7
|
+
- tidy
|
8
|
+
- tcl
|
9
|
+
- tk
|
10
|
+
|
11
|
+
install: bundle install --without=benchmark
|
6
12
|
|
7
13
|
rvm:
|
8
14
|
- 2.0.0
|
9
15
|
- 2.1
|
10
16
|
- 2.2
|
17
|
+
- 2.3
|
18
|
+
- 2.4
|
19
|
+
- 2.5
|
11
20
|
- ruby-head
|
12
21
|
|
22
|
+
matrix:
|
23
|
+
allow_failures:
|
24
|
+
- rvm: ruby-head
|
25
|
+
|
13
26
|
notifications:
|
14
27
|
email: false
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,27 @@
|
|
2
2
|
|
3
3
|
## Unreleased
|
4
4
|
|
5
|
+
## v3.5.1.1
|
6
|
+
|
7
|
+
* Unsupport details and summary tags.
|
8
|
+
|
9
|
+
## v3.5.1.0
|
10
|
+
|
11
|
+
* Update base Redcarpet version to 3.5.1.
|
12
|
+
|
13
|
+
## v3.2.2.4
|
14
|
+
|
15
|
+
* Relax max nesting.
|
16
|
+
|
17
|
+
## v3.2.2.3
|
18
|
+
|
19
|
+
* Change `<code>` attribute for code block metadata (language) from `class` to `data-metadata`.
|
20
|
+
Note that this is a breaking change, though you won't face this breakage if you're using greenmat through qiita-markdown gem and updating both gems.
|
21
|
+
|
22
|
+
## v3.2.2.2
|
23
|
+
|
24
|
+
* Fix bugs in UTF-8 handling. [#3](https://github.com/increments/greenmat/pull/3) ([@gfx](https://github.com/gfx))
|
25
|
+
|
5
26
|
## v3.2.2.1
|
6
27
|
|
7
28
|
* Fix a bug where bad memory access would happen in a document starting with `@`.
|
data/COPYING
CHANGED
@@ -1,14 +1,20 @@
|
|
1
1
|
Copyright (c) 2009, Natacha Porté
|
2
|
-
Copyright (c)
|
2
|
+
Copyright (c) 2015, Vicent Marti
|
3
3
|
|
4
|
-
Permission
|
5
|
-
|
6
|
-
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
6
|
+
in the Software without restriction, including without limitation the rights
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
9
|
+
furnished to do so, subject to the following conditions:
|
7
10
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
OR
|
11
|
+
The above copyright notice and this permission notice shall be included in
|
12
|
+
all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
+
THE SOFTWARE.
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -54,16 +54,22 @@ We appreciate Redcarpet project and the contributors for the great efforts!
|
|
54
54
|
|
55
55
|
### Redcarpet
|
56
56
|
|
57
|
-
Copyright (c) 2011-
|
58
|
-
|
59
|
-
Permission
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
57
|
+
Copyright (c) 2011-2016, Vicent Martí
|
58
|
+
|
59
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
60
|
+
of this software and associated documentation files (the "Software"), to deal
|
61
|
+
in the Software without restriction, including without limitation the rights
|
62
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
63
|
+
copies of the Software, and to permit persons to whom the Software is
|
64
|
+
furnished to do so, subject to the following conditions:
|
65
|
+
|
66
|
+
The above copyright notice and this permission notice shall be included in
|
67
|
+
all copies or substantial portions of the Software.
|
68
|
+
|
69
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
70
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
71
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
72
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
73
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
74
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
75
|
+
THE SOFTWARE.
|
data/bin/greenmat
CHANGED
@@ -1,43 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
|
4
|
-
# no <file> or when <file> is '-', read Markdown source text from standard input.
|
5
|
-
# With <extension>s, perform additional Markdown processing before writing output.
|
6
|
-
# With --smarty, use the SmartyHTML renderer
|
7
|
-
if ARGV.include?('--help') or ARGV.include?('-h')
|
8
|
-
File.read(__FILE__).split("\n").grep(/^# /).each do |line|
|
9
|
-
puts line[2..-1]
|
10
|
-
end
|
11
|
-
exit 0
|
12
|
-
end
|
2
|
+
lib_path = File.expand_path('../../lib', __FILE__)
|
3
|
+
$:.unshift(lib_path)
|
13
4
|
|
14
|
-
require 'greenmat'
|
5
|
+
require 'greenmat/cli'
|
15
6
|
|
16
|
-
|
17
|
-
puts "Greenmat #{Greenmat::VERSION}"
|
18
|
-
exit 0
|
19
|
-
end
|
20
|
-
|
21
|
-
root = File.expand_path('../../', __FILE__)
|
22
|
-
$:.unshift File.expand_path('lib', root)
|
23
|
-
|
24
|
-
render_extensions = {}
|
25
|
-
parse_extensions = {}
|
26
|
-
renderer = Greenmat::Render::HTML
|
27
|
-
|
28
|
-
ARGV.delete_if do |arg|
|
29
|
-
if arg =~ /^--render-([\w-]+)$/
|
30
|
-
arg = $1.gsub('-', '_')
|
31
|
-
render_extensions[arg.to_sym] = true
|
32
|
-
elsif arg =~ /^--parse-([\w-]+)$/
|
33
|
-
arg = $1.gsub('-', '_')
|
34
|
-
parse_extensions[arg.to_sym] = true
|
35
|
-
elsif arg == '--smarty'
|
36
|
-
renderer = Greenmat::Render::SmartyHTML
|
37
|
-
else
|
38
|
-
false
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
render = renderer.new(render_extensions)
|
43
|
-
STDOUT.write(Greenmat::Markdown.new(render, parse_extensions).render(ARGF.read))
|
7
|
+
Greenmat::CLI.process(ARGV)
|
data/ext/greenmat/autolink.c
CHANGED
@@ -1,21 +1,28 @@
|
|
1
1
|
/*
|
2
|
-
* Copyright (c)
|
2
|
+
* Copyright (c) 2015, Vicent Marti
|
3
3
|
*
|
4
|
-
* Permission
|
5
|
-
*
|
6
|
-
*
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
* of this software and associated documentation files (the "Software"), to deal
|
6
|
+
* in the Software without restriction, including without limitation the rights
|
7
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
* copies of the Software, and to permit persons to whom the Software is
|
9
|
+
* furnished to do so, subject to the following conditions:
|
7
10
|
*
|
8
|
-
*
|
9
|
-
*
|
10
|
-
*
|
11
|
-
*
|
12
|
-
*
|
13
|
-
*
|
14
|
-
* OR
|
11
|
+
* The above copyright notice and this permission notice shall be included in
|
12
|
+
* all copies or substantial portions of the Software.
|
13
|
+
*
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
+
* THE SOFTWARE.
|
15
21
|
*/
|
16
22
|
|
17
23
|
#include "buffer.h"
|
18
24
|
#include "autolink.h"
|
25
|
+
#include "houdini.h"
|
19
26
|
|
20
27
|
#include <string.h>
|
21
28
|
#include <stdlib.h>
|
@@ -169,7 +176,7 @@ sd_autolink__www(
|
|
169
176
|
{
|
170
177
|
size_t link_end;
|
171
178
|
|
172
|
-
if (max_rewind > 0 && !ispunct(data[-1]) &&
|
179
|
+
if (max_rewind > 0 && !ispunct(data[-1]) && is_non_space(data[-1]))
|
173
180
|
return 0;
|
174
181
|
|
175
182
|
if (size < 4 || memcmp(data, "www.", strlen("www.")) != 0)
|
@@ -180,7 +187,7 @@ sd_autolink__www(
|
|
180
187
|
if (link_end == 0)
|
181
188
|
return 0;
|
182
189
|
|
183
|
-
while (link_end < size &&
|
190
|
+
while (link_end < size && is_non_space(data[link_end]))
|
184
191
|
link_end++;
|
185
192
|
|
186
193
|
link_end = autolink_delim(data, link_end, max_rewind, size);
|
@@ -222,7 +229,7 @@ sd_autolink__email(
|
|
222
229
|
return 0;
|
223
230
|
|
224
231
|
for (link_end = 0; link_end < size; ++link_end) {
|
225
|
-
|
232
|
+
char c = data[link_end];
|
226
233
|
|
227
234
|
if (isalnum(c))
|
228
235
|
continue;
|
@@ -280,7 +287,7 @@ sd_autolink__url(
|
|
280
287
|
return 0;
|
281
288
|
|
282
289
|
link_end += domain_len;
|
283
|
-
while (link_end < size &&
|
290
|
+
while (link_end < size && is_non_space(data[link_end]))
|
284
291
|
link_end++;
|
285
292
|
|
286
293
|
link_end = autolink_delim(data, link_end, max_rewind, size);
|
@@ -288,9 +295,15 @@ sd_autolink__url(
|
|
288
295
|
if (link_end == 0)
|
289
296
|
return 0;
|
290
297
|
|
298
|
+
/**
|
299
|
+
* In certain cases, we may refer to a link at the end of a
|
300
|
+
* sentence so the period should not be part of the URL.
|
301
|
+
*/
|
302
|
+
if (data[link_end - 1] == '.')
|
303
|
+
link_end--;
|
304
|
+
|
291
305
|
bufput(link, data - rewind, link_end + rewind);
|
292
306
|
*rewind_p = rewind;
|
293
307
|
|
294
308
|
return link_end;
|
295
309
|
}
|
296
|
-
|
data/ext/greenmat/buffer.c
CHANGED
@@ -1,21 +1,28 @@
|
|
1
1
|
/*
|
2
2
|
* Copyright (c) 2008, Natacha Porté
|
3
|
-
* Copyright (c)
|
3
|
+
* Copyright (c) 2015, Vicent Marti
|
4
4
|
*
|
5
|
-
* Permission
|
6
|
-
*
|
7
|
-
*
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
* of this software and associated documentation files (the "Software"), to deal
|
7
|
+
* in the Software without restriction, including without limitation the rights
|
8
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
* copies of the Software, and to permit persons to whom the Software is
|
10
|
+
* furnished to do so, subject to the following conditions:
|
8
11
|
*
|
9
|
-
*
|
10
|
-
*
|
11
|
-
*
|
12
|
-
*
|
13
|
-
*
|
14
|
-
*
|
15
|
-
* OR
|
12
|
+
* The above copyright notice and this permission notice shall be included in
|
13
|
+
* all copies or substantial portions of the Software.
|
14
|
+
*
|
15
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
* THE SOFTWARE.
|
16
22
|
*/
|
17
23
|
|
18
24
|
#define BUFFER_MAX_ALLOC_SIZE (1024 * 1024 * 16) //16mb
|
25
|
+
#define __USE_MINGW_ANSI_STDIO 1
|
19
26
|
|
20
27
|
#include "buffer.h"
|
21
28
|
|
@@ -94,14 +101,14 @@ bufnew(size_t unit)
|
|
94
101
|
|
95
102
|
/* bufnullterm: NULL-termination of the string array */
|
96
103
|
const char *
|
97
|
-
bufcstr(struct buf *buf)
|
104
|
+
bufcstr(const struct buf *buf)
|
98
105
|
{
|
99
106
|
assert(buf && buf->unit);
|
100
107
|
|
101
108
|
if (buf->size < buf->asize && buf->data[buf->size] == 0)
|
102
109
|
return (char *)buf->data;
|
103
110
|
|
104
|
-
if (buf->size + 1 <= buf->asize || bufgrow(buf, buf->size + 1) ==
|
111
|
+
if (buf->size + 1 <= buf->asize || bufgrow(buf, buf->size + 1) == BUF_OK) {
|
105
112
|
buf->data[buf->size] = 0;
|
106
113
|
return (char *)buf->data;
|
107
114
|
}
|
@@ -118,7 +125,7 @@ bufprintf(struct buf *buf, const char *fmt, ...)
|
|
118
125
|
|
119
126
|
assert(buf && buf->unit);
|
120
127
|
|
121
|
-
if (buf->size >= buf->asize && bufgrow(buf, buf->size + 1) <
|
128
|
+
if (buf->size >= buf->asize && bufgrow(buf, buf->size + 1) < BUF_OK)
|
122
129
|
return;
|
123
130
|
|
124
131
|
va_start(ap, fmt);
|
@@ -136,7 +143,7 @@ bufprintf(struct buf *buf, const char *fmt, ...)
|
|
136
143
|
}
|
137
144
|
|
138
145
|
if ((size_t)n >= buf->asize - buf->size) {
|
139
|
-
if (bufgrow(buf, buf->size + n + 1) <
|
146
|
+
if (bufgrow(buf, buf->size + n + 1) < BUF_OK)
|
140
147
|
return;
|
141
148
|
|
142
149
|
va_start(ap, fmt);
|
@@ -156,7 +163,7 @@ bufput(struct buf *buf, const void *data, size_t len)
|
|
156
163
|
{
|
157
164
|
assert(buf && buf->unit);
|
158
165
|
|
159
|
-
if (buf->size + len > buf->asize && bufgrow(buf, buf->size + len) <
|
166
|
+
if (buf->size + len > buf->asize && bufgrow(buf, buf->size + len) < BUF_OK)
|
160
167
|
return;
|
161
168
|
|
162
169
|
memcpy(buf->data + buf->size, data, len);
|
@@ -177,7 +184,7 @@ bufputc(struct buf *buf, int c)
|
|
177
184
|
{
|
178
185
|
assert(buf && buf->unit);
|
179
186
|
|
180
|
-
if (buf->size + 1 > buf->asize && bufgrow(buf, buf->size + 1) <
|
187
|
+
if (buf->size + 1 > buf->asize && bufgrow(buf, buf->size + 1) < BUF_OK)
|
181
188
|
return;
|
182
189
|
|
183
190
|
buf->data[buf->size] = c;
|
data/ext/greenmat/buffer.h
CHANGED
@@ -1,18 +1,24 @@
|
|
1
1
|
/*
|
2
2
|
* Copyright (c) 2008, Natacha Porté
|
3
|
-
* Copyright (c)
|
3
|
+
* Copyright (c) 2015, Vicent Marti
|
4
4
|
*
|
5
|
-
* Permission
|
6
|
-
*
|
7
|
-
*
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
* of this software and associated documentation files (the "Software"), to deal
|
7
|
+
* in the Software without restriction, including without limitation the rights
|
8
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
* copies of the Software, and to permit persons to whom the Software is
|
10
|
+
* furnished to do so, subject to the following conditions:
|
8
11
|
*
|
9
|
-
*
|
10
|
-
*
|
11
|
-
*
|
12
|
-
*
|
13
|
-
*
|
14
|
-
*
|
15
|
-
* OR
|
12
|
+
* The above copyright notice and this permission notice shall be included in
|
13
|
+
* all copies or substantial portions of the Software.
|
14
|
+
*
|
15
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
* THE SOFTWARE.
|
16
22
|
*/
|
17
23
|
|
18
24
|
#ifndef BUFFER_H__
|
@@ -55,7 +61,7 @@ int bufgrow(struct buf *, size_t);
|
|
55
61
|
struct buf *bufnew(size_t) __attribute__ ((malloc));
|
56
62
|
|
57
63
|
/* bufnullterm: NUL-termination of the string array (making a C-string) */
|
58
|
-
const char *bufcstr(struct buf *);
|
64
|
+
const char *bufcstr(const struct buf *);
|
59
65
|
|
60
66
|
/* bufprefix: compare the beginning of a buffer with a string */
|
61
67
|
int bufprefix(const struct buf *buf, const char *prefix);
|
@@ -80,4 +86,3 @@ void bufprintf(struct buf *, const char *, ...) __attribute__ ((format (printf,
|
|
80
86
|
#endif
|
81
87
|
|
82
88
|
#endif
|
83
|
-
|
data/ext/greenmat/gm_markdown.c
CHANGED
@@ -1,25 +1,35 @@
|
|
1
1
|
/*
|
2
|
-
* Copyright (c)
|
2
|
+
* Copyright (c) 2015, Vicent Marti
|
3
3
|
*
|
4
|
-
* Permission
|
5
|
-
*
|
6
|
-
*
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
* of this software and associated documentation files (the "Software"), to deal
|
6
|
+
* in the Software without restriction, including without limitation the rights
|
7
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
* copies of the Software, and to permit persons to whom the Software is
|
9
|
+
* furnished to do so, subject to the following conditions:
|
7
10
|
*
|
8
|
-
*
|
9
|
-
*
|
10
|
-
*
|
11
|
-
*
|
12
|
-
*
|
13
|
-
*
|
14
|
-
* OR
|
11
|
+
* The above copyright notice and this permission notice shall be included in
|
12
|
+
* all copies or substantial portions of the Software.
|
13
|
+
*
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
+
* THE SOFTWARE.
|
15
21
|
*/
|
22
|
+
|
16
23
|
#include "greenmat.h"
|
17
24
|
|
18
25
|
VALUE rb_mGreenmat;
|
19
26
|
VALUE rb_cMarkdown;
|
27
|
+
VALUE rb_cRenderHTML_TOC;
|
20
28
|
|
21
29
|
extern VALUE rb_cRenderBase;
|
22
30
|
|
31
|
+
static size_t MAX_NESTING = 32;
|
32
|
+
|
23
33
|
static void rb_greenmat_md_flags(VALUE hash, unsigned int *enabled_extensions_p)
|
24
34
|
{
|
25
35
|
unsigned int extensions = 0;
|
@@ -82,7 +92,7 @@ rb_greenmat_md__free(void *markdown)
|
|
82
92
|
|
83
93
|
static VALUE rb_greenmat_md__new(int argc, VALUE *argv, VALUE klass)
|
84
94
|
{
|
85
|
-
VALUE rb_markdown, rb_rndr, hash;
|
95
|
+
VALUE rb_markdown, rb_rndr, hash, rndr_options;
|
86
96
|
unsigned int extensions = 0;
|
87
97
|
|
88
98
|
struct rb_greenmat_rndr *rndr;
|
@@ -97,9 +107,24 @@ static VALUE rb_greenmat_md__new(int argc, VALUE *argv, VALUE klass)
|
|
97
107
|
if (!rb_obj_is_kind_of(rb_rndr, rb_cRenderBase))
|
98
108
|
rb_raise(rb_eTypeError, "Invalid Renderer instance given");
|
99
109
|
|
110
|
+
/**
|
111
|
+
* Automatically enable the `fenced_code_blocks` option if
|
112
|
+
* given a kind of `HTML_TOC` object since many languages
|
113
|
+
* like Ruby use the sharp to comment code so these comments
|
114
|
+
* would be processed as titles.
|
115
|
+
*/
|
116
|
+
if (rb_obj_is_kind_of(rb_rndr, rb_cRenderHTML_TOC))
|
117
|
+
extensions |= MKDEXT_FENCED_CODE;
|
118
|
+
|
100
119
|
Data_Get_Struct(rb_rndr, struct rb_greenmat_rndr, rndr);
|
101
120
|
|
102
|
-
|
121
|
+
/* Merge the current options in the @options hash */
|
122
|
+
if (hash != Qnil) {
|
123
|
+
rndr_options = rb_funcall(rb_iv_get(rb_rndr, "@options"), rb_intern("merge"), 1, hash);
|
124
|
+
rb_iv_set(rb_rndr, "@options", rndr_options);
|
125
|
+
}
|
126
|
+
|
127
|
+
markdown = sd_markdown_new(extensions, MAX_NESTING, &rndr->callbacks, &rndr->options);
|
103
128
|
if (!markdown)
|
104
129
|
rb_raise(rb_eRuntimeError, "Failed to create new Renderer class");
|
105
130
|
|
@@ -165,4 +190,3 @@ void Init_greenmat()
|
|
165
190
|
|
166
191
|
Init_greenmat_rndr();
|
167
192
|
}
|
168
|
-
|