plainwiki 0.1

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 (4) hide show
  1. checksums.yaml +7 -0
  2. data/lib/parser.rb +244 -0
  3. data/lib/plainwiki.rb +1 -0
  4. metadata +45 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 63e74a0a4695347315a0666c485031f28e026779
4
+ data.tar.gz: e056e2d0d6e51a1acac87fe32d832b49c11c2135
5
+ SHA512:
6
+ metadata.gz: 4e4985d439e731059d1d5e7db8507701856911a401560c7a127fad71abcbcfd2cbba5b6b5b25a742a1a6e30c3b97b1616e7839e8d87b61f1612a01c905ee285c
7
+ data.tar.gz: fd18271df53de21495be12406048b69151aa237b0688253ee0800f1659e4cad8f508412289cda0c0822bf10641c383d2da9f3c6878f1bde068dba10f5b587d9d
data/lib/parser.rb ADDED
@@ -0,0 +1,244 @@
1
+ module PlainWiki
2
+ class Parser
3
+ def self.parse wikitext
4
+ ps = "detect"
5
+ out = ""
6
+ helper = ""
7
+ linkhelper = ""
8
+ toparse = ""
9
+ linktext = false
10
+ intlinkpiped = false
11
+ speciallev = 0
12
+ wikitext.each_char do |c|
13
+ case ps
14
+ when "detect"
15
+ if c == "'"
16
+ next
17
+ elsif c == "<"
18
+ ps = "markup"
19
+ elsif c == "["
20
+ ps = "link"
21
+ elsif c == "]"
22
+ next
23
+ elsif c == "{"
24
+ ps = "tabledetect"
25
+ else
26
+ out += c
27
+ end
28
+ when "markup"
29
+ if c == ">"
30
+ if helper == "strike"
31
+ ps = "strike"
32
+ elsif helper == "nowiki/" || helper == "nowiki /"
33
+ ps = "detect"
34
+ elsif helper == "nowiki"
35
+ ps = "nowiki"
36
+ elsif helper == "ins" || helper == "u"
37
+ ps = "underline"
38
+ elsif helper == "s" || helper == "del"
39
+ ps = "strike"
40
+ elsif helper == "code" || helper == "tt" || helper == "pre"
41
+ ps = "nowiki"
42
+ elsif helper == "blockquote"
43
+ ps = "blockquote"
44
+ elsif helper == "br" || helper == "br /"
45
+ out += "/n"
46
+ ps = "detect"
47
+ elsif helper.include?("!--")
48
+ ps = "detect"
49
+ elsif helper.match(/ref .*\//) != nil
50
+ ps = "detect"
51
+ elsif helper.match(/ref .*/) != nil
52
+ ps = "ref"
53
+ else
54
+ ps = "detect"
55
+ end
56
+ helper = ""
57
+ else
58
+ helper += c
59
+ end
60
+ when "strike"
61
+ if c == "<"
62
+ ps = "strikeend"
63
+ else
64
+ toparse += c
65
+ end
66
+ when "strikeend"
67
+ if c == ">"
68
+ if helper == "/strike" || helper == "/s" || helper == "/del"
69
+ out += self.parse(toparse)
70
+ toparse = ""
71
+ helper = ""
72
+ ps = "detect"
73
+ else
74
+ toparse += "<"
75
+ toparse += helper
76
+ toparse += ">"
77
+ ps = "strike"
78
+ end
79
+ helper = ""
80
+ else
81
+ helper += c
82
+ end
83
+ when "underline"
84
+ if c == "<"
85
+ ps = "underlineend"
86
+ else
87
+ toparse += c
88
+ end
89
+ when "underlineend"
90
+ if c == ">"
91
+ if helper == "/u" || helper == "/ins"
92
+ out += self.parse(toparse)
93
+ toparse = ""
94
+ helper = ""
95
+ ps = "detect"
96
+ else
97
+ toparse += "<"
98
+ toparse += helper
99
+ toparse += ">"
100
+ ps = "strike"
101
+ end
102
+ helper = ""
103
+ else
104
+ helper += c
105
+ end
106
+ when "nowiki"
107
+ if c == "<"
108
+ ps = "nowikiend"
109
+ else
110
+ out += c
111
+ end
112
+ when "nowikiend"
113
+ if c == ">"
114
+ if helper == "/nowiki" || helper == "/code" || helper == "/tt" || helper == "/pre"
115
+ helper = ""
116
+ ps = "detect"
117
+ else
118
+ out += "<"
119
+ out += helper
120
+ out += ">"
121
+ ps = "nowiki"
122
+ end
123
+ helper = ""
124
+ else
125
+ helper += c
126
+ end
127
+ when "ref"
128
+ if c == "<"
129
+ ps = "refend"
130
+ end
131
+ when "refend"
132
+ if c == ">"
133
+ if helper == "/ref"
134
+ helper = ""
135
+ ps = "detect"
136
+ else
137
+ ps = "ref"
138
+ end
139
+ else
140
+ helper += c
141
+ end
142
+ when "link"
143
+ if c == "["
144
+ ps = "intlink"
145
+ elsif c == "]"
146
+ linktext = false
147
+ out += linkhelper
148
+ out += " "
149
+ out += helper
150
+ linkhelper = ""
151
+ helper = ""
152
+ ps = "detect"
153
+ elsif c == " " && !linktext
154
+ linktext = true
155
+ else
156
+ if !linktext
157
+ linkhelper += c
158
+ else
159
+ helper += c
160
+ end
161
+ end
162
+ when "intlink"
163
+ if c == "]"
164
+ ps = "intlinkend"
165
+ elsif c == "|"
166
+ intlinkpiped = true
167
+ else
168
+ if !intlinkpiped
169
+ linkhelper += c
170
+ else
171
+ helper += c
172
+ end
173
+ end
174
+ when "intlinkend"
175
+ if c == "]"
176
+ if !["Kategoria", "Category", "Plik", "File"].include?(linkhelper.split(":").first)
177
+ if intlinkpiped
178
+ if helper == ""
179
+ hout = ""
180
+ helper.split(":").last.split(" ").each do |s|
181
+ if s.match(/\(.*\)/) == nil
182
+ hout += " "
183
+ hout += s
184
+ else
185
+ next
186
+ end
187
+ end
188
+ hout.strip!
189
+ out += hout
190
+ else
191
+ out += helper
192
+ end
193
+ else
194
+ out += linkhelper
195
+ end
196
+ end
197
+ linkhelper = ""
198
+ helper = ""
199
+ intlinkpiped = false
200
+ ps = "detect"
201
+ else
202
+ if !intlinkpiped
203
+ linkhelper += "]"
204
+ linkhelper += c
205
+ else
206
+ helper += "]"
207
+ helper += c
208
+ end
209
+ end
210
+ when "tabledetect"
211
+ if c == "|"
212
+ ps = "table"
213
+ elsif c == "{"
214
+ ps = "special"
215
+ speciallev += 1
216
+ end
217
+ when "table"
218
+ ps = "special"
219
+ speciallev += 1
220
+ when "special"
221
+ if c == "}"
222
+ ps = "specialend"
223
+ elsif c == "{"
224
+ ps = "tabledetect"
225
+ end
226
+ when "specialend"
227
+ if c == "}"
228
+ speciallev -= 1
229
+ if speciallev == 0
230
+ ps = "detect"
231
+ else
232
+ ps = "special"
233
+ end
234
+ else
235
+ ps = "special"
236
+ end
237
+ else
238
+ ps = "detect"
239
+ end
240
+ end
241
+ out.strip
242
+ end
243
+ end
244
+ end
data/lib/plainwiki.rb ADDED
@@ -0,0 +1 @@
1
+ require 'parser'
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: plainwiki
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Phitherek_
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-27 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: This gem provides a parser that strips out MediaWiki' s wikitext to plain
14
+ text. Not affliated with Wikimedia or MediaWiki in any way.
15
+ email: phitherek@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/parser.rb
21
+ - lib/plainwiki.rb
22
+ homepage: https://github.com/Phitherek/plainwiki
23
+ licenses: []
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 2.2.2
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: A MediaWiki wikitext to plain text parser gem
45
+ test_files: []