redcarpet_yt 0.0.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.
Files changed (47) hide show
  1. checksums.yaml +7 -0
  2. data/COPYING +20 -0
  3. data/Gemfile +9 -0
  4. data/README.markdown +394 -0
  5. data/Rakefile +60 -0
  6. data/bin/redcarpet +7 -0
  7. data/ext/redcarpet/autolink.c +302 -0
  8. data/ext/redcarpet/autolink.h +55 -0
  9. data/ext/redcarpet/buffer.c +203 -0
  10. data/ext/redcarpet/buffer.h +89 -0
  11. data/ext/redcarpet/extconf.rb +6 -0
  12. data/ext/redcarpet/houdini.h +51 -0
  13. data/ext/redcarpet/houdini_href_e.c +124 -0
  14. data/ext/redcarpet/houdini_html_e.c +105 -0
  15. data/ext/redcarpet/html.c +825 -0
  16. data/ext/redcarpet/html.h +84 -0
  17. data/ext/redcarpet/html_blocks.h +229 -0
  18. data/ext/redcarpet/html_smartypants.c +457 -0
  19. data/ext/redcarpet/markdown.c +2917 -0
  20. data/ext/redcarpet/markdown.h +143 -0
  21. data/ext/redcarpet/rc_markdown.c +168 -0
  22. data/ext/redcarpet/rc_render.c +545 -0
  23. data/ext/redcarpet/redcarpet.h +52 -0
  24. data/ext/redcarpet/stack.c +84 -0
  25. data/ext/redcarpet/stack.h +48 -0
  26. data/lib/redcarpet/cli.rb +86 -0
  27. data/lib/redcarpet/compat.rb +73 -0
  28. data/lib/redcarpet/render_man.rb +65 -0
  29. data/lib/redcarpet/render_strip.rb +60 -0
  30. data/lib/redcarpet_yt.rb +103 -0
  31. data/redcarpet_yt.gemspec +71 -0
  32. data/test/benchmark.rb +24 -0
  33. data/test/custom_render_test.rb +28 -0
  34. data/test/fixtures/benchmark.md +232 -0
  35. data/test/html5_test.rb +69 -0
  36. data/test/html_render_test.rb +254 -0
  37. data/test/html_toc_render_test.rb +75 -0
  38. data/test/markdown_test.rb +371 -0
  39. data/test/pathological_inputs_test.rb +34 -0
  40. data/test/redcarpet_bin_test.rb +80 -0
  41. data/test/redcarpet_compat_test.rb +38 -0
  42. data/test/safe_render_test.rb +35 -0
  43. data/test/smarty_html_test.rb +45 -0
  44. data/test/smarty_pants_test.rb +53 -0
  45. data/test/stripdown_render_test.rb +61 -0
  46. data/test/test_helper.rb +39 -0
  47. metadata +151 -0
