Skip to content

Commit

Permalink
Fix the unspecified behavior that happens when you add attributes to …
Browse files Browse the repository at this point in the history
…list items.
  • Loading branch information
jgarber committed Mar 5, 2009
1 parent 497b1c4 commit 28f97a5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/redcloth/formatters/html.rb
Expand Up @@ -48,6 +48,11 @@ def del(opts)
end

def li_open(opts)
# Delete attributes that only apply to ul/ol
opts.delete(:align)
opts.delete(:class)
opts.delete(:style)
opts.delete(:lang)
"#{li_close unless opts.delete(:first)}#{"\t" * opts[:nest]}<li#{pba(opts)}>#{opts[:text]}"
end

Expand Down
28 changes: 27 additions & 1 deletion test/lists.yml
Expand Up @@ -298,4 +298,30 @@ html: |-
<li>notice the leading space</li>
<li>RedCloth 3.0.4 used to accept it</li>
<li>Now we do too</li>
</ol>
</ol>
---
name: unordered with classes
in: |-
*(class-one) one
*(class-two) two
*(class-three) three
html: |-
<ul class="class-one">
<li>one</li>
<li>two</li>
<li>three</li>
</ul>
---
name: unordered with alignments
in: |-
*< one
*> two
*<> three
*= four
html: |-
<ul style="text-align:left;">
<li>one</li>
<li>two</li>
<li>three</li>
<li>four</li>
</ul>

1 comment on commit 28f97a5

@jgarber
Copy link
Owner Author

@jgarber jgarber commented on 28f97a5 Mar 5, 2009

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, RedCloth folks. The other day, I tried this:

*(class-one) one
*(class-two) two
*(class-three) three

thinking I’d get this:

<ul>
    <li class="class-one">one</li>
    <li class="class-two">two</li>
    <li class="class-three">three</li>
</ul>

But that’s not how it works. RedCloth 3 & 4 and Textile 2 both make the class/id you put on the first item in the list the class/id for the whole list. When you put classes/ids on subsequent list items, RedCloth 3 blows up, Textile2 makes them completely separate lists, and RedCloth 4 puts classes on the wrong list items (I’m fixing that now).

Here’s what PyTextile does:
To style a list, the parameters should go before the hash if you want to set the attributes on the <ol> tag:

(class#id)# one
# two
# three

If you want to customize the first <li> tag, apply the parameters after the hash:

#(class#id) one
# two
# three

What do you think? Stick close to Textile 2 or go out on our own to expand Textile’s breadth of expression? Is there a way to be able to specify list-item attributes and be backwards compatible?

Please sign in to comment.