vkhater-redcarpet 2.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/COPYING ADDED
@@ -0,0 +1,14 @@
1
+ Copyright (c) 2009, Natacha Porté
2
+ Copyright (c) 2011, Vicent Marti
3
+
4
+ Permission to use, copy, modify, and distribute this software for any
5
+ purpose with or without fee is hereby granted, provided that the above
6
+ copyright notice and this permission notice appear in all copies.
7
+
8
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source :rubygems
2
+ gemspec
@@ -0,0 +1,20 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ redcarpet (2.2.2)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ nokogiri (1.5.5)
10
+ rake (0.9.2.2)
11
+ rake-compiler (0.8.1)
12
+ rake
13
+
14
+ PLATFORMS
15
+ ruby
16
+
17
+ DEPENDENCIES
18
+ nokogiri
19
+ rake-compiler
20
+ redcarpet!
@@ -0,0 +1,335 @@
1
+ Redcarpet 2 is written with sugar, spice and everything nice
2
+ ============================================================
3
+
4
+ Redcarpet is Ruby library for Markdown processing that smells like
5
+ butterflies and popcorn.
6
+
7
+ Redcarpet used to be a drop-in replacement for Redcloth. This is no longer the
8
+ case since version 2 -- it now has its own API, but retains the old name. Yes,
9
+ that does mean that Redcarpet 2 is not backwards-compatible with the 1.X
10
+ versions.
11
+
12
+ Redcarpet is powered by the [Sundown](https://www.github.com/vmg/sundown)
13
+ library. You might want to find out more about Sundown to see what makes this
14
+ Ruby library so awesome.
15
+
16
+ This library is written by people
17
+ -------------------------------------------------------
18
+
19
+ Redcarpet 2 has been rewritten from scratch by Vicent Martí (@vmg). Why
20
+ are you not following me on Twitter?
21
+
22
+ Redcarpet would not be possible without the Sundown library and its authors
23
+ (Natacha Porté, Vicent Martí, and its many awesome contributors).
24
+
25
+ You can totally install it as a Gem
26
+ -----------------------------------
27
+
28
+ Redcarpet is readily available as a Ruby gem. It will build some native
29
+ extensions, but the parser is standalone and requires no installed libraries.
30
+
31
+ $ [sudo] gem install redcarpet
32
+
33
+ The Redcarpet source (including Sundown as a submodule) is available at GitHub:
34
+
35
+ $ git clone git://github.com/vmg/redcarpet.git
36
+
37
+ And it's like *really* simple to use
38
+ ------------------------------------
39
+
40
+ The core of the Redcarpet library is the `Redcarpet::Markdown` class. Each
41
+ instance of the class is attached to a `Renderer` object; the Markdown class
42
+ performs parsing of a document and uses the attached renderer to generate
43
+ output.
44
+
45
+ The `Markdown` object is encouraged to be instantiated once with the required
46
+ settings, and reused between parses.
47
+
48
+ Markdown.new(renderer, extensions={})
49
+
50
+ Initializes a Markdown parser
51
+
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.
55
+
56
+ extensions - a hash containing the Markdown extensions which the parser
57
+ will identify. The following extensions are accepted:
58
+
59
+ :no_intra_emphasis - do not parse emphasis inside of words.
60
+ Strings such as `foo_bar_baz` will not generate `<em>`
61
+ tags.
62
+
63
+ :tables - parse tables, PHP-Markdown style
64
+
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
70
+
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.`
76
+
77
+ :strikethrough - parse strikethrough, PHP-Markdown style
78
+ Two `~` characters mark the start of a strikethrough,
79
+ e.g. `this is ~~good~~ bad`
80
+
81
+ :lax_spacing - HTML blocks do not require to be surrounded
82
+ by an empty line as in the Markdown standard.
83
+
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.
87
+
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`
92
+
93
+ Example:
94
+
95
+ markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML,
96
+ :autolink => true, :space_after_headers => true)
97
+
98
+ Rendering with the `Markdown` object is done through `Markdown#render`.
99
+ Unlike in the RedCloth API, the text to render is passed as an argument
100
+ and not stored inside the `Markdown` instance, to encourage reusability.
101
+
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>"
112
+
113
+
114
+ Darling, I packed you a couple renderers for lunch
115
+ --------------------------------------------------
116
+
117
+ Redcarpet comes with two built-in renderers, `Redcarpet::Render::HTML` and
118
+ `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
121
+ solutions.
122
+
123
+ All the rendering flags that previously applied only to HTML output have
124
+ now been moved to the `Render::HTML` class, and may be enabled when
125
+ instantiating the renderer:
126
+
127
+ Render::HTML.new(render_options={})
128
+
129
+ Initializes an HTML renderer. The following flags are available:
130
+
131
+ :filter_html - do not allow any user-inputted HTML in the output
132
+
133
+ :no_images - do not generate any `<img>` tags
134
+
135
+ :no_links - do not generate any `<a>` tags
136
+
137
+ :no_styles - do not generate any `<style>` tags
138
+
139
+ :safe_links_only - only generate links for protocols which are considered safe
140
+
141
+ :with_toc_data - add HTML anchors to each header in the output HTML,
142
+ to allow linking to each section.
143
+
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).
147
+
148
+ :xhtml - output XHTML-conformant tags. This option is always enabled in the
149
+ `Render::XHTML` renderer.
150
+
151
+ :link_attributes - hash of extra attributes to add to links
152
+
153
+ Example:
154
+
155
+ rndr = Redcarpet::Render::HTML.new(:no_links => true, :hard_wrap => true)
156
+
157
+
158
+ The `HTML` renderer has an alternate version, `Redcarpet::Render::HTML_TOC`,
159
+ which will output a table of contents in HTML based on the headers of the
160
+ Markdown document.
161
+
162
+ Furthermore, the abstract base class `Redcarpet::Render::Base` can be used
163
+ to write a custom renderer purely in Ruby, or extending an existing renderer.
164
+ See the following section for more information.
165
+
166
+
167
+ And you can even cook your own
168
+ ------------------------------
169
+
170
+ Custom renderers are created by inheriting from an existing renderer. The
171
+ built-in renderers, `HTML` and `XHTML` may be extended as such:
172
+
173
+ ~~~~~ ruby
174
+ # create a custom renderer that allows highlighting of code blocks
175
+ class HTMLwithAlbino < Redcarpet::Render::HTML
176
+ def block_code(code, language)
177
+ Albino.safe_colorize(code, language)
178
+ end
179
+ end
180
+
181
+ markdown = Redcarpet::Markdown.new(HTMLwithAlbino, :fenced_code_blocks => true)
182
+ ~~~~~
183
+
184
+ But new renderers can also be created from scratch (see `lib/render_man.rb` for
185
+ an example implementation of a Manpage renderer)
186
+
187
+ ~~~~~~ ruby
188
+ class ManPage < Redcarpet::Render::Base
189
+ # you get the drill -- keep going from here
190
+ end
191
+ ~~~~~
192
+
193
+ The following instance methods may be implemented by the renderer:
194
+
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)
254
+
255
+ You can look at
256
+ ["How to extend the Redcarpet 2 Markdown library?"](http://dev.af83.com/2012/02/27/howto-extend-the-redcarpet2-markdown-lib.html)
257
+ for some more explanations.
258
+
259
+ Also, now our Pants are much smarter
260
+ ------------------------------------
261
+
262
+ Redcarpet 2 comes with a standalone [SmartyPants](
263
+ http://daringfireball.net/projects/smartypants/) implementation. It is fully
264
+ compliant with the original implementation. It is the fastest SmartyPants
265
+ parser there is, with a difference of several orders of magnitude.
266
+
267
+ The SmartyPants parser can be found in `Redcarpet::Render::SmartyPants`. It has
268
+ been implemented as a module, so it can be used standalone or as a mixin.
269
+
270
+ When mixed with a Renderer class, it will override the `postprocess` method
271
+ to perform SmartyPants replacements once the rendering is complete
272
+
273
+ ~~~~ ruby
274
+ # Mixin
275
+ class HTMLWithPants < Redcarpet::Render::HTML
276
+ include Redcarpet::Render::SmartyPants
277
+ end
278
+
279
+ # Standalone
280
+ Redcarpet::Render::SmartyPants.render("<p>Oh SmartyPants, you're so crazy...</p>")
281
+ ~~~~~
282
+
283
+ 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
285
+ `<code>` or `<pre>`.
286
+
287
+ What? You really want to mix Markdown renderers?
288
+ ------------------------------------------------
289
+
290
+ What a terrible idea! Markdown is already ill-specified enough; if you create
291
+ software that is renderer-independent, the results will be completely unreliable!
292
+
293
+ Each renderer has its own API and its own set of extensions: you should choose one
294
+ (it doesn't have to be Redcarpet, though that would be great!), write your
295
+ software accordingly, and force your users to install it. That's the
296
+ only way to have reliable and predictable Markdown output on your program.
297
+
298
+ Still, if major forces (let's say, tornadoes or other natural disasters) force you
299
+ to keep a Markdown-compatibility layer, Redcarpet also supports this:
300
+
301
+ require 'redcarpet/compat'
302
+
303
+ Requiring the compatibility library will declare a `Markdown` class with the
304
+ classical RedCloth API, e.g.
305
+
306
+ Markdown.new('this is my text').to_html
307
+
308
+ This class renders 100% standards compliant Markdown with 0 extensions. Nada.
309
+ Don't even try to enable extensions with a compatibility layer, because
310
+ that's a maintance nightmare and won't work.
311
+
312
+ On a related topic: if your Markdown gem has a `lib/markdown.rb` file that
313
+ monkeypatches the Markdown class, you're a terrible human being. Just saying.
314
+
315
+ Testing
316
+ -------
317
+ Tests run a lot faster without `bundle exec` :)
318
+
319
+ Boring legal stuff
320
+ ------------------
321
+
322
+ Copyright (c) 2011, Vicent Martí
323
+
324
+ Permission to use, copy, modify, and/or distribute this software for any
325
+ purpose with or without fee is hereby granted, provided that the above
326
+ copyright notice and this permission notice appear in all copies.
327
+
328
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
329
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
330
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
331
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
332
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
333
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
334
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
335
+
@@ -0,0 +1,131 @@
1
+ require 'date'
2
+ require 'rake/clean'
3
+ require 'rake/extensiontask'
4
+ require 'digest/md5'
5
+
6
+ task :default => [:test]
7
+
8
+ # ==========================================================
9
+ # Ruby Extension
10
+ # ==========================================================
11
+
12
+ Rake::ExtensionTask.new('redcarpet')
13
+
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'))
60
+
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
125
+
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