mediacloth 0.0.3 → 0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. data/README.md +36 -0
  2. data/lib/mediacloth/mediawikiast.rb +58 -1
  3. data/lib/mediacloth/mediawikihtmlgenerator.rb +229 -73
  4. data/lib/mediacloth/mediawikilexer.rb +1030 -656
  5. data/lib/mediacloth/mediawikilinkhandler.rb +89 -0
  6. data/lib/mediacloth/mediawikiparams.rb +1 -10
  7. data/lib/mediacloth/mediawikiparser.rb +939 -409
  8. data/lib/mediacloth/mediawikiparser.tab.rb +1357 -0
  9. data/lib/mediacloth/mediawikiparser.y +256 -52
  10. data/lib/mediacloth/mediawikisignedwikigenerator.rb +42 -0
  11. data/lib/mediacloth/mediawikitemplatehandler.rb +8 -0
  12. data/lib/mediacloth/mediawikiwalker.rb +72 -1
  13. data/lib/mediacloth.rb +33 -10
  14. data/test/data/ast1 +68 -0
  15. data/test/data/ast10 +196 -0
  16. data/test/data/ast11 +34 -0
  17. data/test/data/ast12 +39 -0
  18. data/test/data/ast13 +25 -0
  19. data/test/data/ast14 +13 -0
  20. data/test/data/ast15 +25 -0
  21. data/test/data/ast16 +17 -0
  22. data/test/data/ast17 +9 -0
  23. data/test/data/ast18 +21 -0
  24. data/test/data/ast19 +32 -0
  25. data/test/data/ast2 +4 -0
  26. data/test/data/ast20 +10 -0
  27. data/test/data/ast21 +27 -0
  28. data/test/data/ast22 +22 -0
  29. data/test/data/ast23 +5 -0
  30. data/test/data/ast3 +6 -0
  31. data/test/data/ast4 +122 -0
  32. data/test/data/ast5 +122 -0
  33. data/test/data/ast6 +22 -0
  34. data/test/data/ast7 +143 -0
  35. data/test/data/ast8 +3 -0
  36. data/test/data/ast9 +11 -0
  37. data/test/data/html1 +33 -5
  38. data/test/data/html10 +31 -27
  39. data/test/data/html11 +19 -0
  40. data/test/data/html12 +32 -0
  41. data/test/data/html13 +29 -0
  42. data/test/data/html14 +4 -0
  43. data/test/data/html15 +29 -0
  44. data/test/data/html16 +28 -0
  45. data/test/data/html17 +10 -0
  46. data/test/data/html18 +8 -0
  47. data/test/data/html19 +27 -0
  48. data/test/data/html2 +1 -1
  49. data/test/data/html20 +7 -0
  50. data/test/data/html21 +5 -0
  51. data/test/data/html22 +24 -0
  52. data/test/data/html23 +7 -0
  53. data/test/data/html3 +1 -1
  54. data/test/data/html4 +60 -11
  55. data/test/data/html5 +45 -6
  56. data/test/data/html6 +5 -5
  57. data/test/data/html7 +59 -1
  58. data/test/data/html8 +1 -1
  59. data/test/data/html9 +10 -2
  60. data/test/data/input1 +4 -0
  61. data/test/data/input11 +19 -0
  62. data/test/data/input12 +32 -0
  63. data/test/data/input13 +10 -0
  64. data/test/data/input14 +8 -0
  65. data/test/data/input15 +10 -0
  66. data/test/data/input16 +28 -0
  67. data/test/data/input17 +10 -0
  68. data/test/data/input18 +16 -0
  69. data/test/data/input19 +29 -0
  70. data/test/data/input20 +8 -0
  71. data/test/data/input21 +18 -0
  72. data/test/data/input22 +20 -0
  73. data/test/data/input23 +8 -0
  74. data/test/data/input4 +13 -1
  75. data/test/data/input5 +45 -4
  76. data/test/data/input7 +25 -1
  77. data/test/data/lex1 +17 -18
  78. data/test/data/lex10 +57 -87
  79. data/test/data/lex11 +18 -0
  80. data/test/data/lex12 +32 -0
  81. data/test/data/lex13 +3 -0
  82. data/test/data/lex14 +1 -0
  83. data/test/data/lex15 +3 -0
  84. data/test/data/lex16 +27 -0
  85. data/test/data/lex17 +9 -0
  86. data/test/data/lex18 +4 -0
  87. data/test/data/lex19 +27 -0
  88. data/test/data/lex2 +2 -2
  89. data/test/data/lex20 +7 -0
  90. data/test/data/lex21 +4 -0
  91. data/test/data/lex22 +3 -0
  92. data/test/data/lex23 +7 -0
  93. data/test/data/lex3 +1 -1
  94. data/test/data/lex4 +35 -29
  95. data/test/data/lex5 +57 -18
  96. data/test/data/lex6 +7 -7
  97. data/test/data/lex7 +42 -18
  98. data/test/data/lex8 +1 -1
  99. data/test/data/lex9 +6 -6
  100. data/test/dataproducers/ast.rb +24 -0
  101. data/test/dataproducers/html.rb +11 -12
  102. data/test/dataproducers/lex.rb +9 -4
  103. data/test/debugwalker.rb +25 -11
  104. data/test/htmlgenerator.rb +170 -13
  105. data/test/lexer.rb +626 -83
  106. data/test/linkhandler.rb +39 -0
  107. data/test/parser.rb +176 -9
  108. data/test/signedwikigenerator.rb +113 -0
  109. metadata +158 -79
  110. data/README +0 -37
  111. data/lib/mediacloth/mediawikilexer.rb~ +0 -491
  112. data/lib/mediacloth/mediawikiparser.y~ +0 -210
  113. data/test/data/result1 +0 -48
  114. data/test/dataproducers/html.rb~ +0 -24
  115. data/test/dataproducers/lex.rb~ +0 -15
data/test/data/lex4 CHANGED
@@ -1,47 +1,53 @@
1
- PARA_STARTTEXTTest mixing of bold and italic formatting:PARA_END
1
+ PARA_START[0, 0]TEXTTest mixing of bold and italic formatting:
2
2
 
3
- PARA_STARTITALICSTART''TEXTitalicBOLDSTART'''TEXTboldBOLDEND'''TEXTitalicITALICEND''PARA_END
3
+ [0, 44]PARA_END[44, 0]PARA_START[44, 0]ITALIC_START''[44, 2]TEXTitalic[46, 6]BOLD_START'''[52, 3]TEXTbold[55, 4]BOLD_END'''[59, 3]TEXTitalic[62, 6]ITALIC_END''[68, 2]TEXT
4
4
 
5
- PARA_STARTBOLDSTART'''TEXTboldITALICSTART''TEXTitalicITALICEND''TEXTboldBOLDEND'''PARA_END
5
+ [70, 2]PARA_END[72, 0]PARA_START[72, 0]BOLD_START'''[72, 3]TEXTbold[75, 4]ITALIC_START''[79, 2]TEXTitalic[81, 6]ITALIC_END''[87, 2]TEXTbold[89, 4]BOLD_END'''[93, 3]TEXT
6
6
 
