redcarpet 3.2.3 → 3.3.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of redcarpet might be problematic. Click here for more details.

@@ -104,9 +104,6 @@ struct sd_callbacks {
104
104
  void (*doc_footer)(struct buf *ob, void *opaque);
105
105
  };
106
106
 
107
- /* header methods used internally in Redcarpet */
108
- char* header_anchor(struct buf *text);
109
-
110
107
  struct sd_markdown;
111
108
 
112
109
  /*********
@@ -122,13 +122,9 @@ static VALUE rb_redcarpet_md_render(VALUE self, VALUE text)
122
122
  if (NIL_P(text))
123
123
  return Qnil;
124
124
 
125
- #ifdef HAVE_RUBY_ENCODING_H
126
- {
127
- struct rb_redcarpet_rndr *renderer;
128
- Data_Get_Struct(rb_rndr, struct rb_redcarpet_rndr, renderer);
129
- renderer->options.active_enc = rb_enc_get(text);
130
- }
131
- #endif
125
+ struct rb_redcarpet_rndr *renderer;
126
+ Data_Get_Struct(rb_rndr, struct rb_redcarpet_rndr, renderer);
127
+ renderer->options.active_enc = rb_enc_get(text);
132
128
 
133
129
  /* initialize buffers */
134
130
  output_buf = bufnew(128);
@@ -472,25 +472,30 @@ static VALUE rb_redcarpet_html_init(int argc, VALUE *argv, VALUE self)
472
472
  static VALUE rb_redcarpet_htmltoc_init(int argc, VALUE *argv, VALUE self)
473
473
  {
474
474
  struct rb_redcarpet_rndr *rndr;
475
- int nesting_level = 6;
476
- VALUE hash, key = Qnil;
475
+ unsigned int render_flags = HTML_TOC;
476
+ VALUE hash, nesting_level = Qnil;
477
477
 
478
478
  Data_Get_Struct(self, struct rb_redcarpet_rndr, rndr);
479
479
 
480
480
  if (rb_scan_args(argc, argv, "01", &hash) == 1) {
481
481
  Check_Type(hash, T_HASH);
482
482
 
483
- key = CSTR2SYM("nesting_level");
483
+ /* escape_html */
484
+ if (rb_hash_aref(hash, CSTR2SYM("escape_html")) == Qtrue)
485
+ render_flags |= HTML_ESCAPE;
484
486
 
485
- if (RTEST(rb_hash_aref(hash, key))) {
486
- Check_Type(rb_hash_aref(hash, key), T_FIXNUM);
487
- nesting_level = NUM2INT(rb_hash_aref(hash, key));
488
- }
487
+ /* Nesting level */
488
+ nesting_level = rb_hash_aref(hash, CSTR2SYM("nesting_level"));
489
489
  }
490
490
 
491
- sdhtml_toc_renderer(&rndr->callbacks, (struct html_renderopt *)&rndr->options.html, nesting_level);
491
+ sdhtml_toc_renderer(&rndr->callbacks, (struct html_renderopt *)&rndr->options.html, render_flags);
492
492
  rb_redcarpet__overload(self, rb_cRenderHTML_TOC);
493
493
 
494
+ if (!(NIL_P(nesting_level)))
495
+ rndr->options.html.toc_data.nesting_level = NUM2INT(nesting_level);
496
+ else
497
+ rndr->options.html.toc_data.nesting_level = 6;
498
+
494
499
  return Qnil;
495
500
  }
496
501
 
@@ -2,7 +2,7 @@ require 'redcarpet.so'
2
2
  require 'redcarpet/compat'
3
3
 
4
4
  module Redcarpet
5
- VERSION = '3.2.3'
5
+ VERSION = '3.3.0'
6
6
 
7
7
  class Markdown
8
8
  attr_reader :renderer
@@ -1,8 +1,5 @@
1
1
  require 'redcarpet'
2
2
 
3
- # Deprecated: Please use the default API to parse Markdown
4
- # documents ; this layer will be removed in Redcarpet 4.0.
5
- #
6
3
  # Creates an instance of Redcarpet with the RedCloth API.
7
4
  class RedcarpetCompat
8
5
  attr_accessor :text
@@ -1,10 +1,10 @@
1
1
  # encoding: utf-8
