RedCloth 4.0.3 → 4.0.4

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.

@@ -39,7 +39,9 @@ int SYM_escape_preformatted, SYM_escape_attributes;
39
39
  footnote_start = ( ftype A C :> dotspace ) ;
40
40
  ul = "*" %{nest++; list_type = "ul";};
41
41
  ol = "#" %{nest++; list_type = "ol";};
42
- list_start = ( ( ul | ol )+ N A C :> " "+ ) >{nest = 0;} ;
42
+ ul_start = ( ul | ol )* ul A C :> " "+ ;
43
+ ol_start = ( ul | ol )* ol N A C :> " "+ ;
44
+ list_start = ( ul_start | ol_start ) >{nest = 0;} ;
43
45
  dt_start = "-" . " "+ ;
44
46
  dd_start = ":=" ;
45
47
  long_dd = dd_start " "* LF %{ ADD_BLOCK(); ASET(type, dd); } any+ >A %{ TRANSFORM(text) } :>> "=:" ;
@@ -294,7 +296,7 @@ int SYM_escape_preformatted, SYM_escape_attributes;
294
296
  dl := |*
295
297
  LF dt_start { ADD_BLOCK(); ASET(type, dt); };
296
298
  dd_start { ADD_BLOCK(); ASET(type, dd); };
297
- long_dd { INLINE(html, dd); };
299
+ long_dd { INLINE(html, dd); CLEAR_REGS(); };
298
300
  block_end { ADD_BLOCK(); INLINE(html, dl_close); fgoto main; };
299
301
  default => cat;
300
302
  *|;
@@ -361,7 +363,7 @@ redcloth_transform(self, p, pe, refs)
361
363
 
362
364
  %% write exec;
363
365
 
364
- if (RSTRING(block)->len > 0)
366
+ if (RSTRING_LEN(block) > 0)
365
367
  {
366
368
  ADD_BLOCK();
367
369
  }
@@ -381,7 +383,7 @@ redcloth_transform2(self, str)
381
383
  rb_str_cat2(str, "\n");
382
384
  StringValue(str);
383
385
  rb_funcall(self, rb_intern("before_transform"), 1, str);
384
- return redcloth_transform(self, RSTRING(str)->ptr, RSTRING(str)->ptr + RSTRING(str)->len + 1, Qnil);
386
+ return redcloth_transform(self, RSTRING_PTR(str), RSTRING_PTR(str) + RSTRING_LEN(str) + 1, Qnil);
385
387
  }
386
388
 
