redcarpet 2.2.2 → 2.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.

data/Gemfile CHANGED
@@ -1,2 +1,2 @@
1
- source :rubygems
1
+ source "https://rubygems.org/"
2
2
  gemspec
@@ -1,6 +1,8 @@
1
1
  Redcarpet 2 is written with sugar, spice and everything nice
2
2
  ============================================================
3
3
 
4
+ [![Build Status](https://travis-ci.org/vmg/redcarpet.png?branch=master)](https://travis-ci.org/vmg/redcarpet)
5
+
4
6
  Redcarpet is Ruby library for Markdown processing that smells like
5
7
  butterflies and popcorn.
6
8
 
@@ -14,7 +16,7 @@ library. You might want to find out more about Sundown to see what makes this
14
16
  Ruby library so awesome.
15
17
 
16
18
  This library is written by people
17
- -------------------------------------------------------
19
+ ---------------------------------
18
20
 
19
21
  Redcarpet 2 has been rewritten from scratch by Vicent Martí (@vmg). Why
20
22
  are you not following me on Twitter?
@@ -45,114 +47,121 @@ output.
45
47
  The `Markdown` object is encouraged to be instantiated once with the required
46
48
  settings, and reused between parses.
47
49
 
48
- Markdown.new(renderer, extensions={})
50
+ ~~~~~ ruby
51
+ # Initializes a Markdown parser
52
+ Markdown.new(renderer, extensions = {})
53
+ ~~~~~
54
+
55
+
56
+ Here, the `renderer` variable refers to a renderer object, inheriting
57
+ from `Redcarpet::Render::Base`. If the given object has not been
58
+ instantiated, the library will do it with default arguments.
49
59
 
50
- Initializes a Markdown parser
60
+ You can also specify a hash containing the Markdown extensions which the
61
+ parser will identify. The following extensions are accepted:
51
62
 
52
- renderer - a renderer object, inheriting from Redcarpet::Render::Base.
53
- If the given object has not been instantiated, the library
54
- will do it with default arguments.
63
+ * `:no_intra_emphasis`: do not parse emphasis inside of words.
64
+ Strings such as `foo_bar_baz` will not generate `<em>` tags.
55
65
 
56
- extensions - a hash containing the Markdown extensions which the parser
57
- will identify. The following extensions are accepted:
66
+ * `:tables`: parse tables, PHP-Markdown style
58
67
 
59
- :no_intra_emphasis - do not parse emphasis inside of words.
60
- Strings such as `foo_bar_baz` will not generate `<em>`
61
- tags.
68
+ * `:fenced_code_blocks`: parse fenced code blocks, PHP-Markdown
69
+ style. Blocks delimited with 3 or more `~` or backtickswill be considered
70
+ as code, without the need to be indented. An optional language name may
71
+ be added at the end of the opening fence for the code block
62
72
 
63
- :tables - parse tables, PHP-Markdown style
73
+ * `:autolink`: parse links even when they are not enclosed in `<>`
74
+ characters. Autolinks for the http, https and ftp protocols will be
75
+ automatically detected. Email addresses are also handled, and http
76
+ links without protocol, but starting with `www`.
64
77
 
65
- :fenced_code_blocks - parse fenced code blocks, PHP-Markdown
66
- style. Blocks delimited with 3 or more `~` or backticks
67
- will be considered as code, without the need to be
68
- indented. An optional language name may be added at the
69
- end of the opening fence for the code block
78
+ * `:disable_indented_code_blocks`: do not parse usual markdown
79
+ code blocks. Markdown converts text with four spaces at
80
+ the front of each line to code blocks. This options
81
+ prevents it from doing so. Recommended to use
82
+ with `fenced_code_blocks: true`.
70
83
 
71
- :autolink - parse links even when they are not enclosed in
72
- `<>` characters. Autolinks for the http, https and ftp
73
- protocols will be automatically detected. Email addresses
74
- are also handled, and http links without protocol, but
75
- starting with `www.`
84
+ * `:strikethrough`: parse strikethrough, PHP-Markdown style
85
+ Two `~` characters mark the start of a strikethrough,
86
+ e.g. `this is ~~good~~ bad`
76
87
 
77
- :strikethrough - parse strikethrough, PHP-Markdown style
78
- Two `~` characters mark the start of a strikethrough,
79
- e.g. `this is ~~good~~ bad`
88
+ * `:lax_spacing` - HTML blocks do not require to be surrounded by an
89
+ empty line as in the Markdown standard.
80
90
 
81
- :lax_spacing - HTML blocks do not require to be surrounded
82
- by an empty line as in the Markdown standard.
91
+ * `:space_after_headers`: A space is always required between the hash
92
+ at the beginning of a header and its name, e.g. `#this is my header`
93
+ would not be a valid header.
83
94
 
84
- :space_after_headers - A space is always required between the
85
- hash at the beginning of a header and its name, e.g.
86
- `#this is my header` would not be a valid header.
95
+ * `:superscript`: parse superscripts after the `^` character; contiguous superscripts are nested together, and complex values can be enclosed in parenthesis, e.g. `this is the 2^(nd) time`
87
96
 
88
- :superscript - parse superscripts after the `^` character;
89
- contiguous superscripts are nested together, and complex
90
- values can be enclosed in parenthesis,
91
- e.g. `this is the 2^(nd) time`
97
+ * `:underline`: parse underscored emphasis as underlines.
98
+ `This is _underlined_ but this is still *italic*`.
92
99
 
93
- Example:
100
+ Example:
94
101
 
95
- markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML,
96
- :autolink => true, :space_after_headers => true)
102
+ ~~~~~ ruby
103
+ markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, :autolink => true, :space_after_headers => true)
104
+ ~~~~~
97
105
 
