mediacloth 0.0.3 → 0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -0,0 +1,39 @@
1
+ require 'mediacloth/mediawikilinkhandler'
2
+
3
+ require 'test/unit'
4
+ require 'testhelper'
5
+
6
+ class LinkHandler_Test < Test::Unit::TestCase
7
+
8
+ def test_resolves_single_links
9
+ handler = create_handler
10
+ assert_equal '<a href="http://example.com/wiki/MyPage">this is my page</a>',
11
+ handler.link_for('MyPage', 'this is my page')
12
+ end
13
+
14
+ def test_forgets_previous_links
15
+ handler = create_handler
16
+ handler.link_for('MyPage', 'this is my page')
17
+ assert_equal '<a href="http://example.com/wiki/YourPage">this page is yours</a>',
18
+ handler.link_for('YourPage', 'this page is yours')
19
+ end
20
+
21
+ def test_provides_suitable_elem_method_for_subclasses
22
+ handler = create_handler
23
+ def handler.link_for(page, text)
24
+ elem.span(:class => 'empty') {|x| x << text }
25
+ end
26
+ assert_equal '<span class="empty">Here is my page</span>',
27
+ handler.link_for('MyPage', 'Here is my page')
28
+ end
29
+
30
+ private
31
+
32
+ def create_handler
33
+ handler = MediaWikiLinkHandler.new
34
+ def handler.url_for(page); "http://example.com/wiki/#{page}"; end
35
+ handler
36
+ end
37
+
38
+ end
39
+
data/test/parser.rb CHANGED
@@ -7,16 +7,183 @@ require 'debugwalker'
7
7
 
8
8
  class Parser_Test < Test::Unit::TestCase
9
9
 
