RedCloth 4.2.4.pre2-x86-mingw32

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 (66) hide show
  1. data/.gitignore +25 -0
  2. data/.rspec +1 -0
  3. data/.rvmrc +1 -0
  4. data/CHANGELOG +232 -0
  5. data/COPYING +18 -0
  6. data/Gemfile +2 -0
  7. data/Gemfile.lock +33 -0
  8. data/Manifest +52 -0
  9. data/README +196 -0
  10. data/Rakefile +10 -0
  11. data/bin/redcloth +28 -0
  12. data/doc/textile_reference.html +631 -0
  13. data/ext/redcloth_scan/redcloth.h +220 -0
  14. data/lib/case_sensitive_require/RedCloth.rb +6 -0
  15. data/lib/redcloth.rb +44 -0
  16. data/lib/redcloth/erb_extension.rb +27 -0
  17. data/lib/redcloth/formatters/base.rb +63 -0
  18. data/lib/redcloth/formatters/html.rb +345 -0
  19. data/lib/redcloth/formatters/latex.rb +322 -0
  20. data/lib/redcloth/formatters/latex_entities.yml +2414 -0
  21. data/lib/redcloth/textile_doc.rb +103 -0
  22. data/lib/redcloth/version.rb +34 -0
  23. data/lib/tasks/pureruby.rake +17 -0
  24. data/redcloth.gemspec +48 -0
  25. data/setup.rb +1585 -0
  26. data/spec/benchmark_spec.rb +15 -0
  27. data/spec/custom_tags_spec.rb +50 -0
  28. data/spec/erb_spec.rb +10 -0
  29. data/spec/extension_spec.rb +26 -0
  30. data/spec/fixtures/basic.yml +1028 -0
  31. data/spec/fixtures/code.yml +257 -0
  32. data/spec/fixtures/definitions.yml +82 -0
  33. data/spec/fixtures/extra_whitespace.yml +64 -0
  34. data/spec/fixtures/filter_html.yml +177 -0
  35. data/spec/fixtures/filter_pba.yml +20 -0
  36. data/spec/fixtures/html.yml +340 -0
  37. data/spec/fixtures/images.yml +279 -0
  38. data/spec/fixtures/instiki.yml +38 -0
  39. data/spec/fixtures/links.yml +291 -0
  40. data/spec/fixtures/lists.yml +462 -0
  41. data/spec/fixtures/poignant.yml +89 -0
  42. data/spec/fixtures/sanitize_html.yml +42 -0
  43. data/spec/fixtures/table.yml +434 -0
  44. data/spec/fixtures/textism.yml +509 -0
  45. data/spec/fixtures/threshold.yml +762 -0
  46. data/spec/formatters/class_filtered_html_spec.rb +7 -0
  47. data/spec/formatters/filtered_html_spec.rb +7 -0
  48. data/spec/formatters/html_no_breaks_spec.rb +9 -0
  49. data/spec/formatters/html_spec.rb +13 -0
  50. data/spec/formatters/id_filtered_html_spec.rb +7 -0
  51. data/spec/formatters/latex_spec.rb +13 -0
  52. data/spec/formatters/lite_mode_html_spec.rb +7 -0
  53. data/spec/formatters/no_span_caps_html_spec.rb +7 -0
  54. data/spec/formatters/sanitized_html_spec.rb +7 -0
  55. data/spec/formatters/style_filtered_html_spec.rb +7 -0
  56. data/spec/parser_spec.rb +95 -0
  57. data/spec/spec_helper.rb +36 -0
  58. data/tasks/compile.rake +47 -0
  59. data/tasks/gems.rake +38 -0
  60. data/tasks/ragel_extension_task.rb +127 -0
  61. data/tasks/release.rake +15 -0
  62. data/tasks/rspec.rake +11 -0
  63. data/tasks/rvm.rake +43 -0
  64. data/test/ragel_profiler.rb +73 -0
  65. data/test/validate_fixtures.rb +74 -0
  66. metadata +218 -0
