Permalink
Browse files

Fix nested templates rendering.

They are now correctly nested in HTML.
  • Loading branch information...
1 parent 70e5684 commit 94907728896074bfc3e230f748594680e8041d22 @peter17 committed Jul 26, 2011
Showing with 67 additions and 58 deletions.
  1. +2 −1 html.py
  2. +4 −3 mediawiki.pijnu
  3. +3 −1 tests/test_html_postprocessor.py
  4. +1 −1 tests/test_preformatted_paragraphs.py
  5. +48 −45 tests/test_tables.py
  6. +9 −7 wikitextParser.py
View
@@ -86,7 +86,8 @@ def render_tag_autoclose(node):
def render_table(node):
table_parameters = ''
table_content = ''
- if len(node.value) > 1 and node.value[0].tag == 'table_begin':
+ from pijnu.library.node import Nodes
+ if isinstance(node.value, Nodes) and node.value[0].tag == 'table_begin':
attributes = node.value[0].value[0]
for attribute in attributes:
if attribute.tag == 'HTML_attribute':
View
@@ -206,7 +206,7 @@ def replace_by_space(node):
table_parameters_pipe : (SPACETAB* HTML_attribute+ SPACETAB* PIPE !PIPE)? : liftNode
table_parameters : (HTML_attribute / clean_inline)+
table_parameter : table_parameters_pipe{0..1} : liftValue
- table_cell_content : clean_inline+
+ table_cell_content : (clean_inline / (EOL+ table_structure))+
table_first_cell : table_parameter table_cell_content : liftNode
table_other_cell : (PIPE{2} table_first_cell)* : liftValue liftNode
table_line_cells : PIPE table_first_cell table_other_cell EOL : liftValue render_table_normal_cell
@@ -217,9 +217,10 @@ def replace_by_space(node):
table_special_line : table_title / table_line_break
table_normal_line : table_line_cells / table_line_header / table_empty_cell
table_line : !TABLE_END (table_special_line / table_normal_line) : liftNode
- table_content : (table_line / table / EOL)* : liftNode
+ table_content : (table_line / EOL)* : liftNode
table_begin : TABLE_BEGIN table_parameters* : liftValue
- table : table_begin SPACETABEOL* table_content TABLE_END EOL : @ liftValue render_table
+ table_structure : table_begin SPACETABEOL* table_content TABLE_END : @ liftValue render_table
+ table : table_structure EOL : liftValue
# Top pattern
@@ -151,7 +151,8 @@ def test_nested_tables(self):
<tr>
\t<th scope="col"> First (mother)</th>
\t<th scope="col"> table</th>
-<table style="background:red" class="prettyTable">
+\t<td>
+ <table style="background:red" class="prettyTable">
<tr>
\t<th scope="row"> Second (daughter) table</th>
\t<td>data L1.A</td>
@@ -163,6 +164,7 @@ def test_nested_tables(self):
\t<td>data L2.B</td>
</tr>
</table>
+</td>
</tr>
<tr>
\t<td> first</td>
@@ -82,7 +82,7 @@ def test_pre_paragraph_in_table(self):
|}
"""
result = """body:
- @table@:
+ table:
table_line_break:
table_line_header:
@clean_inline@:
View
@@ -135,7 +135,7 @@ def test_table_with_css(self):
| cell D
|}
"""
- result = """@table@:
+ result = """table:
table_line_header:
@clean_inline@:
raw_text: cellA
@@ -163,7 +163,7 @@ def test_table_with_template(self):
| cell 3 || cell 4
|}
"""
- result = """@table@:
+ result = """table:
table_title:
@clean_inline@:
raw_text: Table test: yes
@@ -202,7 +202,7 @@ def test_table_with_HTML_and_template(self):
|data {{template|with|parameters=L2.B}}
|}
"""
- result = """@table@:
+ result = """table:
table_begin:
table_parameters:
HTML_attribute:
@@ -296,7 +296,7 @@ def test_nested_tables(self):
| again
|}
"""
- result = """@table@:
+ result = """table:
table_begin:
table_parameters:
HTML_attribute:
@@ -331,47 +331,50 @@ def test_nested_tables(self):
table_cell_content:
@clean_inline@:
raw_text: table
- table_empty_cell:
- @table@:
- table_begin:
- table_parameters:
- HTML_attribute:
- attribute_name:class
- value_quote:table
- HTML_attribute:
- attribute_name:style
- value_quote:color:blue
- table_content:
- table_line_break:
- table_line_header:
- table_parameter:
- HTML_attribute:
- attribute_name:scope
- value_noquote:row
- table_cell_content:
- @clean_inline@:
- raw_text: Second (daughter) table
- table_line_cells:
- @clean_inline@:
- raw_text:data L1.A
- table_line_cells:
- @clean_inline@:
- raw_text:data L1.B
- table_line_break:
- table_line_header:
- table_parameter:
- HTML_attribute:
- attribute_name:scope
- value_noquote:row
- table_cell_content:
- @clean_inline@:
- raw_text: in the first one
- table_line_cells:
- @clean_inline@:
- raw_text:data L2.A
- table_line_cells:
- @clean_inline@:
- raw_text:data L2.B
+ table_line_cells:
+ <?>:
+ <?>:
+
+ @table_structure@:
+ table_begin:
+ table_parameters:
+ HTML_attribute:
+ attribute_name:class
+ value_quote:table
+ HTML_attribute:
+ attribute_name:style
+ value_quote:color:blue
+ table_content:
+ table_line_break:
+ table_line_header:
+ table_parameter:
+ HTML_attribute:
+ attribute_name:scope
+ value_noquote:row
+ table_cell_content:
+ @clean_inline@:
+ raw_text: Second (daughter) table
+ table_line_cells:
+ @clean_inline@:
+ raw_text:data L1.A
+ table_line_cells:
+ @clean_inline@:
+ raw_text:data L1.B
+ table_line_break:
+ table_line_header:
+ table_parameter:
+ HTML_attribute:
+ attribute_name:scope
+ value_noquote:row
+ table_cell_content:
+ @clean_inline@:
+ raw_text: in the first one
+ table_line_cells:
+ @clean_inline@:
+ raw_text:data L2.A
+ table_line_cells:
+ @clean_inline@:
+ raw_text:data L2.B
table_line_break:
table_line_cells:
@clean_inline@:
View
@@ -202,7 +202,7 @@
table_parameters_pipe : (SPACETAB* HTML_attribute+ SPACETAB* PIPE !PIPE)? : liftNode
table_parameters : (HTML_attribute / clean_inline)+
table_parameter : table_parameters_pipe{0..1} : liftValue
- table_cell_content : clean_inline+
+ table_cell_content : (clean_inline / (EOL+ table_structure))+
table_first_cell : table_parameter table_cell_content : liftNode
table_other_cell : (PIPE{2} table_first_cell)* : liftValue liftNode
table_line_cells : PIPE table_first_cell table_other_cell EOL : liftValue render_table_normal_cell
@@ -213,9 +213,10 @@
table_special_line : table_title / table_line_break
table_normal_line : table_line_cells / table_line_header / table_empty_cell
table_line : !TABLE_END (table_special_line / table_normal_line) : liftNode
- table_content : (table_line / table / EOL)* : liftNode
+ table_content : (table_line / EOL)* : liftNode
table_begin : TABLE_BEGIN table_parameters* : liftValue
- table : table_begin SPACETABEOL* table_content TABLE_END EOL : @ liftValue render_table
+ table_structure : table_begin SPACETABEOL* table_content TABLE_END : @ liftValue render_table
+ table : table_structure EOL : liftValue
# Top pattern
@@ -260,7 +261,7 @@ def replace_by_space(node):
### <definition>
# recursive pattern(s)
- table = Recursive(name='table')
+ table_structure = Recursive(name='table_structure')
list_item = Recursive(name='list_item')
sub_list = Recursive(name='sub_list')
list_leaf = Recursive(name='list_leaf')
@@ -470,7 +471,7 @@ def replace_by_space(node):
table_parameters_pipe = Option(Sequence([Repetition(SPACETAB, numMin=False, numMax=False, expression='SPACETAB*'), Repetition(HTML_attribute, numMin=1, numMax=False, expression='HTML_attribute+'), Repetition(SPACETAB, numMin=False, numMax=False, expression='SPACETAB*'), PIPE, NextNot(PIPE, expression='!PIPE')], expression='SPACETAB* HTML_attribute+ SPACETAB* PIPE !PIPE'), expression='(SPACETAB* HTML_attribute+ SPACETAB* PIPE !PIPE)?', name='table_parameters_pipe')(toolset['liftNode'])
table_parameters = Repetition(Choice([HTML_attribute, clean_inline], expression='HTML_attribute / clean_inline'), numMin=1, numMax=False, expression='(HTML_attribute / clean_inline)+', name='table_parameters')
table_parameter = Repetition(table_parameters_pipe, numMin=0, numMax=1, expression='table_parameters_pipe{0..1}', name='table_parameter')(toolset['liftValue'])
- table_cell_content = Repetition(clean_inline, numMin=1, numMax=False, expression='clean_inline+', name='table_cell_content')
+ table_cell_content = Repetition(Choice([clean_inline, Sequence([Repetition(EOL, numMin=1, numMax=False, expression='EOL+'), table_structure], expression='EOL+ table_structure')], expression='clean_inline / (EOL+ table_structure)'), numMin=1, numMax=False, expression='(clean_inline / (EOL+ table_structure))+', name='table_cell_content')
table_first_cell = Sequence([table_parameter, table_cell_content], expression='table_parameter table_cell_content', name='table_first_cell')(toolset['liftNode'])
table_other_cell = Repetition(Sequence([Repetition(PIPE, numMin=2, numMax=2, expression='PIPE{2}'), table_first_cell], expression='PIPE{2} table_first_cell'), numMin=False, numMax=False, expression='(PIPE{2} table_first_cell)*', name='table_other_cell')(toolset['liftValue'], toolset['liftNode'])
table_line_cells = Sequence([PIPE, table_first_cell, table_other_cell, EOL], expression='PIPE table_first_cell table_other_cell EOL', name='table_line_cells')(toolset['liftValue'], toolset['render_table_normal_cell'])
@@ -481,9 +482,10 @@ def replace_by_space(node):
table_special_line = Choice([table_title, table_line_break], expression='table_title / table_line_break', name='table_special_line')
table_normal_line = Choice([table_line_cells, table_line_header, table_empty_cell], expression='table_line_cells / table_line_header / table_empty_cell', name='table_normal_line')
table_line = Sequence([NextNot(TABLE_END, expression='!TABLE_END'), Choice([table_special_line, table_normal_line], expression='table_special_line / table_normal_line')], expression='!TABLE_END (table_special_line / table_normal_line)', name='table_line')(toolset['liftNode'])
- table_content = Repetition(Choice([table_line, table, EOL], expression='table_line / table / EOL'), numMin=False, numMax=False, expression='(table_line / table / EOL)*', name='table_content')(toolset['liftNode'])
+ table_content = Repetition(Choice([table_line, EOL], expression='table_line / EOL'), numMin=False, numMax=False, expression='(table_line / EOL)*', name='table_content')(toolset['liftNode'])
table_begin = Sequence([TABLE_BEGIN, Repetition(table_parameters, numMin=False, numMax=False, expression='table_parameters*')], expression='TABLE_BEGIN table_parameters*', name='table_begin')(toolset['liftValue'])
- table **= Sequence([table_begin, Repetition(SPACETABEOL, numMin=False, numMax=False, expression='SPACETABEOL*'), table_content, TABLE_END, EOL], expression='table_begin SPACETABEOL* table_content TABLE_END EOL', name='table')(toolset['liftValue'], toolset['render_table'])
+ table_structure **= Sequence([table_begin, Repetition(SPACETABEOL, numMin=False, numMax=False, expression='SPACETABEOL*'), table_content, TABLE_END], expression='table_begin SPACETABEOL* table_content TABLE_END', name='table_structure')(toolset['liftValue'], toolset['render_table'])
+ table = Sequence([table_structure, EOL], expression='table_structure EOL', name='table')(toolset['liftValue'])
# Top pattern

0 comments on commit 9490772

Please sign in to comment.