Skip to content
This repository was archived by the owner on Jan 5, 2025. It is now read-only.

Commit

Permalink
More progress on fixing lists.
Browse files Browse the repository at this point in the history
This removes the :li_span element type, and fixes how Maruku chooses to wrap list items in paragraphs in many cases (though not all). There are still quite a few list cases that still fail, but this fixes #26, fixes #30, fixes #64, fixes #67, and fixes #72, and activates many of the pending list tests.
  • Loading branch information
bhollis committed Feb 20, 2013
1 parent 60c5bad commit 155fdb3
Show file tree
Hide file tree
Showing 32 changed files with 232 additions and 184 deletions.
20 changes: 15 additions & 5 deletions lib/maruku/input/parse_block.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,19 +120,22 @@ def parse_blocks(src)
# get rid of empty line markers
output.delete_if {|x| x == :empty }

# See for each list if we can omit the paragraphs and use li_span
# See for each list if we can omit the paragraphs
# TODO: do this after
output.each do |c|
# Remove paragraphs that we can get rid of
if [:ul, :ol].include?(c.node_type) && c.children.none?(&:want_my_paragraph)
c.children.each do |d|
d.node_type = :li_span
d.children = d.children.first.children if d.children.first
if d.children.first.node_type == :paragraph
d.children = d.children.first.children + d.children[1..-1]
end
end
elsif c.node_type == :definition_list && c.children.none?(&:want_my_paragraph)
c.children.each do |definition|
definition.definitions.each do |dd|
dd.children = dd.children.first.children if dd.children.first
if dd.children.first.node_type == :paragraph
dd.children = dd.children.first.children + dd.children[1..-1]
end
end
end
end
Expand Down Expand Up @@ -299,7 +302,7 @@ def read_list_item(src)
src2 = LineSource.new(lines, src, parent_offset)
children = parse_blocks(src2)

with_par = want_my_paragraph || (children.size > 1)
with_par = want_my_paragraph

md_li(children, with_par, al)
end
Expand Down Expand Up @@ -376,6 +379,13 @@ def read_indented_content(src, indentation, break_list, item_type)
next
end

# Unquestioningly grab anything that's deeper-indented
if md_type != :code && num_leading_spaces > indentation
lines << line
src.shift_line
next
end

# after a white line
if saw_empty
# we expect things to be properly aligned
Expand Down
4 changes: 0 additions & 4 deletions lib/maruku/output/to_html.rb
Original file line number Diff line number Diff line change
Expand Up @@ -416,10 +416,6 @@ def to_html_li
add_ws wrap_as_element('li')
end

def to_html_li_span
add_ws wrap_as_element('li')
end

def to_html_quote
add_ws wrap_as_element('blockquote')
end
Expand Down
4 changes: 0 additions & 4 deletions lib/maruku/output/to_latex.rb
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,6 @@ def to_latex_li
"\\item #{children_to_latex}\n"
end

def to_latex_li_span
"\\item #{children_to_latex}\n"
end

def to_latex_strong
"\\textbf{#{children_to_latex}}"
end
Expand Down
8 changes: 0 additions & 8 deletions lib/maruku/output/to_markdown.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,6 @@ def to_md_ref_definition(context)
"[#{@ref_id}] #{@url}#{" \"#{@title}\"" if @title}"
end

def to_md_li_span(context)
len = (context[:line_length] || DefaultLineLength) - 2
# s = wrap(@children, len-2, context).rstrip.gsub(/^/, ' ')
# s[0] = ?*
# s + "\n"
"* " + wrap(@children, len-2, context).rstrip + "\n"
end