7
- PARA_STARTITALICSTART''BOLDSTART'''TEXTboldalicBOLDEND'''ITALICEND''PARA_END
7
+ [96, 2]PARA_END[98, 0]PARA_START[98, 0]ITALIC_START''[98, 2]BOLD_START'''[100, 3]TEXTboldalic[103, 8]BOLD_END'''[111, 3]ITALIC_END''[114, 2]TEXT
8
8
 
9
- PARA_STARTITALICSTART''TEXTitalicBOLDSTART'''TEXTboldBOLDEND'''TEXTitalicITALICEND''BOLDSTART'''TEXTboldITALICSTART''TEXTitalicITALICEND''TEXTboldBOLDEND'''PARA_END
9
+ [116, 2]PARA_END[118, 0]PARA_START[118, 0]ITALIC_START''[118, 2]TEXTitalic[120, 6]BOLD_START'''[126, 3]TEXTbold[129, 4]BOLD_END'''[133, 3]TEXTitalic[136, 6]ITALIC_END''[142, 2]BOLD_START'''[144, 3]TEXTbold[147, 4]ITALIC_START''[151, 2]TEXTitalic[153, 6]ITALIC_END''[159, 2]TEXTbold[161, 4]BOLD_END'''[165, 3]TEXT
10
10
 
11
- PARA_STARTTEXT
12
- Test bold and italic wrapped around inline links:PARA_END
11
+ [168, 2]PARA_END[170, 0]PARA_START[170, 0]TEXT
12
+ Test bold and italic wrapped around inline links:
13
13
 
14
- PARA_STARTITALICSTART''LINKSTARTTEXThttp://example.comLINKEND]ITALICEND''PARA_END
14
+ [170, 52]PARA_END[222, 0]PARA_START[222, 0]ITALIC_START''[222, 2]LINK_START[224, 0]TEXThttp://example.com[224, 18]LINK_END[242, 0]ITALIC_END''[242, 2]TEXT
15
15
 
16
- PARA_STARTBOLDSTART'''LINKSTARTTEXThttp://example.comLINKEND]BOLDEND'''PARA_END
16
+ [244, 2]PARA_END[246, 0]PARA_START[246, 0]BOLD_START'''[246, 3]LINK_START[249, 0]TEXThttp://example.com[249, 18]LINK_END[267, 0]BOLD_END'''[267, 3]TEXT
17
17
 
18
- PARA_STARTITALICSTART''LINKSTARTTEXThttp://example.com'LINKEND]ITALICEND''PARA_END
18
+ [270, 2]PARA_END[272, 0]PARA_START[272, 0]ITALIC_START''[272, 2]LINK_START[274, 0]TEXThttp://example.com[274, 18]LINK_END[292, 0]BOLD_START'''[292, 3]TEXT
19
19
 
20
- PARA_STARTBOLDSTART'''LINKSTARTTEXThttp://example.com'LINKEND]TEXT is goodBOLDEND'''PARA_END
20
+ [295, 2]BOLD_END[297, 0]ITALIC_END[297, 0]PARA_END[297, 0]PARA_START[297, 0]BOLD_START'''[297, 3]LINK_START[300, 0]TEXThttp://example.com[300, 18]LINK_END[318, 0]TEXT' is good[318, 9]BOLD_END'''[327, 3]TEXT
21
21
 
22
- PARA_STARTITALICSTART''LINKSTARTTEXThttp://example.com'LINKEND]TEXT is goodITALICEND''PARA_END
22
+ [330, 2]PARA_END[332, 0]PARA_START[332, 0]ITALIC_START''[332, 2]LINK_START[334, 0]TEXThttp://example.com[334, 18]LINK_END[352, 0]TEXT' is good[352, 9]ITALIC_END''[361, 2]TEXT
23
23
 
24
- PARA_STARTTEXT
25
- Test unclosed bold and italic formatting:PARA_END
24
+ [363, 2]PARA_END[365, 0]PARA_START[365, 0]TEXT
25
+ Test unclosed bold and italic formatting:
26
26
 
27
- PARA_STARTITALICSTART''TEXTSome italic and now ITALICEND''TEXTbold
28
- PARA_ENDSECTION_START==TEXTHeadingSECTION_END==PARA_STARTTEXT
29
- TextPARA_END
27
+ [365, 44]PARA_END[409, 0]PARA_START[409, 0]ITALIC_START''[409, 2]TEXTSome italic and now [411, 20]ITALIC_END''[431, 2]TEXTbold
28
+ [433, 5]PARA_END[438, 0]SECTION_START==[438, 2]TEXTHeading[440, 7]SECTION_END==[447, 0]PARA_START[447, 3]TEXTText
30
29
 
31
- PARA_STARTITALICSTART''TEXTSome italic and now BOLDSTART'''TEXTbold
32
- BOLDENDITALICENDPARA_ENDSECTION_START==TEXTHeadingSECTION_END==PARA_STARTTEXT
33
- TextPARA_END
30
+ [450, 6]PARA_END[456, 0]PARA_START[456, 1]ITALIC_START''[457, 2]TEXTSome italic and now [459, 20]BOLD_START'''[479, 3]TEXTbold
31
+ [482, 5]BOLD_END[487, 0]ITALIC_END[487, 0]PARA_END[487, 0]SECTION_START==[487, 2]TEXTHeading[489, 7]SECTION_END==[496, 0]PARA_START[496, 3]TEXT
32
+ Text
34
33
 
35
- PARA_STARTITALICSTART''TEXTSome italic and now BOLDSTART'''TEXTboldBOLDEND
34
+ [499, 7]PARA_END[506, 0]PARA_START[506, 1]ITALIC_START''[507, 2]TEXTSome italic and now [509, 20]BOLD_START'''[529, 3]TEXTbold
36
35
 
37
- ITALICENDPARA_ENDSECTION_START==TEXTHeadingSECTION_END==PARA_STARTTEXT
38
- TextPARA_END
36
+ [532, 6]BOLD_END[538, 0]ITALIC_END[538, 0]PARA_END[538, 0]SECTION_START==[538, 2]TEXTHeading[540, 7]SECTION_END==[547, 0]PARA_START[547, 3]TEXT
39
37
 
