RedCloth 3.0.4 → 4.0.0

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

Potentially problematic release.


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

Files changed (63) hide show
  1. data/CHANGELOG +17 -0
  2. data/COPYING +18 -0
  3. data/README +156 -0
  4. data/Rakefile +238 -0
  5. data/bin/redcloth +27 -2
  6. data/ext/redcloth_scan/extconf.rb +9 -0
  7. data/ext/redcloth_scan/redcloth.h +149 -0
  8. data/ext/redcloth_scan/redcloth_attributes.c +650 -0
  9. data/ext/redcloth_scan/redcloth_attributes.rl +78 -0
  10. data/ext/redcloth_scan/redcloth_common.rl +113 -0
  11. data/ext/redcloth_scan/redcloth_inline.c +5102 -0
  12. data/ext/redcloth_scan/redcloth_inline.rl +282 -0
  13. data/ext/redcloth_scan/redcloth_scan.c +9300 -0
  14. data/ext/redcloth_scan/redcloth_scan.rl +523 -0
  15. data/extras/mingw-rbconfig.rb +176 -0
  16. data/extras/ragel_profiler.rb +73 -0
  17. data/lib/redcloth.rb +22 -1128
  18. data/lib/redcloth/formatters/base.rb +50 -0
  19. data/lib/redcloth/formatters/html.rb +342 -0
  20. data/lib/redcloth/formatters/latex.rb +227 -0
  21. data/lib/redcloth/formatters/latex_entities.yml +2414 -0
  22. data/lib/redcloth/textile_doc.rb +105 -0
  23. data/lib/redcloth/version.rb +18 -0
  24. data/test/basic.yml +794 -0
  25. data/test/code.yml +195 -0
  26. data/test/definitions.yml +71 -0
  27. data/test/extra_whitespace.yml +64 -0
  28. data/test/filter_html.yml +177 -0
  29. data/test/filter_pba.yml +12 -0
  30. data/test/helper.rb +108 -0
  31. data/test/html.yml +271 -0
  32. data/test/images.yml +202 -0
  33. data/{tests → test}/instiki.yml +14 -15
  34. data/test/links.yml +214 -0
  35. data/test/lists.yml +283 -0
  36. data/test/poignant.yml +89 -0
  37. data/test/sanitize_html.yml +42 -0
  38. data/test/table.yml +267 -0
  39. data/test/test_custom_tags.rb +46 -0
  40. data/test/test_extensions.rb +31 -0
  41. data/test/test_formatters.rb +15 -0
  42. data/test/test_parser.rb +68 -0
  43. data/test/test_restrictions.rb +41 -0
  44. data/test/textism.yml +480 -0
  45. data/test/threshold.yml +772 -0
  46. data/test/validate_fixtures.rb +73 -0
  47. metadata +94 -60
  48. data/doc/CHANGELOG +0 -160
  49. data/doc/COPYING +0 -25
  50. data/doc/README +0 -106
  51. data/doc/REFERENCE +0 -216
  52. data/doc/make.rb +0 -359
  53. data/run-tests.rb +0 -28
  54. data/setup.rb +0 -1376
  55. data/tests/code.yml +0 -105
  56. data/tests/hard_breaks.yml +0 -26
  57. data/tests/images.yml +0 -171
  58. data/tests/links.yml +0 -155
  59. data/tests/lists.yml +0 -77
  60. data/tests/markdown.yml +0 -218
  61. data/tests/poignant.yml +0 -64
  62. data/tests/table.yml +0 -198
  63. data/tests/textism.yml +0 -406