10
- include TestHelper
10
+ class << self
11
+ include TestHelper
12
+ end
13
+
14
+ test_files("ast") do |input,result,resultname|
15
+ resultname =~ /([0-9]+)$/
16
+ define_method("test_ast_structure_input_#{$1}") do
17
+ assert_generates(result, input, "Mismatch in #{resultname}")
18
+ end
19
+ end
20
+
21
+ def test_ast_structure_paragraphs
22
+ assert_generates "WikiAST[0, 4]\n ParagraphAST[0, 4]\n TextAST[0, 4]: None \n",
23
+ "text"
24
+ assert_generates "WikiAST[0, 14]\n ParagraphAST[0, 5]\n TextAST[0, 5]: None \n SectionAST[5, 9]\n TextAST[6, 7]: None \n",
25
+ "text\n=heading="
26
+ assert_generates "WikiAST[0, 15]\n ParagraphAST[0, 6]\n TextAST[0, 6]: None \n SectionAST[6, 9]\n TextAST[7, 7]: None \n",
27
+ "text\n\n=heading="
28
+ assert_generates "WikiAST[0, 17]\n ParagraphAST[0, 8]\n TextAST[0, 8]: None \n SectionAST[8, 9]\n TextAST[9, 7]: None \n",
29
+ "text\r\n\r\n=heading="
30
+ end
31
+
32
+ def test_ast_structure_formatting
33
+ assert_generates "WikiAST[0, 10]\n ParagraphAST[0, 10]\n FormattedAST[0, 10]\n TextAST[2, 6]: None \n",
34
+ "''italic''"
35
+ assert_generates "WikiAST[0, 10]\n ParagraphAST[0, 10]\n FormattedAST[0, 10]\n TextAST[3, 4]: None \n",
36
+ "'''bold'''"
37
+ assert_generates "WikiAST[0, 26]\n ParagraphAST[0, 26]\n FormattedAST[0, 26]\n TextAST[2, 6]: None \n FormattedAST[8, 10]\n TextAST[11, 4]: None \n TextAST[18, 6]: None \n",
38
+ "''italic'''bold'''italic''"
39
+ assert_generates "WikiAST[0, 10]\n ParagraphAST[0, 10]\n FormattedAST[0, 10]\n TextAST[2, 8]: None \n",
40
+ "''italic\n\n"
41
+ end
42
+
43
+ def test_ast_structure_headings
44
+ assert_generates "WikiAST[0, 9]\n SectionAST[0, 9]\n TextAST[1, 7]: None \n",
45
+ "=heading="
46
+ assert_generates "WikiAST[0, 11]\n SectionAST[0, 11]\n TextAST[2, 7]: None \n",
47
+ "==heading=="
48
+ assert_generates "WikiAST[0, 13]\n SectionAST[0, 8]\n TextAST[1, 7]: None \n ParagraphAST[8, 5]\n TextAST[9, 4]: None \n",
49
+ "=heading=text"
50
+ assert_generates "WikiAST[0, 14]\n SectionAST[0, 9]\n TextAST[2, 7]: None \n ParagraphAST[9, 5]\n TextAST[9, 5]: None \n",
51
+ "==heading\ntext"
52
+ end
53
+
54
+ def test_ast_structure_inline_links
55
+ assert_generates "WikiAST[0, 18]\n ParagraphAST[0, 18]\n LinkAST[0, 18]\n",
56
+ "http://example.com"
57
+ assert_generates "WikiAST[0, 28]\n ParagraphAST[0, 28]\n LinkAST[0, 18]\n FormattedAST[18, 10]\n TextAST[20, 6]: None \n",
58
+ "http://example.com''italic''"
59
+ assert_generates "WikiAST[0, 22]\n SectionAST[0, 22]\n TextAST[1, 1]: None \n LinkAST[2, 18]\n TextAST[20, 1]: None \n",
60
+ "= http://example.com ="
61
+ assert_generates "WikiAST[0, 49]\n ParagraphAST[0, 49]\n LinkAST[0, 49]\n",
62
+ "http://example.com/SpecialCharacters%C3%A7%C3%A3o"
63
+ end
64
+
65
+ def test_ast_structure_links
66
+ assert_generates "WikiAST[0, 2]\n ParagraphAST[0, 2]\n TextAST[0, 2]: None \n",
67
+ "[]"
68
+ assert_generates "WikiAST[0, 3]\n ParagraphAST[0, 3]\n TextAST[0, 3]: None \n",
69
+ "[ ]"
70
+ assert_generates "WikiAST[0, 20]\n ParagraphAST[0, 20]\n LinkAST[0, 20]\n",
71
+ "[http://example.com]"
72
+ assert_generates "WikiAST[0, 31]\n ParagraphAST[0, 31]\n LinkAST[0, 31]\n FormattedAST[20, 10]\n TextAST[22, 6]: None \n",
73
+ "[http://example.com ''italic'']"
74
+ assert_generates "WikiAST[0, 18]\n ParagraphAST[0, 18]\n InternalLinkAST[0, 18]\n TextAST[10, 6]\n",
75
+ "[[example|option]]"
76
+ assert_generates "WikiAST[0, 27]\n ParagraphAST[0, 27]\n InternalLinkAST[0, 27]\n TextAST[10, 15]\n",
77
+ "[[example|option1|option2]]"
78
+ assert_generates "WikiAST[0, 36]\n ParagraphAST[0, 36]\n ResourceLinkAST[0, 36]\n InternalLinkItemAST[0, 36]\n TextAST[19, 7]: None \n InternalLinkItemAST[0, 36]\n TextAST[27, 7]: None \n",
79
+ "[[resource:example|option1|option2]]"
80
+ assert_generates "WikiAST[0, 28]\n ParagraphAST[0, 28]\n ResourceLinkAST[0, 28]\n InternalLinkItemAST[0, 28]\n TextAST[20, 6]: None \n",
81
+ "[[resource:example||option]]"
82
+ end
11
83
 
12
- def test_input
13
- test_files("result") { |input,result|
14
- parser = MediaWikiParser.new
15
- parser.lexer = MediaWikiLexer.new
16
- ast = parser.parse(input)
17
- walker = DebugWalker.new
18
- walker.parse(ast)
19
- }
84
+ def test_ast_structure_table
85
+ assert_generates "WikiAST[0, 5]\n TableAST[0, 5]\n",
86
+ "{|\n|}"
87
+ assert_generates "WikiAST[0, 11]\n TableAST[0, 11]\n TableRowAST[0, 11]\n TableCellAST[3, 6]\n TextAST[4, 1]: None \n TableCellAST[3, 6]\n TextAST[7, 2]: None \n",
88
+ "{|\n|a||b\n|}"
89
+ assert_generates "WikiAST[0, 14]\n TableAST[0, 14]\n TableRowAST[0, 14]\n TableCellAST[3, 3]\n TextAST[4, 2]: None \n TableRowAST[0, 14]\n TableCellAST[6, 6]\n TextAST[10, 2]: None \n",
90
+ "{|\n|a\n|-\n|b\n|}"
91
+ assert_generates "WikiAST[0, 27]\n TableAST[0, 27]\n TableRowAST[0, 27]\n TableCellAST[3, 3]\n TextAST[4, 2]: None \n TableRowAST[0, 27]\n TableCellAST[6, 19]\n TextAST[23, 2]: None \n",
92
+ "{|\n|a\n|- align='left'\n|b\n|}"
20
93
  end