40
- PARA_STARTITALICSTART''TEXTSome italic and now BOLDSTART'''TEXTbold
41
- BOLDENDITALICENDPARA_ENDUL_STARTLI_STARTTEXTone
42
- LI_ENDLI_STARTTEXTtwo
43
- LI_ENDUL_ENDPARA_STARTPARA_END
38
+ [550, 2]PARA_END[552, 0]PARA_START[552, 0]TEXTText
44
39
 
45
- PARA_STARTITALICSTART''TEXTSome italic and now BOLDSTART'''TEXTboldBOLDEND
40
+ [552, 6]PARA_END[558, 0]PARA_START[558, 1]ITALIC_START''[559, 2]TEXTSome italic and now [561, 20]BOLD_START'''[581, 3]TEXTbold
41
+ [584, 5]BOLD_END[589, 0]ITALIC_END[589, 0]PARA_END[589, 0]UL_START[589, 0]LI_START[589, 1]TEXT one
42
+ [590, 5]LI_END[595, 0]LI_START[595, 1]TEXT two
43
+ [596, 5]LI_END[601, 0]UL_END[601, 0]PARA_START[601, 0]TEXT
46
44
 
47
- ITALICENDPARA_ENDPARA_STARTTEXTTextPARA_ENDfalsefalse
45
+ [601, 2]PARA_END[603, 0]PARA_START[603, 0]ITALIC_START''[603, 2]TEXTSome italic and now [605, 20]BOLD_START'''[625, 3]TEXTbold
46
+
47
+ [628, 6]BOLD_END[634, 0]ITALIC_END[634, 0]PARA_END[634, 0]PARA_START[634, 0]TEXTText
48
+
49
+ [634, 6]PARA_END[640, 0]PARA_START[640, 0]TEXTInvalid and weird sections:
50
+ [640, 28]PARA_END[668, 0]SECTION_START======[668, 6]TEXT====[674, 4]SECTION_END======[678, 0]PARA_START[678, 6]TEXT
51
+ =
52
+ ==
53
+ [684, 6]PARA_END[690, 0]SECTION_START=[690, 1]TEXT=[691, 1]SECTION_END=[692, 2]SECTION_START=[694, 1]TEXT==[695, 2]SECTION_END=[697, 2]SECTION_START==[699, 2]TEXT=[701, 1]SECTION_END==[702, 3]SECTION_START==[705, 2]TEXT==[707, 2]SECTION_END==[709, 3]falsefalse[712, 0]
data/test/data/lex5 CHANGED
@@ -1,18 +1,57 @@
1
- UL_STARTLI_STARTTEXTA
2
- UL_STARTLI_STARTTEXTA
3
- UL_STARTLI_STARTTEXTa
4
- LI_ENDLI_STARTTEXTb
5
- UL_STARTLI_STARTTEXTa
6
- LI_ENDUL_ENDLI_ENDUL_ENDLI_ENDUL_ENDLI_ENDLI_STARTTEXTB
7
- UL_STARTLI_STARTTEXTb
8
- LI_ENDUL_ENDLI_ENDUL_ENDOL_STARTLI_STARTTEXTa
9
- OL_STARTLI_STARTTEXTa
10
- OL_STARTLI_STARTTEXTa
11
- OL_STARTLI_STARTTEXTa
12
- LI_ENDOL_ENDLI_ENDOL_ENDLI_ENDOL_ENDLI_ENDLI_STARTTEXTa
13
- OL_STARTLI_STARTTEXTaa
14
- LI_ENDOL_ENDLI_ENDOL_ENDUL_STARTLI_STARTTEXTA
15
- LI_ENDLI_STARTTEXTB
16
- LI_ENDLI_STARTLI_ENDUL_ENDOL_STARTLI_STARTTEXTA
17
- LI_ENDLI_STARTTEXTB
18
- LI_ENDLI_STARTLI_ENDOL_ENDfalsefalse
1
+ PARA_START[0, 0]TEXTUnordered lists
2
+
3
+ [0, 17]PARA_END[17, 0]UL_START[17, 0]LI_START[17, 1]TEXTA
4
+ [18, 2]UL_START[20, 0]LI_START[20, 2]TEXTA
5
+ [22, 2]UL_START[24, 0]LI_START[24, 3]TEXTa
6
+ [27, 2]LI_END[29, 0]LI_START[29, 3]TEXTb
7
+ [32, 2]UL_START[34, 0]LI_START[34, 4]TEXTa
8
+ [38, 2]LI_END[40, 0]UL_END[40, 0]LI_END[40, 0]UL_END[40, 0]LI_END[40, 0]UL_END[40, 0]LI_END[40, 0]LI_START[40, 1]TEXTB
9
+ [41, 2]UL_START[43, 0]LI_START[43, 2]TEXTb
10
+ [45, 2]LI_END[47, 0]UL_END[47, 0]LI_END[47, 0]UL_END[47, 1]UL_START[48, 0]LI_START[48, 1]TEXTA
11
+ [49, 2]LI_END[51, 0]LI_START[51, 1]TEXTB
12
+ [52, 2]LI_END[54, 0]LI_START[54, 2]LI_END[56, 0]UL_END[56, 0]PARA_START[56, 0]TEXT
13
+ Ordered lists
14
+
15
+ [56, 16]PARA_END[72, 0]OL_START[72, 0]LI_START[72, 1]TEXTa
16
+ [73, 2]OL_START[75, 0]LI_START[75, 2]TEXTa
17
+ [77, 2]OL_START[79, 0]LI_START[79, 3]TEXTa
18
+ [82, 2]OL_START[84, 0]LI_START[84, 4]TEXTa
19
+ [88, 2]LI_END[90, 0]OL_END[90, 0]LI_END[90, 0]OL_END[90, 0]LI_END[90, 0]OL_END[90, 0]LI_END[90, 0]LI_START[90, 1]TEXTa
20
+ [91, 2]OL_START[93, 0]LI_START[93, 2]TEXTaa
21
+ [95, 3]LI_END[98, 0]OL_END[98, 0]LI_END[98, 0]OL_END[98, 1]OL_START[99, 0]LI_START[99, 1]TEXTA
22
+ [100, 2]LI_END[102, 0]LI_START[102, 1]TEXTB
23
+ [103, 2]LI_END[105, 0]LI_START[105, 2]LI_END[107, 0]OL_END[107, 0]PARA_START[107, 0]TEXT
24
+ Mixed lists
25
+
26
+ [107, 14]PARA_END[121, 0]UL_START[121, 0]LI_START[121, 1]TEXTa
27
+ [122, 2]OL_START[124, 0]LI_START[124, 2]TEXT1
28
+ [126, 2]LI_END[128, 0]LI_START[128, 2]TEXT2
29
+ [130, 2]LI_END[132, 0]OL_END[132, 0]LI_END[132, 0]LI_START[132, 1]TEXTb
30
+ [133, 2]LI_END[135, 0]UL_END[135, 1]OL_START[136, 0]LI_START[136, 1]TEXTa
31
+ [137, 2]UL_START[139, 0]LI_START[139, 2]TEXT1
32
+ [141, 2]LI_END[143, 0]LI_START[143, 2]TEXT2
33
+ [145, 2]UL_START[147, 0]LI_START[147, 3]TEXT2
34
+ [150, 2]LI_END[152, 0]UL_END[152, 0]LI_END[152, 0]UL_END[152, 0]LI_END[152, 0]LI_START[152, 1]TEXTb
35
+ [153, 2]LI_END[155, 0]OL_END[155, 0]PARA_START[155, 0]TEXT
36
+ Dictionary lists
37
+
38
+ [155, 19]PARA_END[174, 0]DL_START[174, 0]DT_START;[174, 1]TEXTd
39
+ [175, 2]DT_END[177, 0]DL_END[177, 0]PARA_START[177, 0]TEXT
40
+
41
+ [177, 2]PARA_END[179, 0]DL_START[179, 0]DD_START:[179, 1]TEXTt
42
+ [180, 2]DD_END[182, 0]DL_END[182, 0]PARA_START[182, 0]TEXT
43
+
44
+ [182, 2]PARA_END[184, 0]DL_START[184, 0]DT_START;[184, 1]TEXTd
45
+ [185, 2]DT_END[187, 0]DD_START:[187, 1]TEXTt
46
+ [188, 2]DD_END[190, 0]DL_END[190, 0]PARA_START[190, 0]TEXT
47
+
48
+ [190, 2]PARA_END[192, 0]DL_START[192, 0]DT_START;[192, 1]TEXTd
49
+ [193, 2]DT_END[195, 0]DD_START:[195, 1]TEXTt
50
+ [196, 2]DD_END[198, 0]DD_START:[198, 1]TEXTt
51
+ [199, 2]DD_END[201, 0]DL_END[201, 0]PARA_START[201, 0]TEXT
52
+
53
+ [201, 2]PARA_END[203, 0]DL_START[203, 0]DT_START;[203, 1]TEXTd
54
+ [204, 2]DT_END[206, 0]DD_START:[206, 1]TEXTt
55
+ [207, 2]DD_END[209, 0]DL_END[209, 0]DL_START[209, 0]DT_START;[209, 1]TEXTd
56
+ [210, 2]DT_END[212, 0]DD_START:[212, 1]TEXTt
57
+ [213, 2]DD_END[215, 0]DL_END[215, 1]DL_START[216, 0]DT_START;[216, 1]TEXTd [217, 2]DT_END[219, 0]DD_START:[219, 1]TEXTt [220, 2]INTLINK_START[[[222, 2]TEXTimage[224, 5]RESOURCESEP:[229, 1]TEXTfoo.jpg[230, 7]INTLINK_END]][237, 2]DD_END[239, 0]DL_END[239, 0]falsefalse[239, 0]
data/test/data/lex6 CHANGED
@@ -1,8 +1,8 @@
1
- PARA_STARTTEXTThis is some text with BOLDSTART'''TEXTboldBOLDEND'''TEXT and ITALICSTART''TEXTitalicITALICEND''TEXT formating.
1
+ PARA_START[0, 0]TEXTThis is some text with [0, 23]BOLD_START'''[23, 3]TEXTbold[26, 4]BOLD_END'''[30, 3]TEXT and [33, 5]ITALIC_START''[38, 2]TEXTitalic[40, 6]ITALIC_END''[46, 2]TEXT formating.
2
2
  The list is also here:
