mediacloth 0.0.3 → 0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +36 -0
- data/lib/mediacloth/mediawikiast.rb +58 -1
- data/lib/mediacloth/mediawikihtmlgenerator.rb +229 -73
- data/lib/mediacloth/mediawikilexer.rb +1030 -656
- data/lib/mediacloth/mediawikilinkhandler.rb +89 -0
- data/lib/mediacloth/mediawikiparams.rb +1 -10
- data/lib/mediacloth/mediawikiparser.rb +939 -409
- data/lib/mediacloth/mediawikiparser.tab.rb +1357 -0
- data/lib/mediacloth/mediawikiparser.y +256 -52
- data/lib/mediacloth/mediawikisignedwikigenerator.rb +42 -0
- data/lib/mediacloth/mediawikitemplatehandler.rb +8 -0
- data/lib/mediacloth/mediawikiwalker.rb +72 -1
- data/lib/mediacloth.rb +33 -10
- data/test/data/ast1 +68 -0
- data/test/data/ast10 +196 -0
- data/test/data/ast11 +34 -0
- data/test/data/ast12 +39 -0
- data/test/data/ast13 +25 -0
- data/test/data/ast14 +13 -0
- data/test/data/ast15 +25 -0
- data/test/data/ast16 +17 -0
- data/test/data/ast17 +9 -0
- data/test/data/ast18 +21 -0
- data/test/data/ast19 +32 -0
- data/test/data/ast2 +4 -0
- data/test/data/ast20 +10 -0
- data/test/data/ast21 +27 -0
- data/test/data/ast22 +22 -0
- data/test/data/ast23 +5 -0
- data/test/data/ast3 +6 -0
- data/test/data/ast4 +122 -0
- data/test/data/ast5 +122 -0
- data/test/data/ast6 +22 -0
- data/test/data/ast7 +143 -0
- data/test/data/ast8 +3 -0
- data/test/data/ast9 +11 -0
- data/test/data/html1 +33 -5
- data/test/data/html10 +31 -27
- data/test/data/html11 +19 -0
- data/test/data/html12 +32 -0
- data/test/data/html13 +29 -0
- data/test/data/html14 +4 -0
- data/test/data/html15 +29 -0
- data/test/data/html16 +28 -0
- data/test/data/html17 +10 -0
- data/test/data/html18 +8 -0
- data/test/data/html19 +27 -0
- data/test/data/html2 +1 -1
- data/test/data/html20 +7 -0
- data/test/data/html21 +5 -0
- data/test/data/html22 +24 -0
- data/test/data/html23 +7 -0
- data/test/data/html3 +1 -1
- data/test/data/html4 +60 -11
- data/test/data/html5 +45 -6
- data/test/data/html6 +5 -5
- data/test/data/html7 +59 -1
- data/test/data/html8 +1 -1
- data/test/data/html9 +10 -2
- data/test/data/input1 +4 -0
- data/test/data/input11 +19 -0
- data/test/data/input12 +32 -0
- data/test/data/input13 +10 -0
- data/test/data/input14 +8 -0
- data/test/data/input15 +10 -0
- data/test/data/input16 +28 -0
- data/test/data/input17 +10 -0
- data/test/data/input18 +16 -0
- data/test/data/input19 +29 -0
- data/test/data/input20 +8 -0
- data/test/data/input21 +18 -0
- data/test/data/input22 +20 -0
- data/test/data/input23 +8 -0
- data/test/data/input4 +13 -1
- data/test/data/input5 +45 -4
- data/test/data/input7 +25 -1
- data/test/data/lex1 +17 -18
- data/test/data/lex10 +57 -87
- data/test/data/lex11 +18 -0
- data/test/data/lex12 +32 -0
- data/test/data/lex13 +3 -0
- data/test/data/lex14 +1 -0
- data/test/data/lex15 +3 -0
- data/test/data/lex16 +27 -0
- data/test/data/lex17 +9 -0
- data/test/data/lex18 +4 -0
- data/test/data/lex19 +27 -0
- data/test/data/lex2 +2 -2
- data/test/data/lex20 +7 -0
- data/test/data/lex21 +4 -0
- data/test/data/lex22 +3 -0
- data/test/data/lex23 +7 -0
- data/test/data/lex3 +1 -1
- data/test/data/lex4 +35 -29
- data/test/data/lex5 +57 -18
- data/test/data/lex6 +7 -7
- data/test/data/lex7 +42 -18
- data/test/data/lex8 +1 -1
- data/test/data/lex9 +6 -6
- data/test/dataproducers/ast.rb +24 -0
- data/test/dataproducers/html.rb +11 -12
- data/test/dataproducers/lex.rb +9 -4
- data/test/debugwalker.rb +25 -11
- data/test/htmlgenerator.rb +170 -13
- data/test/lexer.rb +626 -83
- data/test/linkhandler.rb +39 -0
- data/test/parser.rb +176 -9
- data/test/signedwikigenerator.rb +113 -0
- metadata +158 -79
- data/README +0 -37
- data/lib/mediacloth/mediawikilexer.rb~ +0 -491
- data/lib/mediacloth/mediawikiparser.y~ +0 -210
- data/test/data/result1 +0 -48
- data/test/dataproducers/html.rb~ +0 -24
- data/test/dataproducers/lex.rb~ +0 -15
@@ -8,13 +8,14 @@
|
|
8
8
|
# parser.parse(input)
|
9
9
|
class MediaWikiParser
|
10
10
|
|
11
|
-
token
|
12
|
-
|
13
|
-
|
14
|
-
HLINE SIGNATURE_NAME SIGNATURE_DATE SIGNATURE_FULL
|
15
|
-
UL_START UL_END LI_START LI_END
|
11
|
+
token TEXT BOLD_START BOLD_END ITALIC_START ITALIC_END LINK_START LINK_END LINKSEP
|
12
|
+
INTLINK_START INTLINK_END INTLINKSEP RESOURCESEP CHAR_ENT
|
13
|
+
PRE_START PRE_END PREINDENT_START PREINDENT_END
|
14
|
+
SECTION_START SECTION_END HLINE SIGNATURE_NAME SIGNATURE_DATE SIGNATURE_FULL
|
15
|
+
PARA_START PARA_END UL_START UL_END OL_START OL_END LI_START LI_END
|
16
|
+
DL_START DL_END DT_START DT_END DD_START DD_END TAG_START TAG_END ATTR_NAME ATTR_VALUE
|
16
17
|
TABLE_START TABLE_END ROW_START ROW_END HEAD_START HEAD_END CELL_START CELL_END
|
17
|
-
|
18
|
+
KEYWORD TEMPLATE_START TEMPLATE_END CATEGORY PASTE_START PASTE_END
|
18
19
|
|
19
20
|
|
20
21
|
rule
|
@@ -22,7 +23,7 @@ rule
|
|
22
23
|
wiki:
|
23
24
|
repeated_contents
|
24
25
|
{
|
25
|
-
@nodes.push WikiAST.new
|
26
|
+
@nodes.push WikiAST.new(0, @wiki_ast_length)
|
26
27
|
#@nodes.last.children.insert(0, val[0])
|
27
28
|
#puts val[0]
|
28
29
|
@nodes.last.children += val[0]
|
@@ -42,50 +43,87 @@ contents:
|
|
42
43
|
{
|
43
44
|
result = val[0]
|
44
45
|
}
|
46
|
+
| dictionary_list
|
47
|
+
{
|
48
|
+
list = ListAST.new(@ast_index, @ast_length)
|
49
|
+
list.list_type = :Dictionary
|
50
|
+
list.children = val[0]
|
51
|
+
result = list
|
52
|
+
}
|
45
53
|
| preformatted
|
46
54
|
{
|
47
|
-
|
48
|
-
p.contents = val[0]
|
49
|
-
result = p
|
55
|
+
result = val[0]
|
50
56
|
}
|
51
57
|
| section
|
52
58
|
{
|
53
59
|
result = val[0]
|
54
60
|
}
|
61
|
+
| tag
|
62
|
+
{
|
63
|
+
result = val[0]
|
64
|
+
}
|
65
|
+
| template
|
66
|
+
{
|
67
|
+
result = val[0]
|
68
|
+
}
|
69
|
+
| KEYWORD
|
70
|
+
{
|
71
|
+
k = KeywordAST.new(@ast_index, @ast_length)
|
72
|
+
k.text = val[0]
|
73
|
+
result = k
|
74
|
+
}
|
55
75
|
| PARA_START para_contents PARA_END
|
56
76
|
{
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
result = p
|
61
|
-
end
|
77
|
+
p = ParagraphAST.new(@ast_index, @ast_length)
|
78
|
+
p.children = val[1]
|
79
|
+
result = p
|
62
80
|
}
|
63
|
-
|
|
81
|
+
| LINK_START link_contents LINK_END
|
64
82
|
{
|
65
|
-
l = LinkAST.new
|
83
|
+
l = LinkAST.new(@ast_index, @ast_length)
|
84
|
+
l.link_type = val[0]
|
66
85
|
l.url = val[1][0]
|
67
86
|
l.children += val[1][1..-1] if val[1].length > 1
|
68
87
|
result = l
|
69
88
|
}
|
70
|
-
|
|
89
|
+
| PASTE_START para_contents PASTE_END
|
90
|
+
{
|
91
|
+
p = PasteAST.new(@ast_index, @ast_length)
|
92
|
+
p.children = val[1]
|
93
|
+
result = p
|
94
|
+
}
|
95
|
+
| INTLINK_START TEXT RESOURCESEP TEXT reslink_repeated_contents INTLINK_END
|
71
96
|
{
|
72
|
-
l = ResourceLinkAST.new
|
97
|
+
l = ResourceLinkAST.new(@ast_index, @ast_length)
|
73
98
|
l.prefix = val[1]
|
74
99
|
l.locator = val[3]
|
75
100
|
l.children = val[4] unless val[4].nil? or val[4].empty?
|
76
101
|
result = l
|
77
102
|
}
|
78
|
-
|
|
103
|
+
| INTLINK_START TEXT intlink_repeated_contents INTLINK_END
|
79
104
|
{
|
80
|
-
l = InternalLinkAST.new
|
105
|
+
l = InternalLinkAST.new(@ast_index, @ast_length)
|
81
106
|
l.locator = val[1]
|
82
107
|
l.children = val[2] unless val[2].nil? or val[2].empty?
|
83
108
|
result = l
|
84
109
|
}
|
110
|
+
| INTLINK_START CATEGORY TEXT cat_sort_contents INTLINK_END
|
111
|
+
{
|
112
|
+
l = CategoryAST.new(@ast_index, @ast_length)
|
113
|
+
l.locator = val[2]
|
114
|
+
l.sort_as = val[3]
|
115
|
+
result = l
|
116
|
+
}
|
117
|
+
| INTLINK_START RESOURCESEP CATEGORY TEXT intlink_repeated_contents INTLINK_END
|
118
|
+
{
|
119
|
+
l = CategoryLinkAST.new(@ast_index, @ast_length)
|
120
|
+
l.locator = val[3]
|
121
|
+
l.children = val[4] unless val[4].nil? or val[4].empty?
|
122
|
+
result = l
|
123
|
+
}
|
85
124
|
| table
|
86
125
|
;
|
87
126
|
|
88
|
-
#TODO: remove empty paragraphs in lexer
|
89
127
|
para_contents:
|
90
128
|
{
|
91
129
|
result = nil
|
@@ -96,6 +134,49 @@ para_contents:
|
|
96
134
|
}
|
97
135
|
;
|
98
136
|
|
137
|
+
tag:
|
138
|
+
TAG_START tag_attributes TAG_END
|
139
|
+
{
|
140
|
+
if val[0] != val[2]
|
141
|
+
raise Racc::ParseError.new("XHTML end tag #{val[2]} does not match start tag #{val[0]}")
|
142
|
+
end
|
143
|
+
elem = ElementAST.new(@ast_index, @ast_length)
|
144
|
+
elem.name = val[0]
|
145
|
+
elem.attributes = val[1]
|
146
|
+
result = elem
|
147
|
+
}
|
148
|
+
| TAG_START tag_attributes repeated_contents TAG_END
|
149
|
+
{
|
150
|
+
if val[0] != val[3]
|
151
|
+
raise Racc::ParseError.new("XHTML end tag #{val[3]} does not match start tag #{val[0]}")
|
152
|
+
end
|
153
|
+
elem = ElementAST.new(@ast_index, @ast_length)
|
154
|
+
elem.name = val[0]
|
155
|
+
elem.attributes = val[1]
|
156
|
+
elem.children += val[2]
|
157
|
+
result = elem
|
158
|
+
}
|
159
|
+
;
|
160
|
+
|
161
|
+
tag_attributes:
|
162
|
+
{
|
163
|
+
result = nil
|
164
|
+
}
|
165
|
+
| ATTR_NAME tag_attributes
|
166
|
+
{
|
167
|
+
attr_map = val[2] ? val[2] : {}
|
168
|
+
attr_map[val[0]] = true
|
169
|
+
result = attr_map
|
170
|
+
}
|
171
|
+
| ATTR_NAME ATTR_VALUE tag_attributes
|
172
|
+
{
|
173
|
+
attr_map = val[2] ? val[2] : {}
|
174
|
+
attr_map[val[0]] = val[1]
|
175
|
+
result = attr_map
|
176
|
+
}
|
177
|
+
;
|
178
|
+
|
179
|
+
|
99
180
|
link_contents:
|
100
181
|
TEXT
|
101
182
|
{
|
@@ -132,6 +213,16 @@ intlink_repeated_contents:
|
|
132
213
|
}
|
133
214
|
;
|
134
215
|
|
216
|
+
cat_sort_contents:
|
217
|
+
{
|
218
|
+
result = nil
|
219
|
+
}
|
220
|
+
| INTLINKSEP TEXT
|
221
|
+
{
|
222
|
+
result = val[1]
|
223
|
+
}
|
224
|
+
;
|
225
|
+
|
135
226
|
reslink_repeated_contents:
|
136
227
|
{
|
137
228
|
result = nil
|
@@ -142,7 +233,7 @@ reslink_repeated_contents:
|
|
142
233
|
}
|
143
234
|
| INTLINKSEP repeated_contents reslink_repeated_contents
|
144
235
|
{
|
145
|
-
i = InternalLinkItemAST.new
|
236
|
+
i = InternalLinkItemAST.new(@ast_index, @ast_length)
|
146
237
|
i.children = val[1]
|
147
238
|
result = [i]
|
148
239
|
result += val[2] if val[2]
|
@@ -164,7 +255,7 @@ repeated_contents: contents
|
|
164
255
|
|
165
256
|
text: element
|
166
257
|
{
|
167
|
-
p = TextAST.new
|
258
|
+
p = TextAST.new(@ast_index, @ast_length)
|
168
259
|
p.formatting = val[0][0]
|
169
260
|
p.contents = val[0][1]
|
170
261
|
result = p
|
@@ -178,13 +269,13 @@ text: element
|
|
178
269
|
table:
|
179
270
|
TABLE_START table_contents TABLE_END
|
180
271
|
{
|
181
|
-
table = TableAST.new
|
272
|
+
table = TableAST.new(@ast_index, @ast_length)
|
182
273
|
table.children = val[1] unless val[1].nil? or val[1].empty?
|
183
274
|
result = table
|
184
275
|
}
|
185
276
|
| TABLE_START TEXT table_contents TABLE_END
|
186
277
|
{
|
187
|
-
table = TableAST.new
|
278
|
+
table = TableAST.new(@ast_index, @ast_length)
|
188
279
|
table.options = val[1]
|
189
280
|
table.children = val[2] unless val[2].nil? or val[2].empty?
|
190
281
|
result = table
|
@@ -196,14 +287,14 @@ table_contents:
|
|
196
287
|
}
|
197
288
|
| ROW_START row_contents ROW_END table_contents
|
198
289
|
{
|
199
|
-
row = TableRowAST.new
|
290
|
+
row = TableRowAST.new(@ast_index, @ast_length)
|
200
291
|
row.children = val[1] unless val[1].nil? or val[1].empty?
|
201
292
|
result = [row]
|
202
293
|
result += val[3] unless val[3].nil? or val[3].empty?
|
203
294
|
}
|
204
295
|
| ROW_START TEXT row_contents ROW_END table_contents
|
205
296
|
{
|
206
|
-
row = TableRowAST.new
|
297
|
+
row = TableRowAST.new(@ast_index, @ast_length)
|
207
298
|
row.children = val[2] unless val[2].nil? or val[2].empty?
|
208
299
|
row.options = val[1]
|
209
300
|
result = [row]
|
@@ -216,14 +307,14 @@ row_contents:
|
|
216
307
|
}
|
217
308
|
| HEAD_START HEAD_END row_contents
|
218
309
|
{
|
219
|
-
cell = TableCellAST.new
|
310
|
+
cell = TableCellAST.new(@ast_index, @ast_length)
|
220
311
|
cell.type = :head
|
221
312
|
result = [cell]
|
222
313
|
result += val[2] unless val[2].nil? or val[2].empty?
|
223
314
|
}
|
224
315
|
| HEAD_START repeated_contents HEAD_END row_contents
|
225
316
|
{
|
226
|
-
cell = TableCellAST.new
|
317
|
+
cell = TableCellAST.new(@ast_index, @ast_length)
|
227
318
|
cell.children = val[1] unless val[1].nil? or val[1].empty?
|
228
319
|
cell.type = :head
|
229
320
|
result = [cell]
|
@@ -231,26 +322,36 @@ row_contents:
|
|
231
322
|
}
|
232
323
|
| CELL_START CELL_END row_contents
|
233
324
|
{
|
234
|
-
cell = TableCellAST.new
|
325
|
+
cell = TableCellAST.new(@ast_index, @ast_length)
|
235
326
|
cell.type = :body
|
236
327
|
result = [cell]
|
237
328
|
result += val[2] unless val[2].nil? or val[2].empty?
|
238
329
|
}
|
239
330
|
| CELL_START repeated_contents CELL_END row_contents
|
240
331
|
{
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
332
|
+
if val[2] == 'attributes'
|
333
|
+
result = []
|
334
|
+
else
|
335
|
+
cell = TableCellAST.new(@ast_index, @ast_length)
|
336
|
+
cell.children = val[1] unless val[1].nil? or val[1].empty?
|
337
|
+
cell.type = :body
|
338
|
+
result = [cell]
|
339
|
+
end
|
245
340
|
result += val[3] unless val[3].nil? or val[3].empty?
|
341
|
+
if val[2] == 'attributes' and val[3] and val[3].first.class == TableCellAST
|
342
|
+
val[3].first.attributes = val[1]
|
343
|
+
end
|
344
|
+
result
|
246
345
|
}
|
247
|
-
|
346
|
+
|
248
347
|
|
249
348
|
element:
|
250
349
|
TEXT
|
251
350
|
{ return [:None, val[0]] }
|
252
351
|
| HLINE
|
253
352
|
{ return [:HLine, val[0]] }
|
353
|
+
| CHAR_ENT
|
354
|
+
{ return [:CharacterEntity, val[0]] }
|
254
355
|
| SIGNATURE_DATE
|
255
356
|
{ return [:SignatureDate, val[0]] }
|
256
357
|
| SIGNATURE_NAME
|
@@ -260,28 +361,28 @@ element:
|
|
260
361
|
;
|
261
362
|
|
262
363
|
formatted_element:
|
263
|
-
|
364
|
+
BOLD_START BOLD_END
|
264
365
|
{
|
265
|
-
result = FormattedAST.new
|
366
|
+
result = FormattedAST.new(@ast_index, @ast_length)
|
266
367
|
result.formatting = :Bold
|
267
368
|
result
|
268
369
|
}
|
269
|
-
|
|
370
|
+
| ITALIC_START ITALIC_END
|
270
371
|
{
|
271
|
-
result = FormattedAST.new
|
372
|
+
result = FormattedAST.new(@ast_index, @ast_length)
|
272
373
|
result.formatting = :Italic
|
273
374
|
result
|
274
375
|
}
|
275
|
-
|
|
376
|
+
| BOLD_START repeated_contents BOLD_END
|
276
377
|
{
|
277
|
-
p = FormattedAST.new
|
378
|
+
p = FormattedAST.new(@ast_index, @ast_length)
|
278
379
|
p.formatting = :Bold
|
279
380
|
p.children += val[1]
|
280
381
|
result = p
|
281
382
|
}
|
282
|
-
|
|
383
|
+
| ITALIC_START repeated_contents ITALIC_END
|
283
384
|
{
|
284
|
-
p = FormattedAST.new
|
385
|
+
p = FormattedAST.new(@ast_index, @ast_length)
|
285
386
|
p.formatting = :Italic
|
286
387
|
p.children += val[1]
|
287
388
|
result = p
|
@@ -290,7 +391,7 @@ formatted_element:
|
|
290
391
|
|
291
392
|
bulleted_list: UL_START list_item list_contents UL_END
|
292
393
|
{
|
293
|
-
list = ListAST.new
|
394
|
+
list = ListAST.new(@ast_index, @ast_length)
|
294
395
|
list.list_type = :Bulleted
|
295
396
|
list.children << val[1]
|
296
397
|
list.children += val[2]
|
@@ -300,7 +401,7 @@ bulleted_list: UL_START list_item list_contents UL_END
|
|
300
401
|
|
301
402
|
numbered_list: OL_START list_item list_contents OL_END
|
302
403
|
{
|
303
|
-
list = ListAST.new
|
404
|
+
list = ListAST.new(@ast_index, @ast_length)
|
304
405
|
list.list_type = :Numbered
|
305
406
|
list.children << val[1]
|
306
407
|
list.children += val[2]
|
@@ -322,29 +423,116 @@ list_contents:
|
|
322
423
|
list_item:
|
323
424
|
LI_START LI_END
|
324
425
|
{
|
325
|
-
result = ListItemAST.new
|
426
|
+
result = ListItemAST.new(@ast_index, @ast_length)
|
326
427
|
}
|
327
428
|
| LI_START repeated_contents LI_END
|
328
429
|
{
|
329
|
-
li = ListItemAST.new
|
430
|
+
li = ListItemAST.new(@ast_index, @ast_length)
|
330
431
|
li.children += val[1]
|
331
432
|
result = li
|
332
433
|
}
|
333
434
|
;
|
334
435
|
|
335
|
-
|
336
|
-
|
436
|
+
dictionary_list:
|
437
|
+
DL_START dictionary_term dictionary_contents DL_END
|
438
|
+
{
|
439
|
+
result = [val[1]]
|
440
|
+
result += val[2]
|
441
|
+
}
|
442
|
+
| DL_START dictionary_contents DL_END
|
443
|
+
{
|
444
|
+
result = val[1]
|
445
|
+
}
|
446
|
+
;
|
447
|
+
|
448
|
+
dictionary_term:
|
449
|
+
DT_START DT_END
|
450
|
+
{
|
451
|
+
result = ListTermAST.new(@ast_index, @ast_length)
|
452
|
+
}
|
453
|
+
| DT_START repeated_contents DT_END
|
454
|
+
{
|
455
|
+
term = ListTermAST.new(@ast_index, @ast_length)
|
456
|
+
term.children += val[1]
|
457
|
+
result = term
|
458
|
+
}
|
459
|
+
|
460
|
+
dictionary_contents:
|
461
|
+
dictionary_definition dictionary_contents
|
462
|
+
{
|
463
|
+
result = [val[0]]
|
464
|
+
result += val[1] if val[1]
|
465
|
+
}
|
466
|
+
|
|
467
|
+
{
|
468
|
+
result = []
|
469
|
+
}
|
470
|
+
|
471
|
+
dictionary_definition:
|
472
|
+
DD_START DD_END
|
473
|
+
{
|
474
|
+
result = ListDefinitionAST.new(@ast_index, @ast_length)
|
475
|
+
}
|
476
|
+
| DD_START repeated_contents DD_END
|
477
|
+
{
|
478
|
+
term = ListDefinitionAST.new(@ast_index, @ast_length)
|
479
|
+
term.children += val[1]
|
480
|
+
result = term
|
481
|
+
}
|
482
|
+
|
483
|
+
preformatted: PRE_START repeated_contents PRE_END
|
484
|
+
{
|
485
|
+
p = PreformattedAST.new(@ast_index, @ast_length)
|
486
|
+
p.children += val[1]
|
487
|
+
result = p
|
488
|
+
}
|
489
|
+
| PREINDENT_START repeated_contents PREINDENT_END
|
490
|
+
{
|
491
|
+
p = PreformattedAST.new(@ast_index, @ast_length)
|
492
|
+
p.indented = true
|
493
|
+
p.children += val[1]
|
494
|
+
result = p
|
495
|
+
}
|
337
496
|
;
|
338
497
|
|
339
498
|
section: SECTION_START repeated_contents SECTION_END
|
340
499
|
{ result = [val[1], val[0].length]
|
341
|
-
s = SectionAST.new
|
500
|
+
s = SectionAST.new(@ast_index, @ast_length)
|
342
501
|
s.children = val[1]
|
343
502
|
s.level = val[0].length
|
344
503
|
result = s
|
345
504
|
}
|
346
505
|
;
|
347
506
|
|
507
|
+
template: TEMPLATE_START TEXT template_parameters TEMPLATE_END
|
508
|
+
{
|
509
|
+
t = TemplateAST.new(@ast_index, @ast_length)
|
510
|
+
t.template_name = val[1]
|
511
|
+
t.children = val[2] unless val[2].nil? or val[2].empty?
|
512
|
+
result = t
|
513
|
+
}
|
514
|
+
;
|
515
|
+
|
516
|
+
template_parameters:
|
517
|
+
{
|
518
|
+
result = nil
|
519
|
+
}
|
520
|
+
| INTLINKSEP TEXT template_parameters
|
521
|
+
{
|
522
|
+
p = TemplateParameterAST.new(@ast_index, @ast_length)
|
523
|
+
p.parameter_value = val[1]
|
524
|
+
result = [p]
|
525
|
+
result += val[2] if val[2]
|
526
|
+
}
|
527
|
+
| INTLINKSEP template template_parameters
|
528
|
+
{
|
529
|
+
p = TemplateParameterAST.new(@ast_index, @ast_length)
|
530
|
+
p.children << val[1]
|
531
|
+
result = [p]
|
532
|
+
result += val[2] if val[2]
|
533
|
+
}
|
534
|
+
;
|
535
|
+
|
348
536
|
end
|
349
537
|
|
350
538
|
---- header ----
|
@@ -356,6 +544,8 @@ attr_accessor :lexer
|
|
356
544
|
|
357
545
|
def initialize
|
358
546
|
@nodes = []
|
547
|
+
@context = []
|
548
|
+
@wiki_ast_length = 0
|
359
549
|
super
|
360
550
|
end
|
361
551
|
|
@@ -369,5 +559,19 @@ end
|
|
369
559
|
|
370
560
|
#Asks the lexer to return the next token.
|
371
561
|
def next_token
|
372
|
-
|
562
|
+
token = @lexer.lex
|
563
|
+
if token[0].to_s.upcase.include? "_START"
|
564
|
+
@context << token[2..3]
|
565
|
+
elsif token[0].to_s.upcase.include? "_END"
|
566
|
+
@ast_index = @context.last[0]
|
567
|
+
@ast_length = token[2] + token[3] - @context.last[0]
|
568
|
+
@context.pop
|
569
|
+
else
|
570
|
+
@ast_index = token[2]
|
571
|
+
@ast_length = token[3]
|
572
|
+
end
|
573
|
+
|
574
|
+
@wiki_ast_length += token[3]
|
575
|
+
|
576
|
+
return token[0..1]
|
373
577
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'mediacloth/mediawikiwalker'
|
2
|
+
require 'mediacloth/mediawikiparams'
|
3
|
+
|
4
|
+
class MediaWikiSignedWikiGenerator < MediaWikiWalker
|
5
|
+
|
6
|
+
attr_reader :signed_wiki
|
7
|
+
|
8
|
+
def parse(ast, wiki)
|
9
|
+
@signed_wiki = wiki
|
10
|
+
#For supporting multiple signatures in wiki
|
11
|
+
@index_inc = 0
|
12
|
+
super(ast)
|
13
|
+
end
|
14
|
+
|
15
|
+
protected
|
16
|
+
|
17
|
+
def parse_wiki_ast(ast)
|
18
|
+
super(ast).join
|
19
|
+
end
|
20
|
+
|
21
|
+
def parse_text(ast)
|
22
|
+
if ast.formatting
|
23
|
+
case(ast.formatting)
|
24
|
+
when :SignatureDate then
|
25
|
+
signature = @params.time
|
26
|
+
@signed_wiki[ast.index + @index_inc, ast.length] = signature
|
27
|
+
@index_inc += signature.length - ast.length
|
28
|
+
when :SignatureName then
|
29
|
+
signature = "[[User:#{@params.author}|#{@params.author}]]"
|
30
|
+
@signed_wiki[ast.index + @index_inc, ast.length] = signature
|
31
|
+
@index_inc += signature.length - ast.length
|
32
|
+
when :SignatureFull then
|
33
|
+
signature = "[[User:#{@params.author}|#{@params.author}]] #{@params.time}"
|
34
|
+
@signed_wiki[ast.index + @index_inc, ast.length] = signature
|
35
|
+
@index_inc += signature.length - ast.length
|
36
|
+
end
|
37
|
+
else
|
38
|
+
ast.contents
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'mediacloth/mediawikiast'
|
2
|
+
require 'mediacloth/mediawikiparams'
|
2
3
|
|
3
4
|
#Default walker to traverse the parse tree.
|
4
5
|
#
|
@@ -14,6 +15,27 @@ class MediaWikiWalker
|
|
14
15
|
def parse(ast)
|
15
16
|
parse_wiki_ast(ast)
|
16
17
|
end
|
18
|
+
|
19
|
+
#Set generator's URL handler.
|
20
|
+
def link_handler=(handler)
|
21
|
+
@link_handler = handler
|
22
|
+
end
|
23
|
+
|
24
|
+
#Returns's this generator URL handler. If no handler was set, returns the
|
25
|
+
#default handler.
|
26
|
+
def link_handler
|
27
|
+
@link_handler ||= MediaWikiLinkHandler.new
|
28
|
+
end
|
29
|
+
|
30
|
+
attr_writer :template_handler
|
31
|
+
def template_handler
|
32
|
+
@template_handler ||= MediaWikiTemplateHandler.new
|
33
|
+
end
|
34
|
+
|
35
|
+
attr_writer :params
|
36
|
+
def params
|
37
|
+
@params ||= MediaWikiParams.new
|
38
|
+
end
|
17
39
|
|
18
40
|
protected
|
19
41
|
|
@@ -28,13 +50,19 @@ protected
|
|
28
50
|
r = parse_preformatted(c) if c.class == PreformattedAST
|
29
51
|
r = parse_section(c) if c.class == SectionAST
|
30
52
|
r = parse_paragraph(c) if c.class == ParagraphAST
|
53
|
+
r = parse_paste(c) if c.class == PasteAST
|
31
54
|
r = parse_link(c) if c.class == LinkAST
|
32
55
|
r = parse_internal_link(c) if c.class == InternalLinkAST
|
33
56
|
r = parse_resource_link(c) if c.class == ResourceLinkAST
|
57
|
+
r = parse_category_link(c) if c.class == CategoryLinkAST
|
34
58
|
r = parse_internal_link_item(c) if c.class == InternalLinkItemAST
|
35
59
|
r = parse_table(c) if c.class == TableAST
|
36
60
|
r = parse_table_row(c) if c.class == TableRowAST
|
37
61
|
r = parse_table_cell(c) if c.class == TableCellAST
|
62
|
+
r = parse_element(c) if c.class == ElementAST
|
63
|
+
r = parse_template(c) if c.class == TemplateAST
|
64
|
+
r = parse_category(c) if c.class == CategoryAST
|
65
|
+
r = parse_keyword(c) if c.class == KeywordAST
|
38
66
|
r
|
39
67
|
end
|
40
68
|
end
|
@@ -44,6 +72,11 @@ protected
|
|
44
72
|
parse_wiki_ast(ast)
|
45
73
|
end
|
46
74
|
|
75
|
+
#Reimplement this
|
76
|
+
def parse_paste(ast)
|
77
|
+
parse_wiki_ast(ast)
|
78
|
+
end
|
79
|
+
|
47
80
|
#Reimplement this
|
48
81
|
def parse_formatted(ast)
|
49
82
|
parse_wiki_ast(ast)
|
@@ -56,7 +89,10 @@ protected
|
|
56
89
|
#Reimplement this
|
57
90
|
def parse_list(ast)
|
58
91
|
ast.children.map do |c|
|
59
|
-
parse_list_item(c) if c.class == ListItemAST
|
92
|
+
r = parse_list_item(c) if c.class == ListItemAST
|
93
|
+
r = parse_list_term(c) if c.class == ListTermAST
|
94
|
+
r = parse_list_definition(c) if c.class == ListDefinitionAST
|
95
|
+
r
|
60
96
|
end
|
61
97
|
end
|
62
98
|
|
@@ -65,8 +101,19 @@ protected
|
|
65
101
|
parse_wiki_ast(ast)
|
66
102
|
end
|
67
103
|
|
104
|
+
#Reimplement this
|
105
|
+
def parse_list_term(ast)
|
106
|
+
parse_wiki_ast(ast)
|
107
|
+
end
|
108
|
+
|
109
|
+
#Reimplement this
|
110
|
+
def parse_list_definition(ast)
|
111
|
+
parse_wiki_ast(ast)
|
112
|
+
end
|
113
|
+
|
68
114
|
#Reimplement this
|
69
115
|
def parse_preformatted(ast)
|
116
|
+
parse_wiki_ast(ast)
|
70
117
|
end
|
71
118
|
|
72
119
|
#Reimplement this
|
@@ -93,6 +140,13 @@ protected
|
|
93
140
|
end
|
94
141
|
end
|
95
142
|
|
143
|
+
#Reimplement this
|
144
|
+
def parse_category_link(ast)
|
145
|
+
ast.children.map do |c|
|
146
|
+
parse_internal_link_item(c) if c.class == InternalLinkItemAST
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
96
150
|
#Reimplement this
|
97
151
|
def parse_internal_link_item(ast)
|
98
152
|
parse_wiki_ast(ast)
|
@@ -113,4 +167,21 @@ protected
|
|
113
167
|
parse_wiki_ast(ast)
|
114
168
|
end
|
115
169
|
|
170
|
+
#Reimplement this
|
171
|
+
def parse_element(ast)
|
172
|
+
parse_wiki_ast(ast)
|
173
|
+
end
|
174
|
+
|
175
|
+
#Reimplement this
|
176
|
+
def parse_template(ast)
|
177
|
+
end
|
178
|
+
|
179
|
+
#Reimplement this
|
180
|
+
def parse_category(ast)
|
181
|
+
end
|
182
|
+
|
183
|
+
#Reimplement this
|
184
|
+
def parse_keyword(ast)
|
185
|
+
end
|
186
|
+
|
116
187
|
end
|