21
94
 
95
+ def test_ast_structure_preformatted
96
+ assert_generates "WikiAST[0, 3]\n ParagraphAST[0, 3]\n TextAST[0, 3]: None \n",
97
+ " \n"
98
+ assert_generates "WikiAST[0, 11]\n ParagraphAST[0, 5]\n TextAST[0, 5]: None \n PreformattedAST[5, 6]\n TextAST[5, 6]: None \n",
99
+ "text\n text\n"
100
+ assert_generates "WikiAST[0, 11]\n ParagraphAST[0, 5]\n TextAST[0, 5]: None \n PreformattedAST[5, 6]\n TextAST[5, 6]: None \n",
101
+ "text\n text\n"
102
+ assert_generates "WikiAST[0, 12]\n PreformattedAST[0, 12]\n TextAST[0, 1]: None \n FormattedAST[1, 10]\n TextAST[3, 6]: None \n TextAST[11, 1]: None \n",
103
+ " ''italic''\n"
104
+ end
105
+
106
+ def test_ast_structure_hline
107
+ assert_generates "WikiAST[0, 9]\n ParagraphAST[0, 5]\n TextAST[0, 5]: None \n TextAST[5, 4]: HLine \n",
108
+ "text\n----"
109
+ assert_generates "WikiAST[0, 10]\n ParagraphAST[0, 6]\n TextAST[0, 6]: None \n TextAST[6, 4]: HLine \n",
110
+ "text\r\n----"
111
+ assert_generates "WikiAST[0, 9]\n TextAST[0, 4]: HLine \n ParagraphAST[4, 5]\n TextAST[4, 5]: None \n",
112
+ "----\ntext"
113
+ assert_generates "WikiAST[0, 10]\n TextAST[0, 4]: HLine \n ParagraphAST[4, 2]\n TextAST[4, 2]: None \n ParagraphAST[6, 4]\n TextAST[6, 4]: None \n",
114
+ "----\n\ntext"
115
+ end
116
+
117
+ def test_ast_structure_nowiki
118
+ assert_generates "WikiAST[0, 18]\n ParagraphAST[0, 27]\n TextAST[8, 10]: None \n",
119
+ "<nowiki>''italic''</nowiki>"
120
+ assert_generates "WikiAST[0, 18]\n ParagraphAST[0, 35]\n TextAST[0, 18]: None \n",
121
+ "text<nowiki>''italic''</nowiki>text"
122
+ assert_generates "WikiAST[0, 18]\n ParagraphAST[0, 27]\n TextAST[8, 10]: None \n",
123
+ "<nowiki><u>uuu</u></nowiki>"
124
+ assert_generates "WikiAST[0, 8]\n ParagraphAST[0, 17]\n TextAST[0, 8]: None \n",
125
+ "text<nowiki/>text"
126
+ end
127
+
128
+ def test_ast_structure_xhtml_markup
129
+ assert_generates "WikiAST[0, 13]\n ParagraphAST[0, 13]\n ElementAST[0, 13]\n TextAST[4, 4]: None \n",
130
+ "<tt>text</tt>"
131
+ assert_generates "WikiAST[0, 5]\n ParagraphAST[0, 5]\n ElementAST[0, 5]\n",
132
+ "<tt/>"
133
+ assert_generates "WikiAST[0, 24]\n ParagraphAST[0, 24]\n ElementAST[0, 24]\n TextAST[15, 4]: None \n",
134
+ "<tt class='tt'>text</tt>"
135
+ assert_generates "WikiAST[0, 16]\n ParagraphAST[0, 16]\n ElementAST[0, 16]\n TextAST[4, 7]: None \n",
136
+ "<tt>\n\ntext\n</tt>"
137
+ assert_generates "WikiAST[0, 29]\n ParagraphAST[0, 29]\n ElementAST[0, 29]\n PasteAST[4, 20]\n TextAST[11, 5]: None \n",
138
+ "<tt><paste>paste</paste></tt>"
139
+ assert_generates "WikiAST[0, 34]\n ParagraphAST[0, 34]\n LinkAST[0, 34]\n ElementAST[20, 13]\n TextAST[24, 4]: None \n",
140
+ "[http://example.com <tt>text</tt>]"
141
+ end
142
+
143
+ def test_ast_structure_lists
144
+ assert_generates "WikiAST[0, 2]\n ListAST[0, 2]: ListAST \n ListItemAST[0, 2]\n TextAST[1, 1]: None \n",
145
+ "*a"
146
+ assert_generates "WikiAST[0, 3]\n ListAST[0, 3]: ListAST \n ListItemAST[0, 3]\n TextAST[1, 2]: None \n",
147
+ "*a\n"
148
+ assert_generates "WikiAST[0, 10]\n ListAST[0, 10]: ListAST \n ListItemAST[0, 7]\n TextAST[1, 2]: None \n ListAST[3, 4]: ListAST \n ListItemAST[3, 4]\n TextAST[5, 2]: None \n ListItemAST[7, 3]\n TextAST[8, 2]: None \n",
149
+ "*a\n**i\n*b\n"
150
+ assert_generates "WikiAST[0, 7]\n ListAST[0, 7]: ListAST \n ListItemAST[0, 4]\n ListAST[1, 3]: ListAST \n ListItemAST[1, 3]\n TextAST[2, 2]: None \n ListItemAST[4, 3]\n TextAST[5, 2]: None \n",
151
+ "**i\n*b\n"
152
+ assert_generates "WikiAST[0, 2]\n ListAST[0, 2]: ListAST \n ListItemAST[0, 2]\n TextAST[1, 1]: None \n",
153
+ "#a"
154
+ assert_generates "WikiAST[0, 3]\n ListAST[0, 3]: ListAST \n ListItemAST[0, 3]\n TextAST[1, 2]: None \n",
155
+ "#a\n"
156
+ assert_generates "WikiAST[0, 10]\n ListAST[0, 10]: ListAST \n ListItemAST[0, 7]\n TextAST[1, 2]: None \n ListAST[3, 4]: ListAST \n ListItemAST[3, 4]\n TextAST[5, 2]: None \n ListItemAST[7, 3]\n TextAST[8, 2]: None \n",
157
+ "#a\n##i\n#b\n"
158
+ assert_generates "WikiAST[0, 7]\n ListAST[0, 7]: ListAST \n ListItemAST[0, 4]\n ListAST[1, 3]: ListAST \n ListItemAST[1, 3]\n TextAST[2, 2]: None \n ListItemAST[4, 3]\n TextAST[5, 2]: None \n",
159
+ "##i\n#b\n"
160
+ assert_generates "WikiAST[0, 6]\n ListAST[0, 3]: ListAST \n ListItemAST[0, 3]\n TextAST[1, 2]: None \n ListAST[3, 3]: ListAST \n ListItemAST[3, 3]\n TextAST[4, 2]: None \n",
161
+ "*a\n#b\n"
162
+ assert_generates "WikiAST[0, 10]\n ListAST[0, 10]: ListAST \n ListItemAST[0, 7]\n TextAST[1, 2]: None \n ListAST[3, 4]: ListAST \n ListItemAST[3, 4]\n TextAST[5, 2]: None \n ListItemAST[7, 3]\n TextAST[8, 2]: None \n",
163
+ "*a\n*#i\n*b\n"
164
+ assert_generates "WikiAST[0, 2]\n ListAST[0, 2]: ListAST \n ListTermAST[0, 2]\n TextAST[1, 1]: None \n",
165
+ ";a"
166
+ assert_generates "WikiAST[0, 2]\n ListAST[0, 2]: ListAST \n ListDefinitionAST[0, 2]\n TextAST[1, 1]: None \n",
167
+ ":b"
168
+ assert_generates "WikiAST[0, 6]\n ListAST[0, 3]: ListAST \n ListTermAST[0, 3]\n TextAST[1, 2]: None \n ListAST[3, 3]: ListAST \n ListTermAST[3, 3]\n TextAST[4, 2]: None \n",
169
+ ";a\n;a\n"
170
+ assert_generates "WikiAST[0, 7]\n ListAST[0, 3]: ListAST \n ListTermAST[0, 3]\n TextAST[1, 2]: None \n ParagraphAST[3, 4]\n TextAST[3, 4]: None \n",
171
+ ";a\ntext"
172
+ end
173
+
174
+ private
175
+
176
+ def assert_generates(result, input, message=nil)
177
+ assert_equal(result, generate(input), message)
178
+ end
179
+
180
+ def generate(input)
181
+ parser = MediaWikiParser.new
182
+ parser.lexer = MediaWikiLexer.new
183
+ ast = parser.parse(input)
184
+ walker = DebugWalker.new
185
+ walker.parse(ast)
186
+ walker.tree
187
+ end
188
+
22
189
  end
