-
Notifications
You must be signed in to change notification settings - Fork 29
/
mediawiki.pijnu
executable file
·245 lines (201 loc) · 17.6 KB
/
mediawiki.pijnu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
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