Skip to content

Commit

Permalink
Fix many nested-lists cases, by tracking the indent correctly as thin…
Browse files Browse the repository at this point in the history
…gs get indented.
  • Loading branch information
bhollis committed Feb 20, 2013
1 parent 4b0fa5e commit 88649fe
Show file tree
Hide file tree
Showing 6 changed files with 149 additions and 23 deletions.
34 changes: 18 additions & 16 deletions lib/maruku/input/parse_block.rb
Expand Up @@ -287,10 +287,9 @@ def read_list_item(src)

indentation, ial = spaces_before_first_char(first)
al = read_attribute_list(CharSource.new(ial, src)) if ial
break_list = [:ulist, :olist, :ial]
# Ugly things going on inside `read_indented_content`
lines, want_my_paragraph =
read_indented_content(src, indentation, break_list, item_type)
read_indented_content(src, indentation, :ial, item_type)

# add first line
# Strip first '*', '-', '+' from first line
Expand Down Expand Up @@ -362,41 +361,44 @@ def read_indented_content(src, indentation, break_list, item_type)
# collect all indented lines
saw_empty = false
saw_anything_after = false
break_list = Array(break_list)

while src.cur_line
# puts "Reading indent = #{indentation} #{src.cur_line.inspect}"
#puts "#{src.cur_line.md_type} #{src.cur_line.inspect}"
if src.cur_line.md_type == :empty
num_leading_spaces = src.cur_line.number_of_leading_spaces
break if num_leading_spaces < indentation && ![:text, :empty].include?(src.cur_line.md_type)

line = strip_indent(src.cur_line, indentation)
md_type = line.md_type

if md_type == :empty
saw_empty = true
lines << src.shift_line
lines << line
src.shift_line
next
end

# after a white line
if saw_empty
# we expect things to be properly aligned
if src.cur_line.number_of_leading_spaces < indentation
#puts "breaking for spaces, only #{ns}: #{src.cur_line}"
break
end
break if num_leading_spaces < indentation
saw_anything_after = true
else
break if Array(break_list).include? src.cur_line.md_type
break if break_list.include?(md_type)
end


stripped = strip_indent(src.shift_line, indentation)
lines << stripped
lines << line
src.shift_line

# You are only required to indent the first line of
# a child paragraph.
if stripped.md_type == :text
while src.cur_line && (src.cur_line.md_type == :text)
if md_type == :text
while src.cur_line && src.cur_line.md_type == :text
lines << strip_indent(src.shift_line, indentation)
end
end
end

# TODO fix this
want_my_paragraph = saw_anything_after ||
(saw_empty && src.cur_line && src.cur_line.md_type == item_type)

Expand Down
42 changes: 42 additions & 0 deletions spec/block_docs/list_multipara.md
@@ -0,0 +1,42 @@
Lists with multiple paragraphs
*** Parameters: ***
{}
*** Markdown input: ***
* A list item with a couple paragraphs,
each of which is indented.

For example, this paragraph.

* Another list item
*** Output of inspect ***
md_el(:document, md_el(:ul, [
md_li([
md_par("A list item with a couple paragraphs, each of which is indented."),
md_par("For example, this paragraph.")
], true),
md_li(md_par("Another list item"), false)
]))
*** Output of to_html ***
<ul>
<li>
<p>A list item with a couple paragraphs, each of which is indented.</p>

<p>For example, this paragraph.</p>
</li>

<li>
<p>Another list item</p>
</li>
</ul>
*** Output of to_latex ***
\begin{itemize}%
\item A list item with a couple paragraphs, each of which is indented.

For example, this paragraph.


\item Another list item



\end{itemize}
35 changes: 35 additions & 0 deletions spec/block_docs/lists_blank.md
@@ -0,0 +1,35 @@
Lists should allow newlines between items.
*** Parameters: ***
{}
*** Markdown input: ***
* A list item



* Another list item
*** Output of inspect ***
md_el(:document,[
md_el(:ul,[
md_li(md_par("A list item"), true),
md_li(md_par("Another list item"), false)
])
])
*** Output of to_html ***
<ul>
<li>
<p>A list item</p>
</li>
<li>
<p>Another list item</p>
</li>
</ul>
*** Output of to_latex ***
\begin{itemize}%
\item A list item


\item Another list item



\end{itemize}
@@ -1,4 +1,4 @@
Write a comment abouth the test here.
Lists should be able to contain blockquotes and code.
*** Parameters: ***
{}
*** Markdown input: ***
Expand Down
47 changes: 47 additions & 0 deletions spec/block_docs/lists_nested.md
@@ -0,0 +1,47 @@
PENDING - Nesting lists. (Pending because Maruku still improperly wraps items in paragraphs)
*** Parameters: ***
{} # params
*** Markdown input: ***
* A list item
* Foo
* Bar
* Bax
* Bap
* Another list item
*** Output of inspect ***
md_el(:document, md_el(:ul, [
md_li([
"A list item",
md_el(:ul, [
md_li("Foo", false),
md_li([
"Bar",
md_el(:ul, [
md_el(:li_span, "Bax", {:want_my_paragraph=>false}),
md_el(:li_span, "Bap", {:want_my_paragraph=>false})
])
], true)
])
], true),
md_li(md_par("Another list item"), false)
]))
*** Output of to_html ***
<ul>
<li>A list item

<ul>
<li>Foo</li>

<li>Bar

<ul>
<li>Bax</li>

<li>Bap</li>
</ul>
</li>
</ul>
</li>

<li>Another list item</li>
</ul>
12 changes: 6 additions & 6 deletions spec/block_docs/lists_tab.md
Expand Up @@ -11,12 +11,12 @@ Ciao
*** Output of inspect ***
md_el(:document,[
md_par(["Ciao"]),
md_el(:ul,[md_el(:li,["Tab"
md_el(:ul,[md_el(:li,["Tab"
md_el(:ul,[md_el(:li,["Tab"],{:want_my_paragraph=>false},[])],{},[]),
{:want_my_paragraph=>false},[])],{},[]),
{:want_my_paragraph=>false},[])],{},[])
],{},[])
md_el(:ul,[md_el(:li,["Tab",
md_el(:ul,[md_el(:li,["Tab",
md_el(:ul,[md_el(:li,["Tab"],{:want_my_paragraph=>false})]),
{:want_my_paragraph=>false})]),
{:want_my_paragraph=>false})])
])
*** Output of to_html ***
<p>Ciao</p>

Expand Down

0 comments on commit 88649fe

Please sign in to comment.