@@ -0,0 +1,113 @@
1
+ require 'mediacloth/mediawikilexer'
2
+ require 'mediacloth/mediawikiparser'
3
+ require 'mediacloth/mediawikisignedwikigenerator'
4
+ require 'mediacloth/mediawikilinkhandler'
5
+ require 'mediacloth/mediawikitemplatehandler'
6
+
7
+ require 'test/unit'
8
+ require 'testhelper'
9
+
10
+ class SignedWikiGenerator_Test < Test::Unit::TestCase
11
+
12
+ class << self
13
+ include TestHelper
14
+ end
15
+
16
+ def test_simple_signature_replacement
17
+ assert_generates "[[User:Creator|Creator]]",
18
+ "~~~",
19
+ "SignatureName replacement failed"
20
+ assert_generates "[[User:Creator|Creator]] Sat Jan 01, 2000 01:01",
21
+ "~~~~",
22
+ "SignatureFull replacement failed"
23
+ assert_generates "Sat Jan 01, 2000 01:01",
24
+ "~~~~~",
25
+ "SignatureDate replacement failed"
26
+ end
27
+
28
+ def test_multiple_signature_replacement
29
+ assert_generates "[[User:Creator|Creator]]sometext[[User:Creator|Creator]]",
30
+ "~~~sometext~~~"
31
+ assert_generates "[[User:Creator|Creator]]sometext[[User:Creator|Creator]] Sat Jan 01, 2000 01:01",
32
+ "~~~sometext~~~~"
33
+ assert_generates "[[User:Creator|Creator]]sometextSat Jan 01, 2000 01:01",
34
+ "~~~sometext~~~~~"
35
+ assert_generates "[[User:Creator|Creator]] Sat Jan 01, 2000 01:01some\ntext[[User:Creator|Creator]]",
36
+ "~~~~some\ntext~~~"
37
+ assert_generates "[[User:Creator|Creator]] Sat Jan 01, 2000 01:01some\ntext[[User:Creator|Creator]] Sat Jan 01, 2000 01:01",
38
+ "~~~~some\ntext~~~~"
39
+ assert_generates "[[User:Creator|Creator]] Sat Jan 01, 2000 01:01some\ntextSat Jan 01, 2000 01:01",
40
+ "~~~~some\ntext~~~~~"
41
+ assert_generates "Sat Jan 01, 2000 01:01sometext[[User:Creator|Creator]]",
42
+ "~~~~~sometext~~~"
43
+ assert_generates "Sat Jan 01, 2000 01:01sometext[[User:Creator|Creator]] Sat Jan 01, 2000 01:01",
44
+ "~~~~~sometext~~~~"
45
+ assert_generates "Sat Jan 01, 2000 01:01sometextSat Jan 01, 2000 01:01",
46
+ "~~~~~sometext~~~~~"
47
+ assert_generates "[[User:Creator|Creator]]some text[[User:Creator|Creator]] Sat Jan 01, 2000 01:01'''bold'''Sat Jan 01, 2000 01:01",
48
+ "~~~some text~~~~'''bold'''~~~~~"
49
+ assert_generates "[[User:Creator|Creator]] Sat Jan 01, 2000 01:01''''bold italic'''''Sat Jan 01, 2000 01:01some\ntext[[User:Creator|Creator]] Sat Jan 01, 2000 01:01",
50
+ "~~~~''''bold italic'''''~~~~~some\ntext~~~~"
51
+ assert_generates "* [[User:Creator|Creator]]\n* [[User:Creator|Creator]] Sat Jan 01, 2000 01:01\n* Sat Jan 01, 2000 01:01\n",
52
+ "* ~~~\n* ~~~~\n* ~~~~~\n"
53
+ end
54
+
55
+ def test_signature_replacement_in_wiki_structures
56
+ assert_generates "<nowiki> ~~~ </nowiki>",
57
+ "<nowiki> ~~~ </nowiki>"
58
+ assert_generates "<nowiki> ~~~~ </nowiki>",
59
+ "<nowiki> ~~~~ </nowiki>"
60
+ assert_generates "<nowiki> ~~~~~ </nowiki>",
61
+ "<nowiki> ~~~~~ </nowiki>"
62
+ assert_generates "<tt> [[User:Creator|Creator]] </tt>",
63
+ "<tt> ~~~ </tt>"
64
+ assert_generates "<tt> [[User:Creator|Creator]] Sat Jan 01, 2000 01:01 </tt>",
65
+ "<tt> ~~~~ </tt>"
66
+ assert_generates "<tt> Sat Jan 01, 2000 01:01 </tt>",
67
+ "<tt> ~~~~~ </tt>"
68
+ assert_generates "<paste> ~~~ </paste>",
69
+ "<paste> ~~~ </paste>"
70
+ assert_generates "<paste> ~~~~ </paste>",
71
+ "<paste> ~~~~ </paste>"
72
+ assert_generates "<paste> ~~~~~ </paste>",
73
+ "<paste> ~~~~~ </paste>"
74
+ assert_generates "'' [[User:Creator|Creator]] ''",
75
+ "'' ~~~ ''"
76
+ assert_generates "'' [[User:Creator|Creator]] Sat Jan 01, 2000 01:01 ''",
77
+ "'' ~~~~ ''"
78
+ assert_generates "'' Sat Jan 01, 2000 01:01 ''",
79
+ "'' ~~~~~ ''"
80
+ assert_generates "''' [[User:Creator|Creator]] '''",
81
+ "''' ~~~ '''"
82
+ assert_generates "''' [[User:Creator|Creator]] Sat Jan 01, 2000 01:01 '''",
83
+ "''' ~~~~ '''"
84
+ assert_generates "''' Sat Jan 01, 2000 01:01 '''",
85
+ "''' ~~~~~ '''"
86
+ end
87
+
88
+ private
89
+
90
+ def assert_generates(result, input, message=nil)
91
+ assert_equal(result, generate(input), message)
92
+ end
93
+
94
+ def generate(input)
95
+ parser = MediaWikiParser.new
96
+ parser.lexer = MediaWikiLexer.new
97
+ ast = parser.parse(input)
98
+ generator = MediaWikiSignedWikiGenerator.new
99
+ generator.link_handler = FullLinkHandler.new
100
+ params = MediaWikiParams.new
101
+ params.time = Time.utc(2000, 1, 1, 1, 1, 1, 1)
102
+ generator.params = params
103
+ generator.parse(ast,input)
104
+ generator.signed_wiki
105
+ end
106
+ end
107
+
108
+ class FullLinkHandler < MediaWikiLinkHandler
109
+ def link_for(page, text)
110
+ "<span class=\"link\">#{text}</span>"
111
+ end
112
+ end
113
+
metadata CHANGED
@@ -1,102 +1,181 @@
1
- --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.0
3
- specification_version: 1
1
+ --- !ruby/object:Gem::Specification
4
2
  name: mediacloth
