Permalink
Browse files

List continuation

  • Loading branch information...
1 parent 348cc61 commit 5ce4cd0976d2cd18bcf7ddaa3a506a5a7166f758 @jgarber committed Apr 12, 2012
@@ -27,6 +27,7 @@ class TableHeader < Element; end
class Footnote < Element; end
class List
+ @@last_list_count = 0
def self.build(li_hashes, opts={})
list_nesting = []
list_layout = ""
@@ -38,6 +39,9 @@ def self.build(li_hashes, opts={})
list_nesting.last.children << closed_list
else
list_nesting << ((li[:layout].to_s[-1,1] == "*") ? Ul.new : Ol.new)
+ if cont = li[:continuation]
+ opts[:start] = cont == '_' ? @@last_list_count + 1 : cont.to_i
+ end
if opts.any?
list_nesting.last.opts = opts
opts = {}
@@ -50,6 +54,8 @@ def self.build(li_hashes, opts={})
closed_list = list_nesting.pop
list_nesting.last.children << closed_list
end
+ list_start_number = list_nesting.first.opts[:start] || 1
+ @@last_list_count = list_start_number + list_nesting.first.children.size - 1
list_nesting.first
end
end
@@ -1,4 +1,6 @@
class RedClothParslet::Parser::Block < Parslet::Parser
+ include RedClothParslet::Parser::Common
+
root(:textile_doc)
rule(:textile_doc) do
block_element.repeat(1)
@@ -10,7 +10,12 @@ class RedClothParslet::Parser::Block < Parslet::Parser
rule(:li) { li_start >> list_content.as(:content) >> li_end }
- rule(:li_start) { match("[*#]").repeat(1).as(:layout) >> attributes?.as(:attributes) >> str(" ") }
+ rule(:li_start) do
+ match("[*#]").repeat(1).as(:layout) >>
+ (digits | str("_")).maybe.as(:continuation) >>
+ attributes?.as(:attributes) >>
+ str(" ")
+ end
rule(:li_end) { block_end.present? | (block_end.absent? >> str("\n") >> li_start.present?) }
rule(:list_content) { RedClothParslet::Parser::Inline.new.list_contents }
@@ -1,8 +1,12 @@
module RedClothParslet::Parser::Common
+ include Parslet
+
def stri(str)
key_chars = str.split(//)
key_chars.
collect! { |char| match["#{char.upcase}#{char.downcase}"] }.
reduce(:>>)
end
+
+ rule(:digits) { match('[0-9]').repeat(1) }
end
@@ -211,7 +211,6 @@ class RedClothParslet::Parser::Inline < Parslet::Parser
rule(:inline_sp) { match('[ \t]').repeat(1) }
rule(:inline_sp?) { inline_sp.maybe }
rule(:sp) { inline_sp | str("\n") }
- rule(:digits) { match('[0-9]').repeat(1) }
# rule(:mtext) { mchar.repeat(1) >> (inline_sp >> mchar.repeat(1)) }
rule(:image_uri) { RedClothParslet::Parser::Attributes::ImageUri.new }
@@ -10,8 +10,8 @@ class RedClothParslet::Transform < Parslet::Transform
rule(:attributes => subtree(:a), :src => simple(:s), :alt => simple(:alt)) {|dict| {:opts => RedClothParslet::Ast::Attributes.new(dict[:a].push({:src => dict[:s], :alt => dict[:alt]}))} }
rule(:attributes => subtree(:a), :src => subtree(:s), :href => simple(:h)) {|dict| {:opts => RedClothParslet::Ast::Attributes.new(dict[:a].push({:src => dict[:s], :alt => dict[:alt], :href => dict[:h]}))} }
- rule(:layout => simple(:l), :attributes => subtree(:a), :content => subtree(:c)) {|dict|
- {:layout => dict[:l], :content => dict[:c], :opts => RedClothParslet::Ast::Attributes.new(dict[:a])}
+ rule(:layout => simple(:l), :continuation => simple(:cont), :attributes => subtree(:a), :content => subtree(:c)) {|dict|
+ {:layout => dict[:l], :continuation => dict[:cont], :content => dict[:c], :opts => RedClothParslet::Ast::Attributes.new(dict[:a])}
}
rule(:extended => subtree(:ext)) { ext[:successive].unshift(ext[:first]) }
@@ -40,6 +40,12 @@
RedClothParslet::Ast::Li.new(["one"]),
RedClothParslet::Ast::Li.new(["two"])
], {:class=>'class', :id=>'id'})]) }
+ it { should parse("#7(class#id) seven\n# eight").with(transform).
+ as([RedClothParslet::Ast::Ol.new([RedClothParslet::Ast::Li.new("seven", {:class=>'class', :id=>'id'}), RedClothParslet::Ast::Li.new("eight")], {:start=>7})]) }
+ it { should parse("# one\n\n#_(class#id) two").with(transform).
+ as([RedClothParslet::Ast::Ol.new(RedClothParslet::Ast::Li.new("one")), RedClothParslet::Ast::Ol.new(RedClothParslet::Ast::Li.new("two", {:class=>'class', :id=>'id'}), {:start=>2})]) }
+ it { should parse("#9 nine\n\n#_ ten").with(transform).
+ as([RedClothParslet::Ast::Ol.new(RedClothParslet::Ast::Li.new("nine"), {:start=>9}), RedClothParslet::Ast::Ol.new(RedClothParslet::Ast::Li.new("ten"), {:start=>10})]) }
end
context "list item attributes" do
@@ -49,4 +55,4 @@
RedClothParslet::Ast::Li.new(["two"])
])]) }
end
-end
+end

0 comments on commit 5ce4cd0

Please sign in to comment.