Skip to content

Commit

Permalink
* Major overhaul on tables complete
Browse files Browse the repository at this point in the history
* Still need many tables features, but a lot more are working
* Still need to sanitize header attributes
  • Loading branch information
relistan committed Oct 15, 2010
1 parent 4ff581a commit 28bf6c2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
21 changes: 19 additions & 2 deletions spec/test_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,6 @@ def parse(wikitext, *args)
end

it "should support full wikitext markup in table cells even with line feeds" do
pending
text = parse("{|
|Lorem ipsum dolor sit amet,
consetetur sadipscing elitr,
Expand All @@ -381,7 +380,17 @@ def parse(wikitext, *args)
end

describe "headers" do
it "should be able to make headers" do
it "should be able to make simple headers" do
text = parse("{|
|+Caption
! heading 1
! heading 2
|}")
text.should include("<th>heading 1</th><th>heading 2</th>");
text.should_not include("{|");
end

it "should be able to make complex headers" do
parse("{|
|+ Caption
! scope=\"col\" | column heading 1
Expand All @@ -407,6 +416,14 @@ def parse(wikitext, *args)
| cell
|}").should == "<p><table><caption>Caption</caption><tr><th scope=\"col\">column heading 1</th><th scope=\"col\">column heading 2</th></tr><tr><th scope=\"row\">row heading</th><td>cell</td><td>cell</td></tr><tr><td>cell</td><td>cell</td></tr></table></p>"
end

it "should be able to do headers even with a first row defined" do
text = parse("{|
|-
! heading 1
! heading 2
|}")
end
end

# TODO: single-pipe separaters for a format modifier
Expand Down
13 changes: 8 additions & 5 deletions src/syntax.leg
Original file line number Diff line number Diff line change
Expand Up @@ -396,16 +396,19 @@ table_specials = ( [|+}!] | '-' )
table_delims = ( ( '|' table_specials ) | ( &{start_of_line} '!' ) | ( &{start_of_line} '|') )
table_open = '{|' { tr_found = 0; bprintf("<table>"); }
table_caption = '|+' space* { bprintf("<caption>"); } ( !table_delims wikitext )* &table_delims { brtrimws(output_buffer); bprintf("</caption>"); }
table_row = '|-' space* { tr_found = 1; bprintf("<tr>"); } eol* ( table_header | table_cell )* { bprintf("</tr>"); }
table_row = '|-' space* { tr_found = 1; bprintf("<tr>"); } eol* ( table_headers | table_cell )* { bprintf("</tr>"); }

table_headers = {
if(!tr_found) { bprintf("<tr>"); }
} table_header+ {
} ( complex_header | simple_header )+ {
if(!tr_found) { bprintf("</tr>"); }
}

table_header = &{start_of_line} '!' space* { bprintf("<th"); } (
< ( !( space* '|') . )* > space* { bprintf(" %s>", yytext); } '|' space* < ( !table_delims !eol . )* > { bprintf("%s", yytext); } ( &table_delims | eol )
complex_header = &{start_of_line} '!' space* { bprintf("<th"); } (
< ( !( space* '|') . )* > space* { bprintf(" %s>", yytext); } '|' space* ( !table_delims !eol wikitext )* ( &table_delims | eol )
) { bprintf("</th>"); }
simple_header = &{start_of_line} '!' space* { bprintf("<th>"); }
( !eol !table_delims wikitext )+ ( eol | &table_delims )
{ bprintf("</th>"); }

table_cell = '|'+ !table_specials space* { bprintf("<td>"); } ( !table_delims wikitext )* &table_delims { brtrimws(output_buffer); bprintf("</td>"); }
table_close = '|}' { brtrimws(output_buffer); bprintf("</table>"); }
Expand Down

0 comments on commit 28bf6c2

Please sign in to comment.