5
- version: !ruby/object:Gem::Version
6
- version: 0.0.3
7
- date: 2007-10-31 00:00:00 +02:00
8
- summary: A MediaWiki syntax parser and HTML generator.
9
- require_paths:
10
- - lib
11
- email: support@pluron.com
12
- homepage: http://mediacloth.rubyforge.org/
13
- rubyforge_project:
14
- description:
15
- autorequire: mediacloth
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: true
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.5'
5
+ prerelease:
25
6
  platform: ruby
26
- signing_key:
27
- cert_chain:
28
- post_install_message:
29
- authors:
7
+ authors:
30
8
  - Pluron Inc.
31
- files:
32
- - lib/mediacloth
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-20 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: racc
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 1.1.3
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 1.1.3
30
+ description: MediaWiki syntax to HTML converter
31
+ email: support@pluron.com
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files:
35
+ - README.md
36
+ files:
33
37
  - lib/mediacloth.rb
34
38
  - lib/mediacloth/mediawikihtmlgenerator.rb
35
- - lib/mediacloth/mediawikilexer.rb~
36
- - lib/mediacloth/mediawikiparams.rb
37
39
  - lib/mediacloth/mediawikiwalker.rb
38
- - lib/mediacloth/mediawikiparser.rb
39
- - lib/mediacloth/mediawikiparser.y~
40
+ - lib/mediacloth/mediawikisignedwikigenerator.rb
41
+ - lib/mediacloth/mediawikilinkhandler.rb
40
42
  - lib/mediacloth/mediawikiparser.y
