parity-RedCloth 4.2.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gemtest +0 -0
- data/.rspec +1 -0
- data/CHANGELOG +265 -0
- data/COPYING +18 -0
- data/Gemfile +7 -0
- data/README.rdoc +215 -0
- data/Rakefile +18 -0
- data/bin/redcloth +28 -0
- data/doc/textile_reference.html +631 -0
- data/ext/redcloth_scan/extconf.rb +6 -0
- data/ext/redcloth_scan/redcloth.h +220 -0
- data/ext/redcloth_scan/redcloth_attributes.c +650 -0
- data/ext/redcloth_scan/redcloth_inline.c +8153 -0
- data/ext/redcloth_scan/redcloth_scan.c +24407 -0
- data/lib/case_sensitive_require/RedCloth.rb +6 -0
- data/lib/redcloth/erb_extension.rb +27 -0
- data/lib/redcloth/formatters/base.rb +63 -0
- data/lib/redcloth/formatters/html.rb +352 -0
- data/lib/redcloth/formatters/latex.rb +331 -0
- data/lib/redcloth/formatters/latex_entities.yml +2414 -0
- data/lib/redcloth/textile_doc.rb +113 -0
- data/lib/redcloth/version.rb +34 -0
- data/lib/redcloth.rb +45 -0
- data/lib/tasks/pureruby.rake +17 -0
- data/redcloth.gemspec +54 -0
- data/spec/benchmark_spec.rb +15 -0
- data/spec/custom_tags_spec.rb +50 -0
- data/spec/erb_spec.rb +10 -0
- data/spec/extension_spec.rb +26 -0
- data/spec/fixtures/basic.yml +1028 -0
- data/spec/fixtures/code.yml +257 -0
- data/spec/fixtures/definitions.yml +82 -0
- data/spec/fixtures/extra_whitespace.yml +64 -0
- data/spec/fixtures/filter_html.yml +177 -0
- data/spec/fixtures/filter_pba.yml +20 -0
- data/spec/fixtures/html.yml +348 -0
- data/spec/fixtures/images.yml +279 -0
- data/spec/fixtures/instiki.yml +38 -0
- data/spec/fixtures/links.yml +291 -0
- data/spec/fixtures/lists.yml +462 -0
- data/spec/fixtures/poignant.yml +89 -0
- data/spec/fixtures/sanitize_html.yml +42 -0
- data/spec/fixtures/table.yml +434 -0
- data/spec/fixtures/textism.yml +509 -0
- data/spec/fixtures/threshold.yml +762 -0
- data/spec/formatters/class_filtered_html_spec.rb +7 -0
- data/spec/formatters/filtered_html_spec.rb +7 -0
- data/spec/formatters/html_no_breaks_spec.rb +9 -0
- data/spec/formatters/html_spec.rb +13 -0
- data/spec/formatters/id_filtered_html_spec.rb +7 -0
- data/spec/formatters/latex_spec.rb +13 -0
- data/spec/formatters/lite_mode_html_spec.rb +7 -0
- data/spec/formatters/no_span_caps_html_spec.rb +7 -0
- data/spec/formatters/sanitized_html_spec.rb +7 -0
- data/spec/formatters/style_filtered_html_spec.rb +7 -0
- data/spec/parser_spec.rb +102 -0
- data/spec/spec_helper.rb +36 -0
- data/tasks/compile.rake +47 -0
- data/tasks/gems.rake +37 -0
- data/tasks/ragel_extension_task.rb +127 -0
- data/tasks/release.rake +15 -0
- data/tasks/rspec.rake +13 -0
- data/tasks/rvm.rake +79 -0
- metadata +239 -0
@@ -0,0 +1,113 @@
|
|
1
|
+
module RedCloth
|
2
|
+
class TextileDoc < String
|
3
|
+
#
|
4
|
+
# Accessors for setting security restrictions.
|
5
|
+
#
|
6
|
+
# This is a nice thing if you're using RedCloth for
|
7
|
+
# formatting in public places (e.g. Wikis) where you
|
8
|
+
# don't want users to abuse HTML for bad things.
|
9
|
+
#
|
10
|
+
# If +:filter_html+ is set, HTML which wasn't
|
11
|
+
# created by the Textile processor will be escaped.
|
12
|
+
# Alternatively, if +:sanitize_html+ is set,
|
13
|
+
# HTML can pass through the Textile processor but
|
14
|
+
# unauthorized tags and attributes will be removed.
|
15
|
+
#
|
16
|
+
# If +:filter_styles+ is set, it will also disable
|
17
|
+
# the style markup specifier. ('{color: red}')
|
18
|
+
#
|
19
|
+
# If +:filter_classes+ is set, it will also disable
|
20
|
+
# class attributes. ('!(classname)image!')
|
21
|
+
#
|
22
|
+
# If +:filter_ids+ is set, it will also disable
|
23
|
+
# id attributes. ('!(classname#id)image!')
|
24
|
+
#
|
25
|
+
attr_accessor :filter_html, :sanitize_html, :filter_styles, :filter_classes, :filter_ids
|
26
|
+
|
27
|
+
#
|
28
|
+
# Deprecated accessor for toggling hard breaks.
|
29
|
+
#
|
30
|
+
# Traditional RedCloth converted single newlines
|
31
|
+
# to HTML break tags, but later versions required
|
32
|
+
# +:hard_breaks+ be set to enable this behavior.
|
33
|
+
# +:hard_breaks+ is once again the default.
|
34
|
+
#
|
35
|
+
attr_accessor :hard_breaks
|
36
|
+
|
37
|
+
# Accessor for toggling lite mode.
|
38
|
+
#
|
39
|
+
# In lite mode, block-level rules are ignored. This means
|
40
|
+
# that tables, paragraphs, lists, and such aren't available.
|
41
|
+
# Only the inline markup for bold, italics, entities and so on.
|
42
|
+
#
|
43
|
+
# r = RedCloth.new( "And then? She *fell*!", [:lite_mode] )
|
44
|
+
# r.to_html
|
45
|
+
# #=> "And then? She <strong>fell</strong>!"
|
46
|
+
#
|
47
|
+
attr_accessor :lite_mode
|
48
|
+
|
49
|
+
#
|
50
|
+
# Accessor for toggling span caps.
|
51
|
+
#
|
52
|
+
# Textile places `span' tags around capitalized
|
53
|
+
# words by default, but this wreaks havoc on Wikis.
|
54
|
+
# If +:no_span_caps+ is set, this will be
|
55
|
+
# suppressed.
|
56
|
+
#
|
57
|
+
attr_accessor :no_span_caps
|
58
|
+
|
59
|
+
#
|
60
|
+
# If +:auto_link+ is set, plaintext urls will be
|
61
|
+
# turned into anchor elements.
|
62
|
+
#
|
63
|
+
# r = RedCloth.new( "Welcome http://zombo.com/", [:auto_link] )
|
64
|
+
# r.to_html
|
65
|
+
# #=> "<p>Welcome <a href="http://zombo.com/">http://zombo.com/</a></p>"
|
66
|
+
#
|
67
|
+
attr_accessor :auto_link_urls
|
68
|
+
|
69
|
+
# Returns a new RedCloth object, based on _string_, observing
|
70
|
+
# any _restrictions_ specified.
|
71
|
+
#
|
72
|
+
# r = RedCloth.new( "h1. A *bold* man" )
|
73
|
+
# #=> "h1. A *bold* man"
|
74
|
+
# r.to_html
|
75
|
+
# #=>"<h1>A <b>bold</b> man</h1>"
|
76
|
+
#
|
77
|
+
def initialize( string, restrictions = [] )
|
78
|
+
restrictions.each { |r| method("#{r}=").call( true ) }
|
79
|
+
super( string )
|
80
|
+
end
|
81
|
+
|
82
|
+
#
|
83
|
+
# Generates HTML from the Textile contents.
|
84
|
+
#
|
85
|
+
# RedCloth.new( "And then? She *fell*!" ).to_html
|
86
|
+
# #=>"<p>And then? She <strong>fell</strong>!</p>"
|
87
|
+
#
|
88
|
+
def to_html( *rules )
|
89
|
+
apply_rules(rules)
|
90
|
+
|
91
|
+
to(RedCloth::Formatters::HTML)
|
92
|
+
end
|
93
|
+
|
94
|
+
#
|
95
|
+
# Generates LaTeX from the Textile contents.
|
96
|
+
#
|
97
|
+
# RedCloth.new( "And then? She *fell*!" ).to_latex
|
98
|
+
# #=> "And then? She \\textbf{fell}!\n\n"
|
99
|
+
#
|
100
|
+
def to_latex( *rules )
|
101
|
+
apply_rules(rules)
|
102
|
+
|
103
|
+
to(RedCloth::Formatters::LATEX)
|
104
|
+
end
|
105
|
+
|
106
|
+
private
|
107
|
+
def apply_rules(rules)
|
108
|
+
rules.each do |r|
|
109
|
+
method(r).call(self) if self.respond_to?(r)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module RedCloth
|
2
|
+
module VERSION
|
3
|
+
MAJOR = 4
|
4
|
+
MINOR = 2
|
5
|
+
TINY = 9
|
6
|
+
RELEASE_CANDIDATE = nil
|
7
|
+
|
8
|
+
STRING = [MAJOR, MINOR, TINY, RELEASE_CANDIDATE].compact.join('.')
|
9
|
+
TAG = "REL_#{[MAJOR, MINOR, TINY, RELEASE_CANDIDATE].compact.join('_')}".upcase.gsub(/\.|-/, '_')
|
10
|
+
FULL_VERSION = "#{[MAJOR, MINOR, TINY, RELEASE_CANDIDATE].compact.join('.')}"
|
11
|
+
|
12
|
+
class << self
|
13
|
+
def to_s
|
14
|
+
STRING
|
15
|
+
end
|
16
|
+
|
17
|
+
def ==(arg)
|
18
|
+
STRING == arg
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
NAME = "RedCloth"
|
24
|
+
GEM_NAME = NAME
|
25
|
+
URL = "http://redcloth.org/"
|
26
|
+
description = "Textile parser for Ruby."
|
27
|
+
|
28
|
+
if RedCloth.const_defined?(:EXTENSION_LANGUAGE)
|
29
|
+
SUMMARY = "#{NAME}-#{VERSION::FULL_VERSION}-#{EXTENSION_LANGUAGE}"
|
30
|
+
else
|
31
|
+
SUMMARY = "#{NAME}-#{VERSION::FULL_VERSION}"
|
32
|
+
end
|
33
|
+
DESCRIPTION = SUMMARY + " - #{description}\n#{URL}"
|
34
|
+
end
|
data/lib/redcloth.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# If this is a frozen gem in Rails 2.1 and RedCloth 3.x was already
|
2
|
+
# loaded by Rails' ActionView::Helpers::TextHelper, the user will get
|
3
|
+
# "redcloth_scan.bundle: Class is not a module (TypeError)"
|
4
|
+
# This hack is to work around that Rails loading problem. The problem
|
5
|
+
# appears to be fixed in Edge Rails [51e4106].
|
6
|
+
Object.send(:remove_const, :RedCloth) if Object.const_defined?(:RedCloth) && RedCloth.is_a?(Class)
|
7
|
+
|
8
|
+
require 'rbconfig'
|
9
|
+
begin
|
10
|
+
conf = Object.const_get(defined?(RbConfig) ? :RbConfig : :Config)::CONFIG
|
11
|
+
prefix = conf['arch'] =~ /mswin|mingw/ ? "#{conf['MAJOR']}.#{conf['MINOR']}/" : ''
|
12
|
+
lib = "#{prefix}redcloth_scan"
|
13
|
+
require lib
|
14
|
+
rescue LoadError => e
|
15
|
+
e.message << %{\nCouldn't load #{lib}\nThe $LOAD_PATH was:\n#{$LOAD_PATH.join("\n")}}
|
16
|
+
raise e
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'redcloth/version'
|
20
|
+
require 'redcloth/textile_doc'
|
21
|
+
require 'redcloth/formatters/base'
|
22
|
+
require 'redcloth/formatters/html'
|
23
|
+
require 'redcloth/formatters/latex'
|
24
|
+
|
25
|
+
module RedCloth
|
26
|
+
|
27
|
+
# A convenience method for creating a new TextileDoc. See
|
28
|
+
# RedCloth::TextileDoc.
|
29
|
+
def self.new( *args, &block )
|
30
|
+
RedCloth::TextileDoc.new( *args, &block )
|
31
|
+
end
|
32
|
+
|
33
|
+
# Include extension modules (if any) in TextileDoc.
|
34
|
+
def self.include(*args)
|
35
|
+
RedCloth::TextileDoc.send(:include, *args)
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
begin
|
41
|
+
require 'erb'
|
42
|
+
require 'redcloth/erb_extension'
|
43
|
+
include ERB::Util
|
44
|
+
rescue LoadError
|
45
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# Apparently this file gets loaded by Rails. Only want to define the pureruby
|
2
|
+
# task in the context of RedCloth compilation (echoe loaded).
|
3
|
+
|
4
|
+
if Gem::Specification.const_defined?(:PLATFORM_CROSS_TARGETS)
|
5
|
+
Gem::Specification::PLATFORM_CROSS_TARGETS << "pureruby"
|
6
|
+
|
7
|
+
task 'pureruby' do
|
8
|
+
reset_target 'pureruby'
|
9
|
+
end
|
10
|
+
|
11
|
+
if target = ARGV.detect do |arg|
|
12
|
+
# Hack to get the platform set before the Rakefile evaluates
|
13
|
+
Gem::Specification::PLATFORM_CROSS_TARGETS.include? arg
|
14
|
+
end
|
15
|
+
reset_target target
|
16
|
+
end
|
17
|
+
end
|
data/redcloth.gemspec
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
redcloth_dir = Dir.pwd =~ /redcloth\/tmp/ ? File.expand_path("../../../..", Dir.pwd) : File.expand_path("..", __FILE__)
|
3
|
+
$LOAD_PATH.unshift File.join(redcloth_dir, 'lib')
|
4
|
+
require "redcloth/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "parity-RedCloth"
|
8
|
+
s.version = RedCloth::VERSION.to_s
|
9
|
+
s.authors = ["Jason Garber", "why the lucky stiff", "Ola Bini", "Jimish Jobanputra"]
|
10
|
+
s.description = "Textile parser for Ruby with auto_link support."
|
11
|
+
s.summary = RedCloth::SUMMARY
|
12
|
+
s.email = "jimish@desidime.com"
|
13
|
+
s.homepage = "http://redcloth.org"
|
14
|
+
s.rubyforge_project = "redcloth"
|
15
|
+
|
16
|
+
s.rubygems_version = "1.3.7"
|
17
|
+
s.default_executable = "redcloth"
|
18
|
+
|
19
|
+
s.files = Dir['.gemtest', '.rspec', 'CHANGELOG', 'COPYING', 'Gemfile', 'README.rdoc', 'Rakefile', 'doc/**/*', 'bin/**/*', 'lib/**/*', 'redcloth.gemspec', 'spec/**/*', 'tasks/**/*']
|
20
|
+
s.test_files = Dir['spec/**/*']
|
21
|
+
s.executables = ['redcloth']
|
22
|
+
s.extra_rdoc_files = ["README.rdoc", "COPYING", "CHANGELOG"]
|
23
|
+
s.rdoc_options = ["--charset=UTF-8", "--line-numbers", "--inline-source", "--title", "RedCloth", "--main", "README.rdoc"]
|
24
|
+
s.require_paths += ["lib/case_sensitive_require", "ext"]
|
25
|
+
|
26
|
+
s.files -= Dir['lib/redcloth.jar']
|
27
|
+
s.files -= Dir['lib/**/*.dll']
|
28
|
+
s.files -= Dir['lib/**/*.bundle']
|
29
|
+
s.files -= Dir['lib/**/*.so']
|
30
|
+
|
31
|
+
s.platform = RUBY_PLATFORM[/java/] || 'ruby'
|
32
|
+
case s.platform.to_s
|
33
|
+
when /java/
|
34
|
+
s.files += ['lib/redcloth_scan.jar']
|
35
|
+
else # MRI or Rubinius
|
36
|
+
s.files += %w[attributes inline scan].map {|f| "ext/redcloth_scan/redcloth_#{f}.c"}
|
37
|
+
s.files += ["ext/redcloth_scan/redcloth.h"]
|
38
|
+
s.extensions = Dir['ext/**/extconf.rb']
|
39
|
+
end
|
40
|
+
|
41
|
+
s.add_development_dependency('bundler', '~> 1.9.1')
|
42
|
+
s.add_development_dependency('rake', '~> 10.0.3')
|
43
|
+
s.add_development_dependency('rspec', '~> 2.4')
|
44
|
+
s.add_development_dependency('diff-lcs', '~> 1.1.2')
|
45
|
+
|
46
|
+
# Have to load these even though they're only needed for
|
47
|
+
# gem packaging. Otherwise, Bundler complains that they're
|
48
|
+
# not installed even though they're not required.
|
49
|
+
# See https://github.com/carlhuda/bundler/issues/issue/1021
|
50
|
+
s.add_development_dependency('rvm', '~> 1.2.6')
|
51
|
+
s.add_development_dependency('rake-compiler', '~> 0.7.1')
|
52
|
+
|
53
|
+
s.license = "MIT"
|
54
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe "Benchmarking", :type => :formatter do
|
4
|
+
version = RedCloth::VERSION.is_a?(Module) ? RedCloth::VERSION::STRING : RedCloth::VERSION
|
5
|
+
platform = RedCloth.const_defined?(:EXTENSION_LANGUAGE) ? RedCloth::EXTENSION_LANGUAGE : (version < "4.0.0" ? "ruby-regex" : "C")
|
6
|
+
|
7
|
+
it "should not be too slow" do
|
8
|
+
# puts "Benchmarking version #{version} compiled in #{platform}..."
|
9
|
+
fixtures.each do |name, doc|
|
10
|
+
if doc['html']
|
11
|
+
RedCloth.new(doc['in']).to_html
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
module FigureTag
|
4
|
+
def fig( opts )
|
5
|
+
label, img = opts[:text].split('|').map! {|str| str.strip}
|
6
|
+
|
7
|
+
html = %Q{<div class="img" id="figure-#{label.tr('.', '-')}">\n}
|
8
|
+
html << %Q{ <a class="fig" href="/images/#{img}">\n}
|
9
|
+
html << %Q{ <img src="/images/thumbs/#{img}" alt="Figure #{label}" />\n}
|
10
|
+
html << %Q{ </a>\n}
|
11
|
+
html << %Q{ <p>Figure #{label}</p>\n}
|
12
|
+
html << %Q{<div>\n}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "custom tags" do
|
17
|
+
it "should recognize the custom tag" do
|
18
|
+
input = %Q{The first line of text.\n\n}
|
19
|
+
input << %Q{fig. 1.1 | img.jpg\n\n}
|
20
|
+
input << %Q{The last line of text.\n}
|
21
|
+
r = RedCloth.new input
|
22
|
+
r.extend FigureTag
|
23
|
+
|
24
|
+
html = %Q{<p>The first line of text.</p>\n}
|
25
|
+
html << %Q{<div class="img" id="figure-1-1">\n}
|
26
|
+
html << %Q{ <a class="fig" href="/images/img.jpg">\n}
|
27
|
+
html << %Q{ <img src="/images/thumbs/img.jpg" alt="Figure 1.1" />\n}
|
28
|
+
html << %Q{ </a>\n}
|
29
|
+
html << %Q{ <p>Figure 1.1</p>\n}
|
30
|
+
html << %Q{<div>\n}
|
31
|
+
html << %Q{<p>The last line of text.</p>}
|
32
|
+
|
33
|
+
r.to_html.should == html
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should fall back if custom tag isn't defined" do
|
37
|
+
r = RedCloth.new %Q/fig()>[no]{color:red}. 1.1 | img.jpg/
|
38
|
+
|
39
|
+
r.to_html.should == "<p>fig()>[no]{color:red}. 1.1 | img.jpg</p>"
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should not call just regular string methods" do
|
43
|
+
r = RedCloth.new "next. "
|
44
|
+
r.extend FigureTag
|
45
|
+
|
46
|
+
html = "<p>next. </p>"
|
47
|
+
|
48
|
+
r.to_html.should == html
|
49
|
+
end
|
50
|
+
end
|
data/spec/erb_spec.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
describe "ERB helper" do
|
4
|
+
it "should add a textile tag to ERB" do
|
5
|
+
template = %{<%=t "This new ERB tag makes is so _easy_ to use *RedCloth*" %>}
|
6
|
+
expected = %{<p>This new <span class="caps">ERB</span> tag makes is so <em>easy</em> to use <strong>RedCloth</strong></p>}
|
7
|
+
|
8
|
+
ERB.new(template).result.should == expected
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper'
|
2
|
+
|
3
|
+
# http://www.ralree.info/2006/9/13/extending-redcloth
|
4
|
+
module RedClothSmileyExtension
|
5
|
+
def refs_smiley(text)
|
6
|
+
text.gsub!(/(\s)~(:P|:D|:O|:o|:S|:\||;\)|:'\(|:\)|:\()/) do |m|
|
7
|
+
bef,ma = $~[1..2]
|
8
|
+
filename = "/images/emoticons/"+(ma.unpack("c*").join('_'))+".png"
|
9
|
+
"#{bef}<img src='#{filename}' title='#{ma}' class='smiley' />"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
RedCloth.send(:include, RedClothSmileyExtension)
|
15
|
+
|
16
|
+
describe RedClothSmileyExtension do
|
17
|
+
|
18
|
+
it "should include the extension" do
|
19
|
+
input = %Q{You're so silly! ~:P}
|
20
|
+
|
21
|
+
html = %Q{<p>You’re so silly! <img src='/images/emoticons/58_80.png' title=':P' class='smiley' /></p>}
|
22
|
+
|
23
|
+
RedCloth.new(input).to_html(:textile, :refs_smiley).should == html
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|