387
389
  /*
@@ -395,12 +397,15 @@ redcloth_html_esc(int argc, VALUE* argv, VALUE self) //(self, str, level)
395
397
  rb_scan_args(argc, argv, "11", &str, &level);
396
398
 
397
399
  VALUE new_str = rb_str_new2("");
400
+ if (str == Qnil)
401
+ return new_str;
402
+
398
403
  StringValue(str);
399
404
 
400
- if (RSTRING(str)->len == 0)
405
+ if (RSTRING_LEN(str) == 0)
401
406
  return new_str;
402
407
 
403
- char *ts = RSTRING(str)->ptr, *te = RSTRING(str)->ptr + RSTRING(str)->len;
408
+ char *ts = RSTRING_PTR(str), *te = RSTRING_PTR(str) + RSTRING_LEN(str);
404
409
  char *t = ts, *t2 = ts, *ch = NULL;
405
410
  if (te <= ts) return;
406
411
 
@@ -450,9 +455,16 @@ static VALUE
450
455
  redcloth_latex_esc(VALUE self, VALUE str)
451
456
  {
452
457
  VALUE new_str = rb_str_new2("");
458
+
459
+ if (str == Qnil)
460
+ return new_str;
461
+
453
462
  StringValue(str);
454
463
 
455
- char *ts = RSTRING(str)->ptr, *te = RSTRING(str)->ptr + RSTRING(str)->len;
464
+ if (RSTRING_LEN(str) == 0)
465
+ return new_str;
466
+
467
+ char *ts = RSTRING_PTR(str), *te = RSTRING_PTR(str) + RSTRING_LEN(str);
456
468
  char *t = ts, *t2 = ts, *ch = NULL;
457
469
  if (te <= ts) return;
458
470
 
@@ -34,8 +34,8 @@ module RedCloth::Formatters
34
34
  RedCloth::VERSION::STRING
35
35
  end
36
36
 
37
- [:del_phrase, :sup_phrase, :sub_phrase].each do |phrase_method|
38
- method = phrase_method.to_s[0..2]
37
+ [:del_phrase, :sup_phrase, :sub_phrase, :span_phrase].each do |phrase_method|
38
+ method = phrase_method.to_s.split('_')[0]
39
39
  define_method(phrase_method) do |opts|
40
40
  "#{opts[:beginning_space]}#{self.send(method, opts)}"
41
41
  end
@@ -172,6 +172,10 @@ module RedCloth::Formatters::HTML
172
172
  "&#8220;#{opts[:text]}&#8221;"
173
173
  end
174
174
 
175
+ def multi_paragraph_quote(opts)
176
+ "&#8220;#{opts[:text]}"
177
+ end
178
+
175
179
  def ellipsis(opts)
176
180
  "#{opts[:text]}&#8230;"
177
181
  end
@@ -4,6 +4,15 @@ module RedCloth::Formatters::LATEX
4
4
  include RedCloth::Formatters::Base
5
5
 
6
6
  ENTITIES = YAML::load(File.read(File.dirname(__FILE__)+'/latex_entities.yml'))
7
+
8
+ module Settings
9
+ # Maps CSS style names to latex formatting options
10
+ def latex_image_styles
11
+ @latex_image_class_styles ||= {}
12
+ end
13
+ end
14
+
15
+ RedCloth::TextileDoc.send(:include, Settings)
7
16
 
8
17
  def escape(text)
9
18
  latex_esc(text)
@@ -136,8 +145,23 @@ module RedCloth::Formatters::LATEX
136
145
  end
137
146
 
138
147
  # FIXME: use includegraphics with security verification
148
+ #
149
+ # Remember to use '\RequirePackage{graphicx}' in your LaTeX header
150
+ #
151
+ # FIXME: Look at dealing with width / height gracefully as this should be
152
+ # specified in a unit like cm rather than px.
139
153
  def image(opts)
140
- ""
154
+ # Don't know how to use remote links, plus can we trust them?
155
+ return "" if opts[:src] =~ /^\w+\:\/\//
156
+ # Resolve CSS styles if any have been set
157
+ styling = opts[:class].to_s.split(/\s+/).collect { |style| latex_image_styles[style] }.compact.join ','
158
+ # Build latex code
159
+ [ "\\begin{figure}[htp]",
160
+ " \\includegraphics[#{styling}]{#{opts[:src]}}",
161
+ (" \\caption{#{escape opts[:title]}}" if opts[:title]),
162
+ (" \\label{#{escape opts[:alt]}}" if opts[:alt]),
163
+ "\\end{figure}",
164
+ ].compact.join "\n"
141
165
  end
142
166
 
143
167
  def footno(opts)
@@ -204,12 +228,14 @@ module RedCloth::Formatters::LATEX
204
228
 
205
229
  private
206
230
 
231
+ # Use this for block level commands that use \begin
207
232
  def begin_chunk(type)
208
233
  chunk_counter[type] += 1
209
234
  return "\\begin{#{type}}" if 1 == chunk_counter[type]
210
235
  ''
211
236
  end
212
237
 
238
+ # Use this for block level commands that use \end
213
239
  def end_chunk(type)
214
240
  chunk_counter[type] -= 1
215
241
  raise RuntimeError, "Bad latex #{type} nesting detected" if chunk_counter[type] < 0 # This should never need to happen
@@ -2,7 +2,7 @@ module RedCloth
2
2
  module VERSION
3
3
  MAJOR = 4
4
4
  MINOR = 0
5
- TINY = 3
5
+ TINY = 4
6
6
  RELEASE_CANDIDATE = nil
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY].join('.')
Binary file
data/test/basic.yml CHANGED
@@ -110,6 +110,15 @@ name: curly quotes
110
110
  desc: Single- and double-quotes around words or phrases are converted to curly quotations, much easier on the eye.
111
111
  in: "\"Observe!\""
112
112
  html: <p>&#8220;Observe!&#8221;</p>
113
+ ---
114
+ name: quotes contained in multi-paragraph quotes
115
+ in: |-
116
+ "I first learned about this thing called "Redcloth" several years ago.
117
+
118
+ "It's wonderful."
119
+ html: |-
120
+ <p>&#8220;I first learned about this thing called &#8220;Redcloth&#8221; several years ago.</p>
121
+ <p>&#8220;It&#8217;s wonderful.&#8221;</p>
113
122
  ---
114
123
  name: double hyphens
115
124
  desc: Double hyphens are replaced with an em-dash.
@@ -225,6 +234,11 @@ desc: Strength can be give to text by surrounding with asterisks. In HTML, this
225
234
  in: And then? She *fell*!
226
235
  html: <p>And then? She <strong>fell</strong>!</p>
227
236
  lite_mode_html: "And then? She <strong>fell</strong>!"
237
+ ---
238
+ name: strong phrase beginning with a number
239
+ desc: A strong phrase at the beginning of a line that begins with a number should not be recognized as a ul with a start value (no such thing)
240
+ in: "*10 times as many*"
241
+ html: "<p><strong>10 times as many</strong></p>"
228
242
  ---
229
243
  name: force bold italics
230
244
  desc: Both italics and bold can be forced by doubling the underscores or asterisks.
@@ -264,12 +278,20 @@ name: superscript
264
278
  desc: To superscript a phrase, surround with carets.
265
279
  in: a ^2^ + b ^2^ = c ^2^
266
280
  html: <p>a <sup>2</sup> + b <sup>2</sup> = c <sup>2</sup></p>
281
+ ---
282
+ name: parenthetical superscript phrase
283
+ in: '^(image courtesy NASA)^'
284
+ html: '<p><sup>(image courtesy <span class="caps">NASA</span>)</sup></p>'
267
285
  ---
268
286
  name: subscript
269
287
  desc: To subscript, surround with tildes.
270
288
  in: log ~2~ x
271
289
  html: <p>log <sub>2</sub> x</p>
272
290
  ---
291
+ name: parenthetical subscript phrase
292
+ in: '~(image courtesy NASA)~'
293
+ html: '<p><sub>(image courtesy <span class="caps">NASA</span>)</sub></p>'
294
+ ---
273
295
  name: tight superscript and subscript
274
296
  desc: if you want your superscript or subscript to not be surrounded by spaces, you must use square brackets
275
297
  in: f(x, n) = log[~4~]x[^n^]
@@ -291,6 +313,15 @@ html: |-
291
313
  lite_mode_html: |-
292
314
  I&#8217;m <span style="color:red;">unaware</span><br />
293
315
  of most soft drinks.
316
+ ---
317
+ name: percent sign
318
+ desc: though percent signs indicate a span, they shouldn't be overly greedy.
319
+ in: |-
320
+ http://blah.com/one%20two%20three
321
+ (min)5%-95%(max)
322
+ html: |-
323
+ <p>http://blah.com/one%20two%20three<br />
324
+ (min)5%-95%(max)</p>
294
325
  ---
295
326
  name: css class
296
327
  desc: A block can be tagged with a CSS class by circling the class in parentheses and placing it just before the period which marks the block.
@@ -812,4 +843,29 @@ name: underscores in parentheses in quotes 2
812
843
  in: |-
813
844
  "one (two _three four_) five"
814
845
  html: |-
815
- <p>&#8220;one (two <em>three four</em>) five&#8221;</p>
846
+ <p>&#8220;one (two <em>three four</em>) five&#8221;</p>
847
+ ---
848
+ name: caps in parentheses
849
+ desc: Uppercase words of three or more characters that are in parentheses should be recognized as well as those not in parentheses.
850
+ in: IBM or (HAL)
851
+ html: <p><span class="caps">IBM</span> or (<span class="caps">HAL</span>)</p>
852
+ no_span_caps_html: <p>IBM or (HAL)</p>
853
+ ---
854
+ name: phrase modifiers in parentheses
855
+ desc: Inline modifiers are expected to work in parentheses as well.
856
+ in: |-
857
+ __Amanita__s are mushrooms.
858
+ Lungworts (__Lobaria__) are lichens.
859
+ Blah blah (normal text **bold**) blah.
860
+ html: |-
861
+ <p>__Amanita__s are mushrooms.<br />
862
+ Lungworts (<i>Lobaria</i>) are lichens.<br />
863
+ Blah blah (normal text <b>bold</b>) blah.</p>
864
+ ---
865
+ name: square brackets are preserved
866
+ in: |-
867
+ citation ["(Berk.) Hilton"], see
868
+ [Papers "blah blah."]
869
+ html: |-
870
+ <p>citation [&#8220;(Berk.) Hilton&#8221;], see<br />
871
+ [Papers &#8220;blah blah.&#8221;]</p>
data/test/html.yml CHANGED
@@ -296,4 +296,10 @@ html: |-
296
296
  ---
297
297
  name: tilde in innerHTML is not altered
298
298
  in: '<a href="http://foo.com/bar?something=1~2~3">http://foo.com/bar?something=1~2~3</a>'
299
- html: '<p><a href="http://foo.com/bar?something=1~2~3">http://foo.com/bar?something=1~2~3</a></p>'
299
+ html: '<p><a href="http://foo.com/bar?something=1~2~3">http://foo.com/bar?something=1~2~3</a></p>'
300
+ ---
301
+ name: empty block
302
+ in: |-
303
+ <embed src="test.swf"></embed>
304
+ html: |-
305
+ <embed src="test.swf"></embed>
data/test/images.yml CHANGED
@@ -1,12 +1,27 @@
1
1
  ---
2
2
  in: This is an !image.jpg!
3
3
  html: <p>This is an <img src="image.jpg" alt="" /></p>
4
+ latex: |+
5
+ This is an \begin{figure}[htp]
6
+ \includegraphics[]{image.jpg}
7
+ \end{figure}
8
+
4
9
  ---
5
10
  in: This is an !image.jpg(with alt text)!
6
11
  html: <p>This is an <img src="image.jpg" title="with alt text" alt="with alt text" /></p>
12
+ latex: |+
13
+ This is an \begin{figure}[htp]
14
+ \includegraphics[]{image.jpg}
15
+ \caption{with alt text}
16
+ \end{figure}
17
+
7
18
  ---
8
19
  in: This is an !http://example.com/i/image.jpg!
9
20
  html: <p>This is an <img src="http://example.com/i/image.jpg" alt="" /></p>
21
+ # Note that we are removing remote links fro security reasons for now
22
+ latex: |+
23
+ This is an
24
+
10
25
  ---
11
26
  in: This is an !http://example.com/i/image.jpg#a1!
12
27
  html: <p>This is an <img src="http://example.com/i/image.jpg#a1" alt="" /></p>
@@ -176,6 +191,11 @@ html: <p>(This is an <a href="http://example.com/index.html?foo=bar&amp;a=b#a10"
176
191
  name: image with relative src with dot
177
192
  in: "!../../image.jpg!"
178
193
  html: <p><img src="../../image.jpg" alt="" /></p>
194
+ latex: |+
195
+ \begin{figure}[htp]
196
+ \includegraphics[]{../../image.jpg}
197
+ \end{figure}
198
+
179
199
  ---
180
200
  name: image with class
181
201
  in: "!(myclass)image.jpg!"
@@ -204,10 +224,22 @@ html: <p><img src="image.jpg" style="color:red;" alt="" /></p>
204
224
  name: image attributes has ampersand html entity in alt and title
205
225
  in: "!/pictures/cat_and_fox.jpg(Trady Blix & The cartoon fox)!"
206
226
  html: '<p><img src="/pictures/cat_and_fox.jpg" title="Trady Blix &amp; The cartoon fox" alt="Trady Blix &amp; The cartoon fox" /></p>'
227
+ latex: |+
228
+ \begin{figure}[htp]
229
+ \includegraphics[]{/pictures/cat_and_fox.jpg}
230
+ \caption{Trady Blix \& The cartoon fox}
231
+ \end{figure}
232
+
207
233
  ---
208
234
  name: image attributes has double quote html entity in alt and title
209
235
  in: '!/pictures/bacon.jpg(The fox said: "Have some chunky bacon")!'
210
236
  html: '<p><img src="/pictures/bacon.jpg" title="The fox said: &quot;Have some chunky bacon&quot;" alt="The fox said: &quot;Have some chunky bacon&quot;" /></p>'
237
+ latex: |+
238
+ \begin{figure}[htp]
239
+ \includegraphics[]{/pictures/bacon.jpg}
240
+ \caption{The fox said: "Have some chunky bacon"}
241
+ \end{figure}
242
+
211
243
  ---
212
244
  name: image attributes has single quote html entity in alt and title
213
245
  in: "!/pictures/bacon.jpg(The fox said: 'Have some chunky bacon')!"
data/test/links.yml CHANGED
@@ -205,6 +205,10 @@ name: linked quoted phrase
205
205
  in: '""Open the pod bay doors please, HAL."":http://www.youtube.com/watch?v=npN9l2Bd06s'
206
206
  html: '<p><a href="http://www.youtube.com/watch?v=npN9l2Bd06s">&#8220;Open the pod bay doors please, <span class="caps">HAL</span>.&#8221;</a></p>'
207
207
  ---
208
+ name: link following quoted phrase
209
+ in: '"quote" text "quote" text "link":http://google.com'
210
+ html: '<p>&#8220;quote&#8221; text &#8220;quote&#8221; text <a href="http://google.com">link</a></p>'
211
+ ---
208
212
  name: links containing underscores
209
213
  in: 'This is a link to a "Wikipedia article about Barack":http://en.wikipedia.org/wiki/Barack_Obama'
210
214
  html: '<p>This is a link to a <a href="http://en.wikipedia.org/wiki/Barack_Obama">Wikipedia article about Barack</a></p>'
@@ -228,4 +232,28 @@ in: |-
228
232
 
229
233
  [google-rocks]http://google.com
230
234
  html: |-
231
- <p><a href="http://google.com">link</a></p>
235
+ <p><a href="http://google.com">link</a></p>
236
+ ---
237
+ name: contained in multi-paragraph quotes
238
+ in: |-
239
+ "I first learned about "Redcloth":http://redcloth.org/ several years ago.
240
+
241
+ "It's wonderful."
242
+ html: |-
243
+ <p>&#8220;I first learned about <a href="http://redcloth.org/">Redcloth</a> several years ago.</p>
244
+ <p>&#8220;It&#8217;s wonderful.&#8221;</p>
245
+ ---
246
+ name: as html in notextile contained in multi-paragraph quotes
247
+ in: |-
248
+ "Here is a <notextile><a href="http://redcloth.org/">link</a></notextile>.
249
+
250
+ "I like links."
251
+ html: |-
252
+ <p>&#8220;Here is a <a href="http://redcloth.org/">link</a>.</p>
253
+ <p>&#8220;I like links.&#8221;</p>
254
+ ---
255
+ name: contained in para with multiple quotes
256
+ in: |-
257
+ "My wife, Tipper, and I will donate 100% of the proceeds of the award to the "Alliance For Climate Protection":http://www.looktothestars.org/charity/638-alliance-for-climate-protection," said Gore in an email. "I am deeply honored to receive the Nobel Peace Prize."
258
+ html: |-
259
+ <p>&#8220;My wife, Tipper, and I will donate 100% of the proceeds of the award to the <a href="http://www.looktothestars.org/charity/638-alliance-for-climate-protection">Alliance For Climate Protection</a>,&#8221; said Gore in an email. &#8220;I am deeply honored to receive the Nobel Peace Prize.&#8221;</p>
@@ -11,7 +11,7 @@ class TestExtensions < Test::Unit::TestCase
11
11
  def refs_smiley(text)
12
12
  text.gsub!(/(\s)~(:P|:D|:O|:o|:S|:\||;\)|:'\(|:\)|:\()/) do |m|
13
13
  bef,ma = $~[1..2]
14
- filename = "/images/emoticons/"+(ma.split(//).collect{|l| l[0] }.join('_'))+".png"
14
+ filename = "/images/emoticons/"+(ma.unpack("c*").join('_'))+".png"
15
15
  "#{bef}<img src='#{filename}' title='#{ma}' class='smiley' />"
16
16
  end
17
17
  end
@@ -8,8 +8,17 @@ class TestFormatters < Test::Unit::TestCase
8
8
  RedCloth.new(doc['in']).to_html
9
9
  end
10
10
 
11
+ def test_html_orphan_parenthesis_in_link_can_be_followed_by_punctuation_and_words
12
+ assert_nothing_raised { RedCloth.new(%Q{Test "(read this":http://test.host), ok}).to_html }
13
+ end
14
+
11
15
  generate_formatter_tests('latex') do |doc|
12
16
  RedCloth.new(doc['in']).to_latex
13
17
  end
14
18
 
19
+ def test_latex_orphan_parenthesis_in_link_can_be_followed_by_punctuation_and_words
20
+ assert_nothing_raised { RedCloth.new(%Q{Test "(read this":http://test.host), ok}).to_latex }
21
+ end
22
+
23
+
15
24
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: RedCloth
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.3
4
+ version: 4.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Garber
@@ -9,11 +9,11 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-08-18 00:00:00 -04:00
12
+ date: 2008-10-02 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
16
- description: RedCloth-4.0.3 - Textile parser for Ruby. http://redcloth.org/
16
+ description: RedCloth-4.0.4 - Textile parser for Ruby. http://redcloth.org/
17
17
  email: redcloth-upwards@rubyforge.org
18
18
  executables:
19
19
  - redcloth
@@ -98,9 +98,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
98
  requirements: []
99
99
 
100
100
  rubyforge_project: redcloth
101
- rubygems_version: 1.1.1
101
+ rubygems_version: 1.2.0
102
102
  signing_key:
103
103
  specification_version: 2
104
- summary: RedCloth-4.0.3 - Textile parser for Ruby. http://redcloth.org/
104
+ summary: RedCloth-4.0.4 - Textile parser for Ruby. http://redcloth.org/
105
105
  test_files: []
106
106