43
+ - lib/mediacloth/mediawikiparser.tab.rb
44
+ - lib/mediacloth/mediawikiparams.rb
41
45
  - lib/mediacloth/mediawikilexer.rb
46
+ - lib/mediacloth/mediawikitemplatehandler.rb
42
47
  - lib/mediacloth/mediawikiast.rb
43
- - test/data
44
- - test/parser.rb
45
- - test/testhelper.rb
46
- - test/lexer.rb
47
- - test/debugwalker.rb
48
- - test/dataproducers
49
- - test/htmlgenerator.rb
50
- - test/data/lex1
51
- - test/data/lex2
52
- - test/data/lex3
53
- - test/data/lex4
54
- - test/data/lex5
48
+ - lib/mediacloth/mediawikiparser.rb
49
+ - test/data/lex16
50
+ - test/data/lex12
51
+ - test/data/ast1
52
+ - test/data/ast17
53
+ - test/data/html11
54
+ - test/data/input19
55
+ - test/data/ast13
56
+ - test/data/input5
57
+ - test/data/ast12
58
+ - test/data/input8
59
+ - test/data/ast4
55
60
  - test/data/lex6
56
- - test/data/lex7
57
- - test/data/lex8
58
- - test/data/lex9
59
- - test/data/result1
60
- - test/data/html1
61
- - test/data/html2
61
+ - test/data/lex23
62
+ - test/data/input16
62
63
  - test/data/html3