def to_md_abbr_def(context)
"*[#{self.abbr}]: #{self.text}\n"
end
Expand Down
2 changes: 1 addition & 1 deletion spec/block_docs/abbrev.md
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ md_el(:document,[
md_entity("rsquo"),
", which no user in the entire world has installed on their computer."
])
],{:want_my_paragraph=>true},[])
],{:want_my_paragraph=>false},[])
],{},[]),
md_par([
"This whole thing is rather worrying - I",
Expand Down
2 changes: 1 addition & 1 deletion spec/block_docs/data_loss.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ijkl

*** Output of inspect ***
md_el(:document,[
md_el(:ol,[md_el(:li_span,["abcd efgh ijkl"],{:want_my_paragraph=>false},[])],{},[])
md_el(:ol,[md_el(:li,["abcd efgh ijkl"],{:want_my_paragraph=>false},[])],{},[])
],{},[])
*** Output of to_html ***
<ol>
Expand Down
16 changes: 9 additions & 7 deletions spec/block_docs/issue26.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PENDING - Nested lists shouldn't get <p> tags wrapped around elements. https://github.com/bhollis/maruku/issues/26
Nested lists shouldn't get <p> tags wrapped around elements. https://github.com/bhollis/maruku/issues/26
*** Parameters: ***
{}
*** Markdown input: ***
Expand All @@ -7,14 +7,16 @@ PENDING - Nested lists shouldn't get <p> tags wrapped around elements. https://g
+ Node
- Root
*** Output of inspect ***
md_el(:document, [])
md_el(:document, md_el(:ul, [
md_li(["Root", md_el(:ul, [md_li("Node", false), md_li("Node", false)])], false),
md_li("Root", false)
]))
*** Output of to_html ***
<ul>
<li> Root

<li>Root
<ul>
<li> Node</li>
<li> Node</li>
<li>Node</li>
<li>Node</li>
</ul></li>
<li> Root</li>
<li>Root</li>
</ul>
4 changes: 2 additions & 2 deletions spec/block_docs/issue30.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ And this:
*** Output of inspect ***
md_el(:document, [
md_par("This is a list:"),
md_el(:ul, md_el(:li_span, "a list", {:want_my_paragraph=>false})),
md_el(:ul, md_el(:li, "a list", {:want_my_paragraph=>false})),
md_par("And this:"),
md_el(:ul, md_el(:li_span, "still a list", {:want_my_paragraph=>false}))
md_el(:ul, md_el(:li, "still a list", {:want_my_paragraph=>false}))
])
*** Output of to_html ***
<p>This is a list:</p>
Expand Down
24 changes: 19 additions & 5 deletions spec/block_docs/issue64.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PENDING - Nested list with a single item. https://github.com/bhollis/maruku/issues/64
Nested list with a single item. https://github.com/bhollis/maruku/issues/64
*** Parameters: ***
{}
*** Markdown input: ***
Expand All @@ -15,25 +15,39 @@ A nested list with a single item (does not work)
- item b

*** Output of inspect ***
md_el(:document,[],{},[])
md_el(:document, [
md_par("A nested list with a single item (does not work)"),
md_el(:ul, [
md_li([
"three items:",
md_el(:ul, [
md_li("item 1", false),
md_li("item 2", false),
md_li("item 3", false)
])
], false),
md_li(["one item:", md_el(:ul, md_li("item", false))], false),
md_li([
"two items:",
md_el(:ul, [md_li("item a", false), md_li("item b", false)])
], false)
])
])
*** Output of to_html ***
<p>A nested list with a single item (does not work)</p>

<ul>
<li>three items:

<ul>
<li>item 1</li>
<li>item 2</li>
<li>item 3</li>
</ul></li>
<li>one item:

<ul>
<li>item</li>
</ul></li>
<li>two items:

<ul>
<li>item a</li>
<li>item b</li>
Expand Down
9 changes: 6 additions & 3 deletions spec/block_docs/issue67.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
PENDING - A span at the beginning of a list item shouldn't cause the other list elements
to be wrapped in paragraphs or remove the inline element. https://github.com/bhollis/maruku/issues/67
A span at the beginning of a list item shouldn't cause the other list elements to be wrapped in paragraphs or remove the inline element. https://github.com/bhollis/maruku/issues/67
*** Parameters: ***
{}
*** Markdown input: ***
- One
- <del>Two</del>
- Three
*** Output of inspect ***
md_el(:document,[],{},[])
md_el(:document, md_el(:ul, [
md_li("One", false),
md_li(md_html("<del>Two</del>"), false),
md_li("Three", false)
]))
*** Output of to_html ***
<ul>
<li>One</li>
Expand Down
4 changes: 2 additions & 2 deletions spec/block_docs/issue72.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ https://github.com/bhollis/maruku/issues/72
2. 句子
*** Output of inspect ***
md_el(:document, md_el(:ol, [
md_el(:li_span, "句子", {:want_my_paragraph=>false}),
md_el(:li_span, "句子", {:want_my_paragraph=>false})
md_el(:li, "句子", {:want_my_paragraph=>false}),
md_el(:li, "句子", {:want_my_paragraph=>false})
]))
*** Output of to_html ***
<ol>
Expand Down
2 changes: 1 addition & 1 deletion spec/block_docs/list12.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Write a comment here
*** Output of inspect ***
md_el(:document,[
md_el(:ul,[
md_el(:li_span,[md_link(["Maruku"],nil), ": good."],{:want_my_paragraph=>false},[])
md_el(:li,[md_link(["Maruku"],nil), ": good."],{:want_my_paragraph=>false},[])
],{},[]),
md_ref_def("maruku", "http://maruku.org/", {:title=>nil})
],{},[])
Expand Down
10 changes: 5 additions & 5 deletions spec/block_docs/lists.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,19 @@ sit amet, consectetuer adipiscing elit.
*** Output of inspect ***
md_el(:document,[
md_el(:ul,[
md_el(:li_span,[
md_el(:li,[
"Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus. Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus."
],{:want_my_paragraph=>false},[]),
md_el(:li_span,[
md_el(:li,[
"Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse id sem consectetuer libero luctus adipiscing."
],{:want_my_paragraph=>false},[]),
md_el(:li_span,[
md_el(:li,[
"Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse id sem consectetuer libero luctus adipiscing."
],{:want_my_paragraph=>false},[]),
md_el(:li_span,[
md_el(:li,[
"Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse id sem consectetuer libero luctus adipiscing."
],{:want_my_paragraph=>false},[]),
md_el(:li_span,[
md_el(:li,[
"Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse id sem consectetuer libero luctus adipiscing."
],{:want_my_paragraph=>false},[])
],{},[]),
Expand Down
2 changes: 1 addition & 1 deletion spec/block_docs/lists10.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ List:
md_el(:document,[
md_par(["List:"]),
md_el(:ul,[
md_el(:li_span,["è", md_code("gcc")],{:want_my_paragraph=>false},[])
md_el(:li,["è", md_code("gcc")],{:want_my_paragraph=>false},[])
],{},[])
],{},[])
*** Output of to_html ***
Expand Down
2 changes: 1 addition & 1 deletion spec/block_docs/lists11.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Write a comment here

*** Output of inspect ***
md_el(:document,[
md_el(:ul,[md_el(:li_span,["ένα"],{:want_my_paragraph=>false},[])],{},[])
md_el(:ul,[md_el(:li,["ένα"],{:want_my_paragraph=>false},[])],{},[])
],{},[])
*** Output of to_html ***
<ul>
Expand Down
6 changes: 3 additions & 3 deletions spec/block_docs/lists12.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ List Items with non alphanumeric content. https://github.com/bhollis/maruku/issu
*** Output of inspect ***
md_el(:document,[
md_el(:ul,[
md_el(:li_span,["A"],{:want_my_paragraph=>false},[]),
md_el(:li_span,["?"],{:want_my_paragraph=>false},[]),
md_el(:li_span,["B"],{:want_my_paragraph=>false},[])
md_el(:li,["A"],{:want_my_paragraph=>false},[]),
md_el(:li,["?"],{:want_my_paragraph=>false},[]),
md_el(:li,["B"],{:want_my_paragraph=>false},[])
],{},[])
],{},[])

Expand Down
10 changes: 5 additions & 5 deletions spec/block_docs/lists13.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ List Items with non alphanumeric content
*** Output of inspect ***
md_el(:document,[
md_el(:ul,[
md_el(:li_span,["A"],{:want_my_paragraph=>false},[[:id, "foo"]]),
md_el(:li_span,["?"],{:want_my_paragraph=>false},[[:id, "bar"]]),
md_el(:li_span,["B"],{:want_my_paragraph=>false},[[:id, "fubar"]]),
md_el(:li_span,["C"],{:want_my_paragraph=>false},[[:id, "fubar2"]]),
md_el(:li_span,["{Not an IAL}"],{:want_my_paragraph=>false},[])
md_el(:li,["A"],{:want_my_paragraph=>false},[[:id, "foo"]]),
md_el(:li,["?"],{:want_my_paragraph=>false},[[:id, "bar"]]),
md_el(:li,["B"],{:want_my_paragraph=>false},[[:id, "fubar"]]),
md_el(:li,["C"],{:want_my_paragraph=>false},[[:id, "fubar2"]]),
md_el(:li,["{Not an IAL}"],{:want_my_paragraph=>false},[])
],{},[]),
],{},[])

Expand Down
Loading

0 comments on commit 155fdb3

Please sign in to comment.