El Dorado

A full-stack community web application written in Ruby/Rails
Fri, 23 May 2008, 8:31am bbcode lists »
irkenInvader
Member
Zim
Registered: May, 2008
Last visit: Wed, 04 Jun 2008
Posts: 85

I'd really like to implement list generation using bbcode for posts.

The code below seems to work, but I think there are two problems I'm hoping you can help me with.

Here's the code I added to the Tags hash in bbcodeizer.rb:

:start_list            => [ /\[list\]/i, '<ul>' ],
:list_item => [ /\[\*\](.+?)$/, '<li>\1</li>' ],
:end_list => [ /\[\/list\]/i, '</ul>' ],

I also added this function:

def list(string)
# list tags must match, else don't do any replacing.
if string.scan(Tags[:start_list].first).size == string.scan(Tags[:end_list].first).size
apply_tags(string, :start_list, :end_list)
end
end

And of course, I added this to the end of the TagList array:

... , :list, :list_item ]

Here is my test post (spaces added so bbcodeizer would ignore the tags):

[ list]
[ *]This is a test
[ *]This is another test
[ *]Third Test
[ /list]

Here is the resulting HTML from the test post on my development site:

<ul>

<br><li>This is a test
<br></li>
<br><li>This is another test
<br></li>
<br><li>Third Test
<br></li>
<br></ul>

There are two problems. Your CSS has, at the very top, the following line, which is suppressing the bullets and indentation:

li { margin: 0; padding: 0; list-style-type: none; }

And finally, I don't know where all those extra <br> tags are getting inserted. It seems that any of your 'blocks' (code blocks, quote blocks, etc.) have the same extra, added <br> tags added in.

Any thoughts/help?


Zim wrote:

Invader’s blood marches through my veins like giant, radioactive rubber pants! The pants command me! Do not ignore my veins!

Offline