63
- - test/data/html4
64
- - test/data/html5
65
- - test/data/html6
66
- - test/data/html7
67
- - test/data/html8
68
- - test/data/html9
64
+ - test/data/ast19
65
+ - test/data/input21
66
+ - test/data/ast15
67
+ - test/data/input14
68
+ - test/data/lex21
69
+ - test/data/html2
69
70
  - test/data/lex10
70
- - test/data/html10
71
- - test/data/input1
72
- - test/data/input2
71
+ - test/data/html8
72
+ - test/data/html6
73
+ - test/data/html12
74
+ - test/data/html19
75
+ - test/data/lex17
73
76
  - test/data/input3
77
+ - test/data/lex4
78
+ - test/data/lex3
79
+ - test/data/html15
80
+ - test/data/ast3
81
+ - test/data/ast2
82
+ - test/data/html20
83
+ - test/data/lex7
84
+ - test/data/input2
85
+ - test/data/html16
86
+ - test/data/html1
87
+ - test/data/ast14
88
+ - test/data/ast18
89
+ - test/data/html10
90
+ - test/data/input13
91
+ - test/data/ast8
92
+ - test/data/html21
93
+ - test/data/lex11
94
+ - test/data/lex20
74
95
  - test/data/input4
75
- - test/data/input5
96
+ - test/data/lex9
97
+ - test/data/lex14
98
+ - test/data/lex15
99
+ - test/data/ast21
100
+ - test/data/lex19
101
+ - test/data/html5
102
+ - test/data/html18
103
+ - test/data/input18
104
+ - test/data/input15
105
+ - test/data/lex18
76
106
  - test/data/input6
