greenmat 3.2.2.4 → 3.5.1.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.
- 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
data/test/safe_render_test.rb
CHANGED
@@ -2,34 +2,33 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
class SafeRenderTest < Greenmat::TestCase
|
4
4
|
def setup
|
5
|
-
@
|
6
|
-
@parser = Greenmat::Markdown.new(@render, fenced_code_blocks: true)
|
5
|
+
@renderer = Greenmat::Render::Safe
|
7
6
|
end
|
8
7
|
|
9
8
|
def test_safe_links_only_is_enabled_by_default
|
10
9
|
markdown = "[foo](javascript:alert('foo'))"
|
11
|
-
output =
|
10
|
+
output = render(markdown)
|
12
11
|
|
13
12
|
assert_not_match %r{a href}, output
|
14
13
|
end
|
15
14
|
|
16
15
|
def test_escape_html_is_enabled_by_default
|
17
16
|
markdown = "<p>Hello world!</p>"
|
18
|
-
output =
|
17
|
+
output = render(markdown)
|
19
18
|
|
20
19
|
assert_match %r{<}, output
|
21
20
|
end
|
22
21
|
|
23
22
|
def test_html_escaping_in_code_blocks
|
24
23
|
markdown = "~~~\n<p>Hello!</p>\n~~~"
|
25
|
-
output =
|
24
|
+
output = render(markdown)
|
26
25
|
|
27
26
|
assert_match %r{<p>}, output
|
28
27
|
end
|
29
28
|
|
30
29
|
def test_lang_class_is_removed
|
31
30
|
markdown = "~~~ruby\nclass Foo; end\n~~~"
|
32
|
-
output =
|
31
|
+
output = render(markdown, with: [:fenced_code_blocks])
|
33
32
|
|
34
33
|
assert_not_match %r{ruby}, output
|
35
34
|
end
|
data/test/smarty_html_test.rb
CHANGED
@@ -3,43 +3,49 @@ require 'test_helper'
|
|
3
3
|
|
4
4
|
class SmartyHTMLTest < Greenmat::TestCase
|
5
5
|
def setup
|
6
|
-
@
|
6
|
+
@renderer = Greenmat::Render::SmartyHTML
|
7
7
|
end
|
8
8
|
|
9
9
|
def test_that_smartyhtml_converts_single_quotes
|
10
|
-
markdown =
|
11
|
-
assert_equal "<p>They’re not for sale.</p
|
10
|
+
markdown = render("They're not for sale.")
|
11
|
+
assert_equal "<p>They’re not for sale.</p>", markdown
|
12
12
|
end
|
13
13
|
|
14
14
|
def test_that_smartyhtml_converts_double_quotes
|
15
|
-
rd =
|
16
|
-
assert_equal %(<p>“Quoted text”</p
|
15
|
+
rd = render(%("Quoted text"))
|
16
|
+
assert_equal %(<p>“Quoted text”</p>), rd
|
17
17
|
end
|
18
18
|
|
19
19
|
def test_that_smartyhtml_converts_double_hyphen
|
20
|
-
rd =
|
21
|
-
assert_equal "<p>double hyphen – ndash</p
|
20
|
+
rd = render("double hyphen -- ndash")
|
21
|
+
assert_equal "<p>double hyphen – ndash</p>", rd
|
22
22
|
end
|
23
23
|
|
24
24
|
def test_that_smartyhtml_converts_triple_hyphen
|
25
|
-
rd =
|
26
|
-
assert_equal "<p>triple hyphen — mdash</p
|
25
|
+
rd = render("triple hyphen --- mdash")
|
26
|
+
assert_equal "<p>triple hyphen — mdash</p>", rd
|
27
27
|
end
|
28
28
|
|
29
29
|
def test_that_smartyhtml_ignores_double_hyphen_in_code
|
30
|
-
rd =
|
31
|
-
assert_equal "<p>double hyphen in <code>--option</code></p
|
30
|
+
rd = render("double hyphen in `--option`")
|
31
|
+
assert_equal "<p>double hyphen in <code>--option</code></p>", rd
|
32
32
|
end
|
33
33
|
|
34
34
|
def test_that_smartyhtml_ignores_pre
|
35
|
-
rd =
|
35
|
+
rd = render(" It's a test of \"pre\"\n")
|
36
36
|
expected = "It's a test of "pre""
|
37
37
|
assert rd.include?(expected), "\"#{rd}\" should contain \"#{expected}\""
|
38
38
|
end
|
39
39
|
|
40
40
|
def test_that_smartyhtml_ignores_code
|
41
|
-
rd =
|
41
|
+
rd = render("`It's a test of \"code\"`\n")
|
42
42
|
expected = "It's a test of "code""
|
43
43
|
assert rd.include?(expected), "\"#{rd}\" should contain \"#{expected}\""
|
44
44
|
end
|
45
|
+
|
46
|
+
def test_that_smartyhtml_ignores_links_for_single_quotes
|
47
|
+
output = render("[John](link)'s cat")
|
48
|
+
expected = %(<p><a href="link">John</a>’s cat</p>)
|
49
|
+
assert_equal expected, output
|
50
|
+
end
|
45
51
|
end
|
data/test/smarty_pants_test.rb
CHANGED
@@ -45,4 +45,14 @@ class SmartyPantsTest < Greenmat::TestCase
|
|
45
45
|
rd = @pants.render("<p>Hopin' that this bug gets some fixin'.</p>")
|
46
46
|
assert_equal "<p>Hopin’ that this bug gets some fixin’.</p>", rd
|
47
47
|
end
|
48
|
+
|
49
|
+
def test_that_is_not_confused_by_fractions
|
50
|
+
rd = @pants.render('I am 1/4... of the way to 1/4/2000')
|
51
|
+
assert_equal "I am ¼… of the way to 1/4/2000", rd
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_that_smart_converts_multiple_single_quotes
|
55
|
+
rd = @pants.render(%(<p>'First' and 'second' and 'third'</p>))
|
56
|
+
assert_equal %(<p>‘First’ and ‘second’ and ‘third’</p>), rd
|
57
|
+
end
|
48
58
|
end
|
@@ -3,37 +3,66 @@ require 'test_helper'
|
|
3
3
|
|
4
4
|
class StripDownRender < Greenmat::TestCase
|
5
5
|
def setup
|
6
|
-
@
|
6
|
+
@renderer = Greenmat::Render::StripDown
|
7
7
|
end
|
8
8
|
|
9
9
|
def test_titles
|
10
10
|
markdown = "# Foo bar"
|
11
|
-
output =
|
11
|
+
output = render(markdown)
|
12
12
|
|
13
|
-
assert_equal "Foo bar
|
13
|
+
assert_equal "Foo bar", output
|
14
14
|
end
|
15
15
|
|
16
16
|
def test_code_blocks
|
17
17
|
markdown = "\tclass Foo\n\tend"
|
18
|
-
output =
|
18
|
+
output = render(markdown)
|
19
19
|
|
20
|
-
assert_equal "class Foo\nend
|
20
|
+
assert_equal "class Foo\nend", output
|
21
21
|
end
|
22
22
|
|
23
23
|
def test_images
|
24
24
|
markdown = "Look at this \n" \
|
25
25
|
"And this: "
|
26
26
|
expected = "Look at this picture http://example.org/picture.png\n" \
|
27
|
-
"And this: http://example.org/image.jpg
|
28
|
-
output =
|
27
|
+
"And this: http://example.org/image.jpg"
|
28
|
+
output = render(markdown)
|
29
29
|
|
30
30
|
assert_equal expected, output
|
31
31
|
end
|
32
32
|
|
33
33
|
def test_links
|
34
34
|
markdown = "Here's an [example](https://github.com)"
|
35
|
-
expected = "Here's an example (https://github.com)
|
36
|
-
output =
|
35
|
+
expected = "Here's an example (https://github.com)"
|
36
|
+
output = render(markdown)
|
37
|
+
|
38
|
+
assert_equal expected, output
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_tables
|
42
|
+
markdown = "| Left-Aligned | Centre Aligned | Right Aligned |\n" \
|
43
|
+
"| :------------ |:---------------:| -----:|\n" \
|
44
|
+
"| col 3 is | some wordy text | $1600 |\n" \
|
45
|
+
"| col 2 is | centered | $12 |"
|
46
|
+
expected = "Left-Aligned\tCentre Aligned\tRight Aligned\t\n" \
|
47
|
+
"col 3 is\tsome wordy text\t$1600\t\n" \
|
48
|
+
"col 2 is\tcentered\t$12\t"
|
49
|
+
output = render(markdown, with: [:tables])
|
50
|
+
|
51
|
+
assert_equal expected, output
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_highlight
|
55
|
+
markdown = "==Hello world!=="
|
56
|
+
expected = "Hello world!"
|
57
|
+
output = render(markdown, with: [:highlight])
|
58
|
+
|
59
|
+
assert_equal expected, output
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_with_quote_option_enabled
|
63
|
+
markdown = %(A common idiom is "Hello world")
|
64
|
+
expected = %(A common idiom is Hello world)
|
65
|
+
output = render(markdown, with: [:quote])
|
37
66
|
|
38
67
|
assert_equal expected, output
|
39
68
|
end
|
data/test/test_helper.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# coding: UTF-8
|
2
|
-
|
2
|
+
$:.unshift(File.expand_path('../../lib', __FILE__))
|
3
|
+
Encoding.default_internal = 'UTF-8'
|
3
4
|
|
4
5
|
gem 'test-unit', '>= 2' # necessary when not using bundle exec
|
5
6
|
|
@@ -9,21 +10,41 @@ require 'nokogiri'
|
|
9
10
|
require 'greenmat'
|
10
11
|
require 'greenmat/render_strip'
|
11
12
|
require 'greenmat/render_man'
|
12
|
-
require 'greenmat/compat'
|
13
13
|
|
14
14
|
class Greenmat::TestCase < Test::Unit::TestCase
|
15
|
-
def
|
16
|
-
assert_equal
|
17
|
-
Nokogiri::HTML::DocumentFragment.parse(html_b).to_html
|
15
|
+
def assert_renders(html, markdown)
|
16
|
+
assert_equal html, render(markdown)
|
18
17
|
end
|
19
18
|
|
20
|
-
def
|
21
|
-
|
19
|
+
def render(markdown, options = {})
|
20
|
+
options = options.fetch(:with, {})
|
21
|
+
|
22
|
+
if options.kind_of?(Array)
|
23
|
+
options = Hash[options.map {|o| [o, true]}]
|
24
|
+
end
|
25
|
+
|
26
|
+
render = begin
|
27
|
+
renderer.new(options)
|
28
|
+
rescue ArgumentError
|
29
|
+
renderer.new
|
30
|
+
end
|
31
|
+
|
32
|
+
parser = Greenmat::Markdown.new(render, options)
|
33
|
+
|
34
|
+
parser.render(markdown).chomp
|
22
35
|
end
|
23
36
|
|
24
37
|
private
|
25
38
|
|
26
|
-
def
|
27
|
-
@
|
39
|
+
def renderer
|
40
|
+
@renderer ||= Greenmat::Render::HTML
|
41
|
+
end
|
42
|
+
|
43
|
+
# Imported from Active Support
|
44
|
+
class ::String
|
45
|
+
def strip_heredoc
|
46
|
+
indent = scan(/^ *(?=\S)/).min.size || 0
|
47
|
+
gsub(/^[ \t]{#{indent}}/, '')
|
48
|
+
end
|
28
49
|
end
|
29
50
|
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: greenmat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.5.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Natacha Porté
|
8
8
|
- Vicent Martí
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2021-02-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -45,28 +45,28 @@ dependencies:
|
|
45
45
|
requirements:
|
46
46
|
- - "~>"
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version:
|
48
|
+
version: 12.2.1
|
49
49
|
type: :development
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
53
|
- - "~>"
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version:
|
55
|
+
version: 12.2.1
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
57
|
name: rake-compiler
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
60
|
- - "~>"
|
61
61
|
- !ruby/object:Gem::Version
|
62
|
-
version: 0.
|
62
|
+
version: 1.0.3
|
63
63
|
type: :development
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
67
|
- - "~>"
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version: 0.
|
69
|
+
version: 1.0.3
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: rspec
|
72
72
|
requirement: !ruby/object:Gem::Requirement
|
@@ -87,14 +87,14 @@ dependencies:
|
|
87
87
|
requirements:
|
88
88
|
- - "~>"
|
89
89
|
- !ruby/object:Gem::Version
|
90
|
-
version: 2.
|
90
|
+
version: 3.2.3
|
91
91
|
type: :development
|
92
92
|
prerelease: false
|
93
93
|
version_requirements: !ruby/object:Gem::Requirement
|
94
94
|
requirements:
|
95
95
|
- - "~>"
|
96
96
|
- !ruby/object:Gem::Version
|
97
|
-
version: 2.
|
97
|
+
version: 3.2.3
|
98
98
|
description: A Markdown parser for Qiita, based on Redcarpet.
|
99
99
|
email: nkymyj@gmail.com
|
100
100
|
executables:
|
@@ -134,6 +134,7 @@ files:
|
|
134
134
|
- ext/greenmat/stack.h
|
135
135
|
- greenmat.gemspec
|
136
136
|
- lib/greenmat.rb
|
137
|
+
- lib/greenmat/cli.rb
|
137
138
|
- lib/greenmat/compat.rb
|
138
139
|
- lib/greenmat/render_man.rb
|
139
140
|
- lib/greenmat/render_strip.rb
|
@@ -229,6 +230,7 @@ files:
|
|
229
230
|
- test/benchmark.rb
|
230
231
|
- test/custom_render_test.rb
|
231
232
|
- test/fixtures/benchmark.md
|
233
|
+
- test/greenmat_bin_test.rb
|
232
234
|
- test/greenmat_compat_test.rb
|
233
235
|
- test/html5_test.rb
|
234
236
|
- test/html_render_test.rb
|
@@ -244,7 +246,7 @@ homepage: https://github.com/increments/greenmat
|
|
244
246
|
licenses:
|
245
247
|
- MIT
|
246
248
|
metadata: {}
|
247
|
-
post_install_message:
|
249
|
+
post_install_message:
|
248
250
|
rdoc_options: []
|
249
251
|
require_paths:
|
250
252
|
- lib
|
@@ -259,9 +261,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
259
261
|
- !ruby/object:Gem::Version
|
260
262
|
version: '0'
|
261
263
|
requirements: []
|
262
|
-
|
263
|
-
|
264
|
-
signing_key:
|
264
|
+
rubygems_version: 3.0.3
|
265
|
+
signing_key:
|
265
266
|
specification_version: 4
|
266
267
|
summary: A Markdown parser for Qiita, based on Redcarpet.
|
267
268
|
test_files:
|
@@ -354,6 +355,7 @@ test_files:
|
|
354
355
|
- test/benchmark.rb
|
355
356
|
- test/custom_render_test.rb
|
356
357
|
- test/fixtures/benchmark.md
|
358
|
+
- test/greenmat_bin_test.rb
|
357
359
|
- test/greenmat_compat_test.rb
|
358
360
|
- test/html5_test.rb
|
359
361
|
- test/html_render_test.rb
|