3
- PARA_ENDUL_STARTLI_STARTTEXTList Item 1
4
- UL_STARTLI_STARTTEXTSub list item 1
5
- LI_ENDLI_STARTTEXTSub list item 2
6
- LI_ENDUL_ENDLI_ENDLI_STARTTEXTList Item 2
7
- LI_ENDUL_ENDPARA_STARTTEXTThe end
8
- PARA_ENDHLINE----falsefalse
3
+ [48, 35]PARA_END[83, 0]UL_START[83, 0]LI_START[83, 1]TEXT List Item 1
4
+ [84, 13]UL_START[97, 0]LI_START[97, 2]TEXT Sub list item 1
5
+ [99, 17]LI_END[116, 0]LI_START[116, 2]TEXT Sub list item 2
6
+ [118, 17]LI_END[135, 0]UL_END[135, 0]LI_END[135, 0]LI_START[135, 1]TEXT List Item 2
7
+ [136, 13]LI_END[149, 0]UL_END[149, 0]PARA_START[149, 0]TEXTThe end
8
+ [149, 8]PARA_END[157, 0]HLINE----[157, 4]falsefalse[162, 0]
data/test/data/lex7 CHANGED
@@ -1,35 +1,59 @@
1
- PARA_STARTLINKSTARTTEXThttp://sun.comLINKEND]PARA_END
1
+ PARA_START[0, 0]LINK_START[0, 0]TEXThttp://sun.com[0, 14]LINK_END[14, 0]TEXT
2
2
 