2
2
  Gem::Specification.new do |s|
3
3
  s.name = 'redcarpet'
4
- s.version = '3.2.3'
4
+ s.version = '3.3.0'
5
5
  s.summary = "Markdown that smells nice"
6
6
  s.description = 'A fast, safe and extensible Markdown to (X)HTML parser'
7
- s.date = '2015-04-05'
7
+ s.date = '2015-06-05'
8
8
  s.email = 'vicent@github.com'
9
9
  s.homepage = 'http://github.com/vmg/redcarpet'
10
10
  s.authors = ["Natacha Porté", "Vicent Martí"]
@@ -43,11 +43,13 @@ Gem::Specification.new do |s|
43
43
  redcarpet.gemspec
44
44
  test/benchmark.rb
45
45
  test/custom_render_test.rb
46
+ test/fixtures/benchmark.md
46
47
  test/html5_test.rb
47
48
  test/html_render_test.rb
48
49
  test/html_toc_render_test.rb
49
50
  test/markdown_test.rb
50
51
  test/pathological_inputs_test.rb
52
+ test/redcarpet_bin_test.rb
51
53
  test/redcarpet_compat_test.rb
52
54
  test/safe_render_test.rb
53
55
  test/smarty_html_test.rb
@@ -62,7 +64,6 @@ Gem::Specification.new do |s|
62
64
  s.executables = ["redcarpet"]
63
65
  s.require_paths = ["lib"]
64
66
 
65
- s.add_development_dependency "nokogiri", "~> 1.6.0"
66
67
  s.add_development_dependency "rake-compiler", "~> 0.8.3"
67
- s.add_development_dependency "test-unit", "~> 2.5.4"
68
+ s.add_development_dependency "test-unit", "~> 3.0.9"
68
69
  end
@@ -10,7 +10,7 @@ class CustomRenderTest < Redcarpet::TestCase
10
10
 
11
11
  def test_simple_overload
12
12
  md = Redcarpet::Markdown.new(SimpleRender)
13
- html_equal "<p>This is <em class=\"cool\">just</em> a test</p>\n",
13
+ assert_equal "<p>This is <em class=\"cool\">just</em> a test</p>\n",
14
14
  md.render("This is *just* a test")
15
15
  end
16
16
 
