motiro 0.6.8 → 0.6.9
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.
- data/AUTHORS +15 -0
- data/README +2 -2
- data/README.en +1 -2
- data/README.pt-br +1 -2
- data/app/controllers/account_controller.rb +1 -1
- data/app/controllers/application.rb +13 -12
- data/app/controllers/javascript_controller.rb +1 -1
- data/app/controllers/report_controller.rb +1 -1
- data/app/controllers/wiki_controller.rb +3 -5
- data/app/core/cache_reporter.rb +1 -1
- data/app/core/cache_reporter_fetcher.rb +1 -1
- data/app/core/chief_editor.rb +1 -1
- data/app/core/reporter.rb +1 -1
- data/app/core/reporter_driver.rb +1 -1
- data/app/core/reporter_fetcher.rb +1 -1
- data/app/core/settings.rb +1 -1
- data/app/core/version.rb +1 -1
- data/app/core/wiki_reporter.rb +1 -1
- data/app/helpers/application_helper.rb +5 -1
- data/app/helpers/default_page_provider.rb +6 -2
- data/app/helpers/report_helper.rb +14 -1
- data/app/models/change.rb +1 -1
- data/app/models/chunk.rb +1 -1
- data/app/models/feed_observer.rb +1 -1
- data/app/models/headline.rb +1 -1
- data/app/models/page.rb +38 -4
- data/app/models/revision.rb +1 -1
- data/app/models/user.rb +1 -1
- data/app/models/wiki_reference.rb +21 -0
- data/app/models/wiki_sweeper.rb +17 -2
- data/app/ports/chdir_runner.rb +1 -1
- data/app/ports/runner.rb +1 -1
- data/app/reporters/darcs_connection.rb +1 -1
- data/app/reporters/darcs_reporter.rb +1 -1
- data/app/reporters/darcs_temp_repo.rb +1 -1
- data/app/reporters/events_reporter.rb +1 -1
- data/app/reporters/features_reporter.rb +1 -1
- data/app/reporters/subversion_reporter.rb +1 -1
- data/app/reporters/svn_connection.rb +1 -1
- data/app/reporters/svn_settings.rb +1 -1
- data/app/views/report/list.rhtml +6 -7
- data/app/views/report/older.rhtml +1 -2
- data/app/views/report/rss.rxml +1 -1
- data/app/views/report/show.rhtml +2 -2
- data/app/views/wiki/_edit_event.rhtml +2 -0
- data/app/views/wiki/_edit_feature.rhtml +2 -0
- data/app/views/wiki/_properties_edit.rhtml +3 -5
- data/app/views/wiki/_properties_show.rhtml +4 -5
- data/app/views/wiki/_show_event.rhtml +3 -0
- data/app/views/wiki/_show_feature.rhtml +2 -0
- data/app/views/wiki/show.rhtml +1 -1
- data/bin/motiro +3 -3
- data/config/routes.rb +1 -1
- data/db/migrate/024_add_feature_status.rb +11 -0
- data/db/migrate/025_add_page_references.rb +12 -0
- data/db/migrate/026_convert_link_syntax.rb +12 -0
- data/db/migrate/027_register_page_references.rb +12 -0
- data/db/motirodb.sqlite.initial +0 -0
- data/db/schema_version +1 -1
- data/db/translation/pt-BR.rb +7 -1
- data/lib/array_extensions.rb +1 -1
- data/lib/diff_chunk_builder.rb +1 -1
- data/lib/differ.rb +1 -1
- data/lib/string_extensions.rb +13 -6
- data/lib/stub_hash.rb +1 -1
- data/lib/tasks/packaging.rake +10 -12
- data/lib/tasks/testing.rake +1 -1
- data/lib/tick_daemon.rb +1 -1
- data/lib/{wiki_url_generator.rb → wiki_link_handler.rb} +13 -3
- data/lib/wiki_renderer.rb +63 -34
- data/public/images/done.png +0 -0
- data/public/images/not-done.png +0 -0
- data/public/stylesheets/motiro.css +8 -0
- data/script/ticker +1 -1
- data/test/acceptance/account_test.rb +1 -1
- data/test/acceptance/darcs_test.rb +1 -1
- data/test/acceptance/events_test.rb +1 -1
- data/test/acceptance/main_page_test.rb +1 -1
- data/test/acceptance/subversion_test.rb +1 -1
- data/test/acceptance/ts_all_suites.rb +1 -1
- data/test/acceptance/wiki_test.rb +3 -3
- data/test/contract/darcs_test.rb +1 -1
- data/test/contract/remote_darcs_test.rb +1 -1
- data/test/contract/svn_test.rb +1 -1
- data/test/fixtures/pages.yml +20 -1
- data/test/fixtures/revisions.yml +40 -1
- data/test/fixtures/wiki_references.yml +5 -0
- data/test/functional/report_controller_test.rb +1 -1
- data/test/functional/report_features_test.rb +8 -1
- data/test/functional/report_subversion_test.rb +1 -1
- data/test/functional/root_controller_test.rb +1 -1
- data/test/functional/wiki_controller_test.rb +67 -2
- data/test/lib/acceptance_test_case.rb +1 -1
- data/test/lib/darcs_excerpts.rb +1 -1
- data/test/lib/darcs_repo.rb +1 -1
- data/test/lib/hash_extensions.rb +22 -0
- data/test/lib/live_mode_test.rb +1 -1
- data/test/lib/netutils.rb +1 -1
- data/test/lib/platform_thread.rb +1 -1
- data/test/lib/selenium_extensions.rb +1 -1
- data/test/lib/stubio.rb +1 -1
- data/test/lib/webserver.rb +1 -1
- data/test/meta/darcs_repo_test.rb +1 -1
- data/test/meta/local_svn_test.rb +1 -1
- data/test/meta/platform_thread_test.rb +1 -1
- data/test/meta/stubio_test.rb +1 -1
- data/test/stubs/{url_generator.rb → wiki_link_handler.rb} +8 -4
- data/test/test_helper.rb +3 -1
- data/test/unit/array_extensions_test.rb +1 -1
- data/test/unit/cache_reporter_fetcher_test.rb +1 -1
- data/test/unit/cache_reporter_test.rb +1 -1
- data/test/unit/change_test.rb +1 -1
- data/test/unit/chdir_runner_test.rb +1 -1
- data/test/unit/chief_editor_test.rb +1 -1
- data/test/unit/darcs_connection_test.rb +1 -1
- data/test/unit/darcs_reporter_test.rb +4 -4
- data/test/unit/darcs_temp_repo_test.rb +1 -1
- data/test/unit/default_page_provider_test.rb +23 -13
- data/test/unit/diff_chunk_builder_test.rb +1 -1
- data/test/unit/page_test.rb +67 -4
- data/test/unit/reporter_driver_test.rb +1 -1
- data/test/unit/reporter_test.rb +1 -1
- data/test/unit/revision_test.rb +1 -1
- data/test/unit/runner_test.rb +1 -1
- data/test/unit/string_extensions_test.rb +15 -3
- data/test/unit/svn_connection_test.rb +1 -1
- data/test/unit/svn_reporter_interaction_test.rb +1 -1
- data/test/unit/svn_reporter_test.rb +1 -1
- data/test/unit/svn_settings_test.rb +1 -1
- data/test/unit/user_test.rb +1 -1
- data/test/unit/{wiki_url_generator_test.rb → wiki_link_handler_test.rb} +3 -3
- data/test/unit/wiki_renderer_test.rb +75 -20
- data/test/unit/wiki_reporter_test.rb +1 -1
- data/vendor/mediacloth-trunk/MIT-LICENSE +20 -0
- data/vendor/mediacloth-trunk/README +32 -0
- data/vendor/mediacloth-trunk/Rakefile +33 -0
- data/vendor/mediacloth-trunk/lib/mediacloth/mediawikiast.rb +122 -0
- data/vendor/mediacloth-trunk/lib/mediacloth/mediawikihtmlgenerator.rb +252 -0
- data/vendor/mediacloth-trunk/lib/mediacloth/mediawikilexer.rb +821 -0
- data/vendor/mediacloth-trunk/lib/mediacloth/mediawikilinkhandler.rb +68 -0
- data/vendor/mediacloth-trunk/lib/mediacloth/mediawikiparams.rb +33 -0
- data/vendor/mediacloth-trunk/lib/mediacloth/mediawikiparser.rb +1218 -0
- data/vendor/mediacloth-trunk/lib/mediacloth/mediawikiparser.y +493 -0
- data/vendor/mediacloth-trunk/lib/mediacloth/mediawikiwalker.rb +146 -0
- data/vendor/mediacloth-trunk/lib/mediacloth.rb +29 -0
- data/vendor/mediacloth-trunk/mediacloth.gemspec +24 -0
- data/vendor/mediacloth-trunk/mediacloth.kdevelop +117 -0
- data/vendor/mediacloth-trunk/setup.rb +1585 -0
- data/vendor/mediacloth-trunk/test/data/html1 +26 -0
- data/vendor/mediacloth-trunk/test/data/html10 +130 -0
- data/vendor/mediacloth-trunk/test/data/html11 +17 -0
- data/vendor/mediacloth-trunk/test/data/html12 +12 -0
- data/vendor/mediacloth-trunk/test/data/html13 +11 -0
- data/vendor/mediacloth-trunk/test/data/html2 +2 -0
- data/vendor/mediacloth-trunk/test/data/html3 +1 -0
- data/vendor/mediacloth-trunk/test/data/html4 +47 -0
- data/vendor/mediacloth-trunk/test/data/html5 +57 -0
- data/vendor/mediacloth-trunk/test/data/html6 +8 -0
- data/vendor/mediacloth-trunk/test/data/html7 +45 -0
- data/vendor/mediacloth-trunk/test/data/html8 +1 -0
- data/vendor/mediacloth-trunk/test/data/html9 +14 -0
- data/vendor/mediacloth-trunk/test/data/input1 +34 -0
- data/vendor/mediacloth-trunk/test/data/input10 +124 -0
- data/vendor/mediacloth-trunk/test/data/input11 +17 -0
- data/vendor/mediacloth-trunk/test/data/input12 +15 -0
- data/vendor/mediacloth-trunk/test/data/input13 +10 -0
- data/vendor/mediacloth-trunk/test/data/input2 +2 -0
- data/vendor/mediacloth-trunk/test/data/input3 +2 -0
- data/vendor/mediacloth-trunk/test/data/input4 +50 -0
- data/vendor/mediacloth-trunk/test/data/input5 +63 -0
- data/vendor/mediacloth-trunk/test/data/input6 +8 -0
- data/vendor/mediacloth-trunk/test/data/input7 +45 -0
- data/vendor/mediacloth-trunk/test/data/input8 +1 -0
- data/vendor/mediacloth-trunk/test/data/input9 +14 -0
- data/vendor/mediacloth-trunk/test/data/lex1 +26 -0
- data/vendor/mediacloth-trunk/test/data/lex10 +85 -0
- data/vendor/mediacloth-trunk/test/data/lex11 +17 -0
- data/vendor/mediacloth-trunk/test/data/lex12 +15 -0
- data/vendor/mediacloth-trunk/test/data/lex13 +3 -0
- data/vendor/mediacloth-trunk/test/data/lex2 +2 -0
- data/vendor/mediacloth-trunk/test/data/lex3 +1 -0
- data/vendor/mediacloth-trunk/test/data/lex4 +47 -0
- data/vendor/mediacloth-trunk/test/data/lex5 +57 -0
- data/vendor/mediacloth-trunk/test/data/lex6 +8 -0
- data/vendor/mediacloth-trunk/test/data/lex7 +45 -0
- data/vendor/mediacloth-trunk/test/data/lex8 +1 -0
- data/vendor/mediacloth-trunk/test/data/lex9 +14 -0
- data/vendor/mediacloth-trunk/test/data/result1 +48 -0
- data/vendor/mediacloth-trunk/test/dataproducers/html.rb +18 -0
- data/vendor/mediacloth-trunk/test/dataproducers/lex.rb +15 -0
- data/vendor/mediacloth-trunk/test/debugwalker.rb +68 -0
- data/vendor/mediacloth-trunk/test/htmlgenerator.rb +97 -0
- data/vendor/mediacloth-trunk/test/lexer.rb +542 -0
- data/vendor/mediacloth-trunk/test/linkhandler.rb +39 -0
- data/vendor/mediacloth-trunk/test/parser.rb +22 -0
- data/vendor/mediacloth-trunk/test/testhelper.rb +27 -0
- data/vendor/mediacloth.rb +3 -0
- data/vendor/motiro-installer.rb +1 -1
- data/vendor/plugins/cache_test-0.2/CHANGELOG +14 -0
- data/vendor/plugins/cache_test-0.2/MIT-LICENSE +20 -0
- data/vendor/plugins/cache_test-0.2/README +124 -0
- data/vendor/plugins/cache_test-0.2/init.rb +8 -0
- data/vendor/plugins/cache_test-0.2/lib/fragment_cache_test.rb +205 -0
- data/vendor/plugins/cache_test-0.2/lib/page_cache_test.rb +140 -0
- data/vendor/plugins/global_routing/init.rb +1 -1
- metadata +517 -455
|
@@ -0,0 +1,493 @@
|
|
|
1
|
+
#The parser for the MediaWiki language.
|
|
2
|
+
#
|
|
3
|
+
#Usage together with a lexer:
|
|
4
|
+
# inputFile = File.new("data/input1", "r")
|
|
5
|
+
# input = inputFile.read
|
|
6
|
+
# parser = MediaWikiParser.new
|
|
7
|
+
# parser.lexer = MediaWikiLexer.new
|
|
8
|
+
# parser.parse(input)
|
|
9
|
+
class MediaWikiParser
|
|
10
|
+
|
|
11
|
+
token TEXT BOLD_START BOLD_END ITALIC_START ITALIC_END LINK_START LINK_END LINKSEP
|
|
12
|
+
INTLINK_START INTLINK_END INTLINKSEP RESOURCESEP PRE_START PRE_END CHAR_ENT
|
|
13
|
+
SECTION_START SECTION_END HLINE SIGNATURE_NAME SIGNATURE_DATE SIGNATURE_FULL
|
|
14
|
+
PARA_START PARA_END UL_START UL_END OL_START OL_END LI_START LI_END
|
|
15
|
+
DL_START DL_END DT_START DT_END DD_START DD_END TAG_START TAG_END ATTR_NAME ATTR_VALUE
|
|
16
|
+
TABLE_START TABLE_END ROW_START ROW_END HEAD_START HEAD_END CELL_START CELL_END
|
|
17
|
+
KEYWORD VARIABLE_START VARIABLE_END
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
rule
|
|
21
|
+
|
|
22
|
+
wiki:
|
|
23
|
+
repeated_contents
|
|
24
|
+
{
|
|
25
|
+
@nodes.push WikiAST.new
|
|
26
|
+
#@nodes.last.children.insert(0, val[0])
|
|
27
|
+
#puts val[0]
|
|
28
|
+
@nodes.last.children += val[0]
|
|
29
|
+
}
|
|
30
|
+
;
|
|
31
|
+
|
|
32
|
+
contents:
|
|
33
|
+
text
|
|
34
|
+
{
|
|
35
|
+
result = val[0]
|
|
36
|
+
}
|
|
37
|
+
| bulleted_list
|
|
38
|
+
{
|
|
39
|
+
result = val[0]
|
|
40
|
+
}
|
|
41
|
+
| numbered_list
|
|
42
|
+
{
|
|
43
|
+
result = val[0]
|
|
44
|
+
}
|
|
45
|
+
| dictionary_list
|
|
46
|
+
{
|
|
47
|
+
list = ListAST.new
|
|
48
|
+
list.list_type = :Dictionary
|
|
49
|
+
list.children = val[0]
|
|
50
|
+
result = list
|
|
51
|
+
}
|
|
52
|
+
| preformatted
|
|
53
|
+
{
|
|
54
|
+
result = val[0]
|
|
55
|
+
}
|
|
56
|
+
| section
|
|
57
|
+
{
|
|
58
|
+
result = val[0]
|
|
59
|
+
}
|
|
60
|
+
| tag
|
|
61
|
+
{
|
|
62
|
+
result = val[0]
|
|
63
|
+
}
|
|
64
|
+
| variable
|
|
65
|
+
{
|
|
66
|
+
result = val[0]
|
|
67
|
+
}
|
|
68
|
+
| KEYWORD
|
|
69
|
+
{
|
|
70
|
+
k = KeywordAST.new
|
|
71
|
+
k.text = val[0]
|
|
72
|
+
result = k
|
|
73
|
+
}
|
|
74
|
+
| PARA_START para_contents PARA_END
|
|
75
|
+
{
|
|
76
|
+
p = ParagraphAST.new
|
|
77
|
+
p.children = val[1]
|
|
78
|
+
result = p
|
|
79
|
+
}
|
|
80
|
+
| LINK_START link_contents LINK_END
|
|
81
|
+
{
|
|
82
|
+
l = LinkAST.new
|
|
83
|
+
l.url = val[1][0]
|
|
84
|
+
l.children += val[1][1..-1] if val[1].length > 1
|
|
85
|
+
result = l
|
|
86
|
+
}
|
|
87
|
+
| INTLINK_START TEXT RESOURCESEP TEXT reslink_repeated_contents INTLINK_END
|
|
88
|
+
{
|
|
89
|
+
l = ResourceLinkAST.new
|
|
90
|
+
l.prefix = val[1]
|
|
91
|
+
l.locator = val[3]
|
|
92
|
+
l.children = val[4] unless val[4].nil? or val[4].empty?
|
|
93
|
+
result = l
|
|
94
|
+
}
|
|
95
|
+
| INTLINK_START TEXT intlink_repeated_contents INTLINK_END
|
|
96
|
+
{
|
|
97
|
+
l = InternalLinkAST.new
|
|
98
|
+
l.locator = val[1]
|
|
99
|
+
l.children = val[2] unless val[2].nil? or val[2].empty?
|
|
100
|
+
result = l
|
|
101
|
+
}
|
|
102
|
+
| table
|
|
103
|
+
;
|
|
104
|
+
|
|
105
|
+
para_contents:
|
|
106
|
+
{
|
|
107
|
+
result = nil
|
|
108
|
+
}
|
|
109
|
+
| repeated_contents
|
|
110
|
+
{
|
|
111
|
+
result = val[0]
|
|
112
|
+
}
|
|
113
|
+
;
|
|
114
|
+
|
|
115
|
+
tag:
|
|
116
|
+
TAG_START tag_attributes TAG_END
|
|
117
|
+
{
|
|
118
|
+
if val[0] != val[2]
|
|
119
|
+
raise Racc::ParseError.new("XHTML end tag #{val[2]} does not match start tag #{val[0]}")
|
|
120
|
+
end
|
|
121
|
+
elem = ElementAST.new
|
|
122
|
+
elem.name = val[0]
|
|
123
|
+
elem.attributes = val[1]
|
|
124
|
+
result = elem
|
|
125
|
+
}
|
|
126
|
+
| TAG_START tag_attributes repeated_contents TAG_END
|
|
127
|
+
{
|
|
128
|
+
if val[0] != val[3]
|
|
129
|
+
raise Racc::ParseError.new("XHTML end tag #{val[3]} does not match start tag #{val[0]}")
|
|
130
|
+
end
|
|
131
|
+
elem = ElementAST.new
|
|
132
|
+
elem.name = val[0]
|
|
133
|
+
elem.attributes = val[1]
|
|
134
|
+
elem.children += val[2]
|
|
135
|
+
result = elem
|
|
136
|
+
}
|
|
137
|
+
;
|
|
138
|
+
|
|
139
|
+
tag_attributes:
|
|
140
|
+
{
|
|
141
|
+
result = nil
|
|
142
|
+
}
|
|
143
|
+
| ATTR_NAME tag_attributes
|
|
144
|
+
{
|
|
145
|
+
attr_map = val[2] ? val[2] : {}
|
|
146
|
+
attr_map[val[0]] = true
|
|
147
|
+
result = attr_map
|
|
148
|
+
}
|
|
149
|
+
| ATTR_NAME ATTR_VALUE tag_attributes
|
|
150
|
+
{
|
|
151
|
+
attr_map = val[2] ? val[2] : {}
|
|
152
|
+
attr_map[val[0]] = val[1]
|
|
153
|
+
result = attr_map
|
|
154
|
+
}
|
|
155
|
+
;
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
link_contents:
|
|
159
|
+
TEXT
|
|
160
|
+
{
|
|
161
|
+
result = val
|
|
162
|
+
}
|
|
163
|
+
| TEXT LINKSEP link_repeated_contents
|
|
164
|
+
{
|
|
165
|
+
result = [val[0]]
|
|
166
|
+
result += val[2]
|
|
167
|
+
}
|
|
168
|
+
;
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
link_repeated_contents:
|
|
172
|
+
repeated_contents
|
|
173
|
+
{
|
|
174
|
+
result = val[0]
|
|
175
|
+
}
|
|
176
|
+
| repeated_contents LINKSEP link_repeated_contents
|
|
177
|
+
{
|
|
178
|
+
result = val[0]
|
|
179
|
+
result += val[2] if val[2]
|
|
180
|
+
}
|
|
181
|
+
;
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
intlink_repeated_contents:
|
|
185
|
+
{
|
|
186
|
+
result = nil
|
|
187
|
+
}
|
|
188
|
+
| INTLINKSEP repeated_contents
|
|
189
|
+
{
|
|
190
|
+
result = val[1]
|
|
191
|
+
}
|
|
192
|
+
;
|
|
193
|
+
|
|
194
|
+
reslink_repeated_contents:
|
|
195
|
+
{
|
|
196
|
+
result = nil
|
|
197
|
+
}
|
|
198
|
+
| INTLINKSEP reslink_repeated_contents
|
|
199
|
+
{
|
|
200
|
+
result = val[1]
|
|
201
|
+
}
|
|
202
|
+
| INTLINKSEP repeated_contents reslink_repeated_contents
|
|
203
|
+
{
|
|
204
|
+
i = InternalLinkItemAST.new
|
|
205
|
+
i.children = val[1]
|
|
206
|
+
result = [i]
|
|
207
|
+
result += val[2] if val[2]
|
|
208
|
+
}
|
|
209
|
+
;
|
|
210
|
+
|
|
211
|
+
repeated_contents: contents
|
|
212
|
+
{
|
|
213
|
+
result = []
|
|
214
|
+
result << val[0]
|
|
215
|
+
}
|
|
216
|
+
| repeated_contents contents
|
|
217
|
+
{
|
|
218
|
+
result = []
|
|
219
|
+
result += val[0]
|
|
220
|
+
result << val[1]
|
|
221
|
+
}
|
|
222
|
+
;
|
|
223
|
+
|
|
224
|
+
text: element
|
|
225
|
+
{
|
|
226
|
+
p = TextAST.new
|
|
227
|
+
p.formatting = val[0][0]
|
|
228
|
+
p.contents = val[0][1]
|
|
229
|
+
result = p
|
|
230
|
+
}
|
|
231
|
+
| formatted_element
|
|
232
|
+
{
|
|
233
|
+
result = val[0]
|
|
234
|
+
}
|
|
235
|
+
;
|
|
236
|
+
|
|
237
|
+
table:
|
|
238
|
+
TABLE_START table_contents TABLE_END
|
|
239
|
+
{
|
|
240
|
+
table = TableAST.new
|
|
241
|
+
table.children = val[1] unless val[1].nil? or val[1].empty?
|
|
242
|
+
result = table
|
|
243
|
+
}
|
|
244
|
+
| TABLE_START TEXT table_contents TABLE_END
|
|
245
|
+
{
|
|
246
|
+
table = TableAST.new
|
|
247
|
+
table.options = val[1]
|
|
248
|
+
table.children = val[2] unless val[2].nil? or val[2].empty?
|
|
249
|
+
result = table
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
table_contents:
|
|
253
|
+
{
|
|
254
|
+
result = nil
|
|
255
|
+
}
|
|
256
|
+
| ROW_START row_contents ROW_END table_contents
|
|
257
|
+
{
|
|
258
|
+
row = TableRowAST.new
|
|
259
|
+
row.children = val[1] unless val[1].nil? or val[1].empty?
|
|
260
|
+
result = [row]
|
|
261
|
+
result += val[3] unless val[3].nil? or val[3].empty?
|
|
262
|
+
}
|
|
263
|
+
| ROW_START TEXT row_contents ROW_END table_contents
|
|
264
|
+
{
|
|
265
|
+
row = TableRowAST.new
|
|
266
|
+
row.children = val[2] unless val[2].nil? or val[2].empty?
|
|
267
|
+
row.options = val[1]
|
|
268
|
+
result = [row]
|
|
269
|
+
result += val[4] unless val[4].nil? or val[4].empty?
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
row_contents:
|
|
273
|
+
{
|
|
274
|
+
result = nil
|
|
275
|
+
}
|
|
276
|
+
| HEAD_START HEAD_END row_contents
|
|
277
|
+
{
|
|
278
|
+
cell = TableCellAST.new
|
|
279
|
+
cell.type = :head
|
|
280
|
+
result = [cell]
|
|
281
|
+
result += val[2] unless val[2].nil? or val[2].empty?
|
|
282
|
+
}
|
|
283
|
+
| HEAD_START repeated_contents HEAD_END row_contents
|
|
284
|
+
{
|
|
285
|
+
cell = TableCellAST.new
|
|
286
|
+
cell.children = val[1] unless val[1].nil? or val[1].empty?
|
|
287
|
+
cell.type = :head
|
|
288
|
+
result = [cell]
|
|
289
|
+
result += val[3] unless val[3].nil? or val[3].empty?
|
|
290
|
+
}
|
|
291
|
+
| CELL_START CELL_END row_contents
|
|
292
|
+
{
|
|
293
|
+
cell = TableCellAST.new
|
|
294
|
+
cell.type = :body
|
|
295
|
+
result = [cell]
|
|
296
|
+
result += val[2] unless val[2].nil? or val[2].empty?
|
|
297
|
+
}
|
|
298
|
+
| CELL_START repeated_contents CELL_END row_contents
|
|
299
|
+
{
|
|
300
|
+
cell = TableCellAST.new
|
|
301
|
+
cell.children = val[1] unless val[1].nil? or val[1].empty?
|
|
302
|
+
cell.type = :body
|
|
303
|
+
result = [cell]
|
|
304
|
+
result += val[3] unless val[3].nil? or val[3].empty?
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
element:
|
|
309
|
+
TEXT
|
|
310
|
+
{ return [:None, val[0]] }
|
|
311
|
+
| HLINE
|
|
312
|
+
{ return [:HLine, val[0]] }
|
|
313
|
+
| CHAR_ENT
|
|
314
|
+
{ return [:CharacterEntity, val[0]] }
|
|
315
|
+
| SIGNATURE_DATE
|
|
316
|
+
{ return [:SignatureDate, val[0]] }
|
|
317
|
+
| SIGNATURE_NAME
|
|
318
|
+
{ return [:SignatureName, val[0]] }
|
|
319
|
+
| SIGNATURE_FULL
|
|
320
|
+
{ return [:SignatureFull, val[0]] }
|
|
321
|
+
;
|
|
322
|
+
|
|
323
|
+
formatted_element:
|
|
324
|
+
BOLD_START BOLD_END
|
|
325
|
+
{
|
|
326
|
+
result = FormattedAST.new
|
|
327
|
+
result.formatting = :Bold
|
|
328
|
+
result
|
|
329
|
+
}
|
|
330
|
+
| ITALIC_START ITALIC_END
|
|
331
|
+
{
|
|
332
|
+
result = FormattedAST.new
|
|
333
|
+
result.formatting = :Italic
|
|
334
|
+
result
|
|
335
|
+
}
|
|
336
|
+
| BOLD_START repeated_contents BOLD_END
|
|
337
|
+
{
|
|
338
|
+
p = FormattedAST.new
|
|
339
|
+
p.formatting = :Bold
|
|
340
|
+
p.children += val[1]
|
|
341
|
+
result = p
|
|
342
|
+
}
|
|
343
|
+
| ITALIC_START repeated_contents ITALIC_END
|
|
344
|
+
{
|
|
345
|
+
p = FormattedAST.new
|
|
346
|
+
p.formatting = :Italic
|
|
347
|
+
p.children += val[1]
|
|
348
|
+
result = p
|
|
349
|
+
}
|
|
350
|
+
;
|
|
351
|
+
|
|
352
|
+
bulleted_list: UL_START list_item list_contents UL_END
|
|
353
|
+
{
|
|
354
|
+
list = ListAST.new
|
|
355
|
+
list.list_type = :Bulleted
|
|
356
|
+
list.children << val[1]
|
|
357
|
+
list.children += val[2]
|
|
358
|
+
result = list
|
|
359
|
+
}
|
|
360
|
+
;
|
|
361
|
+
|
|
362
|
+
numbered_list: OL_START list_item list_contents OL_END
|
|
363
|
+
{
|
|
364
|
+
list = ListAST.new
|
|
365
|
+
list.list_type = :Numbered
|
|
366
|
+
list.children << val[1]
|
|
367
|
+
list.children += val[2]
|
|
368
|
+
result = list
|
|
369
|
+
}
|
|
370
|
+
;
|
|
371
|
+
|
|
372
|
+
list_contents:
|
|
373
|
+
{ result = [] }
|
|
374
|
+
list_item list_contents
|
|
375
|
+
{
|
|
376
|
+
result << val[1]
|
|
377
|
+
result += val[2]
|
|
378
|
+
}
|
|
379
|
+
|
|
|
380
|
+
{ result = [] }
|
|
381
|
+
;
|
|
382
|
+
|
|
383
|
+
list_item:
|
|
384
|
+
LI_START LI_END
|
|
385
|
+
{
|
|
386
|
+
result = ListItemAST.new
|
|
387
|
+
}
|
|
388
|
+
| LI_START repeated_contents LI_END
|
|
389
|
+
{
|
|
390
|
+
li = ListItemAST.new
|
|
391
|
+
li.children += val[1]
|
|
392
|
+
result = li
|
|
393
|
+
}
|
|
394
|
+
;
|
|
395
|
+
|
|
396
|
+
dictionary_list:
|
|
397
|
+
DL_START dictionary_term dictionary_contents DL_END
|
|
398
|
+
{
|
|
399
|
+
result = [val[1]]
|
|
400
|
+
result += val[2]
|
|
401
|
+
}
|
|
402
|
+
| DL_START dictionary_contents DL_END
|
|
403
|
+
{
|
|
404
|
+
result = val[1]
|
|
405
|
+
}
|
|
406
|
+
;
|
|
407
|
+
|
|
408
|
+
dictionary_term:
|
|
409
|
+
DT_START DT_END
|
|
410
|
+
{
|
|
411
|
+
result = ListTermAST.new
|
|
412
|
+
}
|
|
413
|
+
| DT_START repeated_contents DT_END
|
|
414
|
+
{
|
|
415
|
+
term = ListTermAST.new
|
|
416
|
+
term.children += val[1]
|
|
417
|
+
result = term
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
dictionary_contents:
|
|
421
|
+
dictionary_definition dictionary_contents
|
|
422
|
+
{
|
|
423
|
+
result = [val[0]]
|
|
424
|
+
result += val[1] if val[1]
|
|
425
|
+
}
|
|
426
|
+
|
|
|
427
|
+
{
|
|
428
|
+
result = []
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
dictionary_definition:
|
|
432
|
+
DD_START DD_END
|
|
433
|
+
{
|
|
434
|
+
result = ListDefinitionAST.new
|
|
435
|
+
}
|
|
436
|
+
| DD_START repeated_contents DD_END
|
|
437
|
+
{
|
|
438
|
+
term = ListDefinitionAST.new
|
|
439
|
+
term.children += val[1]
|
|
440
|
+
result = term
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
preformatted: PRE_START repeated_contents PRE_END
|
|
444
|
+
{
|
|
445
|
+
p = PreformattedAST.new
|
|
446
|
+
p.children += val[1]
|
|
447
|
+
result = p
|
|
448
|
+
}
|
|
449
|
+
;
|
|
450
|
+
|
|
451
|
+
section: SECTION_START repeated_contents SECTION_END
|
|
452
|
+
{ result = [val[1], val[0].length]
|
|
453
|
+
s = SectionAST.new
|
|
454
|
+
s.children = val[1]
|
|
455
|
+
s.level = val[0].length
|
|
456
|
+
result = s
|
|
457
|
+
}
|
|
458
|
+
;
|
|
459
|
+
|
|
460
|
+
variable: VARIABLE_START TEXT VARIABLE_END
|
|
461
|
+
{
|
|
462
|
+
v = VariableAST.new
|
|
463
|
+
v.text = val[1]
|
|
464
|
+
result = v
|
|
465
|
+
}
|
|
466
|
+
;
|
|
467
|
+
|
|
468
|
+
end
|
|
469
|
+
|
|
470
|
+
---- header ----
|
|
471
|
+
require 'mediacloth/mediawikiast'
|
|
472
|
+
|
|
473
|
+
---- inner ----
|
|
474
|
+
|
|
475
|
+
attr_accessor :lexer
|
|
476
|
+
|
|
477
|
+
def initialize
|
|
478
|
+
@nodes = []
|
|
479
|
+
super
|
|
480
|
+
end
|
|
481
|
+
|
|
482
|
+
#Tokenizes input string and parses it.
|
|
483
|
+
def parse(input)
|
|
484
|
+
@yydebug=true
|
|
485
|
+
lexer.tokenize(input)
|
|
486
|
+
do_parse
|
|
487
|
+
return @nodes.last
|
|
488
|
+
end
|
|
489
|
+
|
|
490
|
+
#Asks the lexer to return the next token.
|
|
491
|
+
def next_token
|
|
492
|
+
return @lexer.lex
|
|
493
|
+
end
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
require 'mediacloth/mediawikiast'
|
|
2
|
+
|
|
3
|
+
#Default walker to traverse the parse tree.
|
|
4
|
+
#
|
|
5
|
+
#The walker traverses the entire parse tree and does nothing.
|
|
6
|
+
#To implement some functionality during this process, reimplement
|
|
7
|
+
#<i>parse...</i> methods and don't forget to call super() to not
|
|
8
|
+
#break the walk.
|
|
9
|
+
#
|
|
10
|
+
#Current implementations: MediaWikiHTMLGenerator, DebugWalker
|
|
11
|
+
class MediaWikiWalker
|
|
12
|
+
|
|
13
|
+
#Walks through the AST
|
|
14
|
+
def parse(ast)
|
|
15
|
+
parse_wiki_ast(ast)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
protected
|
|
19
|
+
|
|
20
|
+
#===== reimplement these methods and don't forget to call super() ====#
|
|
21
|
+
|
|
22
|
+
#Reimplement this
|
|
23
|
+
def parse_wiki_ast(ast)
|
|
24
|
+
ast.children.map do |c|
|
|
25
|
+
r = parse_formatted(c) if c.class == FormattedAST
|
|
26
|
+
r = parse_text(c) if c.class == TextAST
|
|
27
|
+
r = parse_list(c) if c.class == ListAST
|
|
28
|
+
r = parse_preformatted(c) if c.class == PreformattedAST
|
|
29
|
+
r = parse_section(c) if c.class == SectionAST
|
|
30
|
+
r = parse_paragraph(c) if c.class == ParagraphAST
|
|
31
|
+
r = parse_link(c) if c.class == LinkAST
|
|
32
|
+
r = parse_internal_link(c) if c.class == InternalLinkAST
|
|
33
|
+
r = parse_resource_link(c) if c.class == ResourceLinkAST
|
|
34
|
+
r = parse_internal_link_item(c) if c.class == InternalLinkItemAST
|
|
35
|
+
r = parse_table(c) if c.class == TableAST
|
|
36
|
+
r = parse_table_row(c) if c.class == TableRowAST
|
|
37
|
+
r = parse_table_cell(c) if c.class == TableCellAST
|
|
38
|
+
r = parse_element(c) if c.class == ElementAST
|
|
39
|
+
r = parse_variable(c) if c.class == VariableAST
|
|
40
|
+
r = parse_keyword(c) if c.class == KeywordAST
|
|
41
|
+
r
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
#Reimplement this
|
|
46
|
+
def parse_paragraph(ast)
|
|
47
|
+
parse_wiki_ast(ast)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
#Reimplement this
|
|
51
|
+
def parse_formatted(ast)
|
|
52
|
+
parse_wiki_ast(ast)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
#Reimplement this
|
|
56
|
+
def parse_text(ast)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
#Reimplement this
|
|
60
|
+
def parse_list(ast)
|
|
61
|
+
ast.children.map do |c|
|
|
62
|
+
r = parse_list_item(c) if c.class == ListItemAST
|
|
63
|
+
r = parse_list_term(c) if c.class == ListTermAST
|
|
64
|
+
r = parse_list_definition(c) if c.class == ListDefinitionAST
|
|
65
|
+
r
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
#Reimplement this
|
|
70
|
+
def parse_list_item(ast)
|
|
71
|
+
parse_wiki_ast(ast)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
#Reimplement this
|
|
75
|
+
def parse_list_term(ast)
|
|
76
|
+
parse_wiki_ast(ast)
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
#Reimplement this
|
|
80
|
+
def parse_list_definition(ast)
|
|
81
|
+
parse_wiki_ast(ast)
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
#Reimplement this
|
|
85
|
+
def parse_preformatted(ast)
|
|
86
|
+
parse_wiki_ast(ast)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
#Reimplement this
|
|
90
|
+
def parse_section(ast)
|
|
91
|
+
parse_wiki_ast(ast)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
#Reimplement this
|
|
95
|
+
def parse_link(ast)
|
|
96
|
+
parse_wiki_ast(ast)
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
#Reimplement this
|
|
100
|
+
def parse_internal_link(ast)
|
|
101
|
+
ast.children.map do |c|
|
|
102
|
+
parse_internal_link_item(c) if c.class == InternalLinkItemAST
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
#Reimplement this
|
|
107
|
+
def parse_resource_link(ast)
|
|
108
|
+
ast.children.map do |c|
|
|
109
|
+
parse_internal_link_item(c) if c.class == InternalLinkItemAST
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
#Reimplement this
|
|
114
|
+
def parse_internal_link_item(ast)
|
|
115
|
+
parse_wiki_ast(ast)
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
#Reimplement this
|
|
119
|
+
def parse_table(ast)
|
|
120
|
+
parse_wiki_ast(ast)
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
#Reimplement this
|
|
124
|
+
def parse_table_row(ast)
|
|
125
|
+
parse_wiki_ast(ast)
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
#Reimplement this
|
|
129
|
+
def parse_table_cell(ast)
|
|
130
|
+
parse_wiki_ast(ast)
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
#Reimplement this
|
|
134
|
+
def parse_element(ast)
|
|
135
|
+
parse_wiki_ast(ast)
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
#Reimplement this
|
|
139
|
+
def parse_variable(ast)
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
#Reimplement this
|
|
143
|
+
def parse_keyword(ast)
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require 'mediacloth/mediawikilexer'
|
|
2
|
+
require 'mediacloth/mediawikiparser'
|
|
3
|
+
require 'mediacloth/mediawikiast'
|
|
4
|
+
require 'mediacloth/mediawikiparams'
|
|
5
|
+
require 'mediacloth/mediawikiwalker'
|
|
6
|
+
require 'mediacloth/mediawikihtmlgenerator'
|
|
7
|
+
require 'mediacloth/mediawikilinkhandler'
|
|
8
|
+
|
|
9
|
+
#Helper module to facilitate MediaCloth usage.
|
|
10
|
+
module MediaCloth
|
|
11
|
+
|
|
12
|
+
#Parses wiki formatted +input+ and generates its HTML representation.
|
|
13
|
+
#
|
|
14
|
+
#Can reveive options for customizing the HTML renderer and link_handler. These
|
|
15
|
+
#are the available options:
|
|
16
|
+
# :generator => An HTML generator (see MediaWikiHTMLGenerator)
|
|
17
|
+
# :link_handler => A link handler (see MediaWikiLinkHandler)
|
|
18
|
+
def wiki_to_html(input, options={})
|
|
19
|
+
parser = MediaWikiParser.new
|
|
20
|
+
parser.lexer = MediaWikiLexer.new
|
|
21
|
+
tree = parser.parse(input)
|
|
22
|
+
generator = options[:generator] || MediaWikiHTMLGenerator.new
|
|
23
|
+
generator.link_handler = options[:link_handler] if options[:link_handler]
|
|
24
|
+
generator.parse(tree)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
module_function :wiki_to_html
|
|
28
|
+
|
|
29
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
|
|
3
|
+
SPEC = Gem::Specification.new do |s|
|
|
4
|
+
s.name = "mediacloth"
|
|
5
|
+
s.version = "0.0.3"
|
|
6
|
+
s.author = "Pluron Inc."
|
|
7
|
+
s.email = "support@pluron.com"
|
|
8
|
+
s.homepage = "http://mediacloth.rubyforge.org/"
|
|
9
|
+
s.platform = Gem::Platform::RUBY
|
|
10
|
+
s.summary = "A MediaWiki syntax parser and HTML generator."
|
|
11
|
+
|
|
12
|
+
s.add_dependency('builder', '>= 2.1.2')
|
|
13
|
+
|
|
14
|
+
candidates = Dir.glob("{bin,docs,lib,test}/**/*")
|
|
15
|
+
s.files = candidates.delete_if do |item|
|
|
16
|
+
item.include?(".svn") || item.include?("rdoc")
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
s.require_path = "lib"
|
|
20
|
+
s.autorequire = "mediacloth"
|
|
21
|
+
s.has_rdoc = true
|
|
22
|
+
s.extra_rdoc_files = ["README"]
|
|
23
|
+
s.rdoc_options << '--title' << 'MediaCloth' << '--main' << 'README'
|
|
24
|
+
end
|