3
- PARA_STARTLINKSTART[TEXThttp://sun.comLINKEND]PARA_END
3
+ [14, 2]PARA_END[16, 0]PARA_START[16, 0]LINK_START[16, 0]TEXThttp://sun.com:80[16, 17]LINK_END[33, 0]TEXT
4
4
 
5
- PARA_STARTLINKSTART[TEXTmailto:joe@sun.comLINKEND]PARA_END
5
+ [33, 2]PARA_END[35, 0]PARA_START[35, 0]LINK_START[[35, 1]TEXThttp://sun.com[36, 14]LINK_END][50, 1]TEXT
6
6
 
7
- PARA_STARTLINKSTART[TEXThttp://sun.comLINKSEPTEXTstarsLINKEND]PARA_END
7
+ [51, 2]PARA_END[53, 0]PARA_START[53, 0]LINK_START[[53, 1]TEXTmailto:joe@sun.com[54, 18]LINK_END][72, 1]TEXT
8
8
 
9
- PARA_STARTLINKSTART[TEXThttp://sun.comLINKSEPTEXTstars and moonLINKEND]PARA_END
9
+ [73, 2]PARA_END[75, 0]PARA_START[75, 0]LINK_START[[75, 1]TEXThttp://sun.com[76, 14]LINKSEP [90, 1]TEXTstars[91, 5]LINK_END][96, 1]TEXT
10
10
 
11
- PARA_STARTLINKSTART[TEXThttp://sun.comLINKSEPTEXTstars and ITALICSTART''TEXTmoonITALICEND''LINKSEPTEXTand BOLDSTART'''TEXTtreesBOLDEND'''LINKSEPTEXTand birdsLINKEND]PARA_END
11
+ [97, 2]PARA_END[99, 0]PARA_START[99, 0]LINK_START[[99, 1]TEXThttp://sun.com[100, 14]LINKSEP [114, 1]TEXTstars and moon[115, 14]LINK_END][129, 1]TEXT
12
12
 
13
- PARA_STARTINTLINKSTART[[TEXTsunINTLINKEND]]PARA_END
13
+ [130, 2]PARA_END[132, 0]PARA_START[132, 0]LINK_START[[132, 1]TEXThttp://sun.com[133, 14]LINKSEP [147, 1]TEXTstars and [148, 10]ITALIC_START''[158, 2]TEXTmoon[160, 4]ITALIC_END''[164, 2]TEXT and [166, 5]BOLD_START'''[171, 3]TEXTtrees[174, 5]BOLD_END'''[179, 3]TEXT and birds[182, 10]LINK_END][192, 1]TEXT
14
14
 
15
- PARA_STARTINTLINKSTART[[TEXTsunINTLINKSEP|TEXTAll about SunINTLINKEND]]PARA_END
15
+ [193, 2]PARA_END[195, 0]PARA_START[195, 0]LINK_START[[195, 1]TEXThttp://sun.com[196, 14]LINKSEP [210, 1]TAG_STARTtt[211, 4]TEXTsun[215, 3]TAG_ENDtt[218, 5]TEXT and [223, 5]TAG_STARTtt[228, 4]TEXTmoon[232, 4]TAG_ENDtt[236, 5]LINK_END][241, 1]TEXT
16
16
 
17
- PARA_STARTINTLINKSTART[[TEXTimageRESOURCE_SEP:TEXTsunINTLINKSEP|TEXTAll about SunINTLINKEND]]PARA_END
17
+ [242, 2]PARA_END[244, 0]PARA_START[244, 0]LINK_START[[244, 1]TEXThttp://sun.com[245, 14]LINKSEP [259, 1]TEXTsun > moon[260, 10]LINK_END][270, 1]TEXT
18
18
 
19
- PARA_STARTINTLINKSTART[[TEXTsunINTLINKSEP|TEXTnofollow|All about SunINTLINKEND]]PARA_END
19
+ [271, 2]PARA_END[273, 0]PARA_START[273, 0]INTLINK_START[[[273, 2]TEXTsun[275, 3]INTLINK_END]][278, 2]TEXT
20
20
 
21
- PARA_STARTINTLINKSTART[[TEXTimageRESOURCE_SEP:TEXTsunINTLINKSEP|TEXTnofollowINTLINKSEP|TEXTAll about SunINTLINKEND]]PARA_END
21
+ [280, 2]PARA_END[282, 0]PARA_START[282, 0]INTLINK_START[[[282, 2]TEXTsun[284, 3]INTLINKSEP|[287, 1]TEXTAll about Sun[288, 13]INTLINK_END]][301, 2]TEXT
22
22
 
23
- PARA_STARTINTLINKSTART[[TEXTimageRESOURCE_SEP:TEXTsunINTLINKSEP|TEXTAll about INTLINKSTART[[TEXTSunINTLINKEND]]INTLINKEND]]PARA_END
23
+ [303, 2]PARA_END[305, 0]PARA_START[305, 0]INTLINK_START[[[305, 2]TEXTimage[307, 5]RESOURCESEP:[312, 1]TEXTsun[313, 3]INTLINKSEP|[316, 1]TEXTAll about Sun[317, 13]INTLINK_END]][330, 2]TEXT
24
24
 
25
- PARA_STARTINTLINKSTART[[TEXTimageRESOURCE_SEP:TEXTsunINTLINKSEP|TEXTAll about INTLINKSTART[[TEXTsunINTLINKSEP|TEXTMore aboutINTLINKEND]]INTLINKEND]]PARA_END
25
+ [332, 2]PARA_END[334, 0]PARA_START[334, 0]INTLINK_START[[[334, 2]TEXTsun[336, 3]INTLINKSEP|[339, 1]TEXTnofollow|All about Sun[340, 22]INTLINK_END]][362, 2]TEXT
26
26
 
27
- PARA_STARTINTLINKSTART[[TEXTimageRESOURCE_SEP:TEXTsunINTLINKSEP|TEXToneINTLINKSEP|INTLINKSEP|TEXTtwoINTLINKSEP|INTLINKSEP|TEXTthreeINTLINKSEP|INTLINKEND]]PARA_END
27
+ [364, 2]PARA_END[366, 0]PARA_START[366, 0]INTLINK_START[[[366, 2]TEXTsun[368, 3]INTLINKSEP|[371, 1]TEXTnofollow|Sun > Moon[372, 19]INTLINK_END]][391, 2]TEXT
28
28
 
29
- PARA_STARTTEXT[]PARA_END
29
+ [393, 2]PARA_END[395, 0]PARA_START[395, 0]INTLINK_START[[[395, 2]TEXTsun[397, 3]INTLINKSEP|[400, 1]TEXTnofollow|[401, 9]TAG_STARTtt[410, 4]TEXTsun[414, 3]TAG_ENDtt[417, 5]TEXT and [422, 5]TAG_STARTtt[427, 4]TEXTmoon[431, 4]TAG_ENDtt[435, 5]INTLINK_END]][440, 2]TEXT
30
30
 
31
- PARA_STARTTEXT[ ]PARA_END
31
+ [442, 2]PARA_END[444, 0]PARA_START[444, 0]INTLINK_START[[[444, 2]TEXTimage[446, 5]RESOURCESEP:[451, 1]TEXTsun[452, 3]INTLINKSEP|[455, 1]TEXTnofollow[456, 8]INTLINKSEP|[464, 1]TEXTAll about Sun[465, 13]INTLINK_END]][478, 2]TEXT
32
32
 
33
- PARA_STARTTEXT[[]]PARA_END
33
+ [480, 2]PARA_END[482, 0]PARA_START[482, 0]INTLINK_START[[[482, 2]TEXTimage[484, 5]RESOURCESEP:[489, 1]TEXTsun[490, 3]INTLINKSEP|[493, 1]TEXTAll about [494, 10]INTLINK_START[[[504, 2]TEXTSun[506, 3]INTLINK_END]][509, 2]INTLINK_END]][511, 2]TEXT
34
34
 
35
- PARA_STARTTEXT[[ ]]PARA_ENDfalsefalse
35
+ [513, 2]PARA_END[515, 0]PARA_START[515, 0]INTLINK_START[[[515, 2]TEXTimage[517, 5]RESOURCESEP:[522, 1]TEXTsun[523, 3]INTLINKSEP|[526, 1]TEXTAll about [527, 10]INTLINK_START[[[537, 2]TEXTsun[539, 3]INTLINKSEP|[542, 1]TEXTMore about[543, 10]INTLINK_END]][553, 2]INTLINK_END]][555, 2]TEXT
36
+
37
+ [557, 2]PARA_END[559, 0]PARA_START[559, 0]INTLINK_START[[[559, 2]TEXTimage[561, 5]RESOURCESEP:[566, 1]TEXTsun[567, 3]INTLINKSEP|[570, 1]TEXTone[571, 3]INTLINKSEP|[574, 1]INTLINKSEP|[575, 1]TEXTtwo[576, 3]INTLINKSEP|[579, 1]INTLINKSEP|[580, 1]TEXTthree[581, 5]INTLINKSEP|[586, 1]INTLINK_END]][587, 2]TEXT
38
+
39
+ [589, 2]PARA_END[591, 0]PARA_START[591, 0]INTLINK_START[[[591, 2]TEXTimage[593, 5]RESOURCESEP:[598, 1]TEXTsun[599, 3]INTLINKSEP|[602, 1]TEXTone[603, 3]INTLINKSEP|[606, 1]INTLINK_START[[[607, 2]TEXTaaa[609, 3]INTLINKSEP|[612, 1]TEXTbbb|ccc[613, 7]INTLINK_END]][620, 2]INTLINKSEP|[622, 1]INTLINK_START[[[623, 2]TEXTimage[625, 5]RESOURCESEP:[630, 1]TEXTmoon[631, 4]INTLINKSEP|[635, 1]TEXTaaa[636, 3]INTLINKSEP|[639, 1]TEXTbbb[640, 3]INTLINKSEP|[643, 1]TEXTccc[644, 3]INTLINK_END]][647, 2]INTLINKSEP|[649, 1]TEXTtwo[650, 3]INTLINK_END]][653, 2]TEXT
40
+
41
+ [655, 2]PARA_END[657, 0]PARA_START[657, 0]TEXT[]
42
+
43
+ [657, 4]PARA_END[661, 0]PARA_START[661, 0]TEXT[ ]
44
+
45
+ [661, 5]PARA_END[666, 0]PARA_START[666, 0]TEXT[[]]
46
+
47
+ [666, 6]PARA_END[672, 0]PARA_START[672, 0]INTLINK_START[[[672, 2]TEXT [674, 1]INTLINK_END]][675, 2]TEXT
48
+
49
+ [677, 2]PARA_END[679, 0]PARA_START[679, 0]INTLINK_START[[[679, 2]CATEGORYCategory:[681, 9]TEXTCategory[690, 8]INTLINK_END]][698, 2]TEXT
50
+
51
+ [700, 2]PARA_END[702, 0]PARA_START[702, 0]INTLINK_START[[[702, 2]CATEGORYCategory:[704, 9]TEXTCategory name[713, 13]INTLINK_END]][726, 2]TEXT
52
+
53
+ [728, 2]PARA_END[730, 0]PARA_START[730, 0]INTLINK_START[[[730, 2]CATEGORYCategory:[732, 9]TEXTCategory name[741, 13]INTLINKSEP|[754, 1]TEXTSort as[755, 7]INTLINK_END]][762, 2]TEXT
54
+
55
+ [764, 2]PARA_END[766, 0]PARA_START[766, 0]INTLINK_START[[[766, 2]RESOURCESEP:[768, 1]CATEGORYCategory:[769, 9]TEXTCategory[778, 8]INTLINK_END]][786, 2]TEXT
56
+
57
+ [788, 2]PARA_END[790, 0]PARA_START[790, 0]INTLINK_START[[[790, 2]RESOURCESEP:[792, 1]CATEGORYCategory:[793, 9]TEXTCategory name[802, 13]INTLINK_END]][815, 2]TEXT
58
+
59
+ [817, 2]PARA_END[819, 0]PARA_START[819, 0]INTLINK_START[[[819, 2]RESOURCESEP:[821, 1]CATEGORYCategory:[822, 9]TEXTCategory name[831, 13]INTLINKSEP|[844, 1]TEXTFoo[845, 3]INTLINK_END]][848, 2]PARA_END[850, 0]falsefalse[850, 0]
data/test/data/lex8 CHANGED
@@ -1 +1 @@
1
- SECTION_START===TEXT foo SECTION_END===falsefalse
1
+ SECTION_START===[0, 3]TEXT foo [3, 5]SECTION_END===[8, 3]falsefalse[11, 0]
data/test/data/lex9 CHANGED
@@ -1,14 +1,14 @@
1
- PARA_STARTTEXTSome examples of wiki escaping.PARA_END
1
+ PARA_START[0, 0]TEXTSome examples of wiki escaping.
2
2
 
3
- PARA_STARTTEXTA paragraph with some wiki characters: ''italic'' '''bold''' [[Link]]PARA_END
3
+ [0, 33]PARA_END[33, 0]PARA_START[33, 0]TEXTA paragraph with some wiki characters: ''italic'' '''bold''' [[Link]]
4
4
 
5
- PARA_STARTTEXTAn escaped list:
5
+ [33, 71]PARA_END[121, 0]PARA_START[121, 0]TEXTAn escaped list:
6
6
 
7
7
  * one
8
8
  * two
9
9
  * three
10
- PARA_END
11
10
 
12
- PARA_STARTTEXTText escaped in a heading:PARA_END
13
11
 
14
- SECTION_START==TEXTHeading with '''SECTION_END==falsefalse
12
+ [121, 40]PARA_END[178, 0]PARA_START[178, 0]TEXTText escaped in a heading:
13
+
14
+ [178, 28]PARA_END[206, 0]SECTION_START==[206, 2]TEXTHeading with '''[208, 16]SECTION_END==[241, 3]falsefalse[244, 0]
@@ -0,0 +1,24 @@
1
+ require 'mediacloth/mediawikilexer'
2
+ require 'mediacloth/mediawikiparser'
3
+ require 'debugwalker'
4
+
5
+ def produce(index)
6
+ file = File.new("#{File.dirname(__FILE__)}/../data/ast#{index}", "w")
7
+ inputFile = File.new("#{File.dirname(__FILE__)}/../data/input#{index}", "r")
8
+ input = inputFile.read
9
+
10
+ parser = MediaWikiParser.new
11
+ parser.lexer = MediaWikiLexer.new
12
+ ast = parser.parse(input)
13
+ walker = DebugWalker.new
14
+ walker.parse(ast)
15
+
16
+ file.write(walker.tree)
17
+ file.close
18
+ end
19
+
20
+ if ARGV.empty?
21
+ (1..21).each { |i| produce(i) }
22
+ else
23
+ produce ARGV[0].to_i
24
+ end
@@ -1,24 +1,23 @@
1
- require 'mediacloth/mediawikilexer'
2
- require 'mediacloth/mediawikiparser'
3
- require 'mediacloth/mediawikiparams'
4
- require 'mediacloth/mediawikihtmlgenerator'
1
+ require 'mediacloth'
5
2
 
6
3
  def produce(index)
7
- file = File.new("../test/data/html#{index}", "w")
8
- inputFile = File.new("../test/data/input#{index}", "r")
4
+ file = File.new("#{File.dirname(__FILE__)}/../data/html#{index}", "w")
5
+ inputFile = File.new("#{File.dirname(__FILE__)}/../data/input#{index}", "r")
9
6
  input = inputFile.read
10
-
11
7
  parser = MediaWikiParser.new
12
8
  parser.lexer = MediaWikiLexer.new
13
9
  ast = parser.parse(input)
14
- MediaWikiParams.instance.time = Time.mktime(2000, 1, 1, 1, 1, 1, 1)
10
+ params = MediaWikiParams.new
11
+ params.time = Time.mktime(2000, 1, 1, 1, 1, 1, 1)
15
12
  generator = MediaWikiHTMLGenerator.new
13
+ generator.params = params
16
14
  generator.parse(ast)
17
-
18
- # puts generator.html
19
15
  file.write(generator.html)
20
16
  file.close
21
17
  end
22
18
 
23
- # (3..5).each { |i| produce(i) }
24
- produce(5)
19
+ if ARGV.empty?
20
+ (1..13).each { |i| produce(i) }
21
+ else
22
+ produce ARGV[0].to_i
23
+ end
@@ -1,8 +1,10 @@
1
1
  require 'mediacloth/mediawikilexer'
2
2
 
3
+ puts
4
+
3
5
  def produce(index)
4
- file = File.new("../test/data/lex#{index}", "w")
5
- inputFile = File.new("../test/data/input#{index}", "r")
6
+ file = File.new("#{File.dirname(__FILE__)}/../data/lex#{index}", "w")
7
+ inputFile = File.new("#{File.dirname(__FILE__)}/../data/input#{index}", "r")
6
8
  input = inputFile.read
7
9
 
8
10
  lexer = MediaWikiLexer.new
@@ -11,5 +13,8 @@ def produce(index)
11
13
  file.close
12
14
  end
13
15
 
14
- #1..5.each { |i| produce(1) }
15
- produce(5)
16
+ if ARGV.empty?
17
+ (1..13).each { |i| produce(i) }
18
+ else
19
+ produce ARGV[0].to_i
20
+ end
data/test/debugwalker.rb CHANGED
@@ -17,18 +17,16 @@ class DebugWalker < MediaWikiWalker
17
17
  def initialize
18
18
  super
19
19
  @tree = ""
20
+ @left_space = 0
20
21
  end
21
22
 
22
23
  protected
23
24
 
24
25
  def parse_wiki_ast(ast)
25
26
  info(ast)
26
- super(ast)
27
- end
28
-
29
- def parse_paragraph(ast)
30
- info(ast)
31
- super(ast)
27
+ @left_space += 1
28
+ super(ast) if ast.children
29
+ @left_space -= 1
32
30
  end
33
31
 
34
32
  def parse_text(ast)
@@ -38,26 +36,42 @@ protected
38
36
 
39
37
  def parse_list(ast)
40
38
  info(ast, ast.class)
39
+ @left_space += 1
41
40
  super(ast)
41
+ @left_space -= 1
42
42
  end
43
43
 
44
- def parse_list_item(ast)
44
+ def parse_internal_link(ast)
45
45
  info(ast)
46
- super(ast)
46
+ @left_space += 1
47
+ ast.children.map do |c|
48
+ parse_wiki_ast(c)
49
+ end
50
+ @left_space -= 1
47
51
  end
48
52
 
49
- def parse_preformatted(ast)
53
+ def parse_resource_link(ast)
50
54
  info(ast)
55
+ @left_space += 1
56
+ ast.children.map do |c|
57
+ parse_wiki_ast(c)
58
+ end
59
+ @left_space -= 1
51
60
  end
52
61
 
53
- def parse_section(ast)
62
+ def parse_category_link(ast)
54
63
  info(ast)
64
+ @left_space += 1
65
+ ast.children.map do |c|
66
+ parse_wiki_ast(c)
67
+ end
68
+ @left_space -= 1
55
69
  end
56
70
 
57
71
  private
58
72
  #Pretty-print ast node information
59
73
  def info(ast, *args)
60
- @tree += "#{ast.class}"
74
+ @tree += "#{" " * @left_space}#{ast.class}[#{ast.index}, #{ast.length}]"
61
75
  if args.length > 0
62
76
  @tree += ": "
63
77
  args.each { |arg| @tree += "#{arg} " }
@@ -1,26 +1,183 @@
1
1
  require 'mediacloth/mediawikilexer'
2
2
  require 'mediacloth/mediawikiparser'
3
3
  require 'mediacloth/mediawikihtmlgenerator'
4
+ require 'mediacloth/mediawikilinkhandler'
5
+ require 'mediacloth/mediawikitemplatehandler'
4
6
 
5
7
  require 'test/unit'
6
8
  require 'testhelper'
7
9
 
8
10
  class HTMLGenerator_Test < Test::Unit::TestCase
9
11
 
10
- include TestHelper
12
+ class << self
13
+ include TestHelper
14
+ end
15
+
16
+ test_files("html") do |input,result, name|
17
+ name =~ /([0-9]+)$/
18
+ define_method("test_input_#{$1}") do
19
+ assert_generates(result, input, nil, name)
20
+ end
21
+ end
22
+
23
+ def test_http_urls_in_internal_links
24
+ html = generate('[[http://www.google.com]]', MediaWikiLinkHandler.new)
25
+ assert_equal html, '<p><a href="http://www.google.com">http://www.google.com</a></p>'
26
+ html = generate('[[https://www.google.com]]', MediaWikiLinkHandler.new)
27
+ assert_equal html, '<p><a href="https://www.google.com">https://www.google.com</a></p>'
28
+ end
29
+
30
+ def test_punctuation_at_the_end_of_absolute_links
31
+ html = generate('http://example.com.', MediaWikiLinkHandler.new)
32
+ assert_equal html, '<p><a href="http://example.com">http://example.com</a>.</p>'
33
+ html = generate('http://example.com...', MediaWikiLinkHandler.new)
34
+ assert_equal html, '<p><a href="http://example.com">http://example.com</a>...</p>'
35
+ html = generate('http://example.com,', MediaWikiLinkHandler.new)
36
+ assert_equal html, '<p><a href="http://example.com">http://example.com</a>,</p>'
37
+ html = generate('http://example.com:', MediaWikiLinkHandler.new)
38
+ assert_equal html, '<p><a href="http://example.com">http://example.com</a>:</p>'
39
+ html = generate('http://example.com;', MediaWikiLinkHandler.new)
40
+ assert_equal html, '<p><a href="http://example.com">http://example.com</a>;</p>'
41
+ html = generate('http://example.com-', MediaWikiLinkHandler.new)
42
+ assert_equal html, '<p><a href="http://example.com">http://example.com</a>-</p>'
43
+ end
44
+
45
+ def test_punctuation_at_the_end_of_internal_links
46
+ html = generate('[http://example.com/page. Example]', MediaWikiLinkHandler.new)
47
+ assert_equal html, '<p><a href="http://example.com/page.">Example</a></p>'
48
+ html = generate('[http://example.com/page- Example]', MediaWikiLinkHandler.new)
49
+ assert_equal html, '<p><a href="http://example.com/page-">Example</a></p>'
50
+ end
51
+
52
+ def test_uses_element_attributes_from_link_handler
53
+ html = generate('[[InternalLink|This is just an internal link]]', ClassEmptyLinkHandler.new)
54
+ expected1 = '<p><a class="empty" href="http://www.example.com/wiki/InternalLink">This is just an internal link</a></p>'
55
+ expected2 = '<p><a href="http://www.example.com/wiki/InternalLink" class="empty">This is just an internal link</a></p>'
56
+ assert (html == expected1 or html == expected2)
57
+ end
58
+
59
+ def test_accepts_url_only_link_handlers
60
+ assert_generates '<p><a href="http://www.example.com/wiki/InternalLink/">This is just an internal link</a></p>',
61
+ '[[InternalLink|This is just an internal link]]',
62
+ UrlOnlyLinkHandler.new
63
+ end
64
+
65
+ def test_prefers_url_from_attributes_when_provided_with_ambiguous_link_info
66
+ html = generate('[[InternalLink|This is just an internal link]]', AmbiguousLinkHandler.new)
67
+ expected1 = '<p><a rel="nofollow" href="http://www.example.com/wiki/InternalLink">This is just an internal link</a></p>'
68
+ expected2 = '<p><a href="http://www.example.com/wiki/InternalLink" rel="nofollow">This is just an internal link</a></p>'
69
+ assert (html == expected1 or html == expected2)
70
+ end
71
+
72
+ def test_allows_specification_of_all_attributes
73
+ html = generate('[[MyLink|Here is my link]]', LinkAttributeHandler.new)
74
+ expected1 = '<p><a href="http://www.mysite.com/MyLink" id="123">Here is my link</a></p>'
75
+ expected2 = '<p><a id="123" href="http://www.mysite.com/MyLink">Here is my link</a></p>'
76
+ assert (html == expected1 or html == expected2)
77
+ end
78
+
79
+ def test_allows_full_customization_of_link_tags
80
+ assert_generates '<p><span class="link">This doesn\'t even render into a real link</span></p>',
81
+ "[[AnotherLink|This doesn't even render into a real link]]",
82
+ FullLinkHandler.new
83
+ end
84
+
85
+ def test_handles_category_links
86
+ assert_generates '<p><a class="category" href="http://www.mywiki.net/wiki/Category:Foo">More articles on Foo</a></p>',
87
+ "[[:Category:Foo|More articles on Foo]]",
88
+ CategoryLinkHandler.new
89
+ end
90
+
91
+ def test_handles_category_directives
92
+ assert_generates '<p><div id="catlinks">This page belongs to the <a class="category" href="http://www.mywiki.net/wiki/Category:Foo">Foo category</a></div></p>',
93
+ "[[Category:Foo]]",
94
+ CategoryDirectiveHandler.new
95
+ end
96
+
97
+ def test_table_with_column_attributes
98
+ assert_generates "<table cellpadding=\"5\" border=\"1\"><tr><td>a\n</td></tr>\n<tr><td colspan=\"4\" align=\"center\" style=\"background:#ffdead;\"> b\n</td></tr>\n</table>\n",
99
+ "{|\n|a\n|-\n| colspan=\"4\" align=\"center\" style=\"background:#ffdead;\"| b\n|}"
100
+ end
101
+
102
+ def test_table_with_column_attributes_cellspacing_and_border
103
+ assert_generates "<table cellpadding=\"10\" border=\"5\"><tr><td>a\n</td></tr>\n<tr><td colspan=\"4\" align=\"center\" style=\"background:#ffdead;\"> b\n</td></tr>\n</table>\n",
104
+ "{|cellpadding=\"10\" border=\"5\"\n|a\n|-\n| colspan=\"4\" align=\"center\" style=\"background:#ffdead;\"| b\n|}"
105
+ end
11
106
 
12
- def test_input
13
- test_files("html") { |input,result,name|
14
- puts name
15
- parser = MediaWikiParser.new
16
- parser.lexer = MediaWikiLexer.new
17
- ast = parser.parse(input)
18
- MediaWikiParams.instance.time = Time.utc(2000, 1, 1, 1, 1, 1, 1)
19
- generator = MediaWikiHTMLGenerator.new
20
- generator.parse(ast)
21
- assert_equal generator.html, result, name
22
- # puts generator.html
23
- }
107
+ def test_table_with_column_attributes_cellspacing_and_border_and_style
108
+ assert_generates "<table cellspacing=\"0\" cellpadding=\"5\" style=\"border-collapse:collapse\"><tr><td>a\n</td></tr>\n<tr><td colspan=\"4\" align=\"center\" style=\"background:#ffdead;\"> b\n</td></tr>\n</table>\n",
109
+ "{|cellspacing=\"0\" cellpadding=\"5\" style=\"border-collapse:collapse\"\n|a\n|-\n| colspan=\"4\" align=\"center\" style=\"background:#ffdead;\"| b\n|}"
24
110
  end
25
111
 
112
+ def test_table_without_column_attributes
113
+ assert_generates "<table cellpadding=\"5\" border=\"1\"><tr><td> a\n</td><td> b\n</td></tr>\n</table>\n",
114
+ "{|\n| a\n| b\n|}"
115
+ end
116
+
117
+ private
118
+
119
+ def assert_generates(result, input, link_handler=nil, message=nil)
120
+ assert_equal(result, generate(input, link_handler), message)
121
+ end
122
+
123
+ def generate(input, link_handler = nil)
124
+ parser = MediaWikiParser.new
125
+ parser.lexer = MediaWikiLexer.new
126
+ ast = parser.parse(input)
127
+ generator = MediaWikiHTMLGenerator.new
128
+ generator.link_handler = link_handler if link_handler
129
+ params = MediaWikiParams.new
130
+ params.time = Time.utc(2000, 1, 1, 1, 1, 1, 1)
131
+ generator.params = params
132
+ generator.parse(ast)
133
+ generator.html
134
+ end
135
+ end
136
+
137
+ class LinkAttributeHandler < MediaWikiLinkHandler
138
+ def link_attributes_for(page)
139
+ { :href => "http://www.mysite.com/#{page}", :id => '123' }
140
+ end
141
+ end
142
+
143
+ class ClassEmptyLinkHandler < MediaWikiLinkHandler
144
+ def link_attributes_for(resource)
145
+ {:class => 'empty', :href => "http://www.example.com/wiki/#{resource}"}
146
+ end
147
+ end
148
+
149
+ class UrlOnlyLinkHandler < MediaWikiLinkHandler
150
+ def url_for(resource)
151
+ "http://www.example.com/wiki/#{resource}/"
152
+ end
153
+ end
154
+
155
+ class AmbiguousLinkHandler < MediaWikiLinkHandler
156
+ def url_for(resource)
157
+ "http://www.somewhereelse.net"
158
+ end
159
+
160
+ def link_attributes_for(resource)
161
+ {:rel => 'nofollow', :href => "http://www.example.com/wiki/#{resource}"}
162
+ end
163
+ end
164
+
165
+ class FullLinkHandler < MediaWikiLinkHandler
166
+ def link_for(page, text)
167
+ "<span class=\"link\">#{text}</span>"
168
+ end
26
169
  end
170
+
171
+ class CategoryLinkHandler
172
+ def link_for_category(locator, text)
173
+ %(<a class="category" href="http://www.mywiki.net/wiki/Category:#{locator}">#{text}</a>)
174
+ end
175
+ end
176
+
177
+ class CategoryDirectiveHandler
178
+ def category_add(name, sort)
179
+ %(<div id="catlinks">This page belongs to the <a class="category" href="http://www.mywiki.net/wiki/Category:#{name}">#{name} category</a></div>)
180
+ end
181
+ end
182
+
183
+