@@ -0,0 +1,232 @@
1
+ Download
2
+ --------
3
+
4
+ [Markdown 1.0.1][dl] (18 KB) -- 17 Dec 2004
5
+
6
+ [dl]: http://daringfireball.net/projects/downloads/Markdown_1.0.1.zip
7
+
8
+
9
+ Introduction
10
+ ------------
11
+
12
+ Markdown is a text-to-HTML conversion tool for web writers. Markdown
13
+ allows you to write using an easy-to-read, easy-to-write plain text
14
+ format, then convert it to structurally valid XHTML (or HTML).
15
+
16
+ Thus, "Markdown" is two things: (1) a plain text formatting syntax;
17
+ and (2) a software tool, written in Perl, that converts the plain text
18
+ formatting to HTML. See the [Syntax][] page for details pertaining to
19
+ Markdown's formatting syntax. You can try it out, right now, using the
20
+ online [Dingus][].
21
+
22
+ [syntax]: /projects/markdown/syntax
23
+ [dingus]: /projects/markdown/dingus
24
+
25
+ The overriding design goal for Markdown's formatting syntax is to make
26
+ it as readable as possible. The idea is that a Markdown-formatted
27
+ document should be publishable as-is, as plain text, without looking
28
+ like it's been marked up with tags or formatting instructions. While
29
+ Markdown's syntax has been influenced by several existing text-to-HTML
30
+ filters, the single biggest source of inspiration for Markdown's
31
+ syntax is the format of plain text email.
32
+
33
+ The best way to get a feel for Markdown's formatting syntax is simply
34
+ to look at a Markdown-formatted document. For example, you can view
35
+ the Markdown source for the article text on this page here:
36
+ <http://daringfireball.net/projects/markdown/index.text>
37
+
38
+ (You can use this '.text' suffix trick to view the Markdown source for
39
+ the content of each of the pages in this section, e.g. the
40
+ [Syntax][s_src] and [License][l_src] pages.)
41
+
42
+ [s_src]: /projects/markdown/syntax.text
43
+ [l_src]: /projects/markdown/license.text
44
+
45
+ Markdown is free software, available under a BSD-style open source
46
+ license. See the [License] [pl] page for more information.
47
+
48
+ [pl]: /projects/markdown/license
49
+
50
+
51
+ Discussion List <a id="discussion-list" />
52
+ ---------------
53
+
54
+ I've set up a public [mailing list for discussion about Markdown] [ml].
55
+ Any topic related to Markdown -- both its formatting syntax and
56
+ its software -- is fair game for discussion. Anyone who is interested
57
+ is welcome to join.
58
+
59
+ It's my hope that the mailing list will lead to good ideas for future
60
+ improvements to Markdown.
61
+
62
+ [ml]: http://six.pairlist.net/mailman/listinfo/markdown-discuss
63
+
64
+
65
+ Installation and Requirements <a id="install" />
66
+ -----------------------------
67
+
68
+ Markdown requires Perl 5.6.0 or later. Welcome to the 21st Century.
69
+ Markdown also requires the standard Perl library module [Digest::MD5]
70
+ [md5], which is probably already installed on your server.
71
+
72
+ [md5]: http://search.cpan.org/dist/Digest-MD5/MD5.pm
73
+
74
+
75
+ ### Movable Type ###
76
+
77
+ Markdown works with Movable Type version 2.6 or later (including
78
+ Movable Type 3.0).
79
+
80
+ 1. Copy the "Markdown.pl" file into your Movable Type "plugins"
81
+ directory. The "plugins" directory should be in the same directory
82
+ as "mt.cgi"; if the "plugins" directory doesn't already exist, use
83
+ your FTP program to create it. Your installation should look like
84
+ this:
85
+
86
+ (mt home)/plugins/Markdown.pl
87
+
88
+ 2. Once installed, Markdown will appear as an option in Movable Type's
89
+ Text Formatting pop-up menu. This is selectable on a per-post basis:
90
+
91
+ ![Screenshot of Movable Type 'Text Formatting' Menu][tfmenu]
92
+
93
+ Markdown translates your posts to HTML when you publish; the posts
94
+ themselves are stored in your MT database in Markdown format.
95
+
96
+ 3. If you also install SmartyPants 1.5 (or later), Markdown will
97
+ offer a second text formatting option: "Markdown With
98
+ SmartyPants". This option is the same as the regular "Markdown"
99
+ formatter, except that it automatically uses SmartyPants to create
100
+ typographically correct curly quotes, em-dashes, and ellipses. See
101
+ the [SmartyPants web page][sp] for more information.
102
+
103
+ 4. To make Markdown (or "Markdown With SmartyPants") your default
104
+ text formatting option for new posts, go to Weblog Config:
105
+ Preferences.
106
+
107
+ Note that by default, Markdown produces XHTML output. To configure
108
+ Markdown to produce HTML 4 output, see "Configuration", below.
109
+
110
+ [sp]: http://daringfireball.net/projects/smartypants/
111
+
112
+
113
+
114
+ ### Blosxom ###
115
+
116
+ Markdown works with Blosxom version 2.0 or later.
117
+
118
+ 1. Rename the "Markdown.pl" plug-in to "Markdown" (case is
119
+ important). Movable Type requires plug-ins to have a ".pl"
120
+ extension; Blosxom forbids it.
121
+
122
+ 2. Copy the "Markdown" plug-in file to your Blosxom plug-ins folder.
123
+ If you're not sure where your Blosxom plug-ins folder is, see the
124
+ Blosxom documentation for information.
125
+
126
+ 3. That's it. The entries in your weblog will now automatically be
127
+ processed by Markdown.
128
+
129
+ 4. If you'd like to apply Markdown formatting only to certain
130
+ posts, rather than all of them, Markdown can optionally be used in
131
+ conjunction with Blosxom's [Meta][] plug-in. First, install the
132
+ Meta plug-in. Next, open the Markdown plug-in file in a text
133
+ editor, and set the configuration variable `$g_blosxom_use_meta`
134
+ to 1. Then, simply include a "`meta-markup: Markdown`" header line
135
+ at the top of each post you compose using Markdown.
136
+
137
+ [meta]: http://www.blosxom.com/plugins/meta/meta.htm
138
+
139
+
140
+ ### BBEdit ###
141
+
142
+ Markdown works with BBEdit 6.1 or later on Mac OS X. It also works
143
+ with BBEdit 5.1 or later and MacPerl 5.6.1 on Mac OS 8.6 or later. If
144
+ you're running Mac OS X 10.2 (Jaguar), you may need to install the
145
+ Perl module [Digest::MD5] [md5] from CPAN; Digest::MD5 comes
146
+ pre-installed on Mac OS X 10.3 (Panther).
147
+
148
+ 1. Copy the "Markdown.pl" file to appropriate filters folder in your
149
+ "BBEdit Support" folder. On Mac OS X, this should be:
150
+
151
+ BBEdit Support/Unix Support/Unix Filters/
152
+
153
+ See the BBEdit documentation for more details on the location of
154
+ these folders.
155
+
156
+ You can rename "Markdown.pl" to whatever you wish.
157
+
158
+ 2. That's it. To use Markdown, select some text in a BBEdit document,
159
+ then choose Markdown from the Filters sub-menu in the "#!" menu, or
160
+ the Filters floating palette
161
+
162
+
163
+
164
+ Configuration <a id="configuration"></a>
165
+ -------------
166
+
167
+ By default, Markdown produces XHTML output for tags with empty elements.
168
+ E.g.:
169
+
170
+ <br />
171
+
172
+ Markdown can be configured to produce HTML-style tags; e.g.:
173
+
174
+ <br>
175
+
176
+
177
+ ### Movable Type ###
178
+
179
+ You need to use a special `MTMarkdownOptions` container tag in each
180
+ Movable Type template where you want HTML 4-style output:
181
+
182
+ <MTMarkdownOptions output='html4'>
183
+ ... put your entry content here ...
184
+ </MTMarkdownOptions>
185
+
186
+ The easiest way to use MTMarkdownOptions is probably to put the
187
+ opening tag right after your `<body>` tag, and the closing tag right
188
+ before `</body>`.
189
+
190
+ To suppress Markdown processing in a particular template, i.e. to
191
+ publish the raw Markdown-formatted text without translation into
192
+ (X)HTML, set the `output` attribute to 'raw':
193
+
194
+ <MTMarkdownOptions output='raw'>
195
+ ... put your entry content here ...
196
+ </MTMarkdownOptions>
197
+
198
+
199
+ ### Command-Line ###
200
+
201
+ Use the `--html4tags` command-line switch to produce HTML output from a
202
+ Unix-style command line. E.g.:
203
+
204
+ % perl Markdown.pl --html4tags foo.text
205
+
206
+ Type `perldoc Markdown.pl`, or read the POD documentation within the
207
+ Markdown.pl source code for more information.
208
+
209
+
210
+ Acknowledgements <a id="acknowledgements" />
211
+ ----------------
212
+
213
+ [Aaron Swartz][] deserves a tremendous amount of credit for his feedback on the
214
+ design of Markdown's formatting syntax. Markdown is *much* better thanks
215
+ to Aaron's ideas, feedback, and testing. Also, Aaron's [html2text][]
216
+ is a very handy (and free) utility for turning HTML into
217
+ Markdown-formatted plain text.
218
+
219
+ [Nathaniel Irons][], [Dan Benjamin][], [Daniel Bogan][], and [Jason Perkins][]
220
+ also deserve thanks for their feedback.
221
+
222
+ [Michel Fortin][] has ported Markdown to PHP; it's a splendid port, and highly recommended for anyone looking for a PHP implementation of Markdown.
223
+
224
+ [Aaron Swartz]: http://www.aaronsw.com/
225
+ [Nathaniel Irons]: http://bumppo.net/
226
+ [Dan Benjamin]: http://hivelogic.com/
227
+ [Daniel Bogan]: http://waferbaby.com/
228
+ [Jason Perkins]: http://pressedpants.com/
229
+ [Michel Fortin]: http://www.michelf.com/projects/php-markdown/
230
+ [html2text]: http://www.aaronsw.com/2002/html2text/
231
+
232
+ [tfmenu]: /graphics/markdown/mt_textformat_menu.png
@@ -3,21 +3,7 @@ require 'test_helper'
3
3
 