98
106
  Rendering with the `Markdown` object is done through `Markdown#render`.
99
107
  Unlike in the RedCloth API, the text to render is passed as an argument
100
108
  and not stored inside the `Markdown` instance, to encourage reusability.
109
+ Example:
101
110
 
102
- Markdown#render(text)
103
-
104
- Render a Markdown document with the attached renderer
105
-
106
- text - a Markdown document
107
-
108
- Example:
109
-
110
- markdown.render("This is *bongos*, indeed.")
111
- #=> "<p>This is <em>bongos</em>, indeed</p>"
111
+ ~~~~~ ruby
112
+ markdown.render("This is *bongos*, indeed.")
113
+ # => "<p>This is <em>bongos</em>, indeed</p>"
114
+ ~~~~~
112
115
 
113
116
 
114
- Darling, I packed you a couple renderers for lunch
117
+ Darling, I packed you a couple renderers for lunch
115
118
  --------------------------------------------------
116
119
 
117
120
  Redcarpet comes with two built-in renderers, `Redcarpet::Render::HTML` and
118
121
  `Redcarpet::Render::XHTML`, which output HTML and XHTML, respectively. These
119
- renderers are actually implemented in C, and hence offer a brilliant
120
- performance, several degrees of magnitude faster than other Ruby Markdown
122
+ renderers are actually implemented in C and hence offer brilliant
123
+ performance several degrees of magnitude faster than other Ruby Markdown
121
124
  solutions.
122
125
 
123
126
  All the rendering flags that previously applied only to HTML output have
124
127
  now been moved to the `Render::HTML` class, and may be enabled when
125
128
  instantiating the renderer:
126
129
 
127
- Render::HTML.new(render_options={})
130
+ ~~~~~ ruby
131
+ Render::HTML.new(render_options = {})
132
+ ~~~~~
128
133
 
129
134
  Initializes an HTML renderer. The following flags are available:
130
135
 
131
- :filter_html - do not allow any user-inputted HTML in the output
136
+ * `:filter_html`: do not allow any user-inputted HTML in the output
137
+
138
+ * `:no_images`: do not generate any `<img>` tags
132
139
 
133
- :no_images - do not generate any `<img>` tags
140
+ * `:no_links`: do not generate any `<a>` tags
134
141
 
135
- :no_links - do not generate any `<a>` tags
142
+ * `:no_styles`: do not generate any `<style>` tags
136
143
 
137
- :no_styles - do not generate any `<style>` tags
144
+ * `:safe_links_only`: only generate links for protocols which are considered
145
+ safe
138
146
 
139
- :safe_links_only - only generate links for protocols which are considered safe
147
+ * `:with_toc_data`: add HTML anchors to each header in the output HTML,
148
+ to allow linking to each section.
140
149
 
141
- :with_toc_data - add HTML anchors to each header in the output HTML,
142
- to allow linking to each section.
150
+ * `:hard_wrap`: insert HTML `<br>` tags inside on paragraphs where the origin
151
+ Markdown document had newlines (by default, Markdown ignores these newlines).
143
152
 
