greenmat 3.2.2.4 → 3.5.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +19 -4
- data/CHANGELOG.md +4 -0
- data/COPYING +17 -11
- data/Gemfile +2 -2
- data/README.md +19 -13
- data/bin/greenmat +4 -40
- data/ext/greenmat/autolink.c +24 -12
- data/ext/greenmat/buffer.c +24 -17
- data/ext/greenmat/buffer.h +18 -13
- data/ext/greenmat/gm_markdown.c +35 -13
- data/ext/greenmat/gm_render.c +60 -21
- data/ext/greenmat/greenmat.h +22 -0
- data/ext/greenmat/houdini.h +22 -0
- data/ext/greenmat/houdini_href_e.c +27 -11
- data/ext/greenmat/houdini_html_e.c +22 -1
- data/ext/greenmat/html.c +127 -45
- data/ext/greenmat/html.h +19 -14
- data/ext/greenmat/html_blocks.h +68 -70
- 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 +3 -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/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 +51 -38
- data/test/html_render_test.rb +161 -127
- data/test/html_toc_render_test.rb +74 -11
- data/test/markdown_test.rb +258 -182
- 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 +15 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f39bc77cb9919af4e018b008bbc6d1cd8347d7bee919592dbe96d09b8eeab19f
|
4
|
+
data.tar.gz: c3f07e638dddaa7bd603d0d044a6c847abd425c65aa2106701d1e8ccf4b547ce
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '02870d7ebb28e12b26c38b80363be12db1961fcb0c1e2f2a99d0e95eded8f5c203c8750e95afa2300e08784c17ae3ccc5f73d19ff1ef8c3133cb98bf0eae1f22'
|
7
|
+
data.tar.gz: 722bb67d5443e75f266881a60a2dd090c4417dd44f1049ebaaf4185c9e4fa5d72232182794ce648a31cb3a33b0315e2ec7b6c4458428567b4c1a9449c6bfabc9
|
data/.travis.yml
CHANGED
@@ -1,12 +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:
|
14
|
+
- 2.0.0
|
15
|
+
- 2.1
|
8
16
|
- 2.2
|
9
17
|
- 2.3
|
10
18
|
- 2.4
|
19
|
+
- 2.5
|
20
|
+
- ruby-head
|
21
|
+
|
22
|
+
matrix:
|
23
|
+
allow_failures:
|
24
|
+
- rvm: ruby-head
|
25
|
+
|
11
26
|
notifications:
|
12
27
|
email: false
|
data/CHANGELOG.md
CHANGED
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,17 +1,23 @@
|
|
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"
|
@@ -289,9 +295,15 @@ sd_autolink__url(
|
|
289
295
|
if (link_end == 0)
|
290
296
|
return 0;
|
291
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
|
+
|
292
305
|
bufput(link, data - rewind, link_end + rewind);
|
293
306
|
*rewind_p = rewind;
|
294
307
|
|
295
308
|
return link_end;
|
296
309
|
}
|
297
|
-
|
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,22 +1,30 @@
|
|
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
|
|
@@ -84,7 +92,7 @@ rb_greenmat_md__free(void *markdown)
|
|
84
92
|
|
85
93
|
static VALUE rb_greenmat_md__new(int argc, VALUE *argv, VALUE klass)
|
86
94
|
{
|
87
|
-
VALUE rb_markdown, rb_rndr, hash;
|
95
|
+
VALUE rb_markdown, rb_rndr, hash, rndr_options;
|
88
96
|
unsigned int extensions = 0;
|
89
97
|
|
90
98
|
struct rb_greenmat_rndr *rndr;
|
@@ -99,8 +107,23 @@ static VALUE rb_greenmat_md__new(int argc, VALUE *argv, VALUE klass)
|
|
99
107
|
if (!rb_obj_is_kind_of(rb_rndr, rb_cRenderBase))
|
100
108
|
rb_raise(rb_eTypeError, "Invalid Renderer instance given");
|
101
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
|
+
|
102
119
|
Data_Get_Struct(rb_rndr, struct rb_greenmat_rndr, rndr);
|
103
120
|
|
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
|
+
|
104
127
|
markdown = sd_markdown_new(extensions, MAX_NESTING, &rndr->callbacks, &rndr->options);
|
105
128
|
if (!markdown)
|
106
129
|
rb_raise(rb_eRuntimeError, "Failed to create new Renderer class");
|
@@ -167,4 +190,3 @@ void Init_greenmat()
|
|
167
190
|
|
168
191
|
Init_greenmat_rndr();
|
169
192
|
}
|
170
|
-
|