jeremy-RedCloth 4.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. data/CHANGELOG +135 -0
  2. data/COPYING +18 -0
  3. data/Manifest +56 -0
  4. data/README +171 -0
  5. data/Rakefile +205 -0
  6. data/bin/redcloth +28 -0
  7. data/ext/mingw-rbconfig.rb +176 -0
  8. data/ext/redcloth_scan/extconf.rb +9 -0
  9. data/ext/redcloth_scan/redcloth.h +178 -0
  10. data/ext/redcloth_scan/redcloth_attributes.c.rl +56 -0
  11. data/ext/redcloth_scan/redcloth_attributes.java.rl +96 -0
  12. data/ext/redcloth_scan/redcloth_attributes.rl +33 -0
  13. data/ext/redcloth_scan/redcloth_common.c.rl +18 -0
  14. data/ext/redcloth_scan/redcloth_common.java.rl +18 -0
  15. data/ext/redcloth_scan/redcloth_common.rl +111 -0
  16. data/ext/redcloth_scan/redcloth_inline.c.rl +159 -0
  17. data/ext/redcloth_scan/redcloth_inline.java.rl +108 -0
  18. data/ext/redcloth_scan/redcloth_inline.rl +159 -0
  19. data/ext/redcloth_scan/redcloth_scan.c.rl +237 -0
  20. data/ext/redcloth_scan/redcloth_scan.java.rl +573 -0
  21. data/ext/redcloth_scan/redcloth_scan.rl +325 -0
  22. data/extras/ragel_profiler.rb +73 -0
  23. data/lib/case_sensitive_require/RedCloth.rb +6 -0
  24. data/lib/redcloth.rb +37 -0
  25. data/lib/redcloth/erb_extension.rb +27 -0
  26. data/lib/redcloth/formatters/base.rb +57 -0
  27. data/lib/redcloth/formatters/html.rb +353 -0
  28. data/lib/redcloth/formatters/latex.rb +275 -0
  29. data/lib/redcloth/formatters/latex_entities.yml +2414 -0
  30. data/lib/redcloth/textile_doc.rb +103 -0
  31. data/lib/redcloth/version.rb +28 -0
  32. data/setup.rb +1585 -0
  33. data/test/basic.yml +922 -0
  34. data/test/code.yml +229 -0
  35. data/test/definitions.yml +82 -0
  36. data/test/extra_whitespace.yml +64 -0
  37. data/test/filter_html.yml +177 -0
  38. data/test/filter_pba.yml +20 -0
  39. data/test/helper.rb +108 -0
  40. data/test/html.yml +311 -0
  41. data/test/images.yml +254 -0
  42. data/test/instiki.yml +38 -0
  43. data/test/links.yml +275 -0
  44. data/test/lists.yml +283 -0
  45. data/test/poignant.yml +89 -0
  46. data/test/sanitize_html.yml +42 -0
  47. data/test/table.yml +336 -0
  48. data/test/test_custom_tags.rb +58 -0
  49. data/test/test_erb.rb +13 -0
  50. data/test/test_extensions.rb +31 -0
  51. data/test/test_formatters.rb +24 -0
  52. data/test/test_parser.rb +73 -0
  53. data/test/test_restrictions.rb +41 -0
  54. data/test/textism.yml +480 -0
  55. data/test/threshold.yml +772 -0
  56. data/test/validate_fixtures.rb +74 -0
  57. metadata +133 -0