@@ -0,0 +1,34 @@
1
+ # coding: UTF-8
2
+ require 'test_helper'
3
+
4
+ # Disabled by default
5
+ # (these are the easy ones -- the evil ones are not disclosed)
6
+ class PathologicalInputsTest # < Redcarpet::TestCase
7
+ def setup
8
+ @markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML)
9
+ end
10
+
11
+ def test_pathological_1
12
+ star = '*' * 250000
13
+ @markdown.render("#{star}#{star} hi #{star}#{star}")
14
+ end
15
+
16
+ def test_pathological_2
17
+ crt = '^' * 255
18
+ str = "#{crt}(\\)"
19
+ @markdown.render("#{str*300}")
20
+ end
21
+
22
+ def test_pathological_3
23
+ c = "`t`t`t`t`t`t" * 20000000
24
+ @markdown.render(c)
25
+ end
26
+
27
+ def test_pathological_4
28
+ @markdown.render(" [^a]: #{ "A" * 10000 }\n#{ "[^a][]" * 1000000 }\n")
29
+ end
30
+
31
+ def test_unbound_recursion
32
+ @markdown.render(("[" * 10000) + "foo" + ("](bar)" * 10000))
33
+ end
34
+ end
@@ -0,0 +1,80 @@
1
+ require 'test_helper'
2
+ require 'tempfile'
3
+
4
+ class RedcarpetBinTest < Redcarpet::TestCase
5
+ def setup
6
+ @fixture_file = Tempfile.new('bin')
7
+ @fixture_path = @fixture_file.path
8
+
9
+ @fixture_file.write "A ==simple== fixture file -- with " \
10
+ "a [link](https://github.com)."
11
+ @fixture_file.rewind
12
+ end
13
+
14
+ def teardown
15
+ @fixture_file.unlink
16
+ end
17
+
18
+ def test_vanilla_bin
19
+ run_bin(@fixture_path)
20
+
21
+ expected = "<p>A ==simple== fixture file -- with " \
22
+ "a <a href=\"https://github.com\">link</a>.</p>\n"
23
+
24
+ assert_equal expected, @output
25
+ end
26
+
27
+ def test_enabling_a_parse_option
28
+ run_bin("--parse", "highlight", @fixture_path)
29
+
30
+ assert_output "<mark>"
31
+ refute_output "=="
32
+ end
33
+
34
+ def test_enabling_a_render_option
35
+ run_bin("--render", "no-links", @fixture_path)
36
+
37
+ assert_output "[link]"
38
+ refute_output "</a>"
39
+ end
40
+
41
+ def test_enabling_smarty_pants
42
+ run_bin("--smarty", @fixture_path)
43
+
44
+ assert_output "&ndash"
45
+ refute_output "--"
46
+ end
47
+
48
+ def test_version_option
49
+ run_bin("--version")
50
+ assert_output "Redcarpet #{Redcarpet::VERSION}"
51
+ end
52
+
53
+ def test_legacy_option_parsing
54
+ run_bin("--parse-highlight", "--render-no-links", @fixture_path)
55
+
56
+ assert_output "<mark>"
57
+ refute_output "=="
58
+
59
+ assert_output "[link]"
60
+ refute_output "</a>"
61
+ end
62
+
63
+ private
64
+
65
+ def run_bin(*args)
66
+ bin_path = File.expand_path('../../bin/redcarpet', __FILE__)
67
+ ruby = "ruby " if RUBY_PLATFORM =~ /mswin|mingw/
68
+ IO.popen("#{ruby}#{bin_path} #{args.join(" ")}") do |stream|
69
+ @output = stream.read
70
+ end
71
+ end
72
+
73
+ def assert_output(pattern)
74
+ assert_match pattern, @output
75
+ end
76
+
77
+ def refute_output(pattern)
78
+ refute_match Regexp.new(pattern), @output
79
+ end
80
+ end
@@ -0,0 +1,38 @@
1
+ # coding: UTF-8
2
+ require 'test_helper'
3
+
4
+ class RedcarpetCompatTest < Redcarpet::TestCase
5
+ def test_simple_compat_api
6
+ html = RedcarpetCompat.new("This is_just_a test").to_html
7
+ assert_equal "<p>This is<em>just</em>a test</p>\n", html
8
+ end
9
+
10
+ def test_compat_api_enables_extensions
11
+ html = RedcarpetCompat.new("This is_just_a test", :no_intra_emphasis).to_html
12
+ assert_equal "<p>This is_just_a test</p>\n", html
13
+ end
14
+
15
+ def test_compat_api_knows_fenced_code_extension
16
+ text = "```ruby\nx = 'foo'\n```"
17
+ html = RedcarpetCompat.new(text, :fenced_code).to_html
18
+ assert_equal "<pre><code class=\"ruby\">x = &#39;foo&#39;\n</code></pre>\n", html
19
+ end
20
+
21
+ def test_compat_api_ignores_gh_blockcode_extension
22
+ text = "```ruby\nx = 'foo'\n```"
23
+ html = RedcarpetCompat.new(text, :fenced_code, :gh_blockcode).to_html
24
+ assert_equal "<pre><code class=\"ruby\">x = &#39;foo&#39;\n</code></pre>\n", html
25
+ end
26
+
27
+ def test_compat_api_knows_no_intraemphasis_extension
28
+ html = RedcarpetCompat.new("This is_just_a test", :no_intraemphasis).to_html
29
+ assert_equal "<p>This is_just_a test</p>\n", html
30
+ end
31
+
32
+ def test_translate_outdated_extensions
33
+ # these extensions are no longer used
34
+ exts = [:gh_blockcode, :no_tables, :smart, :strict]
35
+ html = RedcarpetCompat.new('"TEST"', *exts).to_html
36
+ assert_equal "<p>&quot;TEST&quot;</p>\n", html
37
+ end
38
+ end
@@ -0,0 +1,35 @@
1
+ require 'test_helper'
2
+
3
+ class SafeRenderTest < Redcarpet::TestCase
4
+ def setup
5
+ @renderer = Redcarpet::Render::Safe
6
+ end
7
+
8
+ def test_safe_links_only_is_enabled_by_default
9
+ markdown = "[foo](javascript:alert('foo'))"
10
+ output = render(markdown)
11
+
12
+ assert_not_match %r{a href}, output
13
+ end
14
+
15
+ def test_escape_html_is_enabled_by_default
16
+ markdown = "<p>Hello world!</p>"
17
+ output = render(markdown)
18
+
19
+ assert_match %r{&lt;}, output
20
+ end
21
+
22
+ def test_html_escaping_in_code_blocks
23
+ markdown = "~~~\n<p>Hello!</p>\n~~~"
24
+ output = render(markdown)
25
+
26
+ assert_match %r{&lt;p&gt;}, output
27
+ end
28
+
29
+ def test_lang_class_is_removed
30
+ markdown = "~~~ruby\nclass Foo; end\n~~~"
31
+ output = render(markdown, with: [:fenced_code_blocks])
32
+
33
+ assert_not_match %r{ruby}, output
34
+ end
35
+ end
@@ -0,0 +1,45 @@
1
+ # coding: UTF-8
2
+ require 'test_helper'
3
+
4
+ class SmartyHTMLTest < Redcarpet::TestCase
5
+ def setup
6
+ @renderer = Redcarpet::Render::SmartyHTML
7
+ end
8
+
9
+ def test_that_smartyhtml_converts_single_quotes
10
+ markdown = render("They're not for sale.")
11
+ assert_equal "<p>They&rsquo;re not for sale.</p>\n", markdown
12
+ end
13
+
14
+ def test_that_smartyhtml_converts_double_quotes
15
+ rd = render(%("Quoted text"))
16
+ assert_equal %(<p>&ldquo;Quoted text&rdquo;</p>\n), rd
17
+ end
18
+
19
+ def test_that_smartyhtml_converts_double_hyphen
20
+ rd = render("double hyphen -- ndash")
21
+ assert_equal "<p>double hyphen &ndash; ndash</p>\n", rd
22
+ end
23
+
24
+ def test_that_smartyhtml_converts_triple_hyphen
25
+ rd = render("triple hyphen --- mdash")
26
+ assert_equal "<p>triple hyphen &mdash; mdash</p>\n", rd
27
+ end
28
+
29
+ def test_that_smartyhtml_ignores_double_hyphen_in_code
30
+ rd = render("double hyphen in `--option`")
31
+ assert_equal "<p>double hyphen in <code>--option</code></p>\n", rd
32
+ end
33
+
34
+ def test_that_smartyhtml_ignores_pre
35
+ rd = render(" It's a test of \"pre\"\n")
36
+ expected = "It&#39;s a test of &quot;pre&quot;"
37
+ assert rd.include?(expected), "\"#{rd}\" should contain \"#{expected}\""
38
+ end
39
+
40
+ def test_that_smartyhtml_ignores_code
41
+ rd = render("`It's a test of \"code\"`\n")
42
+ expected = "It&#39;s a test of &quot;code&quot;"
43
+ assert rd.include?(expected), "\"#{rd}\" should contain \"#{expected}\""
44
+ end
45
+ end
@@ -0,0 +1,53 @@
1
+ # coding: UTF-8
2
+ require 'test_helper'
3
+
4
+ class SmartyPantsTest < Redcarpet::TestCase
5
+ def setup
6
+ @pants = Redcarpet::Render::SmartyPants
7
+ end
8
+
9
+ def test_that_smart_converts_single_quotes_in_words_that_end_in_re
10
+ markdown = @pants.render("<p>They're not for sale.</p>")
11
+ assert_equal "<p>They&rsquo;re not for sale.</p>", markdown
12
+ end
13
+
14
+ def test_that_smart_converts_single_quotes_in_words_that_end_in_ll
15
+ markdown = @pants.render("<p>Well that'll be the day</p>")
16
+ assert_equal "<p>Well that&rsquo;ll be the day</p>", markdown
17
+ end
18
+
19
+ def test_that_smart_converts_double_quotes_to_curly_quotes
20
+ rd = @pants.render(%(<p>"Quoted text"</p>))
21
+ assert_equal %(<p>&ldquo;Quoted text&rdquo;</p>), rd
22
+ end
23
+
24
+ def test_that_smart_gives_ve_suffix_a_rsquo
25
+ rd = @pants.render("<p>I've been meaning to tell you ..</p>")
26
+ assert_equal "<p>I&rsquo;ve been meaning to tell you ..</p>", rd
27
+ end
28
+
29
+ def test_that_smart_gives_m_suffix_a_rsquo
30
+ rd = @pants.render("<p>I'm not kidding</p>")
31
+ assert_equal "<p>I&rsquo;m not kidding</p>", rd
32
+ end
33
+
34
+ def test_that_smart_gives_d_suffix_a_rsquo
35
+ rd = @pants.render("<p>what'd you say?</p>")
36
+ assert_equal "<p>what&rsquo;d you say?</p>", rd
37
+ end
38
+
39
+ def test_that_backticks_are_preserved
40
+ rd = @pants.render("<p>single `backticks` in HTML should be preserved</p>")
41
+ assert_equal "<p>single `backticks` in HTML should be preserved</p>", rd
42
+ end
43
+
44
+ def test_that_smart_converts_trailing_single_quotes_to_curly_quotes
45
+ rd = @pants.render("<p>Hopin' that this bug gets some fixin'.</p>")
46
+ assert_equal "<p>Hopin&rsquo; that this bug gets some fixin&rsquo;.</p>", rd
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 &frac14;&hellip; of the way to 1/4/2000", rd
52
+ end
53
+ end
@@ -0,0 +1,61 @@
1
+ # coding: UTF-8
2
+ require 'test_helper'
3
+
4
+ class StripDownRender < Redcarpet::TestCase
5
+ def setup
6
+ @renderer = Redcarpet::Render::StripDown
7
+ end
8
+
9
+ def test_titles
10
+ markdown = "# Foo bar"
11
+ output = render(markdown)
12
+
13
+ assert_equal "Foo bar\n", output
14
+ end
15
+
16
+ def test_code_blocks
17
+ markdown = "\tclass Foo\n\tend"
18
+ output = render(markdown)
19
+
20
+ assert_equal "class Foo\nend\n", output
21
+ end
22
+
23
+ def test_images
24
+ markdown = "Look at this ![picture](http://example.org/picture.png)\n" \
25
+ "And this: ![](http://example.org/image.jpg)"
26
+ expected = "Look at this picture http://example.org/picture.png\n" \
27
+ "And this: http://example.org/image.jpg\n"
28
+ output = render(markdown)
29
+
30
+ assert_equal expected, output
31
+ end
32
+
33
+ def test_links
34
+ markdown = "Here's an [example](https://github.com)"
35
+ expected = "Here's an example (https://github.com)\n"
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\n"
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!\n"
57
+ output = render(markdown, with: [:highlight])
58
+
59
+ assert_equal expected, output
60
+ end
61
+ end
@@ -0,0 +1,39 @@
1
+ # coding: UTF-8
2
+ $:.unshift(File.expand_path('../../lib', __FILE__))
3
+ Encoding.default_internal = 'UTF-8'
4
+
5
+ require 'test/unit'
6
+
7
+ require 'redcarpet'
8
+ require 'redcarpet/render_strip'
9
+ require 'redcarpet/render_man'
10
+
11
+ class Redcarpet::TestCase < Test::Unit::TestCase
12
+ def assert_renders(html, markdown)
13
+ assert_equal html, render(markdown)
14
+ end
15
+
16
+ def render(markdown, options = {})
17
+ options = options.fetch(:with, {})
18
+
19
+ if options.kind_of?(Array)
20
+ options = Hash[options.map {|o| [o, true]}]
21
+ end
22
+
23
+ render = begin
24
+ renderer.new(options)
25
+ rescue ArgumentError
26
+ renderer.new
27
+ end
28
+
29
+ parser = Redcarpet::Markdown.new(render, options)
30
+
31
+ parser.render(markdown)
32
+ end
33
+
34
+ private
35
+
36
+ def renderer
37
+ @renderer ||= Redcarpet::Render::HTML
38
+ end
39
+ end
metadata ADDED
@@ -0,0 +1,151 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: redcarpet_yt
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Natacha Porté
8
+ - Vicent Martí
9
+ - Scott Werwath
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2016-03-31 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rake
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - "~>"
20
+ - !ruby/object:Gem::Version
21
+ version: '10.5'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - "~>"
27
+ - !ruby/object:Gem::Version
28
+ version: '10.5'
29
+ - !ruby/object:Gem::Dependency
30
+ name: rake-compiler
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - "~>"
34
+ - !ruby/object:Gem::Version
35
+ version: 0.9.5
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: 0.9.5
43
+ - !ruby/object:Gem::Dependency
44
+ name: test-unit
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: 3.1.3
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - "~>"
55
+ - !ruby/object:Gem::Version
56
+ version: 3.1.3
57
+ description: A fast, safe and extensible Markdown to (X)HTML parser, with YouTube
58
+ embedding, based on Redcarpet
59
+ email: swerwath@berkeley.edu
60
+ executables:
61
+ - redcarpet
62
+ extensions:
63
+ - ext/redcarpet/extconf.rb
64
+ extra_rdoc_files:
65
+ - COPYING
66
+ files:
67
+ - COPYING
68
+ - Gemfile
69
+ - README.markdown
70
+ - Rakefile
71
+ - bin/redcarpet
72
+ - ext/redcarpet/autolink.c
73
+ - ext/redcarpet/autolink.h
74
+ - ext/redcarpet/buffer.c
75
+ - ext/redcarpet/buffer.h
76
+ - ext/redcarpet/extconf.rb
77
+ - ext/redcarpet/houdini.h
78
+ - ext/redcarpet/houdini_href_e.c
79
+ - ext/redcarpet/houdini_html_e.c
80
+ - ext/redcarpet/html.c
81
+ - ext/redcarpet/html.h
82
+ - ext/redcarpet/html_blocks.h
83
+ - ext/redcarpet/html_smartypants.c
84
+ - ext/redcarpet/markdown.c
85
+ - ext/redcarpet/markdown.h
86
+ - ext/redcarpet/rc_markdown.c
87
+ - ext/redcarpet/rc_render.c
88
+ - ext/redcarpet/redcarpet.h
89
+ - ext/redcarpet/stack.c
90
+ - ext/redcarpet/stack.h
91
+ - lib/redcarpet/cli.rb
92
+ - lib/redcarpet/compat.rb
93
+ - lib/redcarpet/render_man.rb
94
+ - lib/redcarpet/render_strip.rb
95
+ - lib/redcarpet_yt.rb
96
+ - redcarpet_yt.gemspec
97
+ - test/benchmark.rb
98
+ - test/custom_render_test.rb
99
+ - test/fixtures/benchmark.md
100
+ - test/html5_test.rb
101
+ - test/html_render_test.rb
102
+ - test/html_toc_render_test.rb
103
+ - test/markdown_test.rb
104
+ - test/pathological_inputs_test.rb
105
+ - test/redcarpet_bin_test.rb
106
+ - test/redcarpet_compat_test.rb
107
+ - test/safe_render_test.rb
108
+ - test/smarty_html_test.rb
109
+ - test/smarty_pants_test.rb
110
+ - test/stripdown_render_test.rb
111
+ - test/test_helper.rb
112
+ homepage: http://github.com/swerwath/redcarpet_yt
113
+ licenses:
114
+ - MIT
115
+ metadata: {}
116
+ post_install_message:
117
+ rdoc_options: []
118
+ require_paths:
119
+ - lib
120
+ required_ruby_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: 1.9.2
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - ">="
128
+ - !ruby/object:Gem::Version
129
+ version: '0'
130
+ requirements: []
131
+ rubyforge_project:
132
+ rubygems_version: 2.4.6
133
+ signing_key:
134
+ specification_version: 4
135
+ summary: Markdown that smells nice, now with YouTube embedding
136
+ test_files:
137
+ - test/benchmark.rb
138
+ - test/custom_render_test.rb
139
+ - test/fixtures/benchmark.md
140
+ - test/html5_test.rb
141
+ - test/html_render_test.rb
142
+ - test/html_toc_render_test.rb
143
+ - test/markdown_test.rb
144
+ - test/pathological_inputs_test.rb
145
+ - test/redcarpet_bin_test.rb
146
+ - test/redcarpet_compat_test.rb
147
+ - test/safe_render_test.rb
148
+ - test/smarty_html_test.rb
149
+ - test/smarty_pants_test.rb
150
+ - test/stripdown_render_test.rb
151
+ - test/test_helper.rb