Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

executable file 246 lines (201 sloc) 18.024 kB
wikitext
<toolset>
def replace_by_space(node):
node.value = ' '
def replace_by_2_spaces(node):
node.value = ' '
def replace_by_8_spaces(node):
node.value = ' '
<definition>
# Codes
LF : '
'
CR : '
'
EOL : LF / CR : drop
L_BRACKET : "[" : drop
R_BRACKET : "\]" : drop
L_BRACE : "{" : drop
R_BRACE : "}" : drop
SPACE : " " : drop
TAB : " " : drop
SPACETAB : SPACE / TAB : drop
SPACETABEOL : SPACE / TAB / EOL : drop
AMP : "&" : drop
PIPE : "|" : drop
BANG : "!" : drop
EQUAL : "=" : drop
BULLET : "*" : drop
HASH : "#" : drop
COLON : ":" : drop
LT : "<" : render_lt
GT : ">" : render_gt
SLASH : "/" : drop
SEMICOLON : ";" : drop
DASH : "-" : drop
TABLE_BEGIN : "{|" : drop
TABLE_END : "|}" : drop
TABLE_NEWLINE : "|-" : drop
TABLE_TITLE : "|+" : drop
QUOTE : "\"" : drop
APOSTROPHE : "\'" : drop
TITLE6_BEGIN : EQUAL{6} : drop
TITLE5_BEGIN : EQUAL{5} : drop
TITLE4_BEGIN : EQUAL{4} : drop
TITLE3_BEGIN : EQUAL{3} : drop
TITLE2_BEGIN : EQUAL{2} : drop
TITLE1_BEGIN : EQUAL{1} : drop
TITLE6_END : EQUAL{6} SPACETAB* EOL : drop
TITLE5_END : EQUAL{5} SPACETAB* EOL : drop
TITLE4_END : EQUAL{4} SPACETAB* EOL : drop
TITLE3_END : EQUAL{3} SPACETAB* EOL : drop
TITLE2_END : EQUAL{2} SPACETAB* EOL : drop
TITLE1_END : EQUAL{1} SPACETAB* EOL : drop
LINK_BEGIN : L_BRACKET{2} : drop
LINK_END : R_BRACKET{2} : drop
# Protocols
HTTPS : "https://" : liftValue
HTTP : "http://" : liftValue
FTP : "ftp://" : liftValue
protocol : HTTPS / HTTP / FTP : liftValue
# Predefined tags
NOWIKI_BEGIN : "<nowiki>" : drop
NOWIKI_END : "</nowiki>" : drop
PRE_BEGIN : "<pre>" : drop
PRE_END : "</pre>" : drop
SPECIAL_TAG : NOWIKI_BEGIN/NOWIKI_END/PRE_BEGIN/PRE_END
# Characters
ESC_CHAR : L_BRACKET/R_BRACKET/protocol/PIPE/L_BRACE/R_BRACE/LT/GT/SLASH/AMP/SEMICOLON/TAB
TITLE_END : TITLE6_END/TITLE5_END/TITLE4_END/TITLE3_END/TITLE2_END/TITLE1_END
ESC_SEQ : SPECIAL_TAG / ESC_CHAR / TITLE_END
tab_to_space : TAB+ : replace_by_space
raw_char : (!ESC_SEQ [\x20..\xff])
raw_text : raw_char+ : join render_raw_text
alpha_num : [a..zA..Z0..9]
alpha_num_text : alpha_num+ : join
any_char : [\x20..\xff] / tab_to_space
any_text : any_char+ : join
# HTML tags
value_quote : QUOTE ((!(GT/QUOTE) any_char) / TAB)+ QUOTE : join
value_apostrophe : APOSTROPHE ((!(GT/APOSTROPHE) any_char) / TAB)+ APOSTROPHE : join
value_noquote : (!(GT/SPACETAB/SLASH) raw_char)+ : join
attribute_value : (EQUAL (value_quote / value_apostrophe / value_noquote)) : liftNode
attribute_name : (!(EQUAL/SLASH/SPACETAB) raw_char)+ : join
tag_name : (!(SPACE/SLASH) alpha_num)+ : join
optional_attribute : SPACETABEOL+ attribute_name attribute_value?
optional_attributes : optional_attribute*
tag_lt : LT : drop
tag_gt : GT : drop
tag_open : tag_lt tag_name optional_attributes SPACETABEOL* tag_gt : render_tag_open
tag_close : tag_lt SLASH tag_name tag_gt : render_tag_close
tag_autoclose : tag_lt tag_name optional_attributes SPACETABEOL* SLASH tag_gt : render_tag_autoclose
tag : tag_autoclose / tag_open / tag_close
# HTML entities
entity : AMP alpha_num_text SEMICOLON : render_entity
# HTML comments
# HTML comments are totally ignored and do not appear in the final text
comment_content : ((!(DASH{2} GT) [\x20..\xff])+ / SPACETABEOL)*
html_comment : tag_lt BANG DASH{2} comment_content DASH{2} tag_gt : drop
optional_comment : html_comment*
# Text
page_name : (raw_char / '/')+ : join
# TODO: allow IPv6 addresses (http://[::1]/etc)
address : (!(QUOTE/R_BRACKET) [\x21..\xff])+ : liftValue
url : protocol address : join
inline_url : url{1} : render_url
# Links
allowed_in_link : (!(R_BRACKET/PIPE) ESC_CHAR)+ : restore join
link_text : (clean_inline / allowed_in_link)* : liftValue
link_argument : PIPE link_text : liftValue
link_arguments : link_argument*
internal_link : LINK_BEGIN page_name link_arguments LINK_END : render_internal_link
optional_link_text : SPACETAB+ link_text : liftValue
external_link : L_BRACKET url optional_link_text? R_BRACKET : render_external_link
link : internal_link / external_link
# Pre and nowiki tags
# Preformatted acts like nowiki (disables wikitext parsing)
tab_to_2_spaces : TAB : replace_by_2_spaces
pre_text : (tab_to_2_spaces / (!PRE_END any_char))* : join
preformatted : PRE_BEGIN pre_text PRE_END : liftValue
# We allow any char without parsing them as long as the tag is not closed
eol_to_space : EOL* : replace_by_space
nowiki_text : (!NOWIKI_END (any_char/eol_to_space))* : join
nowiki : NOWIKI_BEGIN nowiki_text NOWIKI_END : liftValue
# Text types
styled_text : link / inline_url / html_comment / tag / entity
not_styled_text : preformatted / nowiki
allowed_char : ESC_CHAR{1} : restore liftValue
allowed_text : raw_text / LT / GT / tab_to_space / allowed_char
clean_inline : (not_styled_text / styled_text / raw_text)+ : @
inline : (not_styled_text / styled_text / allowed_text)+ : @
# Paragraphs
special_line_begin : SPACE/EQUAL/BULLET/HASH/COLON/DASH{4}/TABLE_BEGIN/SEMICOLON
paragraph_line : !special_line_begin inline EOL : liftValue
blank_paragraph : EOL{2} : drop keep
paragraph : paragraph_line+ : liftValue render_paragraph
paragraphs : (blank_paragraph/EOL/paragraph)+
# Titles
title6 : TITLE6_BEGIN inline TITLE6_END : liftValue render_title6
title5 : TITLE5_BEGIN inline TITLE5_END : liftValue render_title5
title4 : TITLE4_BEGIN inline TITLE4_END : liftValue render_title4
title3 : TITLE3_BEGIN inline TITLE3_END : liftValue render_title3
title2 : TITLE2_BEGIN inline TITLE2_END : liftValue render_title2
title1 : TITLE1_BEGIN inline TITLE1_END : liftValue render_title1
title : title6 / title5 / title4 / title3 / title2 / title1
# Lists
LIST_CHAR : BULLET / HASH / COLON / SEMICOLON
list_leaf_content : !LIST_CHAR inline EOL : liftValue
bullet_list_leaf : BULLET optional_comment list_leaf_content : liftValue
bullet_sub_list : BULLET optional_comment list_item : @
number_list_leaf : HASH optional_comment list_leaf_content : liftValue
number_sub_list : HASH optional_comment list_item : @
colon_list_leaf : COLON optional_comment list_leaf_content : liftValue
colon_sub_list : COLON optional_comment list_item : @
semi_colon_list_leaf : SEMICOLON optional_comment list_leaf_content : liftValue
semi_colon_sub_list : SEMICOLON optional_comment list_item : @
list_leaf : semi_colon_list_leaf/colon_list_leaf/number_list_leaf/bullet_list_leaf: @
sub_list : semi_colon_sub_list/colon_sub_list/number_sub_list/bullet_sub_list : @
list_item : sub_list / list_leaf : @
list : list_item+ : render_list
# Preformatted
EOL_KEEP : EOL : restore
tab_to_8_spaces : TAB : replace_by_8_spaces
any_char_but_tab : raw_text / LT / GT / (!TAB ESC_CHAR) : join
preformatted_inline : (tab_to_8_spaces / not_styled_text / styled_text / any_char_but_tab)+
preformatted_line : SPACE preformatted_inline EOL_KEEP : liftValue
preformatted_lines : preformatted_line+
preformatted_text : preformatted_inline EOL? : liftValue
preformatted_paragraph : PRE_BEGIN EOL preformatted_text PRE_END EOL
preformatted_group : preformatted_paragraph / preformatted_lines : render_preformatted
# Special lines
horizontal_rule : DASH{4} DASH* inline* EOL : liftValue keep render_hr
# This should never happen
invalid_line : any_text EOL : liftValue
# Tables
HTML_attribute : SPACETAB* attribute_name attribute_value SPACETAB* : render_attribute
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_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 inline EOL : liftValue render_table_caption
table_special_line : table_title / table_line_break
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
table_structure : table_begin SPACETABEOL* table_content TABLE_END : @ liftValue render_table
table : table_structure EOL : liftValue
# Top pattern
valid_syntax : list/horizontal_rule/preformatted_group/title/table/EOL/paragraphs
wikitext : optional_comment (valid_syntax/invalid_line)+ : liftValue render_wikitext
body : wikitext{1} : liftValue render_body
Jump to Line
Something went wrong with that request. Please try again.