Skip to content

Commit

Permalink
Refactor lists
Browse files Browse the repository at this point in the history
  • Loading branch information
jgarber committed May 21, 2009
1 parent a544be7 commit a68d5f7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
6 changes: 5 additions & 1 deletion ext/redcloth_scan/redcloth_scan.rb.rl
Expand Up @@ -274,7 +274,7 @@ module RedCloth
def RESET_NEST()
@nest = 0
end
def LIST_ITEM()
def LIST_ITEM_OPEN()
aint = 0
aval = @list_index[@nest-1]
aint = aval.to_i unless aval.nil?
Expand Down Expand Up @@ -305,12 +305,16 @@ module RedCloth
@regs[:nest] = @list_layout.length
ASET("type", "li_open")
end
def LIST_ITEM_CLOSE()
@html << @textile_doc.send("li_close", @regs) unless @regs[:first]
end
def LIST_CLOSE()
while (@nest < @list_layout.length)
@regs[:nest] = @list_layout.length
end_list = @list_layout.pop
if (!end_list.nil?)
listm = sprintf("%s_close", end_list)
LIST_ITEM_CLOSE()
@html << @textile_doc.send(listm, @regs)
end
end
Expand Down
8 changes: 4 additions & 4 deletions ext/redcloth_scan/redcloth_scan.rl
Expand Up @@ -134,7 +134,7 @@
double_return next_block_start when not_extended { ADD_BLOCK(); fgoto main; };
html_end_terminating_block when extended { ADD_EXTENDED_BLOCK(); END_EXTENDED(); fgoto main; };
html_end_terminating_block when not_extended { ADD_BLOCK(); fgoto main; };
LF list_start { ADD_BLOCK(); CLEAR_LIST(); LIST_ITEM(); fgoto list; };
LF list_start { ADD_BLOCK(); CLEAR_LIST(); LIST_ITEM_OPEN(); fgoto list; };

default => cat;
*|;
Expand All @@ -145,8 +145,8 @@
*|;

list := |*
LF list_start { ADD_BLOCK(); LIST_ITEM(); };
block_end { ADD_BLOCK(); RESET_NEST(); LIST_CLOSE(); fgoto main; };
LF list_start { LIST_ITEM_CLOSE(); ADD_BLOCK(); LIST_ITEM_OPEN(); };
block_end { LIST_ITEM_CLOSE(); ADD_BLOCK(); RESET_NEST(); LIST_CLOSE(); fgoto main; };
default => cat;
*|;

Expand All @@ -172,7 +172,7 @@
block_start { fgoto block; };
footnote_start { fgoto footnote; };
horizontal_rule { INLINE(html, "hr"); };
list_start { CLEAR_LIST(); LIST_ITEM(); fgoto list; };
list_start { CLEAR_LIST(); LIST_ITEM_OPEN(); fgoto list; };
dl_start { fexec(ts + 1); INLINE(html, "dl_open"); ASET("type", "dt"); fgoto dl; };
table { INLINE(table, "table_close"); DONE(table); fgoto block; };
link_alias { STORE_LINK_ALIAS(); DONE(block); };
Expand Down
9 changes: 2 additions & 7 deletions lib/redcloth/formatters/html.rb
Expand Up @@ -43,17 +43,12 @@ def del(opts)
"#{"\n" if opts[:nest] > 1}#{"\t" * (opts[:nest] - 1)}<#{m}#{pba(opts)}>\n"
end
define_method("#{m}_close") do |opts|
"#{li_close}#{"\t" * (opts[:nest] - 1)}</#{m}>#{"\n" if opts[:nest] <= 1}"
"#{"\t" * (opts[:nest] - 1)}</#{m}>#{"\n" if opts[:nest] <= 1}"
end
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]}"
"#{"\t" * opts[:nest]}<li#{pba(opts)}>#{opts[:text]}"
end

def li_close(opts=nil)
Expand Down
4 changes: 2 additions & 2 deletions lib/redcloth/formatters/latex.rb
Expand Up @@ -96,12 +96,12 @@ def acronym(opts)
"\\begin{#{env}}\n"
end
define_method("#{m}_close") do |opts|
"#{li_close}\\end{#{env}}\n\n"
"\\end{#{env}}\n\n"
end
end

def li_open(opts)
"#{li_close unless opts.delete(:first)} \\item #{opts[:text]}"
" \\item #{opts[:text]}"
end

def li_close(opts=nil)
Expand Down

0 comments on commit a68d5f7

Please sign in to comment.