IAL's for <li> elements

Add a Markdown syntax for attaching
attribute lists to list items (for both
ordered and unordered lists).

The syntax is trivial:

1. This is the first item
2. {: value="3"} We skip straight to #3

* This is an item
* {: style="color:red"} This is a red item
This commit is contained in:
Jacques Distler 2010-06-01 01:50:19 -05:00
parent b8647da41a
commit 17e9cfab87
2 changed files with 17 additions and 5 deletions

View file

@ -251,6 +251,7 @@ module MaRuKu; module In; module Markdown; module BlockLevelParser
"I see that #{h.rest.inspect} is left after the raw HTML.", src "I see that #{h.rest.inspect} is left after the raw HTML.", src
end end
raw_html = h.stuff_you_read raw_html = h.stuff_you_read
return md_html(raw_html) return md_html(raw_html)
end end
@ -283,7 +284,8 @@ module MaRuKu; module In; module Markdown; module BlockLevelParser
item_type = src.cur_line.md_type item_type = src.cur_line.md_type
first = src.shift_line first = src.shift_line
indentation = spaces_before_first_char(first) indentation, ial = spaces_before_first_char(first)
al = read_attribute_list(CharSource.new(ial,src), context=nil, break_on=[nil]) if ial
break_list = [:ulist, :olist, :ial] break_list = [:ulist, :olist, :ial]
# Ugly things going on inside `read_indented_content` # Ugly things going on inside `read_indented_content`
lines, want_my_paragraph = lines, want_my_paragraph =
@ -300,7 +302,7 @@ module MaRuKu; module In; module Markdown; module BlockLevelParser
children = parse_blocks(src2) children = parse_blocks(src2)
with_par = want_my_paragraph || (children.size>1) with_par = want_my_paragraph || (children.size>1)
return md_li(children, with_par) return md_li(children, with_par, al)
end end
def read_abbreviation(src) def read_abbreviation(src)

View file

@ -113,9 +113,14 @@ module MaRuKu; module Strings
while s[i,1] =~ /\s/; i+=1 end while s[i,1] =~ /\s/; i+=1 end
# skip indicator (+, -, *) # skip indicator (+, -, *)
i+=1 i+=1
# skip whitespace
while s[i,1] =~ /\s/; i+=1 end
# find an IAL
ial = s[i,s.length - i][/^\{(.*?)\}/]
i+= ial.length if ial
# skip optional whitespace # skip optional whitespace
while s[i,1] =~ /\s/; i+=1 end while s[i,1] =~ /\s/; i+=1 end
return i return [i, ial]
when :olist when :olist
i=0; i=0;
# skip whitespace # skip whitespace
@ -124,12 +129,17 @@ module MaRuKu; module Strings
while s[i,1] =~ /\d/; i+=1 end while s[i,1] =~ /\d/; i+=1 end
# skip dot # skip dot
i+=1 i+=1
# skip optional whitespace
while s[i,1] =~ /\s/; i+=1 end
# find an IAL
ial = s[i,s.length - i][/^\{(.*?)\}/]
i+= ial.length if ial
# skip whitespace # skip whitespace
while s[i,1] =~ /\s/; i+=1 end while s[i,1] =~ /\s/; i+=1 end
return i return [i, ial]
else else
tell_user "BUG (my bad): '#{s}' is not a list" tell_user "BUG (my bad): '#{s}' is not a list"
0 [0, nil]
end end
end end