@@ -0,0 +1,17 @@
1
+ = RedCloth 4.0
2
+
3
+ * New SuperRedCloth (RedCloth 4.0) is a total rewrite using Ragel for the parsing.
4
+ * Markdown support has been removed.
5
+ * Single newlines become <br> tags, just as in traditional RedCloth and other Textile parsers.
6
+ * HTML special characters are automatically escaped inside code signatures, like Textile 2. This means you can simply write @<br />@ and the symbols are escaped whereas in RedCloth 3 you had to write @&lt;br /&gt;@ to make the code fragment readable.
7
+ * The restrictions parameter is observed just like previous versions (except :hard_breaks is now the default).
8
+ * Arguments to RedCloth#to_html are called so extensions made for prior versions can work. Note: extensions need to be included rather than defined directly within the RedCloth class as was previously possible.
9
+ * Custom block tags can be implemented as in the previous version, though the means of implementing them differs.
10
+ * HTML embedded in the Textile input does not often need to be escaped from Textile parsing.
11
+ * The parser will not wrap lines that begin with a space in paragraph tags.
12
+ * Rudimentary support for LaTeX is built in.
13
+ * RedCloth::VERSION on a line by itself inserts the version number into the output.
14
+ * Output (less newlines and tabs) is identical to Textile 2 except a few cases where the RedCloth
15
+ way was preferable.
16
+ * Over 500 tests prevent regression
17
+ * It's 40 times faster than the previous version.
data/COPYING ADDED
@@ -0,0 +1,18 @@
1
+ Copyright (c) 2008 Jason Garber
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to
5
+ deal in the Software without restriction, including without limitation the
6
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7
+ sell copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
+ THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,156 @@
1
+ = RedCloth - Textile parser for Ruby
2
+
3
+ Homepage:: http://redcloth.org
4
+ Author:: Jason Garber
5
+ Copyright:: (c) 2008 Jason Garber
6
+ License:: MIT
7
+
8
+ (See http://redcloth.org/textile/ for a Textile reference.)
9
+
10
+ = RedCloth
11
+
12
+ RedCloth is a Ruby library for converting Textile into HTML.
13
+
14
+ == Installing
15
+
16
+ RedCloth can be installed via RubyGems:
17
+
18
+ sudo gem install RedCloth
19
+
20
+ Or can be compiled from its Ragel source with <tt>rake compile</tt>. Ragel 6.2
21
+ or greater is required to build RedCloth.
22
+
23
+ == What is Textile?
24
+
25
+ Textile is a simple formatting style for text
26
+ documents, loosely based on some HTML conventions.
27
+
28
+ == Sample Textile Text
29
+
30
+ h2. This is a title
31
+
32
+ h3. This is a subhead
33
+
34
+ This is a bit of paragraph.
35
+
36
+ bq. This is a blockquote.
37
+
38
+ = Writing Textile
39
+
40
+ A Textile document consists of paragraphs. Paragraphs
41
+ can be specially formatted by adding a small instruction
42
+ to the beginning of the paragraph.
43
+
44
+ h3. Header 3.
45
+ bq. Blockquote.
46
+ # Numeric list.
47
+ * Bulleted list.
48
+
49
+ == Quick Phrase Modifiers
50
+
51
+ Quick phrase modifiers are also included, to allow formatting
52
+ of small portions of text within a paragraph.
53
+
54
+ _emphasis_
55
+ __italicized__
56
+ *strong*
57
+ **bold**
58
+ ??citation??
59
+ -deleted text-
60
+ +inserted text+
61
+ ^superscript^
62
+ ~subscript~
63
+ @code@
64
+ %(classname)span%
65
+
66
+ ==notextile== (leave text alone)
67
+
68
+ == Links
69
+
70
+ To make a hypertext link, put the link text in "quotation
71
+ marks" followed immediately by a colon and the URL of the link.
72
+
73
+ Optional: text in (parentheses) following the link text,
74
+ but before the closing quotation mark, will become a title
75
+ attribute for the link, visible as a tool tip when a cursor is above it.
76
+
77
+ Example:
78
+
79
+ "This is a link (This is a title)":http://www.textism.com
80
+
81
+ Will become:
82
+
83
+ <a href="http://www.textism.com" title="This is a title">This is a link</a>
84
+
85
+ == Images
86
+
87
+ To insert an image, put the URL for the image inside exclamation marks.
88
+
89
+ Optional: text that immediately follows the URL in (parentheses) will
90
+ be used as the Alt text for the image. Images on the web should always
91
+ have descriptive Alt text for the benefit of readers using non-graphical
92
+ browsers.
93
+
94
+ Optional: place a colon followed by a URL immediately after the
95
+ closing ! to make the image into a link.
96
+
97
+ Example:
98
+
99
+ !http://www.textism.com/common/textist.gif(Textist)!
100
+
101
+ Will become:
102
+
103
+ <img src="http://www.textism.com/common/textist.gif" alt="Textist" />
104
+
105
+ With a link:
106
+
107
+ !/common/textist.gif(Textist)!:http://textism.com
108
+
109
+ Will become:
110
+
111
+ <a href="http://textism.com"><img src="/common/textist.gif" alt="Textist" /></a>
112
+
113
+ == Defining Acronyms
114
+
115
+ HTML allows authors to define acronyms via the tag. The definition appears as a
116
+ tool tip when a cursor hovers over the acronym. A crucial aid to clear writing,
117
+ this should be used at least once for each acronym in documents where they appear.
118
+
119
+ To quickly define an acronym in Textile, place the full text in (parentheses)
120
+ immediately following the acronym.
121
+
122
+ Example:
123
+
124
+ ACLU(American Civil Liberties Union)
125
+
126
+ Will become:
127
+
128
+ <acronym title="American Civil Liberties Union">ACLU</acronym>
129
+
130
+ == Adding Tables
131
+
132
+ In Textile, simple tables can be added by separating each column by
133
+ a pipe.
134
+
135
+ |a|simple|table|row|
136
+ |And|Another|table|row|
137
+
138
+ Styles are applied with curly braces.
139
+
140
+ table{border:1px solid black}.
141
+ {background:#ddd;color:red}. |a|red|row|
142
+
143
+ == Using RedCloth
144
+
145
+ RedCloth is simply an extension of the String class, which can handle
146
+ Textile formatting. Use it like a String and output HTML with its
147
+ RedCloth#to_html method.
148
+
149
+ doc = RedCloth.new "
150
+
151
+ h2. Test document
152
+
153
+ Just a simple test."
154
+
155
+ puts doc.to_html
156
+
@@ -0,0 +1,238 @@
1
+ require 'rake'
2
+ require 'rake/clean'
3
+ require 'rake/gempackagetask'
4
+ require 'rake/rdoctask'
5
+ require 'rake/testtask'
6
+ require 'fileutils'
7
+ include FileUtils
8
+ require 'lib/redcloth/version'
9
+
10
+ NAME = RedCloth::NAME
11
+ SUMMARY = RedCloth::DESCRIPTION
12
+ VERS = RedCloth::VERSION::STRING
13
+ CLEAN.include ['ext/redcloth_scan/*.{bundle,so,obj,pdb,lib,def,exp,c,o,xml}', 'ext/redcloth_scan/Makefile', '**/.*.sw?', '*.gem', '.config']
14
+ CLOBBER.include ['lib/*.{bundle,so,obj,pdb,lib,def,exp}']
15
+
16
+ desc "Does a full compile, test run"
17
+ task :default => [:compile, :test]
18
+
19
+ desc "Compiles all extensions"
20
+ task :compile => [:redcloth_scan] do
21
+ if Dir.glob(File.join("lib","redcloth_scan.*")).length == 0
22
+ STDERR.puts "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
23
+ STDERR.puts "Gem actually failed to build. Your system is"
24
+ STDERR.puts "NOT configured properly to build redcloth."
25
+ STDERR.puts "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
26
+ exit(1)
27
+ end
28
+ end
29
+
30
+ desc "Packages up RedCloth."
31
+ task :package => [:clean, :compile]
32
+
33
+ desc "Releases packages for all RedCloth packages and platforms."
34
+ task :release => [:package, :rubygems_win32]
35
+
36
+ desc "Run all the tests"
37
+ Rake::TestTask.new do |t|
38
+ t.libs << "test"
39
+ t.test_files = FileList['test/test_*.rb']
40
+ t.verbose = true
41
+ end
42
+
43
+ # Run specific tests or test files
44
+ #
45
+ # rake test:parser
46
+ # => Runs the full TestParser unit test
47
+ #
48
+ # rake test:parser:textism
49
+ # => Runs the tests matching /textism/ in the TestParser unit test
50
+ rule "" do |t|
51
+ # test:file:method
52
+ if /test:(.*)(:([^.]+))?$/.match(t.name)
53
+ arguments = t.name.split(":")[1..-1]
54
+ file_name = arguments.first
55
+ test_name = arguments[1..-1]
56
+
57
+ if File.exist?("test/test_#{file_name}.rb")
58
+ run_file_name = "test_#{file_name}.rb"
59
+ end
60
+
61
+ sh "ruby -Ilib:test test/#{run_file_name} -n /#{test_name}/"
62
+ end
63
+ end
64
+
65
+ Rake::RDocTask.new do |rdoc|
66
+ rdoc.rdoc_dir = 'doc/rdoc'
67
+ # rdoc.options += RDOC_OPTS
68
+ # rdoc.template = "extras/flipbook_rdoc.rb"
69
+ rdoc.main = "README"
70
+ rdoc.title = "RedCloth Documentation"
71
+ rdoc.rdoc_files.add ['README', 'CHANGELOG', 'COPYING', 'lib/**/*.rb', 'ext/**/*.c']
72
+ end
73
+
74
+ PKG_FILES = %w(CHANGELOG COPYING README Rakefile) +
75
+ Dir.glob("{bin,doc,test,lib,extras}/**/*") +
76
+ Dir.glob("ext/**/*.{h,c,rb,rl}") +
77
+ %w[attributes inline scan].map {|f| "ext/redcloth_scan/redcloth_#{f}.c"}
78
+
79
+ spec =
80
+ Gem::Specification.new do |s|
81
+ s.name = NAME
82
+ s.version = VERS
83
+ s.platform = Gem::Platform::RUBY
84
+ s.has_rdoc = true
85
+ s.extra_rdoc_files = ["README", "CHANGELOG", "COPYING"]
86
+ s.summary = SUMMARY
87
+ s.description = s.summary
88
+ s.author = "Jason Garber"
89
+ s.email = 'redcloth-upwards@rubyforge.org'
90
+ s.homepage = 'http://redcloth.org/'
91
+
92
+ s.files = PKG_FILES
93
+
94
+ s.require_path = "lib"
95
+ #s.autorequire = "redcloth" # no no no this is tHe 3v1l
96
+ s.extensions = FileList["ext/**/extconf.rb"].to_a
97
+ s.executables = ["redcloth"]
98
+ end
99
+
100
+ Rake::GemPackageTask.new(spec) do |p|
101
+ p.need_tar = true
102
+ p.gem_spec = spec
103
+ end
104
+
105
+ extension = "redcloth_scan"
106
+ ext = "ext/redcloth_scan"
107
+ ext_so = "#{ext}/#{extension}.#{Config::CONFIG['DLEXT']}"
108
+ ext_files = FileList[
109
+ "#{ext}/redcloth_scan.c",
110
+ "#{ext}/redcloth_inline.c",
111
+ "#{ext}/redcloth_attributes.c",
112
+ "#{ext}/extconf.rb",
113
+ "#{ext}/Makefile",
114
+ "lib"
115
+ ]
116
+
117
+ file ext_so => ext_files do
118
+ Dir.chdir(ext) do
119
+ sh(PLATFORM =~ /win32/ ? 'nmake' : 'make')
120
+ end
121
+ cp ext_so, "lib"
122
+ end
123
+
124
+ task "lib" do
125
+ directory "lib"
126
+ end
127
+
128
+ ["#{ext}/redcloth_scan.c","#{ext}/redcloth_inline.c","#{ext}/redcloth_attributes.c"].each do |name|
129
+ @code_style ||= "T0"
130
+ source = name.sub(/\.c$/, '.rl')
131
+ file name => [source, "#{ext}/redcloth_common.rl", "#{ext}/redcloth.h"] do
132
+ @ragel_v ||= `ragel -v`[/(version )(\S*)/,2].split('.').map{|s| s.to_i}
133
+ if @ragel_v[0] > 6 || (@ragel_v[0] == 6 && @ragel_v[1] >= 2)
134
+ sh %{ragel #{source} -#{@code_style} -o #{name}}
135
+ else
136
+ STDERR.puts "Ragel 6.2 or greater is required to generate #{name}."
137
+ exit(1)
138
+ end
139
+ end
140
+ end
141
+
142
+ desc "Builds just the #{extension} extension"
143
+ task extension.to_sym => ["#{ext}/Makefile", ext_so ]
144
+
145
+ file "#{ext}/Makefile" => ["#{ext}/extconf.rb", "#{ext}/redcloth_scan.c","#{ext}/redcloth_inline.c","#{ext}/redcloth_attributes.c"] do
146
+ Dir.chdir(ext) do ruby "extconf.rb" end
147
+ end
148
+
149
+ Win32Spec = Gem::Specification.new do |s|
150
+ s.name = NAME
151
+ s.version = VERS
152
+ s.platform = 'mswin32'
153
+ s.has_rdoc = false
154
+ s.extra_rdoc_files = ["README", "CHANGELOG", "COPYING"]
155
+ s.summary = SUMMARY
156
+ s.description = s.summary
157
+ s.author = "Jason Garber"
158
+ s.email = 'redcloth-upwards@rubyforge.org'
159
+ s.homepage = 'http://redcloth.org/'
160
+
161
+ s.files = PKG_FILES + ["lib/redcloth_scan.so"]
162
+
163
+ s.require_path = "lib"
164
+ #s.autorequire = "redcloth" # no no no this is tHe 3v1l
165
+ s.extensions = []
166
+ s.bindir = "bin"
167
+ end
168
+
169
+ WIN32_PKG_DIR = "pkg/#{NAME}-#{VERS}-mswin32"
170
+
171
+ file WIN32_PKG_DIR => [:package] do
172
+ cp_r "pkg/#{NAME}-#{VERS}", "#{WIN32_PKG_DIR}"
173
+ end
174
+
175
+ desc "Cross-compile the redcloth_scan extension for win32"
176
+ file "redcloth_scan_win32" => [WIN32_PKG_DIR] do
177
+ cp "extras/mingw-rbconfig.rb", "#{WIN32_PKG_DIR}/ext/redcloth_scan/rbconfig.rb"
178
+ sh "cd #{WIN32_PKG_DIR}/ext/redcloth_scan/ && ruby -I. extconf.rb && make"
179
+ mv "#{WIN32_PKG_DIR}/ext/redcloth_scan/redcloth_scan.so", "#{WIN32_PKG_DIR}/lib"
180
+ end
181
+
182
+ desc "Build the binary RubyGems package for win32"
183
+ task :rubygems_win32 => ["redcloth_scan_win32"] do
184
+ Dir.chdir("#{WIN32_PKG_DIR}") do
185
+ Gem::Builder.new(Win32Spec).build
186
+ verbose(true) {
187
+ cp Dir["*.gem"].first, "../"
188
+ }
189
+ end
190
+ end
191
+
192
+ CLEAN.include WIN32_PKG_DIR
193
+
194
+ desc "Build and install the RedCloth gem on your system"
195
+ task :install => [:package] do
196
+ sh %{sudo gem install pkg/#{NAME}-#{VERS}}
197
+ end
198
+
199
+ desc "Uninstall the RedCloth gem from your system"
200
+ task :uninstall => [:clean] do
201
+ sh %{sudo gem uninstall #{NAME}}
202
+ end
203
+
204
+ RAGEL_CODE_GENERATION_STYLES = {
205
+ 'T0' => "Table driven FSM (default)",
206
+ 'T1' => "Faster table driven FSM",
207
+ 'F0' => "Flat table driven FSM",
208
+ 'F1' => "Faster flat table-driven FSM",
209
+ 'G0' => "Goto-driven FSM",
210
+ 'G1' => "Faster goto-driven FSM",
211
+ 'G2' => "Really fast goto-driven FSM"
212
+ }
213
+
214
+ desc "Find the fastest code generation style for Ragel"
215
+ task :optimize do
216
+ require 'extras/ragel_profiler'
217
+ results = []
218
+ RAGEL_CODE_GENERATION_STYLES.each do |style, name|
219
+ @code_style = style
220
+ profiler = RagelProfiler.new(style + " " + name)
221
+
222
+ # Hack to get everything to invoke again. Could use #execute, but then it
223
+ # doesn't execute prerequisites the second+ time
224
+ Rake::Task.tasks.each {|t| t.instance_eval "@already_invoked = false" }
225
+
226
+ Rake::Task['clobber'].invoke
227
+
228
+ profiler.measure(:compile) do
229
+ Rake::Task['compile'].invoke
230
+ end
231
+ profiler.measure(:test) do
232
+ Rake::Task['test'].invoke
233
+ end
234
+ profiler.ext_size(ext_so)
235
+
236
+ end
237
+ puts RagelProfiler.results
238
+ end
@@ -1,3 +1,28 @@
1
- #!/usr/bin/ruby18
1
+ #!/usr/bin/env ruby
2
+ $:.unshift(File.dirname(__FILE__) + '/../lib/')
3
+ require 'optparse'
2
4
  require 'redcloth'
3
- puts RedCloth.new( ARGF.read ).to_html
5
+
6
+ if %w(--version -v).include? ARGV.first
7
+ puts "#{RedCloth::NAME} #{RedCloth::VERSION::STRING}"
8
+ exit(0)
9
+ end
10
+
11
+ output_as = "html"
12
+ opts = OptionParser.new do |opts|
13
+ opts.banner = "Usage: redcloth [options] [redcloth_formatted.txt]"
14
+ opts.separator "If no file specified, STDIN will be used. If you are typing input, you can send an EOF by pressing ^D (^Z on Windows)"
15
+ opts.separator ""
16
+ opts.on("-o", "--output STYLE", "Output format (defaults to #{output_as})") do |o|
17
+ output_as = o
18
+ end
19
+ end
20
+ opts.parse! ARGV
21
+
22
+ red = RedCloth.new( ARGF.read )
23
+ out_meth = "to_#{ output_as }"
24
+ if red.respond_to? out_meth
25
+ puts red.method( out_meth ).call
26
+ else
27
+ abort "** No to_#{ output_as } method found for the `#{ output_as }' format"
28
+ end