RedCloth 4.1.1-universal-java → 4.1.9-universal-java

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.

@@ -1,19 +1,18 @@
1
1
  /*
2
2
  * redcloth_scan.rl
3
3
  *
4
- * Copyright (C) 2008 Jason Garber
4
+ * Copyright (C) 2009 Jason Garber
5
5
  */
6
6
  %%{
7
7
 
8
8
  machine redcloth_scan;
9
9
 
10
10
  # blocks
11
- notextile_tag_start = "<notextile>" ;
12
- notextile_tag_end = "</notextile>" LF? ;
11
+ notextile_tag = notextile (LF | EOF) ;
13
12
  noparagraph_line_start = " "+ ;
14
13
  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? ;
14
+ pre_tag_start = "<pre" [^>]* ">" (space* code_tag_start)? ;
15
+ pre_tag_end = (code_tag_end space*)? "</pre>" LF? ;
17
16
  pre_block_start = ( "pre" >A %{ STORE("type"); } A C :> "." ( "." %extend | "" ) " "+ ) ;
18
17
  bc_start = ( "bc" >A %{ STORE("type"); } A C :> "." ( "." %extend | "" ) " "+ ) ;
19
18
  bq_start = ( "bq" >A %{ STORE("type"); } A C :> "." ( "." %extend | "" ) ( ":" %A uri %{ STORE("cite"); } )? " "+ ) ;
@@ -30,7 +29,7 @@
30
29
  ol = "#" %{nest++; list_type = "ol";};
31
30
  ul_start = ( ul | ol )* ul A C :> " "+ ;
32
31
  ol_start = ( ul | ol )* ol N A C :> " "+ ;
33
- list_start = ( ul_start | ol_start ) >{nest = 0;} ;
32
+ list_start = " "* ( ul_start | ol_start ) >{nest = 0;} ;
34
33
  dt_start = "-" . " "+ ;
35
34
  dd_start = ":=" ;
36
35
  long_dd = dd_start " "* LF %{ ADD_BLOCK(); ASET("type", "dd"); } any+ >A %{ TRANSFORM("text"); } :>> "=:" ;
@@ -109,11 +108,6 @@
109
108
  LF { ADD_BLOCK(); fgoto main; };
110
109
  default => cat;
111
110
  *|;
112
-
113
- notextile_tag := |*
114
- notextile_tag_end { ADD_BLOCK(); fgoto main; };
115
- default => cat;
116
- *|;
117
111
 
118
112
  notextile_block := |*
119
113
  EOF {
@@ -178,6 +172,7 @@
178
172
  } else {
179
173
  ADD_EXTENDED_BLOCKCODE();
180
174
  CAT(html);
175
+ RSTRIP_BANG(html);
181
176
  INLINE(html, "bc_close");
182
177
  SET_PLAIN_BLOCK("p");
183
178
  END_EXTENDED();
@@ -293,7 +288,7 @@
293
288
 
294
289
  main := |*
295
290
  noparagraph_line_start { ASET("type", "ignored_line"); fgoto noparagraph_line; };
296
- notextile_tag_start { ASET("type", "notextile"); fgoto notextile_tag; };
291
+ notextile_tag { INLINE(block, "notextile"); };
297
292
  notextile_block_start { ASET("type", "notextile"); fgoto notextile_block; };
298
293
  script_tag_start { CAT(block); fgoto script_tag; };
299
294
  pre_tag_start { ASET("type", "notextile"); CAT(block); fgoto pre_tag; };
@@ -1,26 +1,6 @@
1
1
  module RedCloth::Formatters
2
2
  module Base
3
3
 
4
- def pba(opts)
5
- opts.delete(:style) if filter_styles
6
- opts.delete(:class) if filter_classes
7
- opts.delete(:id) if filter_ids
8
-
9
- atts = ''
10
- opts[:"text-align"] = opts.delete(:align)
11
- opts[:style] += ';' if opts[:style] && (opts[:style][-1..-1] != ';')
12
- [:float, :"text-align", :"vertical-align"].each do |a|
13
- opts[:style] = "#{a}:#{opts[a]};#{opts[:style]}" if opts[a]
14
- end
15
- [:"padding-right", :"padding-left"].each do |a|
16
- opts[:style] = "#{a}:#{opts[a]}em;#{opts[:style]}" if opts[a]
17
- end
18
- [:style, :class, :lang, :id, :colspan, :rowspan, :title, :start, :align].each do |a|
19
- atts << " #{a}=\"#{ html_esc(opts[a].to_s, :html_escape_attributes) }\"" if opts[a]
20
- end
21
- atts
22
- end
23
-
24
4
  def ignore(opts)
25
5
  opts[:text]
26
6
  end
@@ -41,6 +21,28 @@ module RedCloth::Formatters
41
21
  end
42
22
  end
43
23
 
24
+ private
25
+
26
+ def pba(opts)
27
+ opts.delete(:style) if filter_styles
28
+ opts.delete(:class) if filter_classes
29
+ opts.delete(:id) if filter_ids
30
+
31
+ atts = ''
32
+ opts[:"text-align"] = opts.delete(:align)
33
+ opts[:style] += ';' if opts[:style] && (opts[:style][-1..-1] != ';')
34
+ [:float, :"text-align", :"vertical-align"].each do |a|
35
+ opts[:style] = "#{a}:#{opts[a]};#{opts[:style]}" if opts[a]
36
+ end
37
+ [:"padding-right", :"padding-left"].each do |a|
38
+ opts[:style] = "#{a}:#{opts[a]}em;#{opts[:style]}" if opts[a]
39
+ end
40
+ [:style, :class, :lang, :id, :colspan, :rowspan, :title, :start, :align].each do |a|
41
+ atts << " #{a}=\"#{ html_esc(opts[a].to_s, :html_escape_attributes) }\"" if opts[a]
42
+ end
43
+ atts
44
+ end
45
+
44
46
  def method_missing(method, opts)
45
47
  opts[:text] || ""
46
48
  end
@@ -52,6 +54,10 @@ module RedCloth::Formatters
52
54
  def after_transform(text)
53
55
 
54
56
  end
57
+
58
+ def formatter_methods
59
+ singleton_methods.map! {|method| method.to_sym }
60
+ end
55
61
 
56
62
  end
57
63
  end
@@ -1,25 +1,6 @@
1
1
  module RedCloth::Formatters::HTML
2
2
  include RedCloth::Formatters::Base
3
3
 
4
- # escapement for regular HTML (not in PRE tag)
5
- def escape(text)
6
- html_esc(text)
7
- end
8
-
9
- # escapement for HTML in a PRE tag
10
- def escape_pre(text)
11
- html_esc(text, :html_escape_preformatted)
12
- end
13
-
14
- # escaping for HTML attributes
15
- def escape_attribute(text)
16
- html_esc(text, :html_escape_attributes)
17
- end
18
-
19
- def after_transform(text)
20
- text.chomp!
21
- end
22
-
23
4
  [:h1, :h2, :h3, :h4, :h5, :h6, :p, :pre, :div].each do |m|
24
5
  define_method(m) do |opts|
25
6
  "<#{m}#{pba(opts)}>#{opts[:text]}</#{m}>\n"
@@ -129,18 +110,7 @@ module RedCloth::Formatters::HTML
129
110
  "</blockquote>\n"
130
111
  end
131
112
 
132
- LINK_TEXT_WITH_TITLE_RE = /
133
- ([^"]+?) # $text
134
- \s?
135
- \(([^)]+?)\) # $title
136
- $
137
- /x
138
113
  def link(opts)
139
- if opts[:name] =~ LINK_TEXT_WITH_TITLE_RE
140
- md = LINK_TEXT_WITH_TITLE_RE.match(opts[:name])
141
- opts[:name] = md[1]
142
- opts[:title] = md[2]
143
- end
144
114
  "<a href=\"#{escape_attribute opts[:href]}\"#{pba(opts)}>#{opts[:name]}</a>"
145
115
  end
146
116
 
@@ -281,6 +251,28 @@ module RedCloth::Formatters::HTML
281
251
  opts[:text] + "\n"
282
252
  end
283
253
 
254
+ private
255
+
256
+ # escapement for regular HTML (not in PRE tag)
257
+ def escape(text)
258
+ html_esc(text)
259
+ end
260
+
261
+ # escapement for HTML in a PRE tag
262
+ def escape_pre(text)
263
+ html_esc(text, :html_escape_preformatted)
264
+ end
265
+
266
+ # escaping for HTML attributes
267
+ def escape_attribute(text)
268
+ html_esc(text, :html_escape_attributes)
269
+ end
270
+
271
+ def after_transform(text)
272
+ text.chomp!
273
+ end
274
+
275
+
284
276
  def before_transform(text)
285
277
  clean_html(text) if sanitize_html
286
278
  end
@@ -14,14 +14,6 @@ module RedCloth::Formatters::LATEX
14
14
 
15
15
  RedCloth::TextileDoc.send(:include, Settings)
16
16
 
17
- def escape(text)
18
- latex_esc(text)
19
- end
20
-
21
- def escape_pre(text)
22
- text
23
- end
24
-
25
17
  # headers
26
18
  { :h1 => 'section*',
27
19
  :h2 => 'subsection*',
@@ -38,7 +30,7 @@ module RedCloth::Formatters::LATEX
38
30
  # commands
39
31
  { :strong => 'textbf',
40
32
  :em => 'emph',
41
- :i => 'emph',
33
+ :i => 'textit',
42
34
  :b => 'textbf',
43
35
  :ins => 'underline',
44
36
  :del => 'sout',
@@ -102,24 +94,50 @@ module RedCloth::Formatters::LATEX
102
94
  end
103
95
 
104
96
  def td(opts)
105
- "\t\t\t#{opts[:text]} &\n"
97
+ column = @table_row.size
98
+ if opts[:colspan]
99
+ opts[:text] = "\\multicolumn{#{opts[:colspan]}}{ #{"l " * opts[:colspan].to_i}}{#{opts[:text]}}"
100
+ end
101
+ if opts[:rowspan]
102
+ @table_multirow_next[column] = opts[:rowspan].to_i - 1
103
+ opts[:text] = "\\multirow{#{opts[:rowspan]}}{*}{#{opts[:text]}}"
104
+ end
105
+ @table_row.push(opts[:text])
106
+ return ""
106
107
  end
107
108
 
108
109
  def tr_open(opts)
109
- "\t\t"
110
+ @table_row = []
111
+ return ""
110
112
  end
111
113
 
112
114
  def tr_close(opts)
113
- "\t\t\\\\\n"
115
+ multirow_columns = @table_multirow.find_all {|c,n| n > 0}
116
+ multirow_columns.each do |c,n|
117
+ @table_row.insert(c,"")
118
+ @table_multirow[c] -= 1
119
+ end
120
+ @table_multirow.merge!(@table_multirow_next)
121
+ @table_multirow_next = {}
122
+ @table.push(@table_row)
123
+ return ""
114
124
  end
115
125
 
116
- # FIXME: we need to know the column count before opening tabular context.
126
+ # We need to know the column count before opening tabular context.
117
127
  def table_open(opts)
118
- "\\begin{align*}\n"
128
+ @table = []
129
+ @table_multirow = {}
130
+ @table_multirow_next = {}
131
+ return ""
119
132
  end
120
133
 
121
134
  def table_close(opts)
122
- "\t\\end{align*}\n"
135
+ output = "\\begin{tabular}{ #{"l " * @table[0].size }}\n"
136
+ @table.each do |row|
137
+ output << " #{row.join(" & ")} \\\\\n"
138
+ end
139
+ output << "\\end{tabular}\n"
140
+ output
123
141
  end
124
142
 
125
143
  def bc_open(opts)
@@ -222,12 +240,22 @@ module RedCloth::Formatters::LATEX
222
240
  end
223
241
 
224
242
  def dim(opts)
225
- space = opts[:space] ? " " : ''
226
- "#{opts[:text]}#{space}\\texttimes{}#{space}"
243
+ opts[:text].gsub!('x', '\times')
244
+ opts[:text].gsub!('"', "''")
245
+ period = opts[:text].slice!(/\.$/)
246
+ "$#{opts[:text]}$#{period}"
227
247
  end
228
248
 
229
249
  private
230
250
 
251
+ def escape(text)
252
+ latex_esc(text)
253
+ end
254
+
255
+ def escape_pre(text)
256
+ text
257
+ end
258
+
231
259
  # Use this for block level commands that use \begin
232
260
  def begin_chunk(type)
233
261
  chunk_counter[type] += 1
@@ -30,9 +30,7 @@ module RedCloth
30
30
  # Traditional RedCloth converted single newlines
31
31
  # to HTML break tags, but later versions required
32
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.
33
+ # +:hard_breaks+ is once again the default.
36
34
  #
37
35
  attr_accessor :hard_breaks
38
36
 
@@ -2,7 +2,7 @@ module RedCloth
2
2
  module VERSION
3
3
  MAJOR = 4
4
4
  MINOR = 1
5
- TINY = 1
5
+ TINY = 9
6
6
  RELEASE_CANDIDATE = nil
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY].join('.')
Binary file
@@ -164,27 +164,33 @@ name: dimension sign
164
164
  desc: The letter 'x' becomes a dimension sign when used between digits.
165
165
  in: "Observe: 2x3."
166
166
  html: "<p>Observe: 2&#215;3.</p>"
167
+ latex: "Observe: $2\\times3$.\n\n"
167
168
  ---
168
169
  name: dimension sign with space after
169
170
  in: "The room is 2x3 inches big."
170
171
  html: "<p>The room is 2&#215;3 inches big.</p>"
172
+ latex: "The room is $2\\times3$ inches big.\n\n"
171
173
  ---
172
174
  name: dimension sign with spaces
173
175
  in: "Observe: 2 x 4."
174
176
  html: "<p>Observe: 2 &#215; 4.</p>"
177
+ latex: "Observe: $2 \\times 4$.\n\n"
175
178
  ---
176
179
  name: dimension signs chained
177
180
  in: "Observe: 2x3x4."
178
181
  html: "<p>Observe: 2&#215;3&#215;4.</p>"
179
182
  lite_mode_html: "Observe: 2&#215;3&#215;4."
183
+ latex: "Observe: $2\\times3\\times4$.\n\n"
180
184
  ---
181
185
  name: dimension signs with double primes
182
186
  in: 'My mouse: 2.5" x 4".'
183
187
  html: '<p>My mouse: 2.5&#8243; &#215; 4&#8243;.</p>'
188
+ latex: "My mouse: $2.5'' \\times 4''$.\n\n"
184
189
  ---
185
190
  name: dimension signs with single primes
186
191
  in: "My office: 5' x 4.5'."
187
192
  html: "<p>My office: 5&#8242; &#215; 4.5&#8242;.</p>"
193
+ latex: "My office: $5' \\times 4.5'$.\n\n"
188
194
  ---
189
195
  name: trademark and copyright
190
196
  desc: Conversion of trademark and copyright symbols.
@@ -266,7 +272,11 @@ html: <p>Please email why@domain.com or jason@domain.com.</p>
266
272
  name: del
267
273
  desc: To indicate a passage which has been deleted, surround the passage with hypens.
268
274
  in: I'm -sure- not sure.
269
- html: <p>I&#8217;m <del>sure</del> not sure.</p>
275
+ html: "<p>I&#8217;m <del>sure</del> not sure.</p>"
276
+ ---
277
+ name: del beginning a phrase
278
+ in: -delete-
279
+ html: "<p><del>delete</del></p>"
270
280
  ---
271
281
  name: ins
272
282
  desc: Pluses around a passage indicate its insertion.
@@ -915,4 +925,8 @@ in: |-
915
925
  html: |-
916
926
  <p>Just some <em>_</em> text</p>
917
927
  <hr />
918
- <p>Some more text.</p>
928
+ <p>Some more text.</p>
929
+ ---
930
+ name: lang attribute cannot contain square brackets
931
+ in: "some @[[code]]@"
932
+ html: "<p>some <code>[[code]]</code></p>"
@@ -96,7 +96,10 @@ in: |-
96
96
  <notextile>
97
97
  # *test*
98
98
  html: |-
99
- # *test*
99
+ <p><notextile></p>
100
+ <ol>
101
+ <li><strong>test</strong></li>
102
+ </ol>
100
103
  valid_html: false
101
104
  ---
102
105
  name: unfinished script tag
@@ -140,9 +143,7 @@ html: |-
140
143
  <pre><code>./foo.pl%
141
144
  &lt;p&gt;foo outputs an HTML paragraph&lt;/p&gt;</code>
142
145
 
143
- <code>&lt;p&gt;block of code keeps going until a different block signature is encountered&lt;/p&gt;</code>
144
-
145
- </pre>
146
+ <code>&lt;p&gt;block of code keeps going until a different block signature is encountered&lt;/p&gt;</code></pre>
146
147
  <p>And then go back with a normal paragraph.</p>
147
148
  ---
148
149
  name: extended block code preserves leading whitespace after blank line
@@ -167,9 +168,7 @@ html: |-
167
168
  <code> def baz
168
169
  'baz'
169
170
  end
170
- end</code>
171
-
172
- </pre>
171
+ end</code></pre>
173
172
  <p>That&#8217;s it!</p>
174
173
  ---
175
174
  name: block code containing code avoids nesting code tags
@@ -308,4 +308,18 @@ name: objects in paragraphs are not modified
308
308
  in: |-
309
309
  <p><object width="340" height="280"><param name="movie" value="http://www.youtube.com/v/iUbK1cBHm6E"></param><param name="wmode" value="opaque"></param><param name="allowScriptAccess" value="sameDomain"></param><embed src="http://www.youtube.com/v/iUbK1cBHm6E" type="application/x-shockwave-flash" width="340" height="280" wmode="opaque" allowScriptAccess="sameDomain"></embed></object></p>
310
310
  html: |-
311
- <p><object width="340" height="280"><param name="movie" value="http://www.youtube.com/v/iUbK1cBHm6E"></param><param name="wmode" value="opaque"></param><param name="allowScriptAccess" value="sameDomain"></param><embed src="http://www.youtube.com/v/iUbK1cBHm6E" type="application/x-shockwave-flash" width="340" height="280" wmode="opaque" allowScriptAccess="sameDomain"></embed></object></p>
311
+ <p><object width="340" height="280"><param name="movie" value="http://www.youtube.com/v/iUbK1cBHm6E"></param><param name="wmode" value="opaque"></param><param name="allowScriptAccess" value="sameDomain"></param><embed src="http://www.youtube.com/v/iUbK1cBHm6E" type="application/x-shockwave-flash" width="340" height="280" wmode="opaque" allowScriptAccess="sameDomain"></embed></object></p>
312
+ ---
313
+ name: in code escaped properly
314
+ in: "<pre><code>some <b>bold</b> text</code></pre>"
315
+ html: "<pre><code>some &lt;b&gt;bold&lt;/b&gt; text</code></pre>"
316
+ ---
317
+ name: in code with class attribute escaped properly
318
+ in: "<pre><code class='myclass'>some <b>bold</b> text</code></pre>"
319
+ html: "<pre><code class='myclass'>some &lt;b&gt;bold&lt;/b&gt; text</code></pre>"
320
+ ---
321
+ name: notextile beginning the line
322
+ in: |-
323
+ <notextile><a href="http://a.com">Sir Bobby Robson</a></notextile>, is a famous footballer
324
+ html: |-
325
+ <p><a href="http://a.com">Sir Bobby Robson</a>, is a famous footballer</p>
@@ -244,3 +244,26 @@ latex: |+
244
244
  name: image attributes has single quote html entity in alt and title
245
245
  in: "!/pictures/bacon.jpg(The fox said: 'Have some chunky bacon')!"
246
246
  html: '<p><img src="/pictures/bacon.jpg" title="The fox said: &#39;Have some chunky bacon&#39;" alt="The fox said: &#39;Have some chunky bacon&#39;" /></p>'
247
+ ---
248
+ name: in square brackets
249
+ in: This is an [!image.jpg!] you see.
250
+ html: <p>This is an <img src="image.jpg" alt="" /> you see.</p>
251
+ ---
252
+ name: with link in square brackets
253
+ in: This is an [!image.jpg!:http://example.com/] you see.
254
+ html: <p>This is an <a href="http://example.com/"><img src="image.jpg" alt="" /></a> you see.</p>
255
+ ---
256
+ name: url containing parentheses
257
+ in: "!http://commons.wikimedia.org/wiki/File:Rubis_sur_calcite_2(Vietnam).jpg!"
258
+ html: |-
259
+ <p><img src="http://commons.wikimedia.org/wiki/File:Rubis_sur_calcite_2(Vietnam).jpg" alt="" /></p>
260
+ ---
261
+ name: with alt and url containing parentheses
262
+ in: "!http://commons.wikimedia.org/wiki/File:Rubis_sur_calcite_2(Vietnam).jpg(a big rock)!"
263
+ html: |-
264
+ <p><img src="http://commons.wikimedia.org/wiki/File:Rubis_sur_calcite_2(Vietnam).jpg" title="a big rock" alt="a big rock" /></p>
265
+ ---
266
+ name: with link that contains parentheses
267
+ in: "!image.jpg(Alt text with (parentheses).)!"
268
+ html: |-
269
+ <p><img src="image.jpg" title="Alt text with (parentheses)." alt="Alt text with (parentheses)." /></p>