tight-redcarpet 3.1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e9e24786ab824e442074458d6b37acc2f5cca468
4
+ data.tar.gz: 3e99a9c16cdb6e9b8c373088f38936e9c463654a
5
+ SHA512:
6
+ metadata.gz: 6da988577142c15cc12fc677fbce214d1356b3ec88b417727a42ec33d35921eba26445299b7f4821602c5afae32dcc339b9ebb5af1b397c8a36cf14cd7610e64
7
+ data.tar.gz: 1c1ca54286878e014e2280baea35b6030a4a97bbb2870f89c6f4225e76285b3fb0f21f0b6edfbaa95fa4460013ac997b08b4e42836fa592fc60d97086ffdb817
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,9 @@
1
+ source "https://rubygems.org/"
2
+
3
+ gemspec
4
+
5
+ group :benchmark do
6
+ gem "benchmark-ips", "~> 1.2.0"
7
+ gem "bluecloth", "~> 2.2.0"
8
+ gem "kramdown", "~> 1.0.2"
9
+ end
data/README.markdown ADDED
@@ -0,0 +1,386 @@
1
+ Redcarpet is written with sugar, spice and everything nice
2
+ ============================================================
3
+
4
+ [![Build Status](https://travis-ci.org/vmg/redcarpet.svg?branch=master)](https://travis-ci.org/vmg/redcarpet)
5
+
6
+ Redcarpet is Ruby library for Markdown processing that smells like
7
+ butterflies and popcorn.
8
+
9
+ This library is written by people
10
+ ---------------------------------
11
+
12
+ Redcarpet was written by [Vicent Martí](https://github.com/vmg). It is maintained by
13
+ [Robin Dupret](https://github.com/robin850) and [Matt Rogers](https://github.com/mattr-).
14
+
15
+ Redcarpet would not be possible without the [Sundown](https://www.github.com/vmg/sundown)
16
+ library and its authors (Natacha Porté, Vicent Martí, and its many awesome contributors).
17
+
18
+ You can totally install it as a Gem
19
+ -----------------------------------
20
+
21
+ Redcarpet is readily available as a Ruby gem. It will build some native
22
+ extensions, but the parser is standalone and requires no installed libraries.
23
+ Starting with Redcarpet 3.0, the minimum required Ruby version is 1.9.2 (or Rubinius in 1.9 mode).
24
+
25
+ $ [sudo] gem install redcarpet
26
+
27
+ If you need to use it with Ruby 1.8.7, you will need to stick with 2.3.0:
28
+
29
+ $ [sudo] gem install redcarpet -v 2.3.0
30
+
31
+ The Redcarpet source is available at GitHub:
32
+
33
+ $ git clone git://github.com/vmg/redcarpet.git
34
+
35
+
36
+ And it's like *really* simple to use
37
+ ------------------------------------
38
+
39
+ The core of the Redcarpet library is the `Redcarpet::Markdown` class. Each
40
+ instance of the class is attached to a `Renderer` object; the Markdown class
41
+ performs parsing of a document and uses the attached renderer to generate
42
+ output.
43
+
44
+ The `Redcarpet::Markdown` object is encouraged to be instantiated once with the
45
+ required settings, and reused between parses.
46
+
47
+ ~~~~~ ruby
48
+ # Initializes a Markdown parser
49
+ markdown = Redcarpet::Markdown.new(renderer, extensions = {})
50
+ ~~~~~
51
+
52
+ Here, the `renderer` variable refers to a renderer object, inheriting
53
+ from `Redcarpet::Render::Base`. If the given object has not been
54
+ instantiated, the library will do it with default arguments.
55
+
56
+ Rendering with the `Markdown` object is done through `Markdown#render`.
57
+ Unlike in the RedCloth API, the text to render is passed as an argument
58
+ and not stored inside the `Markdown` instance, to encourage reusability.
59
+ Example:
60
+
61
+ ~~~~~ ruby
62
+ markdown.render("This is *bongos*, indeed.")
63
+ # => "<p>This is <em>bongos</em>, indeed.</p>"
64
+ ~~~~~
65
+
66
+ You can also specify a hash containing the Markdown extensions which the
67
+ parser will identify. The following extensions are accepted:
68
+
69
+ * `:no_intra_emphasis`: do not parse emphasis inside of words.
70
+ Strings such as `foo_bar_baz` will not generate `<em>` tags.
71
+
72
+ * `:tables`: parse tables, PHP-Markdown style.
73
+
74
+ * `:fenced_code_blocks`: parse fenced code blocks, PHP-Markdown
75
+ style. Blocks delimited with 3 or more `~` or backticks will be considered
76
+ as code, without the need to be indented. An optional language name may
77
+ be added at the end of the opening fence for the code block.
78
+
79
+ * `:autolink`: parse links even when they are not enclosed in `<>`
80
+ characters. Autolinks for the http, https and ftp protocols will be
81
+ automatically detected. Email addresses are also handled, and http
82
+ links without protocol, but starting with `www`.
83
+
84
+ * `:disable_indented_code_blocks`: do not parse usual markdown
85
+ code blocks. Markdown converts text with four spaces at
86
+ the front of each line to code blocks. This options
87
+ prevents it from doing so. Recommended to use
88
+ with `fenced_code_blocks: true`.
89
+
90
+ * `:strikethrough`: parse strikethrough, PHP-Markdown style.
91
+ Two `~` characters mark the start of a strikethrough,
92
+ e.g. `this is ~~good~~ bad`.
93
+
94
+ * `:lax_spacing`: HTML blocks do not require to be surrounded by an
95
+ empty line as in the Markdown standard.
96
+
97
+ * `:space_after_headers`: A space is always required between the hash
98
+ at the beginning of a header and its name, e.g. `#this is my header`
99
+ would not be a valid header.
100
+
101
+ * `:superscript`: parse superscripts after the `^` character; contiguous superscripts
102
+ are nested together, and complex values can be enclosed in parenthesis, e.g.
103
+ `this is the 2^(nd) time`.
104
+
105
+ * `:underline`: parse underscored emphasis as underlines.
106
+ `This is _underlined_ but this is still *italic*`.
107
+
108
+ * `:highlight`: parse highlights.
109
+ `This is ==highlighted==`. It looks like this: `<mark>highlighted</mark>`
110
+
111
+ * `:quote`: parse quotes.
112
+ `This is a "quote"`. It looks like this: `<q>quote</q>`
113
+
114
+ * `:footnotes`: parse footnotes, PHP-Markdown style. A footnote works very much
115
+ like a reference-style link: it consists of a marker next to the text (e.g.
116
+ `This is a sentence.[^1]`) and a footnote definition on its own line anywhere
117
+ within the document (e.g. `[^1]: This is a footnote.`).
118
+
119
+ Example:
120
+
121
+ ~~~ruby
122
+ markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: true, tables: true)
123
+ ~~~~~
124
+
125
+ Darling, I packed you a couple renderers for lunch
126
+ --------------------------------------------------
127
+
128
+ Redcarpet comes with two built-in renderers, `Redcarpet::Render::HTML` and
129
+ `Redcarpet::Render::XHTML`, which output HTML and XHTML, respectively. These
130
+ renderers are actually implemented in C and hence offer brilliant
131
+ performance — several degrees of magnitude faster than other Ruby Markdown
132
+ solutions.
133
+
134
+ All the rendering flags that previously applied only to HTML output have
135
+ now been moved to the `Redcarpet::Render::HTML` class, and may be enabled when
136
+ instantiating the renderer:
137
+
138
+ ~~~~~ ruby
139
+ Redcarpet::Render::HTML.new(render_options = {})
140
+ ~~~~~
141
+
142
+ Initializes an HTML renderer. The following flags are available:
143
+
144
+ * `:filter_html`: do not allow any user-inputted HTML in the output.
145
+
146
+ * `:no_images`: do not generate any `<img>` tags.
147
+
148
+ * `:no_links`: do not generate any `<a>` tags.
149
+
150
+ * `:no_styles`: do not generate any `<style>` tags.
151
+
152
+ * `:escape_html`: escape any HTML tags. This option has precedence over
153
+ `:no_styles`, `:no_links`, `:no_images` and `:filter_html` which means
154
+ that any existing tag will be escaped instead of being removed.
155
+
156
+ * `:safe_links_only`: only generate links for protocols which are considered
157
+ safe.
158
+
159
+ * `:with_toc_data`: add HTML anchors to each header in the output HTML,
160
+ to allow linking to each section.
161
+
162
+ * `:hard_wrap`: insert HTML `<br>` tags inside on paragraphs where the origin
163
+ Markdown document had newlines (by default, Markdown ignores these newlines).
164
+
165
+ * `:xhtml`: output XHTML-conformant tags. This option is always enabled in the
166
+ `Render::XHTML` renderer.
167
+
168
+ * `:prettify`: add prettyprint classes to `<code>` tags for google-code-prettify.
169
+
170
+ * `:link_attributes`: hash of extra attributes to add to links.
171
+
172
+ Example:
173
+
174
+ ~~~~~ ruby
175
+ renderer = Redcarpet::Render::HTML.new(no_links: true, hard_wrap: true)
176
+ ~~~~~
177
+
178
+
179
+ The `HTML` renderer has an alternate version, `Redcarpet::Render::HTML_TOC`,
180
+ which will output a table of contents in HTML based on the headers of the
181
+ Markdown document.
182
+
183
+ When instantiating this render object, you can optionally pass a `nesting_level`
184
+ option which takes an integer and allows you to make it render only headers
185
+ until a specific level.
186
+
187
+ Furthermore, the abstract base class `Redcarpet::Render::Base` can be used
188
+ to write a custom renderer purely in Ruby, or extending an existing renderer.
189
+ See the following section for more information.
190
+
191
+
192
+ And you can even cook your own
193
+ ------------------------------
194
+
195
+ Custom renderers are created by inheriting from an existing renderer. The
196
+ built-in renderers, `HTML` and `XHTML` may be extended as such:
197
+
198
+ ~~~~~ ruby
199
+ # create a custom renderer that allows highlighting of code blocks
200
+ class HTMLwithPygments < Redcarpet::Render::HTML
201
+ def block_code(code, language)
202
+ Pygments.highlight(code, lexer: language)
203
+ end
204
+ end
205
+
206
+ markdown = Redcarpet::Markdown.new(HTMLwithPygments, fenced_code_blocks: true)
207
+ ~~~~~
208
+
209
+ But new renderers can also be created from scratch (see `lib/redcarpet/render_man.rb` for
210
+ an example implementation of a Manpage renderer)
211
+
212
+ ~~~~~~ ruby
213
+ class ManPage < Redcarpet::Render::Base
214
+ # you get the drill -- keep going from here
215
+ end
216
+ ~~~~~
217
+
218
+ The following instance methods may be implemented by the renderer:
219
+
220
+ ### Block-level calls
221
+
222
+ If the return value of the method is `nil`, the block will be skipped.
223
+ If the method for a document element is not implemented, the block will
224
+ be skipped.
225
+
226
+ Example:
227
+
228
+ ~~~~ ruby
229
+ class RenderWithoutCode < Redcarpet::Render::HTML
230
+ def block_code(code, language)
231
+ nil
232
+ end
233
+ end
234
+ ~~~~
235
+
236
+ * block_code(code, language)
237
+ * block_quote(quote)
238
+ * block_html(raw_html)
239
+ * footnotes(content)
240
+ * footnote_def(content, number)
241
+ * header(text, header_level)
242
+ * hrule()
243
+ * list(contents, list_type)
244
+ * list_item(text, list_type)
245
+ * paragraph(text)
246
+ * table(header, body)
247
+ * table_row(content)
248
+ * table_cell(content, alignment)
249
+
250
+ ### Span-level calls
251
+
252
+ A return value of `nil` will not output any data. If the method for
253
+ a document element is not implemented, the contents of the span will
254
+ be copied verbatim:
255
+
256
+ * autolink(link, link_type)
257
+ * codespan(code)
258
+ * double_emphasis(text)
259
+ * emphasis(text)
260
+ * image(link, title, alt_text)
261
+ * linebreak()
262
+ * link(link, title, content)
263
+ * raw_html(raw_html)
264
+ * triple_emphasis(text)
265
+ * strikethrough(text)
266
+ * superscript(text)
267
+ * underline(text)
268
+ * highlight(text)
269
+ * quote(text)
270
+ * footnote_ref(number)
271
+
272
+ **Note**: When overriding a renderer's method, be sure to return a HTML
273
+ element with a level that match the level of that method (e.g. return a block
274
+ element when overriding a block-level callback). Otherwise, the output may
275
+ be unexpected.
276
+
277
+ ### Low level rendering
278
+
279
+ * entity(text)
280
+ * normal_text(text)
281
+
282
+ ### Header of the document
283
+
284
+ Rendered before any another elements:
285
+
286
+ * doc_header()
287
+
288
+ ### Footer of the document
289
+
290
+ Rendered after all the other elements:
291
+
292
+ * doc_footer()
293
+
294
+ ### Pre/post-process
295
+
296
+ Special callback: preprocess or postprocess the whole document before
297
+ or after the rendering process begins:
298
+
299
+ * preprocess(full_document)
300
+ * postprocess(full_document)
301
+
302
+ You can look at
303
+ ["How to extend the Redcarpet 2 Markdown library?"](http://dev.af83.com/2012/02/27/howto-extend-the-redcarpet2-markdown-lib.html)
304
+ for some more explanations.
305
+
306
+ Also, now our Pants are much smarter
307
+ ------------------------------------
308
+
309
+ Redcarpet 2 comes with a standalone [SmartyPants](
310
+ http://daringfireball.net/projects/smartypants/) implementation. It is fully
311
+ compliant with the original implementation. It is the fastest SmartyPants
312
+ parser there is, with a difference of several orders of magnitude.
313
+
314
+ The SmartyPants parser can be found in `Redcarpet::Render::SmartyPants`. It has
315
+ been implemented as a module, so it can be used standalone or as a mixin.
316
+
317
+ When mixed with a Renderer class, it will override the `postprocess` method
318
+ to perform SmartyPants replacements once the rendering is complete.
319
+
320
+ ~~~~ ruby
321
+ # Mixin
322
+ class HTMLWithPants < Redcarpet::Render::HTML
323
+ include Redcarpet::Render::SmartyPants
324
+ end
325
+
326
+ # Standalone
327
+ Redcarpet::Render::SmartyPants.render("<p>Oh SmartyPants, you're so crazy...</p>")
328
+ ~~~~~
329
+
330
+ SmartyPants works on top of already-rendered HTML, and will ignore replacements
331
+ inside the content of HTML tags and inside specific HTML blocks such as
332
+ `<code>` or `<pre>`.
333
+
334
+ What? You really want to mix Markdown renderers?
335
+ ------------------------------------------------
336
+
337
+ Redcarpet used to be a drop-in replacement for Redcloth. This is no longer the
338
+ case since version 2 -- it now has its own API, but retains the old name. Yes,
339
+ that does mean that Redcarpet is not backwards-compatible with the 1.X
340
+ versions.
341
+
342
+ Each renderer has its own API and its own set of extensions: you should choose one
343
+ (it doesn't have to be Redcarpet, though that would be great!), write your
344
+ software accordingly, and force your users to install it. That's the
345
+ only way to have reliable and predictable Markdown output on your program.
346
+
347
+ Markdown is already ill-specified enough; if you create software that is
348
+ renderer-independent, the results will be completely unreliable!
349
+
350
+ Still, if major forces (let's say, tornadoes or other natural disasters) force you
351
+ to keep a Markdown-compatibility layer, Redcarpet also supports this:
352
+
353
+ ~~~~~ ruby
354
+ require 'redcarpet/compat'
355
+ ~~~~~
356
+
357
+ Requiring the compatibility library will declare a `Markdown` class with the
358
+ classical RedCloth API, e.g.
359
+
360
+ ~~~~~ ruby
361
+ Markdown.new('this is my text').to_html
362
+ ~~~~~
363
+
364
+ This class renders 100% standards compliant Markdown with 0 extensions. Nada.
365
+ Don't even try to enable extensions with a compatibility layer, because
366
+ that's a maintenance nightmare and won't work.
367
+
368
+ On a related topic: if your Markdown gem has a `lib/markdown.rb` file that
369
+ monkeypatches the Markdown class, you're a terrible human being. Just saying.
370
+
371
+ Boring legal stuff
372
+ ------------------
373
+
374
+ Copyright (c) 2011-2013, Vicent Martí
375
+
376
+ Permission to use, copy, modify, and/or distribute this software for any
377
+ purpose with or without fee is hereby granted, provided that the above
378
+ copyright notice and this permission notice appear in all copies.
379
+
380
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
381
+ WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
382
+ MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
383
+ ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
384
+ WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
385
+ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
386
+ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,60 @@
1
+ require 'date'
2
+ require 'rake/clean'
3
+ require 'rake/extensiontask'
4
+ require 'digest/md5'
5
+
6
+ task :default => [:test]
7
+
8
+ # Gem Spec
9
+ gem_spec = Gem::Specification.load('redcarpet.gemspec')
10
+
11
+ # Ruby Extension
12
+ Rake::ExtensionTask.new('redcarpet', gem_spec)
13
+
14
+ # Packaging
15
+ require 'bundler/gem_tasks'
16
+
17
+ # Testing
18
+ require 'rake/testtask'
19
+
20
+ Rake::TestTask.new('test:unit') do |t|
21
+ t.libs << 'lib'
22
+ t.libs << 'test'
23
+ t.pattern = 'test/*_test.rb'
24
+ t.verbose = true
25
+ t.warning = false
26
+ end
27
+
28
+ task 'test:unit' => :compile
29
+
30
+ desc 'Run conformance tests (MARKDOWN_TEST_VER=1.0)'
31
+ task 'test:conformance' => :compile do |t|
32
+ script = "#{pwd}/bin/redcarpet"
33
+ test_version = ENV['MARKDOWN_TEST_VER'] || '1.0.3'
34
+ lib_dir = "#{pwd}/lib"
35
+
36
+ chdir("test/MarkdownTest_#{test_version}") do
37
+ sh "RUBYLIB=#{lib_dir} ./MarkdownTest.pl --script='#{script}' --tidy"
38
+ end
39
+ end
40
+
41
+ desc 'Run version 1.0 conformance suite'
42
+ task 'test:conformance:1.0' => :compile do |t|
43
+ ENV['MARKDOWN_TEST_VER'] = '1.0'
44
+ Rake::Task['test:conformance'].invoke
45
+ end
46
+
47
+ desc 'Run 1.0.3 conformance suite'
48
+ task 'test:conformance:1.0.3' => :compile do |t|
49
+ ENV['MARKDOWN_TEST_VER'] = '1.0.3'
50
+ Rake::Task['test:conformance'].invoke
51
+ end
52
+
53
+ desc 'Run unit and conformance tests'
54
+ task :test => %w[test:unit test:conformance]
55
+
56
+ desc 'Run benchmarks'
57
+ task :benchmark => :compile do |t|
58
+ $:.unshift 'lib'
59
+ load 'test/benchmark.rb'
60
+ end