@@ -0,0 +1,7 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe "class_filtered_html" do
4
+ examples_from_yaml do |doc|
5
+ RedCloth.new(doc['in'], [:filter_classes]).to_html
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe "filtered_html" do
4
+ examples_from_yaml do |doc|
5
+ RedCloth.new(doc['in'], [:filter_html]).to_html
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe "html_no_breaks" do
4
+ examples_from_yaml do |doc|
5
+ red = RedCloth.new(doc['in'])
6
+ red.hard_breaks = false
7
+ red.to_html
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe "HTML" do
4
+ examples_from_yaml do |doc|
5
+ RedCloth.new(doc['in']).to_html
6
+ end
7
+
8
+ it "should not raise an error when orphaned parentheses in a link are followed by punctuation and words in HTML" do
9
+ lambda {
10
+ RedCloth.new(%Q{Test "(read this":http://test.host), ok}).to_html
11
+ }.should_not raise_error
12
+ end
13
+ end
@@ -0,0 +1,7 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe "id_filtered_html" do
4
+ examples_from_yaml do |doc|
5
+ RedCloth.new(doc['in'], [:filter_ids]).to_html
6
+ end
7
+ end
@@ -0,0 +1,13 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe "LaTeX" do
4
+ examples_from_yaml do |doc|
5
+ RedCloth.new(doc['in']).to_latex
6
+ end
7
+
8
+ it "should not raise an error when orphaned parentheses in a link are followed by punctuation and words in LaTeX" do
9
+ lambda {
10
+ RedCloth.new(%Q{Test "(read this":http://test.host), ok}).to_latex
11
+ }.should_not raise_error
12
+ end
13
+ end
@@ -0,0 +1,7 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe "lite_mode_html" do
4
+ examples_from_yaml do |doc|
5
+ RedCloth.new(doc['in'], [:lite_mode]).to_html
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe "no_span_caps_html" do
4
+ examples_from_yaml do |doc|
5
+ RedCloth.new(doc['in'], [:no_span_caps]).to_html
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe "sanitized_html" do
4
+ examples_from_yaml do |doc|
5
+ RedCloth.new(doc['in'], [:sanitize_html]).to_html
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe "style_filtered_html" do
4
+ examples_from_yaml do |doc|
5
+ RedCloth.new(doc['in'], [:filter_styles]).to_html
6
+ end
7
+ end
@@ -0,0 +1,95 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe RedCloth do
4
+
5
+ describe "#new" do
6
+ it "should accept options" do
7
+ lambda {
8
+ RedCloth.new("test", [:hard_breaks])
9
+ }.should_not raise_error(ArgumentError)
10
+ end
11
+ end
12
+
13
+ it "should have a VERSION" do
14
+ RedCloth.const_defined?("VERSION").should be_true
15
+ RedCloth::VERSION.const_defined?("STRING").should be_true
16
+ end
17
+
18
+ it "should show the version as a string" do
19
+ RedCloth::VERSION::STRING.should == RedCloth::VERSION.to_s
20
+ RedCloth::VERSION.should == RedCloth::VERSION::STRING
21
+ end
22
+
23
+ it "should have EXTENSION_LANGUAGE" do
24
+ RedCloth.const_defined?("EXTENSION_LANGUAGE").should be_true
25
+ RedCloth::EXTENSION_LANGUAGE.should_not be_empty
26
+ RedCloth::DESCRIPTION.should include(RedCloth::EXTENSION_LANGUAGE)
27
+ end
28
+
29
+ it "should not segfault on a badly formatted table" do
30
+ RedCloth.new(%Q{| one | two |\nthree | four |}).to_html.should =~ /td/
31
+ end
32
+
33
+ it "should not segfault on a table without a block end" do
34
+ RedCloth.new("| a | b |\n| c | d |\nh3. foo").to_html.should =~ /h3/
35
+ end
36
+
37
+ it "should not segfault on a table with empty cells" do
38
+ RedCloth.new(%Q{|one || |\nthree | four |}).to_html.should =~ /td/
39
+ end
40
+
41
+ it "should not segfault on an unfinished html block with filter_html" do
42
+ lambda { RedCloth.new(%Q{<hr> Some text}, [:filter_html]).to_html }.should_not raise_error
43
+ end
44
+
45
+ it "should parse RedCloth::VERSION in input" do
46
+ RedCloth.new("RedCloth::VERSION").to_html.should == "<p>#{RedCloth::VERSION::STRING}</p>"
47
+ end
48
+
49
+ it "should not parse RedCloth::VERSION if it's not on a line by itself" do
50
+ input = "RedCloth::VERSION won't output the RedCloth::VERSION unless it's on a line all by itself.\n\nRedCloth::VERSION"
51
+ html = "<p>RedCloth::<span class=\"caps\">VERSION</span> won&#8217;t output the RedCloth::<span class=\"caps\">VERSION</span> unless it&#8217;s on a line all by itself.</p>\n<p>#{RedCloth::VERSION::STRING}</p>"
52
+ RedCloth.new(input).to_html.should == html
53
+ end
54
+
55
+ it "should output the RedCloth::VERSION if it's labeled on a line by itself" do
56
+ input = "RedCloth::VERSION: RedCloth::VERSION"
57
+ html = "<p>RedCloth::VERSION: #{RedCloth::VERSION::STRING}</p>"
58
+ RedCloth.new(input).to_html.should == html
59
+ end
60
+
61
+ it "should output the RedCloth::VERSION if it's labeled in a sentence on a line by itself" do
62
+ input = "RedCloth version RedCloth::VERSION"
63
+ html = "<p>RedCloth version #{RedCloth::VERSION::STRING}</p>"
64
+ RedCloth.new(input).to_html.should == html
65
+ end
66
+
67
+ it "should output the RedCloth::VERSION in brackets" do
68
+ input = "The current RedCloth version is [RedCloth::VERSION]"
69
+ html = "<p>The current RedCloth version is #{RedCloth::VERSION::STRING}</p>"
70
+ RedCloth.new(input).to_html.should == html
71
+ end
72
+
73
+ it "should strip carriage returns" do
74
+ input = "This is a paragraph\r\n\r\nThis is a\r\nline break.\r\n\r\n<div>\r\ntest\r\n\r\n</div>"
75
+ html = "<p>This is a paragraph</p>\n<p>This is a<br />\nline break.</p>\n<div>\n<p>test</p>\n</div>"
76
+ RedCloth.new(input).to_html.should == html
77
+ end
78
+
79
+ if RUBY_VERSION > "1.9.0"
80
+ it "should preserve character encoding" do
81
+ input = "This is an ISO-8859-1 string"
82
+ input.force_encoding 'iso-8859-1'
83
+ output = RedCloth.new(input).to_html
84
+
85
+ output.should == "<p>This is an <span class=\"caps\">ISO</span>-8859-1 string</p>"
86
+ output.encoding.to_s.should == "ISO-8859-1"
87
+ end
88
+
89
+ it "should not raise ArgumentError: invalid byte sequence" do
90
+ s = "\xa3"
91
+ s.force_encoding 'iso-8859-1'
92
+ lambda { RedCloth.new(s).to_html }.should_not raise_error
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,36 @@
1
+ $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
2
+ require 'redcloth'
3
+ require 'yaml'
4
+
5
+ def examples_from_yaml(&block)
6
+ formatter = description.downcase
7
+ define_method("format_as_#{formatter}", &block)
8
+
9
+ fixtures.each do |name, doc|
10
+ if doc[formatter]
11
+ example("should output #{formatter} for #{name}") do
12
+ output = method("format_as_#{formatter}").call(doc)
13
+ output.should == doc[formatter]
14
+ end
15
+ else
16
+ example("should not raise errors when rendering #{formatter} for #{name}") do
17
+ lambda { method("format_as_#{formatter}").call(doc) }.should_not raise_error
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ def fixtures
24
+ return @fixtures if @fixtures
25
+ @fixtures = {}
26
+ Dir[File.join(File.dirname(__FILE__), *%w[fixtures *.yml])].each do |testfile|
27
+ testgroup = File.basename(testfile, '.yml')
28
+ num = 0
29
+ YAML::load_documents(File.open(testfile)) do |doc|
30
+ name = doc['name'] || num
31
+ @fixtures["#{testgroup} #{name}"] = doc
32
+ num += 1
33
+ end
34
+ end
35
+ @fixtures
36
+ end
@@ -0,0 +1,47 @@
1
+ CLEAN.include [
2
+ 'tmp',
3
+ '**/*.{o,obj,class,pdb,lib,def,exp,log,rbc}',
4
+ 'ext/redcloth_scan/**/redcloth_*.rb',
5
+ 'ext/redcloth_scan/Makefile', 'ext/redcloth_scan/extconf.rb',
6
+ ]
7
+ CLOBBER.include [
8
+ 'pkg',
9
+ '**/*.{c}',
10
+ 'lib/*.{bundle,so,o,obj,pdb,lib,def,exp,jar}',
11
+ 'lib/redcloth_scan.rb',
12
+ ]
13
+
14
+ # Load the Gem specification for the current platform (Ruby or JRuby).
15
+ def gemspec(platform = RUBY_PLATFORM[/java/] || 'ruby')
16
+ Gem::Specification.load(File.expand_path('../../redcloth.gemspec', __FILE__))
17
+ end
18
+
19
+ require 'rake/extensiontask'
20
+ require 'rake/javaextensiontask'
21
+ require File.dirname(__FILE__) + '/ragel_extension_task'
22
+
23
+ if defined?(JRUBY_VERSION)
24
+ Rake::JavaRagelExtensionTask.new('redcloth_scan', gemspec)
25
+ else
26
+ extconf = "ext/redcloth_scan/extconf.rb"
27
+ file extconf do
28
+ FileUtils.mkdir(File.dirname(extconf)) unless File.directory?(File.dirname(extconf))
29
+ File.open(extconf, "w") do |io|
30
+ io.write(<<-EOF)
31
+ require 'mkmf'
32
+ CONFIG['warnflags'].gsub!(/-Wshorten-64-to-32/, '') if CONFIG['warnflags']
33
+ $CFLAGS << ' -O0 -Wall' if CONFIG['CC'] =~ /gcc/
34
+ dir_config("redcloth_scan")
35
+ have_library("c", "main")
36
+ create_makefile("redcloth_scan")
37
+ EOF
38
+ end
39
+ end
40
+
41
+ Rake::RagelExtensionTask.new("redcloth_scan", gemspec) do |ext|
42
+ if ENV['RUBY_CC_VERSION']
43
+ ext.cross_compile = true
44
+ ext.cross_platform = ['i386-mingw32', 'i386-mswin32-60']
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,38 @@
1
+ Rake::Task['build'].prerequisites.unshift('compile')
2
+
3
+ namespace :build do
4
+ desc "Generate Windows binary gems"
5
+ task :win do
6
+ unless File.directory?(File.expand_path('~/.rake-compiler'))
7
+ STDERR.puts <<-EOM
8
+
9
+ You must install Windows rubies to ~/.rake-compiler with:
10
+
11
+ rake-compiler cross-ruby VERSION=1.8.6-p398
12
+ # (Later 1.9.1 patch levels don't compile on mingw)
13
+ rake-compiler cross-ruby VERSION=1.9.1-p243
14
+ EOM
15
+ exit(1)
16
+ end
17
+ # rvm and mingw ruby versions have to match to avoid errors
18
+ sh "rvm ruby-1.8.6-p398@redcloth rake cross compile RUBY_CC_VERSION=1.8.6"
19
+ sh "rvm ruby-1.9.1-p243@redcloth rake cross compile RUBY_CC_VERSION=1.9.1"
20
+ # This will copy the .so files to the proper place
21
+ sh "rake cross native gem RUBY_CC_VERSION=1.8.6:1.9.1"
22
+ end
23
+
24
+ desc 'Generate JRuby binary gem'
25
+ task :jruby do
26
+ sh "rvm jruby@redcloth rake java gem"
27
+ end
28
+
29
+ desc "Build ruby, windows, and jruby gems into the pkg directory"
30
+ task :all => [
31
+ "rvm:bundle",
32
+ :clobber,
33
+ :spec,
34
+ :jruby,
35
+ :win,
36
+ :build
37
+ ]
38
+ end
@@ -0,0 +1,127 @@
1
+ module Rake
2
+ module RagelGenerationTasks
3
+ RAGEL_INCLUDE_PATTERN = /include \w+ "([^"]+)";/
4
+ RAGEL_VERSION_COMMAND = "ragel -v"
5
+
6
+ attr_accessor :rl_dir
7
+ attr_accessor :machines
8
+
9
+ def init(name = nil, gem_spec = nil)
10
+ super
11
+
12
+ @rl_dir = "ragel"
13
+ @machines = %w(scan inline attributes)
14
+ end
15
+
16
+ def lang
17
+ raise NotImplementedError
18
+ end
19
+
20
+ def source_files
21
+ @source_files ||= machines.map {|m| target(m) }
22
+ end
23
+
24
+ def define
25
+ super
26
+ define_ragel_tasks
27
+ end
28
+
29
+ def define_ragel_tasks
30
+ machines.each do |machine|
31
+ file target(machine) => [*ragel_sources(machine)] do
32
+ mkdir_p(File.dirname(target(machine))) unless File.directory?(File.dirname(target(machine)))
33
+ ensure_ragel_version
34
+ sh "ragel #{flags} #{lang_ragel(machine)} -o #{target(machine)}"
35
+ end
36
+
37
+ file extconf => [target(machine)] if lang == 'c'
38
+ end
39
+ end
40
+
41
+ def target(machine)
42
+ {
43
+ 'scan' => {
44
+ 'c' => "#{@ext_dir}/redcloth_scan.c",
45
+ 'java' => "#{@ext_dir}/RedclothScanService.java",
46
+ 'rb' => "#{@ext_dir}/redcloth_scan.rb"
47
+ },
48
+ 'inline' => {
49
+ 'c' => "#{@ext_dir}/redcloth_inline.c",
50
+ 'java' => "#{@ext_dir}/RedclothInline.java",
51
+ 'rb' => "#{@ext_dir}/redcloth_inline.rb"
52
+ },
53
+ 'attributes' => {
54
+ 'c' => "#{@ext_dir}/redcloth_attributes.c",
55
+ 'java' => "#{@ext_dir}/RedclothAttributes.java",
56
+ 'rb' => "#{@ext_dir}/redcloth_attributes.rb"
57
+ }
58
+ }[machine][lang]
59
+ end
60
+
61
+ def lang_ragel(machine)
62
+ "#{@rl_dir}/redcloth_#{machine}.#{lang}.rl"
63
+ end
64
+
65
+ def ragel_sources(machine)
66
+ deps = [lang_ragel(machine), ragel_file_dependencies(lang_ragel(machine))].flatten.dup
67
+ deps += ["#{@ext_dir}/redcloth.h"] if lang == 'c'
68
+ deps
69
+ # FIXME: merge that header file into other places so it can be eliminated?
70
+ end
71
+
72
+ def ragel_file_dependencies(ragel_file)
73
+ found = find_ragel_includes(ragel_file)
74
+ found + found.collect {|file| ragel_file_dependencies(file)}
75
+ end
76
+
77
+ def find_ragel_includes(file)
78
+ File.open(file).grep(RAGEL_INCLUDE_PATTERN) { $1 }.map do |file|
79
+ "#{@rl_dir}/#{file}"
80
+ end
81
+ end
82
+
83
+ def flags
84
+ code_style_flag = preferred_code_style ? " -" + preferred_code_style : ""
85
+ "-#{host_language_flag}#{code_style_flag}"
86
+ end
87
+
88
+ def host_language_flag
89
+ {
90
+ 'c' => 'C',
91
+ 'java' => 'J',
92
+ 'rb' => 'R'
93
+ }[lang]
94
+ end
95
+
96
+ def preferred_code_style
97
+ {
98
+ 'c' => 'T0',
99
+ 'java' => nil,
100
+ 'rb' => 'F1'
101
+ }[lang]
102
+ end
103
+
104
+ def ensure_ragel_version
105
+ @ragel_v ||= `ragel -v`[/(version )(\S*)/,2].split('.').map{|s| s.to_i}
106
+ raise unless @ragel_v[0] > 6 || (@ragel_v[0] == 6 && @ragel_v[1] >= 3)
107
+ rescue
108
+ STDERR.puts "Ragel 6.3 or greater is required."
109
+ exit(1)
110
+ end
111
+
112
+ end
113
+ class RagelExtensionTask < ExtensionTask
114
+ include RagelGenerationTasks
115
+
116
+ def lang
117
+ "c"
118
+ end
119
+ end
120
+ class JavaRagelExtensionTask < JavaExtensionTask
121
+ include RagelGenerationTasks
122
+
123
+ def lang
124
+ "java"
125
+ end
126
+ end
127
+ end