greenmat 3.2.2.2 → 3.5.1.2
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 +21 -8
- data/CHANGELOG.md +24 -0
- data/COPYING +17 -11
- data/Gemfile +2 -2
- data/README.md +19 -13
- data/Rakefile +1 -0
- 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 +41 -14
- data/ext/greenmat/gm_render.c +68 -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 +177 -47
- data/ext/greenmat/html.h +19 -14
- data/ext/greenmat/html_smartypants.c +47 -20
- data/ext/greenmat/markdown.c +181 -30
- data/ext/greenmat/markdown.h +20 -16
- 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 +166 -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 +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 +29 -13
data/ext/greenmat/markdown.h
CHANGED
@@ -1,19 +1,24 @@
|
|
1
|
-
/* markdown.h - generic markdown parser */
|
2
|
-
|
3
1
|
/*
|
4
2
|
* Copyright (c) 2009, Natacha Porté
|
3
|
+
* Copyright (c) 2015, Vicent Marti
|
4
|
+
*
|
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:
|
5
11
|
*
|
6
|
-
*
|
7
|
-
*
|
8
|
-
* copyright notice and this permission notice appear in all copies.
|
12
|
+
* The above copyright notice and this permission notice shall be included in
|
13
|
+
* all copies or substantial portions of the Software.
|
9
14
|
*
|
10
|
-
* THE SOFTWARE IS PROVIDED "AS IS"
|
11
|
-
*
|
12
|
-
*
|
13
|
-
*
|
14
|
-
*
|
15
|
-
*
|
16
|
-
*
|
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.
|
17
22
|
*/
|
18
23
|
|
19
24
|
#ifndef MARKDOWN_H__
|
@@ -59,13 +64,15 @@ enum mkd_extensions {
|
|
59
64
|
MKDEXT_HIGHLIGHT = (1 << 10),
|
60
65
|
MKDEXT_FOOTNOTES = (1 << 11),
|
61
66
|
MKDEXT_QUOTE = (1 << 12),
|
62
|
-
MKDEXT_NO_MENTION_EMPHASIS = (1 << 13)
|
67
|
+
MKDEXT_NO_MENTION_EMPHASIS = (1 << 13),
|
68
|
+
MKDEXT_FENCED_CUSTOM = (1 << 14)
|
63
69
|
};
|
64
70
|
|
65
71
|
/* sd_callbacks - functions for rendering parsed data */
|
66
72
|
struct sd_callbacks {
|
67
73
|
/* block level callbacks - NULL skips the block */
|
68
74
|
void (*blockcode)(struct buf *ob, const struct buf *text, const struct buf *lang, void *opaque);
|
75
|
+
void (*blockcustom)(struct buf *ob, const struct buf *text, const struct buf *type, void *opaque);
|
69
76
|
void (*blockquote)(struct buf *ob, const struct buf *text, void *opaque);
|
70
77
|
void (*blockhtml)(struct buf *ob,const struct buf *text, void *opaque);
|
71
78
|
void (*header)(struct buf *ob, const struct buf *text, int level, void *opaque);
|
@@ -105,9 +112,6 @@ struct sd_callbacks {
|
|
105
112
|
void (*doc_footer)(struct buf *ob, void *opaque);
|
106
113
|
};
|
107
114
|
|
108
|
-
/* header methods used internally in Greenmat */
|
109
|
-
char* header_anchor(struct buf *text);
|
110
|
-
|
111
115
|
struct sd_markdown;
|
112
116
|
|
113
117
|
/*********
|
data/ext/greenmat/stack.c
CHANGED
@@ -1,3 +1,25 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2015, Vicent Marti
|
3
|
+
*
|
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:
|
10
|
+
*
|
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.
|
21
|
+
*/
|
22
|
+
|
1
23
|
#include "stack.h"
|
2
24
|
#include <string.h>
|
3
25
|
|
data/ext/greenmat/stack.h
CHANGED
@@ -1,3 +1,25 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2015, Vicent Marti
|
3
|
+
*
|
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:
|
10
|
+
*
|
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.
|
21
|
+
*/
|
22
|
+
|
1
23
|
#ifndef STACK_H__
|
2
24
|
#define STACK_H__
|
3
25
|
|
data/greenmat.gemspec
CHANGED
@@ -21,9 +21,10 @@ Gem::Specification.new do |s|
|
|
21
21
|
s.executables = ["greenmat"]
|
22
22
|
s.require_paths = ["lib"]
|
23
23
|
|
24
|
+
s.add_development_dependency "activesupport"
|
24
25
|
s.add_development_dependency "nokogiri", "~> 1.6.0"
|
25
|
-
s.add_development_dependency "rake", "~>
|
26
|
-
s.add_development_dependency "rake-compiler", "~> 0.
|
26
|
+
s.add_development_dependency "rake", "~> 12.2.1"
|
27
|
+
s.add_development_dependency "rake-compiler", "~> 1.0.3"
|
27
28
|
s.add_development_dependency "rspec", "~> 3.2"
|
28
|
-
s.add_development_dependency "test-unit", "~> 2.
|
29
|
+
s.add_development_dependency "test-unit", "~> 3.2.3"
|
29
30
|
end
|
data/lib/greenmat.rb
CHANGED
data/lib/greenmat/cli.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'greenmat'
|
2
|
+
require 'optparse'
|
3
|
+
|
4
|
+
module Greenmat
|
5
|
+
# This class aims at easing the creation of custom
|
6
|
+
# binary for your needs. For example, you can add new
|
7
|
+
# options or change the existing ones. The parsing
|
8
|
+
# is handled by Ruby's OptionParser. For instance:
|
9
|
+
#
|
10
|
+
# class Custom::CLI < Greenmat::CLI
|
11
|
+
# def self.options_parser
|
12
|
+
# super.tap do |opts|
|
13
|
+
# opts.on("--rainbow") do
|
14
|
+
# @@options[:rainbow] = true
|
15
|
+
# end
|
16
|
+
# end
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
# def self.render_object
|
20
|
+
# @@options[:rainbow] ? RainbowRender : super
|
21
|
+
# end
|
22
|
+
# end
|
23
|
+
class CLI
|
24
|
+
def self.options_parser
|
25
|
+
@@options = {
|
26
|
+
render_extensions: {},
|
27
|
+
parse_extensions: {},
|
28
|
+
smarty_pants: false
|
29
|
+
}
|
30
|
+
|
31
|
+
OptionParser.new do |opts|
|
32
|
+
opts.banner = "Usage: greenmat [--parse <extension>...] " \
|
33
|
+
"[--render <extension>...] [--smarty] <file>..."
|
34
|
+
|
35
|
+
opts.on("--parse EXTENSION", "Enable a parsing extension") do |ext|
|
36
|
+
ext = ext.gsub('-', '_').to_sym
|
37
|
+
@@options[:parse_extensions][ext] = true
|
38
|
+
end
|
39
|
+
|
40
|
+
opts.on("--render EXTENSION", "Enable a rendering extension") do |ext|
|
41
|
+
ext = ext.gsub('-', '_').to_sym
|
42
|
+
@@options[:render_extensions][ext] = true
|
43
|
+
end
|
44
|
+
|
45
|
+
opts.on("--smarty", "Enable Smarty Pants") do
|
46
|
+
@@options[:smarty_pants] = true
|
47
|
+
end
|
48
|
+
|
49
|
+
opts.on_tail("-v", "--version", "Display the current version") do
|
50
|
+
STDOUT.puts "Greenmat #{Greenmat::VERSION}"
|
51
|
+
exit
|
52
|
+
end
|
53
|
+
|
54
|
+
opts.on_tail("-h", "--help", "Display this help message") do
|
55
|
+
puts opts
|
56
|
+
exit
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.process(args)
|
62
|
+
self.legacy_parse!(args)
|
63
|
+
self.options_parser.parse!(args)
|
64
|
+
STDOUT.write parser_object.render(ARGF.read)
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.render_object
|
68
|
+
@@options[:smarty_pants] ? Render::SmartyHTML : Render::HTML
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.parser_object
|
72
|
+
renderer = render_object.new(@@options[:render_extensions])
|
73
|
+
Greenmat::Markdown.new(renderer, @@options[:parse_extensions])
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.legacy_parse!(args) # :nodoc:
|
77
|
+
# Workaround for backward compatibility as OptionParser
|
78
|
+
# doesn't support the --flag-OPTION syntax.
|
79
|
+
args.select {|a| a =~ /--(parse|render)-/ }.each do |arg|
|
80
|
+
args.delete(arg)
|
81
|
+
arg = arg.partition(/\b-/)
|
82
|
+
args.push(arg.first, arg.last)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
data/lib/greenmat/compat.rb
CHANGED
@@ -13,7 +13,7 @@ module Greenmat
|
|
13
13
|
:autolink, :codespan, :double_emphasis,
|
14
14
|
:emphasis, :underline, :raw_html,
|
15
15
|
:triple_emphasis, :strikethrough,
|
16
|
-
:superscript,
|
16
|
+
:superscript, :highlight, :quote,
|
17
17
|
|
18
18
|
# footnotes
|
19
19
|
:footnotes, :footnote_def, :footnote_ref,
|
@@ -43,6 +43,18 @@ module Greenmat
|
|
43
43
|
def header(text, header_level)
|
44
44
|
text + "\n"
|
45
45
|
end
|
46
|
+
|
47
|
+
def table(header, body)
|
48
|
+
"#{header}#{body}"
|
49
|
+
end
|
50
|
+
|
51
|
+
def table_row(content)
|
52
|
+
content + "\n"
|
53
|
+
end
|
54
|
+
|
55
|
+
def table_cell(content, alignment)
|
56
|
+
content + "\t"
|
57
|
+
end
|
46
58
|
end
|
47
59
|
end
|
48
60
|
end
|
data/lib/greenmat/version.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'greenmat'
|
2
|
+
require "active_support/core_ext/string/strip"
|
2
3
|
|
3
4
|
module Greenmat
|
4
5
|
RSpec.describe Markdown do
|
@@ -61,5 +62,170 @@ module Greenmat
|
|
61
62
|
end
|
62
63
|
end
|
63
64
|
end
|
65
|
+
|
66
|
+
context 'with fenced_code_blocks option' do
|
67
|
+
let(:options) { { fenced_code_blocks: true } }
|
68
|
+
|
69
|
+
context 'with language and filename syntax' do
|
70
|
+
let(:text) do
|
71
|
+
<<-EOS.strip_heredoc
|
72
|
+
```ruby:example.rb
|
73
|
+
puts :foo
|
74
|
+
```
|
75
|
+
EOS
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'generates <code> tag with data-metadata attribute' do
|
79
|
+
expect(rendered_html).to eq <<-EOS.strip_heredoc
|
80
|
+
<pre><code data-metadata="ruby:example.rb">puts :foo
|
81
|
+
</code></pre>
|
82
|
+
EOS
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context 'with deeply nested list' do
|
88
|
+
let(:text) do
|
89
|
+
<<-EOS.strip_heredoc
|
90
|
+
* 1
|
91
|
+
* 2
|
92
|
+
* 3
|
93
|
+
* 4
|
94
|
+
* 5
|
95
|
+
* 6
|
96
|
+
* 7
|
97
|
+
* 8
|
98
|
+
* 9
|
99
|
+
* 10
|
100
|
+
* 11
|
101
|
+
EOS
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'renders the list up to 10 nesting and then gives up' do
|
105
|
+
expect(rendered_html).to eq <<-EOS.strip_heredoc
|
106
|
+
<ul>
|
107
|
+
<li>1
|
108
|
+
|
109
|
+
<ul>
|
110
|
+
<li>2
|
111
|
+
|
112
|
+
<ul>
|
113
|
+
<li>3
|
114
|
+
|
115
|
+
<ul>
|
116
|
+
<li>4
|
117
|
+
|
118
|
+
<ul>
|
119
|
+
<li>5
|
120
|
+
|
121
|
+
<ul>
|
122
|
+
<li>6
|
123
|
+
|
124
|
+
<ul>
|
125
|
+
<li>7
|
126
|
+
|
127
|
+
<ul>
|
128
|
+
<li>8
|
129
|
+
|
130
|
+
<ul>
|
131
|
+
<li>9
|
132
|
+
|
133
|
+
<ul>
|
134
|
+
<li>10
|
135
|
+
|
136
|
+
<ul>
|
137
|
+
<li></li>
|
138
|
+
</ul></li>
|
139
|
+
</ul></li>
|
140
|
+
</ul></li>
|
141
|
+
</ul></li>
|
142
|
+
</ul></li>
|
143
|
+
</ul></li>
|
144
|
+
</ul></li>
|
145
|
+
</ul></li>
|
146
|
+
</ul></li>
|
147
|
+
</ul></li>
|
148
|
+
</ul>
|
149
|
+
EOS
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
context 'with a deeply nested structure that can exist in the wild' do
|
154
|
+
let(:text) do
|
155
|
+
<<-EOS.strip_heredoc
|
156
|
+
> > * 1
|
157
|
+
> > * 2
|
158
|
+
> > * 3
|
159
|
+
> > * [_**Qiita**_](https://qiita.com)
|
160
|
+
EOS
|
161
|
+
end
|
162
|
+
|
163
|
+
it 'renders it properly' do
|
164
|
+
expect(rendered_html).to eq <<-EOS.strip_heredoc
|
165
|
+
<blockquote>
|
166
|
+
<blockquote>
|
167
|
+
<ul>
|
168
|
+
<li>1
|
169
|
+
|
170
|
+
<ul>
|
171
|
+
<li>2
|
172
|
+
|
173
|
+
<ul>
|
174
|
+
<li>3
|
175
|
+
|
176
|
+
<ul>
|
177
|
+
<li><a href="https://qiita.com"><em><strong>Qiita</strong></em></a></li>
|
178
|
+
</ul></li>
|
179
|
+
</ul></li>
|
180
|
+
</ul></li>
|
181
|
+
</ul>
|
182
|
+
</blockquote>
|
183
|
+
</blockquote>
|
184
|
+
EOS
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
context 'with fenced_custom_blocks option' do
|
189
|
+
let(:options) { { fenced_custom_blocks: true } }
|
190
|
+
|
191
|
+
context 'with custom block with any metadata' do
|
192
|
+
let(:text) do
|
193
|
+
<<-EOS.strip_heredoc
|
194
|
+
:::foo bar
|
195
|
+
message
|
196
|
+
:::
|
197
|
+
EOS
|
198
|
+
end
|
199
|
+
|
200
|
+
it 'renders text with <div> tag that have customblock class & metadata in a data-metadata attribute' do
|
201
|
+
expect(rendered_html).to eq <<-EOS.strip_heredoc
|
202
|
+
<div data-type="customblock" data-metadata="foo bar">message
|
203
|
+
</div>
|
204
|
+
EOS
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
context 'without fenced_custom_blocks option' do
|
210
|
+
let(:options) { {} }
|
211
|
+
|
212
|
+
context 'with custom block with any metadata' do
|
213
|
+
let(:text) do
|
214
|
+
<<-EOS.strip_heredoc
|
215
|
+
:::foo bar
|
216
|
+
message
|
217
|
+
:::
|
218
|
+
EOS
|
219
|
+
end
|
220
|
+
|
221
|
+
it 'renders text with p tag' do
|
222
|
+
expect(rendered_html).to eq <<-EOS.strip_heredoc
|
223
|
+
<p>:::foo bar
|
224
|
+
message
|
225
|
+
:::</p>
|
226
|
+
EOS
|
227
|
+
end
|
228
|
+
end
|
229
|
+
end
|
64
230
|
end
|
65
231
|
end
|