144
- :hard_wrap - insert HTML `<br>` tags inside on paragraphs where the origin
145
- Markdown document had newlines (by default, Markdown ignores these
146
- newlines).
153
+ * `:xhtml`: output XHTML-conformant tags. This option is always enabled in the
154
+ `Render::XHTML` renderer.
147
155
 
148
- :xhtml - output XHTML-conformant tags. This option is always enabled in the
149
- `Render::XHTML` renderer.
156
+ * `:prettify`: add prettyprint classes to `<code>` tags for google-code-prettify
150
157
 
151
- :link_attributes - hash of extra attributes to add to links
158
+ * `:link_attributes`: hash of extra attributes to add to links
152
159
 
153
160
  Example:
154
161
 
155
- rndr = Redcarpet::Render::HTML.new(:no_links => true, :hard_wrap => true)
162
+ ~~~~~ ruby
163
+ renderer = Redcarpet::Render::HTML.new(:no_links => true, :hard_wrap => true)
164
+ ~~~~~
156
165
 
157
166
 
158
167
  The `HTML` renderer has an alternate version, `Redcarpet::Render::HTML_TOC`,
@@ -172,13 +181,13 @@ built-in renderers, `HTML` and `XHTML` may be extended as such:
172
181
 
173
182
  ~~~~~ ruby
174
183
  # create a custom renderer that allows highlighting of code blocks
175
- class HTMLwithAlbino < Redcarpet::Render::HTML
184
+ class HTMLwithPygments < Redcarpet::Render::HTML
176
185
  def block_code(code, language)
177
- Albino.safe_colorize(code, language)
186
+ Pygments.highlight(code, :lexer => language)
178
187
  end
179
188
  end
180
189
 
181
- markdown = Redcarpet::Markdown.new(HTMLwithAlbino, :fenced_code_blocks => true)
190
+ markdown = Redcarpet::Markdown.new(HTMLwithPygments, :fenced_code_blocks => true)
182
191
  ~~~~~
183
192
 
