Permalink
Browse files

* Major overhaul on tables complete

* Still need many tables features, but a lot more are working
* Still need to sanitize header attributes
  • Loading branch information...
1 parent 4ff581a commit 28bf6c26eea7ee0dedb35eddff20559cca6a71f0 @relistan relistan committed Oct 15, 2010
Showing with 27 additions and 7 deletions.
  1. +19 −2 spec/test_spec.rb
  2. +8 −5 src/syntax.leg
View
21 spec/test_spec.rb
@@ -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,
@@ -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
@@ -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
View
13 src/syntax.leg
@@ -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>"); }

0 comments on commit 28bf6c2

Please sign in to comment.