4
4
  class HTMLRenderTest < Redcarpet::TestCase
5
5
  def setup
6
- @markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML)
7
- @rndr = {
8
- :no_html => Redcarpet::Render::HTML.new(:filter_html => true),
9
- :no_images => Redcarpet::Render::HTML.new(:no_images => true),
10
- :no_links => Redcarpet::Render::HTML.new(:no_links => true),
11
- :safe_links => Redcarpet::Render::HTML.new(:safe_links_only => true),
12
- :escape_html => Redcarpet::Render::HTML.new(:escape_html => true),
13
- :hard_wrap => Redcarpet::Render::HTML.new(:hard_wrap => true),
14
- :toc_data => Redcarpet::Render::HTML.new(:with_toc_data => true),
15
- :prettify => Redcarpet::Render::HTML.new(:prettify => true)
16
- }
17
- end
18
-
19
- def render_with(rndr, text)
20
- Redcarpet::Markdown.new(rndr).render(text)
6
+ @renderer = Redcarpet::Render::HTML
21
7
  end
22
8
 
23
9
  # Hint: overrides filter_html, no_images and no_links
@@ -37,45 +23,55 @@ EOS
37
23
  <p>&lt;img src=&quot;/favicon.ico&quot; /&gt;</p>
38
24
  EOE