184
193
  But new renderers can also be created from scratch (see `lib/render_man.rb` for
@@ -192,65 +201,76 @@ end
192
201
 
193
202
  The following instance methods may be implemented by the renderer:
194
203
 
195
- # Block-level calls
196
- # If the return value of the method is `nil`, the block
197
- # will be skipped.
198
- # If the method for a document element is not implemented,
199
- # the block will be skipped.
200
- #
201
- # Example:
202
- #
203
- # class RenderWithoutCode < Redcarpet::Render::HTML
204
- # def block_code(code, language)
205
- # nil
206
- # end
207
- # end
208
- #
209
- block_code(code, language)
210
- block_quote(quote)
211
- block_html(raw_html)
212
- header(text, header_level)
213
- hrule()
214
- list(contents, list_type)
215
- list_item(text, list_type)
216
- paragraph(text)
217
- table(header, body)
218
- table_row(content)
219
- table_cell(content, alignment)
220
-
221
- # Span-level calls
222
- # A return value of `nil` will not output any data
223
- # If the method for a document element is not implemented,
224
- # the contents of the span will be copied verbatim
225
- autolink(link, link_type)
226
- codespan(code)
227
- double_emphasis(text)
228
- emphasis(text)
229
- image(link, title, alt_text)
230
- linebreak()
231
- link(link, title, content)
232
- raw_html(raw_html)
233
- triple_emphasis(text)
234
- strikethrough(text)
235
- superscript(text)
236
-
237
- # Low level rendering
238
- entity(text)
239
- normal_text(text)
240
-
241
- # Header of the document
242
- # Rendered before any another elements
243
- doc_header()
244
-
245
- # Footer of the document
246
- # Rendered after all the other elements
247
- doc_footer()
248
-
249
- # Pre/post-process
250
- # Special callback: preprocess or postprocess the whole
251
- # document before or after the rendering process begins
252
- preprocess(full_document)
253
- postprocess(full_document)
204
+ ### Block-level calls
205
+ If the return value of the method is `nil`, the block will be skipped.
206
+ If the method for a document element is not implemented, the block will
207
+ be skipped.
208
+
209
+ Example:
210
+
211
+ ~~~~ ruby
212
+ class RenderWithoutCode < Redcarpet::Render::HTML
213
+ def block_code(code, language)
214
+ nil
215
+ end
216
+ end
217
+ ~~~~
218
+
219
+ * block_code(code, language)
220
+ * block_quote(quote)
221
+ * block_html(raw_html)
222
+ * header(text, header_level)
223
+ * hrule()
224
+ * list(contents, list_type)
225
+ * list_item(text, list_type)
226
+ * paragraph(text)
227
+ * table(header, body)
228
+ * table_row(content)
229
+ * table_cell(content, alignment)
230
+
231
+ ### Span-level calls
232
+
233
+ A return value of `nil` will not output any data. If the method for
234
+ a document element is not implemented, the contents of the span will
235
+ be copied verbatim:
236
+
237
+ * autolink(link, link_type)
238
+ * codespan(code)
239
+ * double_emphasis(text)
240
+ * emphasis(text)
241
+ * image(link, title, alt_text)
242
+ * linebreak()
243
+ * link(link, title, content)
244
+ * raw_html(raw_html)
245
+ * triple_emphasis(text)
246
+ * strikethrough(text)
247
+ * superscript(text)
248
+ * underline(text)
249
+
250
+ ### Low level rendering
251
+
252
+ * entity(text)
253
+ * normal_text(text)
254
+
255
+ ### Header of the document
256
+
257
+ Rendered before any another elements:
258
+
259
+ * doc_header()
260
+
261
+ ### Footer of the document
262
+
263
+ Rendered after all the other elements:
264
+
265
+ * doc_footer()
266
+
267
+ ### Pre/post-process
268
+
269
+ Special callback: preprocess or postprocess the whole document before
270
+ or after the rendering process begins:
271
+
272
+ * preprocess(full_document)
273
+ * postprocess(full_document)
254
274
 
255
275
  You can look at
256
276
  ["How to extend the Redcarpet 2 Markdown library?"](http://dev.af83.com/2012/02/27/howto-extend-the-redcarpet2-markdown-lib.html)
@@ -281,7 +301,7 @@ Redcarpet::Render::SmartyPants.render("<p>Oh SmartyPants, you're so crazy...</p>
281
301
  ~~~~~
282
302
 
283
303
  SmartyPants works on top of already-rendered HTML, and will ignore replacements
284
- inside the content of HTML tags and inside specific HTML blocks such as
304
+ inside the content of HTML tags and inside specific HTML blocks such as
285
305
  `<code>` or `<pre>`.
286
306
 
287
307
  What? You really want to mix Markdown renderers?
@@ -298,16 +318,20 @@ only way to have reliable and predictable Markdown output on your program.
298
318
  Still, if major forces (let's say, tornadoes or other natural disasters) force you
299
319
  to keep a Markdown-compatibility layer, Redcarpet also supports this:
300
320
 
301
- require 'redcarpet/compat'
321
+ ~~~~~ ruby
322
+ require 'redcarpet/compat'
323
+ ~~~~~
302
324
 
303
325
  Requiring the compatibility library will declare a `Markdown` class with the
304
326
  classical RedCloth API, e.g.
305
327
 
306
- Markdown.new('this is my text').to_html
328
+ ~~~~~ ruby
329
+ Markdown.new('this is my text').to_html
330
+ ~~~~~
307
331
 
308
332
  This class renders 100% standards compliant Markdown with 0 extensions. Nada.
309
333
  Don't even try to enable extensions with a compatibility layer, because
310
- that's a maintance nightmare and won't work.
334
+ that's a maintenance nightmare and won't work.
311
335
 
312
336
  On a related topic: if your Markdown gem has a `lib/markdown.rb` file that
313
337
  monkeypatches the Markdown class, you're a terrible human being. Just saying.
@@ -332,4 +356,3 @@ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
332
356
  WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
333
357
  ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
334
358
  OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
335
-
data/Rakefile CHANGED
@@ -5,127 +5,14 @@ require 'digest/md5'
5
5
 
6
6
  task :default => [:test]
7
7
 
8
- # ==========================================================
9
8
  # Ruby Extension
10
- # ==========================================================
11
-
12
9
  Rake::ExtensionTask.new('redcarpet')
13
10
 
14
- # ==========================================================
15
- # Testing
16
- # ==========================================================
17
-
18
- require 'rake/testtask'
19
- Rake::TestTask.new('test:unit') do |t|
20
- t.test_files = FileList['test/*_test.rb']
21
- t.ruby_opts += ['-rubygems'] if defined? Gem
22
- end
23
- task 'test:unit' => [:compile]
24
-
25
- desc 'Run conformance tests (MARKDOWN_TEST_VER=1.0)'
26
- task 'test:conformance' => [:compile] do |t|
27
- script = "#{pwd}/bin/redcarpet"
28
- test_version = ENV['MARKDOWN_TEST_VER'] || '1.0.3'
29
- lib_dir = "#{pwd}/lib"
30
- chdir("test/MarkdownTest_#{test_version}") do
31
- sh "RUBYLIB=#{lib_dir} ./MarkdownTest.pl --script='#{script}' --tidy"
32
- end
33
- end
34
-
35
- desc 'Run version 1.0 conformance suite'
36
- task 'test:conformance:1.0' => [:compile] do |t|
37
- ENV['MARKDOWN_TEST_VER'] = '1.0'
38
- Rake::Task['test:conformance'].invoke
39
- end
40
-
41
- desc 'Run 1.0.3 conformance suite'
42
- task 'test:conformance:1.0.3' => [:compile] do |t|
43
- ENV['MARKDOWN_TEST_VER'] = '1.0.3'
44
- Rake::Task['test:conformance'].invoke
45
- end
46
-
47
- desc 'Run unit and conformance tests'
48
- task :test => %w[test:unit test:conformance]
49
-
50
- desc 'Run benchmarks'
51
- task :benchmark => :build do |t|
52
- $:.unshift 'lib'
53
- load 'test/benchmark.rb'
54
- end
55
-
56
- # PACKAGING =================================================================
57
-
58
- require 'rubygems'
59
- $spec = eval(File.read('redcarpet.gemspec'))
11
+ # Packaging
12
+ require 'bundler/gem_tasks'
60
13
 
61
- def package(ext='')
62
- "pkg/redcarpet-#{$spec.version}" + ext
63
- end
64
-
65
- desc 'Build packages'
66
- task :package => %w[.gem .tar.gz].map {|e| package(e)}
67
-
68
- desc 'Build and install as local gem'
69
- task :install => package('.gem') do
70
- sh "gem install #{package('.gem')}"
71
- end
72
-
73
- directory 'pkg/'
74
-
75
- file package('.gem') => %w[pkg/ redcarpet.gemspec] + $spec.files do |f|
76
- sh "gem build redcarpet.gemspec"
77
- mv File.basename(f.name), f.name
78
- end
79
-
80
- file package('.tar.gz') => %w[pkg/] + $spec.files do |f|
81
- sh "git archive --format=tar HEAD | gzip > #{f.name}"
82
- end
83
-
84
- # GEMSPEC HELPERS ==========================================================
85
-
86
- def source_version
87
- line = File.read('lib/redcarpet.rb')[/^\s*VERSION = .*/]
88
- line.match(/.*VERSION = '(.*)'/)[1]
89
- end
90
-
91
- task :update_gem do
92
- # read spec file and split out manifest section
93
- GEMFILE = 'redcarpet.gemspec'
94
- spec = File.read(GEMFILE)
95
- head, manifest, tail = spec.split(" # = MANIFEST =\n")
96
- head.sub!(/\.version = '.*'/, ".version = '#{source_version}'")
97
- head.sub!(/\.date = '.*'/, ".date = '#{Date.today.to_s}'")
98
- # determine file list from git ls-files
99
- files = `git ls-files`.
100
- split("\n").
101
- sort.
102
- reject{ |file| file =~ /^\./ || file =~ /^test\/MarkdownTest/ }.
103
- map{ |file| " #{file}" }.
104
- join("\n")
105
- # piece file back together and write...
106
- manifest = " s.files = %w[\n#{files}\n ]\n"
107
- spec = [head,manifest,tail].join(" # = MANIFEST =\n")
108
- File.open(GEMFILE, 'w') { |io| io.write(spec) }
109
- puts "updated #{GEMFILE}"
110
- end
111
-
112
- desc 'Gather required Sundown sources into extension directory'
113
- task :gather => 'sundown:checkout' do |t|
114
- files =
115
- FileList[
116
- 'sundown/src/{markdown,buffer,stack,autolink,html_blocks}.h',
117
- 'sundown/src/{markdown,buffer,stack,autolink}.c',
118
- 'sundown/html/{html,html_smartypants,houdini_html_e,houdini_href_e}.c',
119
- 'sundown/html/{html,houdini}.h',
120
- ]
121
- cp files, 'ext/redcarpet/',
122
- :preserve => true,
123
- :verbose => true
124
- end
14
+ # Testing
15
+ load 'tasks/testing.rake'
125
16
 
126
- task 'sundown:checkout' do |t|
127
- unless File.exists?('sundown/src/markdown.h')
128
- sh 'git submodule init'
129
- sh 'git submodule update'
130
- end
131
- end
17
+ # Sundown
18
+ load 'tasks/sundown.rake'