Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Solve bugs and add tests for them.

 * Allow / in template names.
 * Allow wikitext in table cells
 * Allow newline inside template parameters but not at the end
  • Loading branch information...
commit c600d71d520ed7ac379706aeae33baf15fde82b9 1 parent 859a40a
@peter17 peter17 authored
View
6 article.htm
@@ -9,13 +9,13 @@
<h2>Dans la musique classique</h2>
<p>Les berceuses en musique classique obéissent souvent à une forme nommée aussi "berceuse" dans les langues étrangères. Elles sont généralement à trois <a href="Temps (solfège)">temps</a>, à <a href="tonalité">tonalité</a> simple, alternant des harmonies <a href="dominante">dominante</a> et <a href="Tonique (musique)">tonique</a>.</p>
<p><strong>Berceuses célèbres classées par compositeurs :</strong></p>
-<table style="text-align:center; background: #f9f9f9; color: #000;font-size:90%; line-height:1.1em; float:right;clear:right; margin:1em 1.5em 1em 1em; width:300px; border: 1px solid #aaa; padding: 0.1em;" >
+<table style="text-align:center; background: #f9f9f9; color: #000;font-size:90%; line-height:1.1em; float:right;clear:right; margin:1em 1.5em 1em 1em; width:300px; border: 1px solid #aaa; padding: 0.1em;">
<tr>
<th class="media audio" style="background-color:#ccf; line-height:3.1em"> Fichier audio</th>
</tr>
<tr>
-<td><span style="height:20px; width:100%; padding:4pt; padding-left:0.3em; line-height:2em;"><strong><a href="Media:Brahms_-_Schumann-Heink_-_Wiegenlied_(Berceuse)_(1915).ogg‎"><em>Wiegenlied</em> (Berceuse, op 49/4)</a></strong> <em>(<a href="Fichier:Brahms_-_Schumann-Heink_-_Wiegenlied_(Berceuse)_(1915).ogg‎">info</a>)</em><br /><small><em>Wiegenlied</em> interprété par <a href="Ernestine Schumann-Heink">Ernestine Schumann-Heink</a></small>
-<center><img src="Brahms_-_Schumann-Heink_-_Wiegenlied_(Berceuse)_(1915).ogg‎" style="" alt="" /></center></span><br /><span style="height:20px; width:100%; padding-left:0.3em;"><span><img src="Circle question mark.png" style="width:14px;" alt="" /> <em><a href="Aide:Écouter des sons ogg">Des problèmes pour écouter le fichier ?</a></em></span></span></td>
+ <td><span style="height:20px; width:100%; padding:4pt; padding-left:0.3em; line-height:2em;"><strong><a href="Media:Brahms_-_Schumann-Heink_-_Wiegenlied_(Berceuse)_(1915).ogg‎"><em>Wiegenlied</em> (Berceuse, op 49/4)</a></strong> <em>(<a href="Fichier:Brahms_-_Schumann-Heink_-_Wiegenlied_(Berceuse)_(1915).ogg‎">info</a>)</em><br /><small><em>Wiegenlied</em> interprété par <a href="Ernestine Schumann-Heink">Ernestine Schumann-Heink</a></small><p><center><img src="Brahms_-_Schumann-Heink_-_Wiegenlied_(Berceuse)_(1915).ogg‎" style="" alt="" /></center></span><br /><span style="height:20px; width:100%; padding-left:0.3em;"><span><img src="Circle question mark.png" style="width:14px;" alt="" /> <em><a href="Aide:Écouter des sons ogg">Des problèmes pour écouter le fichier ?</a></em></span></span></p>
+</td>
</tr>
</table>
<ul>
View
41 html.py
@@ -1,5 +1,5 @@
from constants import html_entities
-from pijnu.library.node import Nil, Nodes
+from pijnu.library.node import Nil, Nodes, Node
from mediawiki_parser import wikitextParser
from mutagen import Metadata
import apostrophes
@@ -166,7 +166,7 @@ def render_table(node):
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':
+ if attribute.tag == 'HTML_attribute' and attribute.value != '':
table_parameters += ' ' + attribute.value
contents = node.value[1].value
for item in contents:
@@ -183,24 +183,41 @@ def render_cell_content(node):
if len(node.value) > 1:
values = node.value[0].value
for value in values:
- if value.tag == 'HTML_attribute':
- cell_parameters += ' ' + value.value
+ if isinstance(value, Node):
+ if value.tag == 'HTML_attribute' and value.value != '':
+ cell_parameters += ' ' + value.value
+ else:
+ cell_content += value.leaf()
else:
- cell_content += value.value
+ cell_content += value
cell_content += content(node.value[1])
else:
cell_content = content(node)
return (cell_parameters, cell_content)
def render_table_header_cell(node):
- content = render_cell_content(node)
- if content is not None:
- node.value = '\t<th%s>%s</th>\n' % content
+ result = ''
+ if isinstance(node.value, Nodes):
+ for i in range(len(node.value)):
+ content = render_cell_content(node.value[i])
+ result += '\t<th%s>%s</th>\n' % content
+ else:
+ content = render_cell_content(node)
+ result = '\t<th%s>%s</th>\n' % content
+ if result != '':
+ node.value = result
def render_table_normal_cell(node):
- content = render_cell_content(node)
- if content is not None:
- node.value = '\t<td%s>%s</td>\n' % content
+ result = ''
+ if isinstance(node.value, Nodes):
+ for i in range(len(node.value)):
+ content = render_cell_content(node.value[i])
+ result += '\t<td%s>%s</td>\n' % content
+ else:
+ content = render_cell_content(node)
+ result = '\t<td%s>%s</td>\n' % content
+ if result != '':
+ node.value = result
def render_table_empty_cell(node):
node.value = '\t<td></td>\n'
@@ -216,7 +233,7 @@ def render_table_line_break(node):
assert len(node.value) == 1, "Bad AST shape!"
parameters = node.value[0].value
for value in parameters:
- if value.tag == 'HTML_attribute':
+ if value.tag == 'HTML_attribute' and value.value != '':
line_parameters += ' ' + value.value
node.value = '</tr>\n<tr%s>\n' % line_parameters
View
23 mediawiki.pijnu
@@ -109,7 +109,7 @@ def replace_by_space(node):
# Text
- page_name : raw_char+ : join
+ page_name : (raw_char / '/')+ : join
# TODO: allow IPv6 addresses (http://[::1]/etc)
address : (!(QUOTE/R_BRACKET) [\x21..\xff])+ : liftValue
url : protocol address : join
@@ -207,17 +207,20 @@ 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_multiline_content : EOL_KEEP !(PIPE/BANG) clean_inline
- table_cell_content : (clean_inline / (EOL+ table_structure) / table_multiline_content)+
- 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
- table_line_header : BANG table_first_cell table_other_cell EOL : liftValue render_table_header_cell
- table_empty_cell : PIPE EOL : keep
+ table_wikitext : list/horizontal_rule/preformatted_group/title/table_structure
+ table_inline : !(PIPE/BANG) clean_inline EOL? : liftNode
+ table_paragraph : (!(PIPE/BANG/TABLE_NEWLINE/TABLE_TITLE/TABLE_END) paragraph_line) : render_paragraph
+ table_multiline_content : (table_paragraph / table_wikitext / EOL)*
+ table_cell_content : table_inline? table_multiline_content : liftValue
+ table_cell : table_parameter table_cell_content
+ table_other_cell : (PIPE{2} table_cell)* : liftValue liftNode
+ table_line_cells : PIPE table_cell table_other_cell : render_table_normal_cell
+ table_line_header : BANG table_cell table_other_cell : render_table_header_cell
+ table_empty_cell : PIPE EOL &(PIPE/BANG/TABLE_END) : keep
table_line_break : TABLE_NEWLINE table_parameters* EOL : keep liftValue render_table_line_break
- table_title : TABLE_TITLE table_parameter table_cell_content EOL : liftValue render_table_caption
+ table_title : TABLE_TITLE table_parameter inline EOL : liftValue render_table_caption
table_special_line : table_title / table_line_break
- table_normal_line : table_line_cells / table_line_header / table_empty_cell
+ table_normal_line : table_empty_cell / table_line_cells / table_line_header
table_line : !TABLE_END (table_special_line / table_normal_line) : liftNode
table_content : (table_line / EOL)* : liftNode
table_begin : TABLE_BEGIN table_parameters* : liftValue
View
6 parser.py
@@ -1,5 +1,8 @@
# -*- coding: utf8 -*-
+import time
+start_time = time.time()
+
# get the parser
from pijnu import makeParser
preprocessorGrammar = file("preprocessor.pijnu").read()
@@ -62,3 +65,6 @@
<head><title>Test!</title></head>""" + tree.leaves() + "</html>"
file("article.htm", "w").write(output.encode('UTF-8'))
+
+end_time = time.time()
+print "Parsed and rendered in", end_time - start_time, "s."
View
4 preprocessor.pijnu
@@ -43,7 +43,7 @@ def replace_by_space(node):
# Characters
- any_char : [\x20..\xff]
+ any_char : [\x20..\xff] / '/'
esc_char : L_BRACKET/R_BRACKET/PIPE/L_BRACE/R_BRACE/LT/GT/AMP/SEMICOLON
raw_char : !esc_char any_char
raw_text : raw_char+ : join
@@ -76,7 +76,7 @@ def replace_by_space(node):
# Templates
- value_content : (inline / (!(TEMPLATE_END/PIPE) any_char) / EOL)* : keep
+ value_content : (inline / (!(SPACETABEOL* (TEMPLATE_END / PIPE)) (any_char / EOL)))* : keep
parameter_value : value_content SPACETABEOL*
optional_value : parameter_value?
parameter_equal : SPACETABEOL* EQUAL SPACETABEOL*
View
44 tests/test_html_postprocessor.py
@@ -119,6 +119,47 @@ def test_complex_table(self):
'title': 'This is the title with a {{{1}}}!'}
self.parsed_equal_string(source, result, 'wikitext', templates, 'html')
+ def test_wikitext_in_table(self):
+ source = """{| cellpadding="10"
+|- valign="top"
+|
+
+* Line : {{template}}
+* other line : [[link]]...
+|
+== title ==
+----
+::: lists
+|}
+"""
+ result = """<table>
+<tr>
+</tr>
+<tr>
+\t<td><ul>
+\t<li> Line : <a href="Template:template">Template:template</a></li>
+\t<li> other line : <a href="link">link</a>...</li>
+</ul>
+</td>
+\t<td><h2> title </h2>
+<hr />
+<dl>
+\t<dd><dl>
+\t<dd><dl>
+\t<dd> lists</dd>
+</dl>
+</dd>
+</dl>
+</dd>
+</dl>
+</td>
+</tr>
+</table>
+"""
+ templates = {'prettyTable': 'class="prettyTable"',
+ 'title': 'This is the title with a {{{1}}}!'}
+ self.parsed_equal_string(source, result, 'wikitext', templates, 'html')
+
def test_nested_tables(self):
source = """{| style="background:blue" {{prettyTable}}
|+ style="color:red" | Table {{title|1=true}}
@@ -148,8 +189,7 @@ def test_nested_tables(self):
<tr>
\t<th scope="col"> First (mother)</th>
\t<th scope="col"> table</th>
-\t<td>
-<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>
View
7 tests/test_preformatted_paragraphs.py
@@ -101,7 +101,8 @@ def test_pre_paragraph_in_table(self):
table:
table_line_break:
table_line_header:
- @clean_inline@:
- raw_text:
- preformatted:Text"""
+ table_cell:
+ table_cell_content:
+ raw_text:
+ preformatted:Text"""
self.parsed_equal_tree(source, result, None)
View
347 tests/test_tables.py
@@ -4,21 +4,20 @@
class TablesTests(ParserTestCase):
- def test_table_first_cell(self):
+ def test_table_cell(self):
source = 'style="color:red" | cell 1'
- result = """table_first_cell:
+ result = """table_cell:
table_parameter:
HTML_attribute:
attribute_name:style
value_quote:color:red
table_cell_content:
- @clean_inline@:
- raw_text: cell 1"""
- self.parsed_equal_tree(source, result, 'table_first_cell')
+ raw_text: cell 1"""
+ self.parsed_equal_tree(source, result, 'table_cell')
def test_table_other_cell(self):
source = '|| cell 1'
- result = "[@clean_inline@:[raw_text:' cell 1']]"
+ result = "[table_cell_content:[raw_text:' cell 1']]"
self.parsed_equal_string(source, result, 'table_other_cell')
def test_table_special_line(self):
@@ -29,95 +28,93 @@ def test_table_special_line(self):
def test_table_line_with_css(self):
source = '| style="color:red" | cell 1\n'
result = """table_line_cells:
- table_parameter:
- HTML_attribute:
- attribute_name:style
- value_quote:color:red
- table_cell_content:
- @clean_inline@:
+ table_cell:
+ table_parameter:
+ HTML_attribute:
+ attribute_name:style
+ value_quote:color:red
+ table_cell_content:
raw_text: cell 1"""
self.parsed_equal_tree(source, result, 'table_line')
def test_table_line_with_multiple_attributes(self):
source = '| style="color:red" id=\'test\' name=test| cell 1\n'
result = """table_line_cells:
- table_parameter:
- HTML_attribute:
- attribute_name:style
- value_quote:color:red
- HTML_attribute:
- attribute_name:id
- value_apostrophe:test
- HTML_attribute:
- attribute_name:name
- value_noquote:test
- table_cell_content:
- @clean_inline@:
+ table_cell:
+ table_parameter:
+ HTML_attribute:
+ attribute_name:style
+ value_quote:color:red
+ HTML_attribute:
+ attribute_name:id
+ value_apostrophe:test
+ HTML_attribute:
+ attribute_name:name
+ value_noquote:test
+ table_cell_content:
raw_text: cell 1"""
self.parsed_equal_tree(source, result, 'table_line')
def test_table_line_without_css(self):
source = '| cell 1\n'
- result = "[@clean_inline@:[raw_text:' cell 1']]"
+ result = "[table_cell:[table_cell_content:[raw_text:' cell 1']]]"
self.parsed_equal_string(source, result, 'table_line')
def test_table_line_with_dash(self):
source = '|data L2-B\n'
- result = "[@clean_inline@:[raw_text:'data L2-B']]"
+ result = "[table_cell:[table_cell_content:[raw_text:'data L2-B']]]"
self.parsed_equal_string(source, result, 'table_line')
def test_table_line_with_2_cells(self):
source = '| cell 1 || cell 2\n'
result = """table_line_cells:
- table_cell_content:
- @clean_inline@:
+ table_cell:
+ table_cell_content:
raw_text: cell 1
- table_cell_content:
- @clean_inline@:
+ table_cell:
+ table_cell_content:
raw_text: cell 2"""
self.parsed_equal_tree(source, result, 'table_line')
def test_table_line_with_HTML_in_1st_cell(self):
source = '| style="color:red" | cell 1 || cell 2\n'
result = """table_line_cells:
- table_first_cell:
+ table_cell:
table_parameter:
HTML_attribute:
attribute_name:style
value_quote:color:red
table_cell_content:
- @clean_inline@:
- raw_text: cell 1
- table_cell_content:
- @clean_inline@:
+ raw_text: cell 1
+ table_cell:
+ table_cell_content:
raw_text: cell 2"""
self.parsed_equal_tree(source, result, 'table_line')
def test_table_line_with_HTML_in_2nd_cell(self):
source = '| cell 1 || style="color:red" | cell 2\n'
result = """table_line_cells:
- table_cell_content:
- @clean_inline@:
+ table_cell:
+ table_cell_content:
raw_text: cell 1
- table_first_cell:
+ table_cell:
table_parameter:
HTML_attribute:
attribute_name:style
value_quote:color:red
table_cell_content:
- @clean_inline@:
- raw_text: cell 2"""
+ raw_text: cell 2"""
self.parsed_equal_tree(source, result, 'table_line')
def test_table_header_with_css(self):
source = '! scope=row | Line 1\n'
result = """table_line_header:
- table_parameter:
- HTML_attribute:
- attribute_name:scope
- value_noquote:row
- table_cell_content:
- @clean_inline@:
+ table_cell:
+ table_parameter:
+ HTML_attribute:
+ attribute_name:scope
+ value_noquote:row
+ table_cell_content:
raw_text: Line 1"""
self.parsed_equal_tree(source, result, 'table_line')
@@ -131,15 +128,16 @@ def test_table_multiline_content(self):
| test1
test2
|}
-"""
+"""
result = """table:
- @clean_inline@:
- raw_text: test1
- table_multiline_content:
- EOL_KEEP:
-
- @clean_inline@:
- raw_text:test2"""
+ table_cell:
+ table_cell_content:
+ @clean_inline@:
+ raw_text: test1
+ table_multiline_content:
+ table_paragraph:
+ paragraph_line:
+ raw_text:test2"""
self.parsed_equal_tree(source, result, 'table')
def test_table_with_css(self):
@@ -153,22 +151,26 @@ def test_table_with_css(self):
"""
result = """table:
table_line_header:
- @clean_inline@:
- raw_text: cellA
+ table_cell:
+ table_cell_content:
+ raw_text: cellA
table_line_header:
- @clean_inline@:
- raw_text: cellB
+ table_cell:
+ table_cell_content:
+ raw_text: cellB
table_line_break:
table_parameters:
HTML_attribute:
attribute_name:style
value_quote:color:red
table_line_cells:
- @clean_inline@:
- raw_text: cell C
+ table_cell:
+ table_cell_content:
+ raw_text: cell C
table_line_cells:
- @clean_inline@:
- raw_text: cell D"""
+ table_cell:
+ table_cell_content:
+ raw_text: cell D"""
self.parsed_equal_tree(source, result, "table")
def test_table_with_template(self):
@@ -181,22 +183,21 @@ def test_table_with_template(self):
"""
result = """table:
table_title:
- @clean_inline@:
- raw_text: Table test: yes
+ raw_text: Table test: yes
table_line_cells:
- table_cell_content:
- @clean_inline@:
+ table_cell:
+ table_cell_content:
raw_text: cell 1
- table_cell_content:
- @clean_inline@:
+ table_cell:
+ table_cell_content:
raw_text: cell 2
table_line_break:
table_line_cells:
- table_cell_content:
- @clean_inline@:
+ table_cell:
+ table_cell_content:
raw_text: cell 3
- table_cell_content:
- @clean_inline@:
+ table_cell:
+ table_cell_content:
raw_text: cell 4"""
templates = {'title': 'test: {{{parameter}}}'}
self.parsed_equal_tree(source, result, "table", templates)
@@ -233,57 +234,60 @@ def test_table_with_HTML_and_template(self):
HTML_attribute:
attribute_name:style
value_quote:color:red
- table_cell_content:
- @clean_inline@:
- raw_text: Table test: parameter
+ @inline@:
+ raw_text: Table test: parameter
table_line_break:
table_empty_cell:
table_line_header:
- table_parameter:
- HTML_attribute:
- attribute_name:scope
- value_noquote:col
- table_cell_content:
- @clean_inline@:
+ table_cell:
+ table_parameter:
+ HTML_attribute:
+ attribute_name:scope
+ value_noquote:col
+ table_cell_content:
raw_text: Title A
table_line_header:
- table_parameter:
- HTML_attribute:
- attribute_name:scope
- value_noquote:col
- table_cell_content:
- @clean_inline@:
+ table_cell:
+ table_parameter:
+ HTML_attribute:
+ attribute_name:scope
+ value_noquote:col
+ table_cell_content:
raw_text: Title B
table_line_break:
table_line_header:
- table_parameter:
- HTML_attribute:
- attribute_name:scope
- value_noquote:row
- table_cell_content:
- @clean_inline@:
+ table_cell:
+ table_parameter:
+ HTML_attribute:
+ attribute_name:scope
+ value_noquote:row
+ table_cell_content:
raw_text: Line 1
table_line_cells:
- @clean_inline@:
- raw_text:data L1.A
+ table_cell:
+ table_cell_content:
+ raw_text:data L1.A
table_line_cells:
- @clean_inline@:
- raw_text:data L1.B
+ table_cell:
+ table_cell_content:
+ 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@:
+ table_cell:
+ table_parameter:
+ HTML_attribute:
+ attribute_name:scope
+ value_noquote:row
+ table_cell_content:
raw_text: Line 2
table_line_cells:
- @clean_inline@:
- raw_text:data L2.A
+ table_cell:
+ table_cell_content:
+ raw_text:data L2.A
table_line_cells:
- @clean_inline@:
- raw_text:data with and L2.B..."""
+ table_cell:
+ table_cell_content:
+ raw_text:data with and L2.B..."""
templates = {'prettyTable': 'style="color:blue"',
'title': 'test: {{{1}}}',
'template': '{{{1}}} and {{{parameters}}}...'}
@@ -327,80 +331,85 @@ def test_nested_tables(self):
HTML_attribute:
attribute_name:style
value_quote:color:red
- table_cell_content:
- @clean_inline@:
- raw_text: Table test: true
+ @inline@:
+ raw_text: Table test: true
table_line_break:
table_line_header:
- table_parameter:
- HTML_attribute:
- attribute_name:scope
- value_noquote:col
- table_cell_content:
- @clean_inline@:
+ table_cell:
+ table_parameter:
+ HTML_attribute:
+ attribute_name:scope
+ value_noquote:col
+ table_cell_content:
raw_text: First (mother)
table_line_header:
- table_parameter:
- HTML_attribute:
- attribute_name:scope
- value_noquote:col
- table_cell_content:
- @clean_inline@:
+ table_cell:
+ table_parameter:
+ HTML_attribute:
+ attribute_name:scope
+ value_noquote:col
+ table_cell_content:
raw_text: table
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:
+ table_cell:
+ table_cell_content:
+ @table_structure@:
+ table_begin:
+ table_parameters:
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:
+ attribute_name:class
+ value_quote:table
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
+ attribute_name:style
+ value_quote:color:blue
+ table_content:
+ table_line_break:
+ table_line_header:
+ table_cell:
+ table_parameter:
+ HTML_attribute:
+ attribute_name:scope
+ value_noquote:row
+ table_cell_content:
+ raw_text: Second (daughter) table
+ table_line_cells:
+ table_cell:
+ table_cell_content:
+ raw_text:data L1.A
+ table_line_cells:
+ table_cell:
+ table_cell_content:
+ raw_text:data L1.B
+ table_line_break:
+ table_line_header:
+ table_cell:
+ table_parameter:
+ HTML_attribute:
+ attribute_name:scope
+ value_noquote:row
+ table_cell_content:
+ raw_text: in the first one
+ table_line_cells:
+ table_cell:
+ table_cell_content:
+ raw_text:data L2.A
+ table_line_cells:
+ table_cell:
+ table_cell_content:
+ raw_text:data L2.B
table_line_break:
table_line_cells:
- @clean_inline@:
- raw_text: first
+ table_cell:
+ table_cell_content:
+ raw_text: first
table_line_cells:
- @clean_inline@:
- raw_text: table
+ table_cell:
+ table_cell_content:
+ raw_text: table
table_line_cells:
- @clean_inline@:
- raw_text: again"""
+ table_cell:
+ table_cell_content:
+ raw_text: again"""
templates = {'prettyTable': 'style="color:blue"',
'title': 'test: {{{1}}}'}
self.parsed_equal_tree(source, result, "table", templates)
View
2  tests/test_templates.py
@@ -94,7 +94,7 @@ def test_template_with_multiline_named_parameters(self):
| multi = test2
| line parameters = test3
}}"""
- result = "Tests: test1\ncontinues here\n test3\n test2\n ..."
+ result = "Tests: test1\ncontinues here test3 test2..."
templates = {'Template which': 'Tests: {{{has}}} {{{line parameters}}} {{{multi}}}...'}
self.parsed_equal_string(source, result, templates)
View
46 wikitextParser.py
@@ -105,7 +105,7 @@
# Text
- page_name : raw_char+ : join
+ page_name : (raw_char / '/')+ : join
# TODO: allow IPv6 addresses (http://[::1]/etc)
address : (!(QUOTE/R_BRACKET) [\x21..\xff])+ : liftValue
url : protocol address : join
@@ -203,17 +203,20 @@
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_multiline_content : EOL_KEEP !(PIPE/BANG) clean_inline
- table_cell_content : (clean_inline / (EOL+ table_structure) / table_multiline_content)+
- 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
- table_line_header : BANG table_first_cell table_other_cell EOL : liftValue render_table_header_cell
- table_empty_cell : PIPE EOL : keep
+ table_wikitext : list/horizontal_rule/preformatted_group/title/table_structure
+ table_inline : !(PIPE/BANG) clean_inline EOL? : liftNode
+ table_paragraph : (!(PIPE/BANG/TABLE_NEWLINE/TABLE_TITLE/TABLE_END) paragraph_line) : render_paragraph
+ table_multiline_content : (table_paragraph / table_wikitext / EOL)*
+ table_cell_content : table_inline? table_multiline_content : liftValue
+ table_cell : table_parameter table_cell_content
+ table_other_cell : (PIPE{2} table_cell)* : liftValue liftNode
+ table_line_cells : PIPE table_cell table_other_cell : render_table_normal_cell
+ table_line_header : BANG table_cell table_other_cell : render_table_header_cell
+ table_empty_cell : PIPE EOL &(PIPE/BANG/TABLE_END) : keep
table_line_break : TABLE_NEWLINE table_parameters* EOL : keep liftValue render_table_line_break
- table_title : TABLE_TITLE table_parameter table_cell_content EOL : liftValue render_table_caption
+ table_title : TABLE_TITLE table_parameter inline EOL : liftValue render_table_caption
table_special_line : table_title / table_line_break
- table_normal_line : table_line_cells / table_line_header / table_empty_cell
+ table_normal_line : table_empty_cell / table_line_cells / table_line_header
table_line : !TABLE_END (table_special_line / table_normal_line) : liftNode
table_content : (table_line / EOL)* : liftNode
table_begin : TABLE_BEGIN table_parameters* : liftValue
@@ -377,7 +380,7 @@ def replace_by_space(node):
# Text
- page_name = Repetition(raw_char, numMin=1, numMax=False, expression='raw_char+', name='page_name')(toolset['join'])
+ page_name = Repetition(Choice([raw_char, Char('/', expression="'/'")], expression="raw_char / '/'"), numMin=1, numMax=False, expression="(raw_char / '/')+", name='page_name')(toolset['join'])
# TODO: allow IPv6 addresses (http://[::1]/etc)
address = Repetition(Sequence([NextNot(Choice([QUOTE, R_BRACKET], expression='QUOTE/R_BRACKET'), expression='!(QUOTE/R_BRACKET)'), Klass(u'!"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff', expression='[\\x21..\\xff]')], expression='!(QUOTE/R_BRACKET) [\\x21..\\xff]'), numMin=1, numMax=False, expression='(!(QUOTE/R_BRACKET) [\\x21..\\xff])+', name='address')(toolset['liftValue'])
url = Sequence([protocol, address], expression='protocol address', name='url')(toolset['join'])
@@ -475,17 +478,20 @@ 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_multiline_content = Sequence([EOL_KEEP, NextNot(Choice([PIPE, BANG], expression='PIPE/BANG'), expression='!(PIPE/BANG)'), clean_inline], expression='EOL_KEEP !(PIPE/BANG) clean_inline', name='table_multiline_content')
- table_cell_content = Repetition(Choice([clean_inline, Sequence([Repetition(EOL, numMin=1, numMax=False, expression='EOL+'), table_structure], expression='EOL+ table_structure'), table_multiline_content], expression='clean_inline / (EOL+ table_structure) / table_multiline_content'), numMin=1, numMax=False, expression='(clean_inline / (EOL+ table_structure) / table_multiline_content)+', 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'])
- table_line_header = Sequence([BANG, table_first_cell, table_other_cell, EOL], expression='BANG table_first_cell table_other_cell EOL', name='table_line_header')(toolset['liftValue'], toolset['render_table_header_cell'])
- table_empty_cell = Sequence([PIPE, EOL], expression='PIPE EOL', name='table_empty_cell')(toolset['keep'])
+ table_wikitext = Choice([list, horizontal_rule, preformatted_group, title, table_structure], expression='list/horizontal_rule/preformatted_group/title/table_structure', name='table_wikitext')
+ table_inline = Sequence([NextNot(Choice([PIPE, BANG], expression='PIPE/BANG'), expression='!(PIPE/BANG)'), clean_inline, Option(EOL, expression='EOL?')], expression='!(PIPE/BANG) clean_inline EOL?', name='table_inline')(toolset['liftNode'])
+ table_paragraph = Sequence([NextNot(Choice([PIPE, BANG, TABLE_NEWLINE, TABLE_TITLE, TABLE_END], expression='PIPE/BANG/TABLE_NEWLINE/TABLE_TITLE/TABLE_END'), expression='!(PIPE/BANG/TABLE_NEWLINE/TABLE_TITLE/TABLE_END)'), paragraph_line], expression='!(PIPE/BANG/TABLE_NEWLINE/TABLE_TITLE/TABLE_END) paragraph_line', name='table_paragraph')(toolset['render_paragraph'])
+ table_multiline_content = Repetition(Choice([table_paragraph, table_wikitext, EOL], expression='table_paragraph / table_wikitext / EOL'), numMin=False, numMax=False, expression='(table_paragraph / table_wikitext / EOL)*', name='table_multiline_content')
+ table_cell_content = Sequence([Option(table_inline, expression='table_inline?'), table_multiline_content], expression='table_inline? table_multiline_content', name='table_cell_content')(toolset['liftValue'])
+ table_cell = Sequence([table_parameter, table_cell_content], expression='table_parameter table_cell_content', name='table_cell')
+ table_other_cell = Repetition(Sequence([Repetition(PIPE, numMin=2, numMax=2, expression='PIPE{2}'), table_cell], expression='PIPE{2} table_cell'), numMin=False, numMax=False, expression='(PIPE{2} table_cell)*', name='table_other_cell')(toolset['liftValue'], toolset['liftNode'])
+ table_line_cells = Sequence([PIPE, table_cell, table_other_cell], expression='PIPE table_cell table_other_cell', name='table_line_cells')(toolset['render_table_normal_cell'])
+ table_line_header = Sequence([BANG, table_cell, table_other_cell], expression='BANG table_cell table_other_cell', name='table_line_header')(toolset['render_table_header_cell'])
+ table_empty_cell = Sequence([PIPE, EOL, Next(Choice([PIPE, BANG, TABLE_END], expression='PIPE/BANG/TABLE_END'), expression='&(PIPE/BANG/TABLE_END)')], expression='PIPE EOL &(PIPE/BANG/TABLE_END)', name='table_empty_cell')(toolset['keep'])
table_line_break = Sequence([TABLE_NEWLINE, Repetition(table_parameters, numMin=False, numMax=False, expression='table_parameters*'), EOL], expression='TABLE_NEWLINE table_parameters* EOL', name='table_line_break')(toolset['keep'], toolset['liftValue'], toolset['render_table_line_break'])
- table_title = Sequence([TABLE_TITLE, table_parameter, table_cell_content, EOL], expression='TABLE_TITLE table_parameter table_cell_content EOL', name='table_title')(toolset['liftValue'], toolset['render_table_caption'])
+ table_title = Sequence([TABLE_TITLE, table_parameter, inline, EOL], expression='TABLE_TITLE table_parameter inline EOL', name='table_title')(toolset['liftValue'], toolset['render_table_caption'])
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_normal_line = Choice([table_empty_cell, table_line_cells, table_line_header], expression='table_empty_cell / table_line_cells / table_line_header', 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, 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'])
Please sign in to comment.
Something went wrong with that request. Please try again.