77
- - test/data/input7
78
- - test/data/input8
107
+ - test/data/ast10
108
+ - test/data/input20
109
+ - test/data/ast16
110
+ - test/data/input1
79
111
  - test/data/input9
112
+ - test/data/input23
113
+ - test/data/ast6
114
+ - test/data/ast9
115
+ - test/data/input22
116
+ - test/data/html14
117
+ - test/data/html7
118
+ - test/data/html13
119
+ - test/data/input11
120
+ - test/data/lex1
121
+ - test/data/input7
122
+ - test/data/ast7
123
+ - test/data/html17
124
+ - test/data/lex22
125
+ - test/data/html9
126
+ - test/data/ast23
127
+ - test/data/lex8
128
+ - test/data/lex5
129
+ - test/data/html22
130
+ - test/data/ast5
131
+ - test/data/ast22
80
132
  - test/data/input10
81
- - test/dataproducers/html.rb~
82
- - test/dataproducers/lex.rb~
133
+ - test/data/input17
134
+ - test/data/lex2
135
+ - test/data/lex13
136
+ - test/data/html4
137
+ - test/data/ast11
138
+ - test/data/html23
139
+ - test/data/input12
140
+ - test/data/ast20
141
+ - test/testhelper.rb
142
+ - test/signedwikigenerator.rb
143
+ - test/linkhandler.rb
144
+ - test/debugwalker.rb
145
+ - test/lexer.rb
146
+ - test/dataproducers/ast.rb
83
147
  - test/dataproducers/lex.rb
84
148
  - test/dataproducers/html.rb
85
- - README
86
- test_files: []
87
-
88
- rdoc_options:
149
+ - test/parser.rb
150
+ - test/htmlgenerator.rb
151
+ - README.md
152
+ homepage: https://github.com/adymo/mediacloth
153
+ licenses: []
154
+ post_install_message:
155
+ rdoc_options:
89
156
  - --title
90
157
  - MediaCloth
91
158
  - --main
92
- - README
93
- extra_rdoc_files:
94
- - README
95
- executables: []
96
-
97
- extensions: []
98
-
159
+ - README.md
160
+ require_paths:
161
+ - lib
162
+ required_ruby_version: !ruby/object:Gem::Requirement
163
+ none: false
164
+ requirements:
165
+ - - ! '>='
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ required_rubygems_version: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
99
174
  requirements: []
100
-
101
- dependencies: []
102
-
175
+ rubyforge_project:
176
+ rubygems_version: 1.8.23
177
+ signing_key:
178
+ specification_version: 3
179
+ summary: Ruby library to convert MediaWiki syntax to HTML, similar to Kramdown or
180
+ Redcloth.
181
+ test_files: []
data/README DELETED
@@ -1,37 +0,0 @@
1
- MediaCloth is the first MediaWiki parser and html generator written in ruby.
2
- It's small, fast and aims to recognize the complete MediaWiki language.
3
-
4
- = INSTALLATION
5
- To install the library run:
6
- ruby setup.rb
7
-
8
-
9
- = USAGE
10
- The quickest way to parse your input and produce html formatted text is:
11
- require 'mediacloth'
12
- puts MediaCloth::wiki_to_html("'''Hello'''''World''!")
13
-
14
- Alternatively, it's possible to create and use each component of MediaCloth manually:
15
- require 'mediacloth'
16
-
17
- parser = MediaWikiParser.new
18
- parser.lexer = MediaWikiLexer.new
19
- ast = parser.parse("'''Hello'''''World''!")
20
- walker = MediaWikiHTMLGenerator.new
21
- walker.parse(ast)
22
- puts walker.html
23
- This is useful if you want to use another generator.
24
-
25
- Both examples should produce
26
- <b>Hello</b><i>World</i>!
27
-
28
- = API DOCS
29
- To generate API documentation run:
30
- rake rdoc
31
-
32
- = DEVELOPMENT
33
- If you want to modify mediacloth sources you will need:
34
- 1. Download and install RACC parser generator (http://i.loveruby.net/en/projects/racc/)
35
- 2. Execute "rake parser" to update your parser from .y definition
36
- To run tests execute
37
- rake test