39
25
 
40
- markdown = render_with(@rndr[:escape_html], source)
41
- html_equal expected, markdown
26
+ assert_equal expected, render(source, with: [:escape_html])
42
27
  end
43
28
 
44
29
  def test_that_filter_html_works
45
- markdown = render_with(@rndr[:no_html], 'Through <em>NO</em> <script>DOUBLE NO</script>')
46
- html_equal "<p>Through NO DOUBLE NO</p>\n", markdown
30
+ markdown = 'Through <em>NO</em> <script>DOUBLE NO</script>'
31
+ output = render(markdown, with: [:filter_html])
32
+
33
+ assert_equal "<p>Through NO DOUBLE NO</p>\n", output
47
34
  end
48
35
 
49
36
  def test_filter_html_doesnt_break_two_space_hard_break
50
- markdown = render_with(@rndr[:no_html], "Lorem, \nipsum\n")
51
- html_equal "<p>Lorem,<br/>\nipsum</p>\n", markdown
37
+ markdown = "Lorem, \nipsum\n"
38
+ output = render(markdown, with: [:filter_html])
39
+
40
+ assert_equal "<p>Lorem,<br>\nipsum</p>\n", output
52
41
  end
53
42
 
54
43
  def test_that_no_image_flag_works
55
- rd = render_with(@rndr[:no_images], %(![dust mite](http://dust.mite/image.png) <img src="image.png" />))
56
- assert rd !~ /<img/
44
+ markdown = %(![dust mite](http://dust.mite/image.png) <img src="image.png" />)
45
+ output = render(markdown, with: [:no_images])
46
+
47
+ assert_no_match %r{<img}, output
57
48
  end
58
49
 
59
50
  def test_that_no_links_flag_works
60
- rd = render_with(@rndr[:no_links], %([This link](http://example.net/) <a href="links.html">links</a>))
61
- assert rd !~ /<a /
51
+ markdown = %([This link](http://example.net/) <a href="links.html">links</a>)
52
+ output = render(markdown, with: [:no_links])
53
+
54
+ assert_no_match %r{<a }, output
62
55
  end
63
56
 
64
57
  def test_that_safelink_flag_works
65
- rd = render_with(@rndr[:safe_links], "[IRC](irc://chat.freenode.org/#freenode)")
66
- html_equal "<p>[IRC](irc://chat.freenode.org/#freenode)</p>\n", rd
58
+ markdown = "[IRC](irc://chat.freenode.org/#freenode)"
59
+ output = render(markdown, with: [:safe_links_only])
60
+
61
+ assert_equal "<p>[IRC](irc://chat.freenode.org/#freenode)</p>\n", output
67
62
  end
68
63
 
69
64
  def test_that_hard_wrap_works
70
- rd = render_with(@rndr[:hard_wrap], <<EOE)
65
+ markdown = <<EOE
71
66
  Hello world,
72
67
  this is just a simple test
73
68
 
74
69
  With hard wraps
75
70
  and other *things*.
76
71
  EOE
72
+ output = render(markdown, with: [:hard_wrap])
77
73
 
78
- assert rd =~ /<br>/
74
+ assert_match %r{<br>}, output
79
75
  end
80
76
 
81
77
  def test_that_link_attributes_work
@@ -85,11 +81,11 @@ EOE
85
81
  end
86
82
 
87
83
  def test_that_link_works_with_quotes
88
- rd = render_with(Redcarpet::Render::HTML.new, %([This'link"is](http://example.net/)))
89
- assert_equal "<p><a href=\"http://example.net/\">This&#39;link&quot;is</a></p>\n", rd
84
+ markdown = %([This'link"is](http://example.net/))
85
+ expected = %(<p><a href="http://example.net/">This&#39;link&quot;is</a></p>\n)
90
86
 
91
- rd = render_with(@rndr[:escape_html], %([This'link"is](http://example.net/)))
92
- assert_equal "<p><a href=\"http://example.net/\">This&#39;link&quot;is</a></p>\n", rd
87
+ assert_equal expected, render(markdown)
88
+ assert_equal expected, render(markdown, with: [:escape_html])
93
89
  end
94
90
 
95
91
  def test_that_code_emphasis_work
@@ -111,22 +107,19 @@ However, this should be <em><code>an emphasised codespan</code></em></p>
111
107
  </ul>
112
108
  HTML
113
109
 
114
- output = render_with(Redcarpet::Render::HTML.new, markdown)
115
- assert_equal html, output
110
+ assert_equal html, render(markdown)
116
111
  end
117
112
 
118
113
  def test_that_parenthesis_are_handled_into_links
119
- markdown = "Hey have a look at the [bash man page](man:bash(1))!"
120
- html = "<p>Hey have a look at the <a href=\"man:bash(1)\">bash man page</a>!</p>\n"
121
- output = render_with(Redcarpet::Render::HTML.new, markdown)
114
+ markdown = %(The [bash man page](man:bash(1))!)
115
+ expected = %(<p>The <a href="man:bash(1)">bash man page</a>!</p>\n)
122
116
 
123
- assert_equal html, output
117
+ assert_equal expected, render(markdown)
124
118
  end
125
119
 
126
120
  def test_autolinking_works_as_expected
127
- markdown = "Example of uri ftp://user:pass@example.com/. Email foo@bar.com and link http://bar.com"
128
- renderer = Redcarpet::Markdown.new(Redcarpet::Render::HTML, :autolink => true)
129
- output = renderer.render(markdown)
121
+ markdown = "Uri ftp://user:pass@example.com/. Email foo@bar.com and link http://bar.com"
122
+ output = render(markdown, with: [:autolink])
130
123
 
131
124
  assert output.include? '<a href="ftp://user:pass@example.com/">ftp://user:pass@example.com/</a>'
132
125
  assert output.include? 'mailto:foo@bar.com'
@@ -155,8 +148,7 @@ MD
155
148
  </div>
156
149
  HTML
157
150
 
158
- renderer = Redcarpet::Markdown.new(Redcarpet::Render::HTML, :footnotes => true)
159
- output = renderer.render(markdown)
151
+ output = render(markdown, with: [:footnotes])
160
152
  assert_equal html, output
161
153
  end
162
154
 
@@ -172,69 +164,78 @@ MD
172
164
  <p>[^1] And a trailing definition</p>
173
165
  HTML
174
166
 
175
- renderer = Redcarpet::Markdown.new(Redcarpet::Render::HTML, :footnotes => true)
176
- output = renderer.render(markdown)
167
+ output = render(markdown, with: [:footnotes])
177
168
  assert_equal html, output
178
169
  end
179
170
 
180
171
  def test_footnotes_enabled_but_missing_definition
181
172
  markdown = "Some text with a marker[^1] but no definition."
182
- html = "<p>Some text with a marker[^1] but no definition.</p>\n"
173
+ expected = "<p>Some text with a marker[^1] but no definition.</p>\n"
183
174
 
184
- renderer = Redcarpet::Markdown.new(Redcarpet::Render::HTML, :footnotes => true)
185
- output = renderer.render(markdown)
186
- assert_equal html, output
175
+ output = render(markdown, with: [:footnotes])
176
+ assert_equal expected, output
187
177
  end
188
178
 
189
179
  def test_autolink_short_domains
190
180
  markdown = "Example of uri ftp://auto/short/domains. Email auto@l.n and link http://a/u/t/o/s/h/o/r/t"
191
- renderer = Redcarpet::Markdown.new(Redcarpet::Render::HTML, :autolink => true)
192
- output = renderer.render(markdown)
181
+ output = render(markdown, with: [:autolink])
193
182
 
194
183
  assert output.include? '<a href="ftp://auto/short/domains">ftp://auto/short/domains</a>'
195
184
  assert output.include? 'mailto:auto@l.n'
196
185
  assert output.include? '<a href="http://a/u/t/o/s/h/o/r/t">http://a/u/t/o/s/h/o/r/t</a>'
197
186
  end
198
187
 
199
- def test_toc_heading_id
200
- markdown = "# First level heading\n## Second level heading"
201
- output = render_with(@rndr[:toc_data], markdown)
202
- assert_match /<h1 id="first-level-heading">/, output
203
- assert_match /<h2 id="second-level-heading">/, output
204
- end
205
-
206
188
  def test_that_prettify_works
207
- text = <<-Markdown
208
- Foo
189
+ markdown = "\tclass Foo\nend"
190
+ output = render(markdown, with: [:prettify])
209
191
 
210
- ~~~ruby
211
- some
212
- code
213
- ~~~
192
+ assert output.include?("<pre><code class=\"prettyprint\">")
214
193
 
215
- Bar
216
- Markdown
194
+ markdown = "`class`"
195
+ output = render(markdown, with: [:prettify])
217
196
 
218
- renderer = Redcarpet::Markdown.new(@rndr[:prettify], fenced_code_blocks: true)
219
- output = renderer.render(text)
197
+ assert output.include?("<code class=\"prettyprint\">")
198
+ end
199
+
200
+ def test_prettify_with_fenced_code_blocks
201
+ markdown = "~~~ruby\ncode\n~~~"
202
+ output = render(markdown, with: [:fenced_code_blocks, :prettify])
220
203
 
221
- assert output.include?("<code class=\"prettyprint ruby\">")
204
+ assert output.include?("<code class=\"prettyprint lang-ruby\">")
222
205
  end
223
206
 
224
207
  def test_safe_links_only_with_anchors
225
208
  markdown = "An [anchor link](#anchor) on a page."
226
-
227
- renderer = Redcarpet::Markdown.new(@rndr[:safe_links])
228
- output = renderer.render(markdown)
209
+ output = render(markdown, with: [:safe_links_only])
229
210
 
230
211
  assert_match %r{<a href="#anchor">anchor link</a>}, output
231
212
  end
232
213
 
233
214
  def test_autolink_with_link_attributes
234
- render = Redcarpet::Render::HTML.new(link_attributes: {rel: "nofollow"})
235
- parser = Redcarpet::Markdown.new(render, autolink: true)
215
+ options = { autolink: true, link_attributes: {rel: "nofollow"} }
216
+ output = render("https://github.com/", with: options)
236
217
 
237
- output = parser.render("https://github.com/")
238
218
  assert_match %r{rel="nofollow"}, output
239
219
  end
220
+
221
+ def test_image_unsafe_src_with_safe_links_only
222
+ markdown = "![foo](javascript:while(1);)"
223
+ output = render(markdown, with: [:safe_links_only])
224
+
225
+ assert_not_match %r{img src}, output
226
+ end
227
+
228
+ def test_no_styles_option_inside_a_paragraph
229
+ markdown = "Hello <style> foo { bar: baz; } </style> !"
230
+ output = render(markdown, with: [:no_styles])
231
+
232
+ assert_no_match %r{<style>}, output
233
+ end
234
+
235
+ def test_no_styles_inside_html_block_rendering
236
+ markdown = "<style> foo { bar: baz; } </style>"
237
+ output = render(markdown, with: [:no_styles])
238
+
239
+ assert_no_match %r{<style>}, output
240
+ end
240
241
  end