BBRedCloth 0.8.0
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.
- data/BBRedCloth.gemspec +36 -0
- data/CHANGELOG +123 -0
- data/COPYING +18 -0
- data/Manifest +45 -0
- data/README.textile +149 -0
- data/Rakefile +247 -0
- data/bin/bbredcloth +34 -0
- data/ext/mingw-rbconfig.rb +176 -0
- data/ext/redcloth_scan/extconf.rb +9 -0
- data/ext/redcloth_scan/redcloth.h +196 -0
- data/ext/redcloth_scan/redcloth_attributes.c +655 -0
- data/ext/redcloth_scan/redcloth_bbcode.c +2457 -0
- data/ext/redcloth_scan/redcloth_bbcode_inline.c +1890 -0
- data/ext/redcloth_scan/redcloth_inline.c +12387 -0
- data/ext/redcloth_scan/redcloth_scan.c +10848 -0
- data/extras/ragel_profiler.rb +73 -0
- data/lib/case_sensitive_require/RedCloth.rb +6 -0
- data/lib/redcloth/erb_extension.rb +27 -0
- data/lib/redcloth/formatters/base.rb +57 -0
- data/lib/redcloth/formatters/html.rb +487 -0
- data/lib/redcloth/formatters/latex.rb +249 -0
- data/lib/redcloth/formatters/latex_entities.yml +2414 -0
- data/lib/redcloth/textile_doc.rb +196 -0
- data/lib/redcloth/version.rb +28 -0
- data/lib/redcloth.rb +37 -0
- data/setup.rb +1585 -0
- data/test/basic.yml +933 -0
- data/test/code.yml +229 -0
- data/test/definitions.yml +82 -0
- data/test/extra_whitespace.yml +64 -0
- data/test/filter_html.yml +177 -0
- data/test/filter_pba.yml +20 -0
- data/test/helper.rb +109 -0
- data/test/html.yml +313 -0
- data/test/images.yml +254 -0
- data/test/instiki.yml +38 -0
- data/test/links.yml +275 -0
- data/test/lists.yml +283 -0
- data/test/poignant.yml +89 -0
- data/test/sanitize_html.yml +42 -0
- data/test/table.yml +267 -0
- data/test/test_custom_tags.rb +46 -0
- data/test/test_erb.rb +13 -0
- data/test/test_extensions.rb +31 -0
- data/test/test_formatters.rb +24 -0
- data/test/test_parser.rb +73 -0
- data/test/test_restrictions.rb +61 -0
- data/test/textism.yml +484 -0
- data/test/threshold.yml +772 -0
- data/test/validate_fixtures.rb +74 -0
- metadata +139 -0
|
@@ -0,0 +1,196 @@
|
|
|
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. The
|
|
34
|
+
# accessor is deprecated and will be removed in a
|
|
35
|
+
# future version.
|
|
36
|
+
#
|
|
37
|
+
attr_accessor :hard_breaks
|
|
38
|
+
|
|
39
|
+
# Accessor for toggling lite mode.
|
|
40
|
+
#
|
|
41
|
+
# In lite mode, block-level rules are ignored. This means
|
|
42
|
+
# that tables, paragraphs, lists, and such aren't available.
|
|
43
|
+
# Only the inline markup for bold, italics, entities and so on.
|
|
44
|
+
#
|
|
45
|
+
# r = RedCloth.new( "And then? She *fell*!", [:lite_mode] )
|
|
46
|
+
# r.to_html
|
|
47
|
+
# #=> "And then? She <strong>fell</strong>!"
|
|
48
|
+
#
|
|
49
|
+
attr_accessor :lite_mode
|
|
50
|
+
|
|
51
|
+
# Accessor for toggling BBCode
|
|
52
|
+
#
|
|
53
|
+
# BBCode is the language traditionally used in on a bulletin-board / forum
|
|
54
|
+
# to stylize text. When +:bbcode+ is set, it will enable the parsing of
|
|
55
|
+
# BBCode. Note that link aliases are disabled due to causing havoc on
|
|
56
|
+
# malformed coded. The following are the tags supported:
|
|
57
|
+
#
|
|
58
|
+
# * [b]
|
|
59
|
+
# * [i]
|
|
60
|
+
# * [u]
|
|
61
|
+
# * [s]
|
|
62
|
+
# * [ins]
|
|
63
|
+
# * [del]
|
|
64
|
+
# * [sup]
|
|
65
|
+
# * [sub]
|
|
66
|
+
# * [notextile]
|
|
67
|
+
# * [color]
|
|
68
|
+
# * [size]
|
|
69
|
+
# * [align]
|
|
70
|
+
# * [acronym]
|
|
71
|
+
# * [url]
|
|
72
|
+
# * [img]
|
|
73
|
+
# * [pre]
|
|
74
|
+
# * [quote]
|
|
75
|
+
# * [spoiler]
|
|
76
|
+
#
|
|
77
|
+
# r = RedCloth.new( "Some text is meant to be [b]bold[/b], others [i]italic[/i].", [:bbcode] )
|
|
78
|
+
# r.to_html
|
|
79
|
+
# #=> "<p>Some text is meant to be <strong>bold</strong>, others <em>italic</em>.</p>"
|
|
80
|
+
#
|
|
81
|
+
attr_accessor :bbcode
|
|
82
|
+
|
|
83
|
+
def bbcode=(boolean)
|
|
84
|
+
#link_aliases seriously mess up bbcode, so they MUST be disabled if using BBCode.
|
|
85
|
+
boolean ? (@disable_inline << :link_alias) : @disable_inline.delete(:link_alias)
|
|
86
|
+
@no_span_caps = true
|
|
87
|
+
@bbcode = boolean
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
# Accessor for toggling BBCode only
|
|
91
|
+
#
|
|
92
|
+
# When dealing with large size forums, a lot of older users are
|
|
93
|
+
# too used to BBCode and do not want to apply Textile. Use +:bbcode_only+
|
|
94
|
+
# to only parse BBCode without parsing Textile.
|
|
95
|
+
#
|
|
96
|
+
attr_accessor :bbcode_only
|
|
97
|
+
|
|
98
|
+
# Accessor for enabling the swear filter.
|
|
99
|
+
#
|
|
100
|
+
# Uses the HTML swear filters. May add more to RedCloth::Formatters::HTML::SWEARWORDS
|
|
101
|
+
attr_accessor :filter_swears
|
|
102
|
+
|
|
103
|
+
def bbcode_only=(boolean)
|
|
104
|
+
#span caps shouldn't apply since we're not parsing for Textile
|
|
105
|
+
@no_span_caps = boolean
|
|
106
|
+
@bbcode_only = boolean
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
#
|
|
110
|
+
# Accessor for toggling span caps.
|
|
111
|
+
#
|
|
112
|
+
# Textile places `span' tags around capitalized
|
|
113
|
+
# words by default, but this wreaks havoc on Wikis.
|
|
114
|
+
# If +:no_span_caps+ is set, this will be
|
|
115
|
+
# suppressed.
|
|
116
|
+
#
|
|
117
|
+
attr_accessor :no_span_caps
|
|
118
|
+
|
|
119
|
+
#
|
|
120
|
+
# Accessor for disabling inline elements.
|
|
121
|
+
#
|
|
122
|
+
# Depending upon the needs of the application,
|
|
123
|
+
# some inline elements, such as images, may be
|
|
124
|
+
# disabled using the array in +:disable_inline+.
|
|
125
|
+
#
|
|
126
|
+
# RedCloth.new( "Images should *not* be allowed! !test_image.jpg!" ).to_html
|
|
127
|
+
# #=> "<p>Images should <strong>not</strong> be allowed! <img src=\"test_image.jpg\" alt=\"\" /></p>"
|
|
128
|
+
# RedCloth.new( "Images should *not* be allowed! !test_image.jpg!", [:disable_inline=>:image] ).to_html
|
|
129
|
+
# #=> "<p>Images should <strong>not</strong> be allowed! !test_image.jpg!</p>"
|
|
130
|
+
# RedCloth.new( "Images should *not* be allowed! !test_image.jpg!", [:disable_inline=>[:image,:strong]] ).to_html
|
|
131
|
+
# #=> "<p>Images should *not* be allowed! !test_image.jpg!</p>"
|
|
132
|
+
#
|
|
133
|
+
attr_accessor :disable_inline
|
|
134
|
+
|
|
135
|
+
#
|
|
136
|
+
# Insures that disable_inline is an Array
|
|
137
|
+
#
|
|
138
|
+
def disable_inline=(disablers)
|
|
139
|
+
disablers.is_a?(Array) ?
|
|
140
|
+
@disable_inline = disablers :
|
|
141
|
+
@disable_inline = [disablers]
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
# Returns a new RedCloth object, based on _string_, observing
|
|
145
|
+
# any _restrictions_ specified.
|
|
146
|
+
#
|
|
147
|
+
# r = RedCloth.new( "h1. A *bold* man" )
|
|
148
|
+
# #=> "h1. A *bold* man"
|
|
149
|
+
# r.to_html
|
|
150
|
+
# #=>"<h1>A <b>bold</b> man</h1>"
|
|
151
|
+
#
|
|
152
|
+
def initialize( string, restrictions = [] )
|
|
153
|
+
@disable_inline = []
|
|
154
|
+
restrictions.each do |r|
|
|
155
|
+
case r
|
|
156
|
+
when Hash
|
|
157
|
+
r.each {|k,v| method("#{k}=").call( v )}
|
|
158
|
+
else
|
|
159
|
+
method("#{r}=").call( true )
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
super( string )
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
#
|
|
166
|
+
# Generates HTML from the Textile contents.
|
|
167
|
+
#
|
|
168
|
+
# RedCloth.new( "And then? She *fell*!" ).to_html
|
|
169
|
+
# #=>"<p>And then? She <strong>fell</strong>!</p>"
|
|
170
|
+
#
|
|
171
|
+
def to_html( *rules )
|
|
172
|
+
apply_rules(rules)
|
|
173
|
+
|
|
174
|
+
to(RedCloth::Formatters::HTML)
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
#
|
|
178
|
+
# Generates LaTeX from the Textile contents.
|
|
179
|
+
#
|
|
180
|
+
# RedCloth.new( "And then? She *fell*!" ).to_latex
|
|
181
|
+
# #=> "And then? She \\textbf{fell}!\n\n"
|
|
182
|
+
#
|
|
183
|
+
def to_latex( *rules )
|
|
184
|
+
apply_rules(rules)
|
|
185
|
+
|
|
186
|
+
to(RedCloth::Formatters::LATEX)
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
private
|
|
190
|
+
def apply_rules(rules)
|
|
191
|
+
rules.each do |r|
|
|
192
|
+
method(r).call(self) if self.respond_to?(r)
|
|
193
|
+
end
|
|
194
|
+
end
|
|
195
|
+
end
|
|
196
|
+
end
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
module RedCloth
|
|
2
|
+
module VERSION
|
|
3
|
+
MAJOR = 0
|
|
4
|
+
MINOR = 8
|
|
5
|
+
TINY = 0
|
|
6
|
+
RELEASE_CANDIDATE = nil
|
|
7
|
+
|
|
8
|
+
STRING = [MAJOR, MINOR, TINY].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 = "BBRedCloth"
|
|
24
|
+
GEM_NAME = NAME
|
|
25
|
+
URL = "http://redcloth.org/"
|
|
26
|
+
|
|
27
|
+
DESCRIPTION = "#{NAME}-#{VERSION::FULL_VERSION} - Textile parser for Ruby. Includes BBCode additions.\n#{URL}"
|
|
28
|
+
end
|
data/lib/redcloth.rb
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
$:.unshift(File.dirname(__FILE__))
|
|
2
|
+
|
|
3
|
+
# If this is a frozen gem in Rails 2.1 and RedCloth 3.x was already
|
|
4
|
+
# loaded by Rails' ActionView::Helpers::TextHelper, the user will get
|
|
5
|
+
# "redcloth_scan.bundle: Class is not a module (TypeError)"
|
|
6
|
+
# This hack is to work around that Rails loading problem. The problem
|
|
7
|
+
# appears to be fixed in Edge Rails [51e4106].
|
|
8
|
+
Object.send(:remove_const, :RedCloth) if Object.const_defined?(:RedCloth) && RedCloth.is_a?(Class)
|
|
9
|
+
|
|
10
|
+
require 'redcloth_scan'
|
|
11
|
+
require 'redcloth/version'
|
|
12
|
+
require 'redcloth/textile_doc'
|
|
13
|
+
require 'redcloth/formatters/base'
|
|
14
|
+
require 'redcloth/formatters/html'
|
|
15
|
+
require 'redcloth/formatters/latex'
|
|
16
|
+
|
|
17
|
+
module RedCloth
|
|
18
|
+
|
|
19
|
+
# A convenience method for creating a new TextileDoc. See
|
|
20
|
+
# RedCloth::TextileDoc.
|
|
21
|
+
def self.new( *args, &block )
|
|
22
|
+
RedCloth::TextileDoc.new( *args, &block )
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Include extension modules (if any) in TextileDoc.
|
|
26
|
+
def self.include(*args)
|
|
27
|
+
RedCloth::TextileDoc.send(:include, *args)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
begin
|
|
33
|
+
require 'erb'
|
|
34
|
+
require 'redcloth/erb_extension'
|
|
35
|
+
include ERB::Util
|
|
36
|
+
rescue LoadError
|
|
37
|
+
end
|