RedCloth problem with a nested list

S

Stephan Kämper

Hi all,

The test given below leaves me with this result:


Loaded suite E:/test_redcloth_nestedlist
Started
F.
Finished in 0.03 seconds.

1) Failure:
test_all_in_one_go(Test_Nested_List) [E:/test_redcloth_nestedlist.rb:15]:
Exception raised:
Class: <NoMethodError>
Message: <"undefined method `length' for nil:NilClass">
---Backtrace---
C:/ruby/lib/ruby/site_ruby/1.8/redcloth.rb:457:in `lists'
C:/ruby/lib/ruby/site_ruby/1.8/redcloth.rb:446:in `each_with_index'
C:/ruby/lib/ruby/site_ruby/1.8/redcloth.rb:446:in `each'
C:/ruby/lib/ruby/site_ruby/1.8/redcloth.rb:446:in `each_with_index'
C:/ruby/lib/ruby/site_ruby/1.8/redcloth.rb:446:in `lists'
C:/ruby/lib/ruby/site_ruby/1.8/redcloth.rb:442:in `gsub!'
C:/ruby/lib/ruby/site_ruby/1.8/redcloth.rb:442:in `lists'
C:/ruby/lib/ruby/site_ruby/1.8/redcloth.rb:787:in `inline'
C:/ruby/lib/ruby/site_ruby/1.8/redcloth.rb:239:in `to_html'
E:/test_redcloth_nestedlist.rb:14:in `test_all_in_one_go'
E:/test_redcloth_nestedlist.rb:12:in `assert_nothing_raised'
E:/test_redcloth_nestedlist.rb:15:in `test_all_in_one_go'
---------------

2 tests, 3 assertions, 1 failures, 0 errors



Im running Ruby 1.8.1 from the 1-click-installer on WinXP
using RedCloth 2.0.11. The same happenes when running the test using Linux


While it doesn't make too much sense to have this order of '*' and '**',
the given situation is the smallest and closest piece of RedCloth I
could com up with that shows this behaviour.

The original data ia a list with a sublist with one line similar to
"!pic/pic.png!:http://www.rubygarden.org/". In _that_ situation the
result is the same ("undefined method `length' for nil:NilClass"),
except that the problem disappears after inserting a space before the
line containing the link.

May be I'll dig a bit deeper into this tomorrow...

Am I missing something? May be it's time to get me some sleep. ;-)

Happy rubying

Stephan


require 'test/unit'
require 'redcloth'

class Test_Nested_List < Test::Unit::TestCase

def setup
@lines = DATA.readlines.join( '' )
end

def test_all_in_one_go
assert_equal( "2.0.11", RedCloth::VERSION )
assert_nothing_raised do
r = RedCloth.new( @lines )
r_htmlized = r.to_html
end
end

def test_each_line_for_itself
assert_nothing_raised do
r = RedCloth.new( '' )
@lines.each do | line |
r = RedCloth.new( line )
r_htmlized += r.to_html
end
end
end

end

__END__
** And another
!pic/pic.png!:http://www.rubygarden.org/
* another item
 
W

why the lucky stiff

Stephan said:
** And another
!pic/pic.png!:http://www.rubygarden.org/
* another item

The problem is that the first list you're creating starts with two
asterisks. RedCloth doesn't know what to do with a list that starts
with two asterisks. Such a situation hasn't been tested really and I
need to add a nice error message. This fix is due out in RedCloth 2.0.12.

Incidentally, what is the above RedCloth supposed to look like?

_why
 
S

Stephan Kämper

Hi.

First of all, thanks for the answer _why.
The problem is that the first list you're creating starts with two
asterisks. RedCloth doesn't know what to do with a list that starts
with two asterisks. Such a situation hasn't been tested really and I
need to add a nice error message. This fix is due out in RedCloth 2.0.12.

Incidentally, what is the above RedCloth supposed to look like?

Good question. At first I thought I'd expect the same result as if each
line was processed for itself. Now, after getting some sleep, that seems
silly to me, as you'd definitely loose the context/state (which sub list
you're in, whether you're inside a pair of quotes spanning several
lines...).

This morning I realized that the tests I wrote (and which contain a bug
:-/ I admit, but the 2nd test didn't get executed), don't behave
_exactly_ like the rakefile which processes the RedCloth files.
After fixing that (insertion of extra line breaks), it works as I
thought it should.

And I just found out that indenting lists with spaces (in the RedCloth
'source' I mean) is not a good idea, while using tabs is OK. Is that an
intended behaviour?

I've learned quite a bit about Textile & RedCloth last night and this
morning. :)

Thanks & happy rubying

Stephan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top