@@ -0,0 +1,325 @@
1
+ /*
2
+ * redcloth_scan.rl
3
+ *
4
+ * Copyright (C) 2008 Jason Garber
5
+ */
6
+ %%{
7
+
8
+ machine redcloth_scan;
9
+
10
+ # blocks
11
+ notextile_tag_start = "<notextile>" ;
12
+ notextile_tag_end = "</notextile>" LF? ;
13
+ noparagraph_line_start = " "+ ;
14
+ notextile_block_start = ( "notextile" >A %{ STORE("type"); } A C :> "." ( "." %extend | "" ) " "+ ) ;
15
+ pre_tag_start = "<pre" [^>]* ">" (space* "<code>")? ;
16
+ pre_tag_end = ("</code>" space*)? "</pre>" LF? ;
17
+ pre_block_start = ( "pre" >A %{ STORE("type"); } A C :> "." ( "." %extend | "" ) " "+ ) ;
18
+ bc_start = ( "bc" >A %{ STORE("type"); } A C :> "." ( "." %extend | "" ) " "+ ) ;
19
+ bq_start = ( "bq" >A %{ STORE("type"); } A C :> "." ( "." %extend | "" ) ( ":" %A uri %{ STORE("cite"); } )? " "+ ) ;
20
+ non_ac_btype = ( "bq" | "bc" | "pre" | "notextile" );
21
+ btype = (alpha alnum*) -- (non_ac_btype | "fn" digit+);
22
+ block_start = ( btype >A %{ STORE("type"); } A C :> "." ( "." %extend | "" ) " "+ ) >B %{ STORE_B("fallback"); };
23
+ all_btypes = btype | non_ac_btype;
24
+ next_block_start = ( all_btypes A_noactions C_noactions :> "."+ " " ) >A @{ p = reg - 1; } ;
25
+ double_return = LF{2,} ;
26
+ block_end = ( double_return | EOF );
27
+ ftype = ( "fn" >A %{ STORE("type"); } digit+ >A %{ STORE("id"); } ) ;
28
+ footnote_start = ( ftype A C :> dotspace ) ;
29
+ ul = "*" %{nest++; list_type = "ul";};
30
+ ol = "#" %{nest++; list_type = "ol";};
31
+ ul_start = ( ul | ol )* ul A C :> " "+ ;
32
+ ol_start = ( ul | ol )* ol N A C :> " "+ ;
33
+ list_start = ( ul_start | ol_start ) >{nest = 0;} ;
34
+ dt_start = "-" . " "+ ;
35
+ dd_start = ":=" ;
36
+ long_dd = dd_start " "* LF %{ ADD_BLOCK(); ASET("type", "dd"); } any+ >A %{ TRANSFORM("text"); } :>> "=:" ;
37
+ dl_start = (dt_start mtext (LF dt_start mtext)* " "* dd_start) ;
38
+ blank_line = LF;
39
+ link_alias = ( "[" >{ ASET("type", "ignore"); } %A chars %T "]" %A uri %{ STORE_URL("href"); } ) ;
40
+ horizontal_rule = '*'{3,} | '-'{3,} | '_'{3,} ;
41
+
42
+ # image lookahead
43
+ IMG_A_LEFT = "<" %{ ASET("float", "left"); } ;
44
+ IMG_A_RIGHT = ">" %{ ASET("float", "right"); } ;
45
+ aligned_image = ( "["? "!" (IMG_A_LEFT | IMG_A_RIGHT) ) >A @{ p = reg - 1; } ;
46
+
47
+ # html blocks
48
+ BlockTagName = Name - ("pre" | "notextile" | "a" | "applet" | "basefont" | "bdo" | "br" | "font" | "iframe" | "img" | "map" | "object" | "param" | "embed" | "q" | "script" | "span" | "sub" | "sup" | "abbr" | "acronym" | "cite" | "code" | "del" | "dfn" | "em" | "ins" | "kbd" | "samp" | "strong" | "var" | "b" | "big" | "i" | "s" | "small" | "strike" | "tt" | "u");
49
+ block_start_tag = "<" BlockTagName space+ AttrSet* (AttrEnd)? ">" | "<" BlockTagName ">";
50
+ block_empty_tag = "<" BlockTagName space+ AttrSet* (AttrEnd)? "/>" | "<" BlockTagName "/>" ;
51
+ block_end_tag = "</" BlockTagName space* ">" ;
52
+ html_start = indent >B %{STORE_B("indent_before_start");} block_start_tag >B %{STORE_B("start_tag");} indent >B %{STORE_B("indent_after_start");} ;
53
+ html_end = indent >B %{STORE_B("indent_before_end");} block_end_tag >B %{STORE_B("end_tag");} (indent LF?) >B %{STORE_B("indent_after_end");} ;
54
+ standalone_html = indent (block_start_tag | block_empty_tag | block_end_tag) indent (LF+ | EOF);
55
+ html_end_terminating_block = ( LF indent block_end_tag ) >A @{ p = reg - 1; } ;
56
+
57
+ # tables
58
+ para = ( default+ ) -- LF ;
59
+ btext = para ( LF{2} )? ;
60
+ tddef = ( D? S A C :> dotspace ) ;
61
+ td = ( tddef? btext >A %T :> "|" >{PASS(table, "text", "td");} ) >X ;
62
+ trdef = ( A C :> dotspace ) ;
63
+ tr = ( trdef? "|" %{INLINE(table, "tr_open");} td+ ) >X %{INLINE(table, "tr_close");} ;
64
+ trows = ( tr (LF >X tr)* ) ;
65
+ tdef = ( "table" >X A C :> dotspace LF ) ;
66
+ table = ( tdef? trows >{CLEAR(table); INLINE(table, "table_open"); RESET_REG();} ) ;
67
+
68
+ # info
69
+ redcloth_version = ("RedCloth" >A ("::" | " " ) "VERSION"i ":"? " ")? %{STORE("prefix");} "RedCloth::VERSION" (LF* EOF | double_return) ;
70
+
71
+ pre_tag := |*
72
+ pre_tag_end { CAT(block); DONE(block); fgoto main; };
73
+ default => esc_pre;
74
+ *|;
75
+
76
+ pre_block := |*
77
+ EOF {
78
+ ADD_BLOCKCODE();
79
+ fgoto main;
80
+ };
81
+ double_return {
82
+ if (IS_NOT_EXTENDED()) {
83
+ ADD_BLOCKCODE();
84
+ fgoto main;
85
+ } else {
86
+ ADD_EXTENDED_BLOCKCODE();
87
+ }
88
+ };
89
+ double_return next_block_start {
90
+ if (IS_NOT_EXTENDED()) {
91
+ ADD_BLOCKCODE();
92
+ fgoto main;
93
+ } else {
94
+ ADD_EXTENDED_BLOCKCODE();
95
+ END_EXTENDED();
96
+ fgoto main;
97
+ }
98
+ };
99
+ default => esc_pre;
100
+ *|;
101
+
102
+ script_tag := |*
103
+ script_tag_end { CAT(block); ASET("type", "ignore"); ADD_BLOCK(); fgoto main; };
104
+ EOF { ASET("type", "ignore"); ADD_BLOCK(); fgoto main; };
105
+ default => cat;
106
+ *|;
107
+
108
+ noparagraph_line := |*
109
+ LF { ADD_BLOCK(); fgoto main; };
110
+ default => cat;
111
+ *|;
112
+
113
+ notextile_tag := |*
114
+ notextile_tag_end { ADD_BLOCK(); fgoto main; };
115
+ default => cat;
116
+ *|;
117
+
118
+ notextile_block := |*
119
+ EOF {
120
+ ADD_BLOCK();
121
+ fgoto main;
122
+ };
123
+ double_return {
124
+ if (IS_NOT_EXTENDED()) {
125
+ ADD_BLOCK();
126
+ CAT(html);
127
+ fgoto main;
128
+ } else {
129
+ CAT(block);
130
+ ADD_EXTENDED_BLOCK();
131
+ CAT(html);
132
+ }
133
+ };
134
+ double_return next_block_start {
135
+ if (IS_NOT_EXTENDED()) {
136
+ ADD_BLOCK();
137
+ CAT(html);
138
+ fgoto main;
139
+ } else {
140
+ CAT(block);
141
+ ADD_EXTENDED_BLOCK();
142
+ END_EXTENDED();
143
+ fgoto main;
144
+ }
145
+ };
146
+ default => cat;
147
+ *|;
148
+
149
+ html := |*
150
+ html_end { ADD_BLOCK(); fgoto main; };
151
+ default => cat;
152
+ *|;
153
+
154
+ bc := |*
155
+ EOF {
156
+ ADD_BLOCKCODE();
157
+ INLINE(html, "bc_close");
158
+ SET_PLAIN_BLOCK("p");
159
+ fgoto main;
160
+ };
161
+ double_return {
162
+ if (IS_NOT_EXTENDED()) {
163
+ ADD_BLOCKCODE();
164
+ INLINE(html, "bc_close");
165
+ SET_PLAIN_BLOCK("p");
166
+ fgoto main;
167
+ } else {
168
+ ADD_EXTENDED_BLOCKCODE();
169
+ CAT(html);
170
+ }
171
+ };
172
+ double_return next_block_start {
173
+ if (IS_NOT_EXTENDED()) {
174
+ ADD_BLOCKCODE();
175
+ INLINE(html, "bc_close");
176
+ SET_PLAIN_BLOCK("p");
177
+ fgoto main;
178
+ } else {
179
+ ADD_EXTENDED_BLOCKCODE();
180
+ CAT(html);
181
+ INLINE(html, "bc_close");
182
+ SET_PLAIN_BLOCK("p");
183
+ END_EXTENDED();
184
+ fgoto main;
185
+ }
186
+ };
187
+ default => esc_pre;
188
+ *|;
189
+
190
+ bq := |*
191
+ EOF {
192
+ ADD_BLOCK();
193
+ INLINE(html, "bq_close");
194
+ fgoto main;
195
+ };
196
+ double_return {
197
+ if (IS_NOT_EXTENDED()) {
198
+ ADD_BLOCK();
199
+ INLINE(html, "bq_close");
200
+ fgoto main;
201
+ } else {
202
+ ADD_EXTENDED_BLOCK();
203
+ }
204
+ };
205
+ double_return next_block_start {
206
+ if (IS_NOT_EXTENDED()) {
207
+ ADD_BLOCK();
208
+ INLINE(html, "bq_close");
209
+ fgoto main;
210
+ } else {
211
+ ADD_EXTENDED_BLOCK();
212
+ INLINE(html, "bq_close");
213
+ END_EXTENDED();
214
+ fgoto main;
215
+ }
216
+ };
217
+ html_end_terminating_block {
218
+ if (IS_NOT_EXTENDED()) {
219
+ ADD_BLOCK();
220
+ INLINE(html, "bq_close");
221
+ fgoto main;
222
+ } else {
223
+ ADD_EXTENDED_BLOCK();
224
+ INLINE(html, "bq_close");
225
+ END_EXTENDED();
226
+ fgoto main;
227
+ }
228
+ };
229
+ default => cat;
230
+ *|;
231
+
232
+ block := |*
233
+ EOF {
234
+ ADD_BLOCK();
235
+ fgoto main;
236
+ };
237
+ double_return {
238
+ if (IS_NOT_EXTENDED()) {
239
+ ADD_BLOCK();
240
+ fgoto main;
241
+ } else {
242
+ ADD_EXTENDED_BLOCK();
243
+ }
244
+ };
245
+ double_return next_block_start {
246
+ if (IS_NOT_EXTENDED()) {
247
+ ADD_BLOCK();
248
+ fgoto main;
249
+ } else {
250
+ ADD_EXTENDED_BLOCK();
251
+ END_EXTENDED();
252
+ fgoto main;
253
+ }
254
+ };
255
+ html_end_terminating_block {
256
+ if (IS_NOT_EXTENDED()) {
257
+ ADD_BLOCK();
258
+ fgoto main;
259
+ } else {
260
+ ADD_EXTENDED_BLOCK();
261
+ END_EXTENDED();
262
+ fgoto main;
263
+ }
264
+ };
265
+ LF list_start {
266
+ ADD_BLOCK();
267
+ CLEAR_LIST();
268
+ LIST_ITEM();
269
+ fgoto list;
270
+ };
271
+
272
+ default => cat;
273
+ *|;
274
+
275
+ footnote := |*
276
+ block_end { ADD_BLOCK(); fgoto main; };
277
+ default => cat;
278
+ *|;
279
+
280
+ list := |*
281
+ LF list_start { ADD_BLOCK(); LIST_ITEM(); };
282
+ block_end { ADD_BLOCK(); nest = 0; LIST_CLOSE(); fgoto main; };
283
+ default => cat;
284
+ *|;
285
+
286
+ dl := |*
287
+ LF dt_start { ADD_BLOCK(); ASET("type", "dt"); };
288
+ dd_start { ADD_BLOCK(); ASET("type", "dd"); };
289
+ long_dd { INLINE(html, "dd"); CLEAR_REGS(); };
290
+ block_end { ADD_BLOCK(); INLINE(html, "dl_close"); fgoto main; };
291
+ default => cat;
292
+ *|;
293
+
294
+ main := |*
295
+ noparagraph_line_start { ASET("type", "ignored_line"); fgoto noparagraph_line; };
296
+ notextile_tag_start { ASET("type", "notextile"); fgoto notextile_tag; };
297
+ notextile_block_start { ASET("type", "notextile"); fgoto notextile_block; };
298
+ script_tag_start { CAT(block); fgoto script_tag; };
299
+ pre_tag_start { ASET("type", "notextile"); CAT(block); fgoto pre_tag; };
300
+ pre_block_start { fgoto pre_block; };
301
+ standalone_html { ASET("type", "html"); CAT(block); ADD_BLOCK(); };
302
+ html_start { ASET("type", "html_block"); fgoto html; };
303
+ bc_start { INLINE(html, "bc_open"); ASET("type", "code"); SET_PLAIN_BLOCK("code"); fgoto bc; };
304
+ bq_start { INLINE(html, "bq_open"); ASET("type", "p"); fgoto bq; };
305
+ block_start { fgoto block; };
306
+ footnote_start { fgoto footnote; };
307
+ horizontal_rule { INLINE(html, "hr"); };
308
+ list_start { CLEAR_LIST(); LIST_ITEM(); fgoto list; };
309
+ dl_start { p = ts; INLINE(html, "dl_open"); ASET("type", "dt"); fgoto dl; };
310
+ table { INLINE(table, "table_close"); DONE(table); fgoto block; };
311
+ link_alias { STORE_LINK_ALIAS(); DONE(block); };
312
+ aligned_image { RESET_TYPE(); fgoto block; };
313
+ redcloth_version { INLINE(html, "redcloth_version"); };
314
+ blank_line => cat;
315
+ default
316
+ {
317
+ CLEAR_REGS();
318
+ RESET_TYPE();
319
+ CAT(block);
320
+ fgoto block;
321
+ };
322
+ EOF;
323
+ *|;
324
+
325
+ }%%;
@@ -0,0 +1,73 @@
1
+ class RagelProfiler
2
+ MEM_CONVERSION = 1024
3
+
4
+ COMMANDS = { :compile => %w(ragel rlgen-cd gcc-4.0 gnumake cc1),
5
+ :test => %w(ruby) }
6
+
7
+ FIELDS = %w(compile_time compile_max_rss test_time test_max_rss ext_so_size)
8
+
9
+ @@results = {}
10
+
11
+ def initialize(name)
12
+ @name = name
13
+ @@results[name] = []
14
+ end
15
+
16
+ def measure(type)
17
+ raise "not a valid type" unless COMMANDS.keys.include?(type)
18
+ regex = COMMANDS[type].map {|c| Regexp.escape(c) }.join("|")
19
+ t = Thread.new do
20
+ Thread.current[:max] = 0
21
+ loop do
22
+ Thread.current[:max] = [run(regex), Thread.current[:max]].max
23
+ sleep 0.5
24
+ end
25
+ end
26
+ begin_time = Time.now
27
+ yield
28
+ total_time = Time.now - begin_time
29
+
30
+ t.kill
31
+ store_result(type, "time", total_time)
32
+ store_result(type, "max_rss", t[:max])
33
+ end
34
+
35
+ def ext_size(ext_so)
36
+ store_result(:ext_so, "size", File.size(ext_so) / MEM_CONVERSION)
37
+ end
38
+
39
+ def self.results
40
+ out = []
41
+ out << "name\t" + FIELDS.join("\t")
42
+ @@results.each do |name, results|
43
+ out << [name, results ].flatten.join("\t")
44
+ end
45
+ out.join("\n")
46
+ end
47
+
48
+ private
49
+
50
+ def store_result(type, metric, value)
51
+ index = FIELDS.index("#{type.to_s}_#{metric}")
52
+ @@results[@name][index] = "%.2f" % value
53
+ end
54
+
55
+ def run(ps_regex)
56
+ ps_command = "ps axucww"
57
+ ps_output = `#{ps_command}`
58
+ fields = ps_output.to_a.first.downcase.split
59
+ memory_index = fields.index("rss")
60
+ pid_index = fields.index("pid")
61
+ ppid_index = fields.index("ppid")
62
+ total = ps_output.grep(/(#{ps_regex})\s+$/i).map do |com|
63
+ Float(com.split[memory_index]).abs
64
+ end.inject(0) { |s,v| s += v }
65
+ if total
66
+ return total/MEM_CONVERSION
67
+ else
68
+ STDERR.puts "Command not found. No processes found matching #{ps_regex}."
69
+ end
70
+
71
+ end
72
+
73
+ end
@@ -0,0 +1,6 @@
1
+ # A workaround to make Rails 2.1 gem dependency easier on case-sensitive filesystems.
2
+ # Since the gem name is RedCloth and the file is redcloth.rb, config.gem 'RedCloth' doesn't
3
+ # work. You'd have to use config.gem 'RedCloth', :lib => 'redcloth', and that's not
4
+ # immediately obvious. This file remedies that.
5
+ #
6
+ require File.join(File.dirname(__FILE__), '..', 'redcloth')
@@ -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
@@ -0,0 +1,27 @@
1
+ class ERB
2
+ module Util
3
+
4
+ #
5
+ # A utility method for transforming Textile in _s_ to HTML.
6
+ #
7
+ # require "erb"
8
+ # include ERB::Util
9
+ #
10
+ # puts textilize("Isn't ERB *great*?")
11
+ #
12
+ # _Generates_
13
+ #
14
+ # <p>Isn&#8217;t <span class="caps">ERB</span> <strong>great</strong>?</p>
15
+ #
16
+ def textilize( s )
17
+ if s && s.respond_to?(:to_s)
18
+ RedCloth.new( s.to_s ).to_html
19
+ end
20
+ end
21
+
22
+ alias t textilize
23
+ module_function :t
24
+ module_function :textilize
25
+
26
+ end
27
+ end