cewebs-didaktiki 3.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.
@@ -0,0 +1,294 @@
1
+ module Wiki
2
+ class Parser
3
+
4
+ class LaTeX < ReDel::Output
5
+ def initialize(storage,rev,strings,miw,cites,refs)
6
+ @storage = storage
7
+ @rev = rev
8
+ @strings = strings
9
+ @prevMarg = false
10
+ @miw = miw
11
+ @cites = cites
12
+ @refs = refs
13
+ @tab_count = -1
14
+ @row_heading = {}
15
+ @cols = {}
16
+ @start = true
17
+ @formula = 0
18
+ @formulas = {}
19
+ end
20
+
21
+ def finish_prepare
22
+ @tab_count = -1
23
+ end
24
+
25
+ def string(c,current,tree,data)
26
+ return data if tree[current-1].class == ReDel::OpenTag && tree[current-1].type =~ /^P_RAW/
27
+ temp = data.clone
28
+ temp.gsub!(/\\/,"$\\backslash$")
29
+ temp.gsub!(/\{/,"\\{")
30
+ temp.gsub!(/\}/,"\\}")
31
+ temp.gsub!(/&amp;/,"\\\\&")
32
+ temp.gsub!(/([\n\r\t ;:]|^)&quot;/,"\\1\\hbox{''}")
33
+ temp.gsub!(/&quot;/,"\\hbox{``}")
34
+ temp.gsub!(/&lt;/,"<")
35
+ temp.gsub!(/&gt;/,">")
36
+ temp.gsub!(/\#/,"\\#")
37
+ temp.gsub!(/_/,"\\_")
38
+ temp.gsub!(/%/,"\\%")
39
+ temp.gsub!(/LaTeX/,"\\LaTeX{}")
40
+ temp.gsub!(/TeX(?!\{)/,"\\TeX{}")
41
+ temp
42
+ end
43
+
44
+ def mOP_CHARS(data)
45
+ case data
46
+ when "___"
47
+ "~"
48
+ when "..."
49
+ "\\ldots"
50
+ when "---"
51
+ "---"
52
+ when "--"
53
+ "--"
54
+ when "->", "-&gt;"
55
+ "$\\rightarrow$"
56
+ when "<-", "&lt;-"
57
+ "$\\leftarrow$"
58
+ when "<=", "&lt;="
59
+ "$\\Leftarrow$"
60
+ when "=>", "=&gt;"
61
+ "$\\Rightarrow$"
62
+ when "<->", "&lt;-&gt;"
63
+ "$\\leftrightarrow$"
64
+ when "<=>", "&lt;=&gt;"
65
+ "$\\Leftrightarrow$"
66
+ when "<-'", "&lt;-'", "&lt;-&apos;"
67
+ "$\\hookleftarrow$"
68
+ else
69
+ ""
70
+ end
71
+ end
72
+
73
+ def mOP_SECTION1(data)
74
+ res = ''
75
+ if @start
76
+ res << "% !Mode:: \"TeX:UTF-8:Hard\"\n"
77
+ res << "% LaTeX export by DIDAKTIKI\n\n"
78
+ @start = false
79
+ end
80
+ res << "\\section#{data[0] == true ? '*' : ''}{#{data[1]}}\n\\label{sec:#{Wiki::Encoding::latex(data[1])}}\n\n" unless data.nil?;
81
+ res
82
+ end
83
+ def mOP_SECTION2(data) "\\subsection#{data[0] == true ? '*' : ''}{#{data[1]}}\n\\label{sec:#{Wiki::Encoding::latex(data[1])}}\n\n" unless data.nil?; end
84
+ def mOP_SECTION3(data) "\\subsubsection#{data[0] == true ? '*' : ''}{#{data[1]}}\n\\label{sec:#{Wiki::Encoding::latex(data[1])}}\n\n" unless data.nil?; end
85
+
86
+ def mOP_SEPARATOR(data) "\\hrule\n\n"; end
87
+
88
+ def mOP_CODE(data)
89
+ temp = data[:data].gsub(/\[file:([^\]]+)\]/) do |m|
90
+ @storage.get_object($1,:files,@rev).data rescue ""
91
+ end
92
+ begin
93
+ out = ""; props = ""
94
+ props << "label=#{data[:label]}" unless data[:label] == ""
95
+ props << "#{props.length > 0 ? ',' : ''}caption={#{data[:caption]}}" unless data[:caption] == ""
96
+ props = "[#{props}]" if props != ""
97
+ out << "\\lstset{language=#{data[:language]}}\n" if data[:language] != ""
98
+ out << "\\begin{lstlisting}#{props}\n"
99
+ end
100
+ out << ReDel::XHTML::unweb(temp)
101
+ end
102
+ def mCP_CODE(data) "\\end{lstlisting}\n\n"; end
103
+
104
+ def mOP_P(c,current,tree,data)
105
+ @prevMarg = (!tree[current-1].is_a?(String) && tree[current-1].type =~ /^P_[OUD]L\d$|^P_BLOCKQUOTE$|^P_CODE$|^P_IMAGE$/)
106
+ ""
107
+ end
108
+ def mCP_P(c,current,tree,data)
109
+ following = tree[current+1].respond_to?(:type) ? tree[current+1].type : ''
110
+ case data
111
+ when 1
112
+ nextPara = (following == "P_P")
113
+ nextSect = (following =~ /^P_SECTION\d$/)
114
+ if @prevMarg
115
+ ""
116
+ else
117
+ out = (nextPara ? "~\\\\\n" : "\n")
118
+ out << (nextSect ? "\n" : "")
119
+ end
120
+ when 2 then "\n\n"
121
+ else
122
+ "\n\n\n"
123
+ end
124
+ end
125
+
126
+ def mOP_LINK(data) raise ReDel::TagContentSkipError; end
127
+ def mCP_LINK(data) "#{@strings.sfind('page')}~\\pageref{sec:#{Wiki::Encoding::latex(data[1] == "" ? data[0] : data[1])}}" end
128
+
129
+ def mOP_LINK_CEWEBS(data) ""; end
130
+ def mCP_LINK_CEWEBS(data) "" end
131
+
132
+ def mOP_LINK_MAIL(data) "\\href{mailto:#{data}}{"; end
133
+ def mCP_LINK_MAIL(data) "}"; end
134
+
135
+ def mOP_LINK_WEB(data) "\\href{#{data}}{"; end
136
+ def mCP_LINK_WEB(data) "}"; end
137
+
138
+ def mOP_FILE(data) ""; end
139
+ def mCP_FILE(data) ""; end
140
+
141
+ def mOP_COMMENT(data) raise ReDel::TagContentSkipError; end
142
+
143
+ def mOP_EM(data) "\\textit{"; end
144
+ def mCP_EM(data) "}"; end
145
+
146
+ def mOP_STRONG(data) "\\textbf{"; end
147
+ def mCP_STRONG(data) "}"; end
148
+
149
+ def mOP_TT(data) "\\texttt{"; end
150
+ def mCP_TT(data) "}"; end
151
+
152
+ def mOP_DL(data) "\\begin{description}\n"; end
153
+ def mCP_DL(data) "\\end{description}\n\n"; end
154
+ def mOP_LD(c,current,tree,data) " \\item[#{string(c,current,tree,data)}:]~"; end
155
+ def mCP_LD(data) ""; end
156
+
157
+ def mOP_UL1(data) "\\begin{itemize}\n"; end
158
+ def mCP_UL1(data) "\\end{itemize}\n\n"; end
159
+ def mOP_LU1(data) " \\item "; end
160
+ def mCP_LU1(data) ""; end
161
+ def mOP_UL2(data) " \\begin{itemize}\n"; end
162
+ def mCP_UL2(data) " \\end{itemize}\n\n"; end
163
+ def mOP_LU2(data) " \\item "; end
164
+ def mCP_LU2(data) ""; end
165
+ def mOP_UL3(data) " \\begin{itemize}\n"; end
166
+ def mCP_UL3(data) " \\end{itemize}\n\n"; end
167
+ def mOP_LU3(data) " \\item "; end
168
+ def mCP_LU3(data) ""; end
169
+
170
+ def mOP_OL1(data) "\\begin{enumerate}\n"; end
171
+ def mCP_OL1(data) "\\end{enumerate}\n\n"; end
172
+ def mOP_LO1(data) " \\item "; end
173
+ def mCP_LO1(data) ""; end
174
+ def mOP_OL2(data) " \\begin{enumerate}\n"; end
175
+ def mCP_OL2(data) " \\end{enumerate}\n\n"; end
176
+ def mOP_LO2(data) " \\item "; end
177
+ def mCP_LO2(data) ""; end
178
+ def mOP_OL3(data) " \\begin{enumerate}\n"; end
179
+ def mCP_OL3(data) " \\end{enumerate}\n\n"; end
180
+ def mOP_LO3(data) " \\item "; end
181
+ def mCP_LO3(data) ""; end
182
+
183
+ def mOP_IMAGE(data)
184
+ out = ""
185
+ data = data[1].dup # file name and caption
186
+ oid = @storage.get_object_id(data[0],:images_orig,@rev)
187
+ data[0] = Wiki::Encoding::escape(data[0])
188
+ out << "\\begin{figure}[htbp]\n"
189
+ unless oid.nil?
190
+ width = @storage.get_object_meta(data[0],"width",:images,@rev)
191
+ out << " \\begin{center}\n"
192
+ out << " \\includegraphics[width=#{width.to_f/@miw}\\columnwidth]{Images/#{@storage.subject.gsub(/\~/,"\\string~")}/#{data[0]}}\n"
193
+ out << " \\end{center}\n"
194
+ end
195
+ out << " \\caption{#{data[1]}}\n" unless data[1] == ""
196
+ out << " \\label{fig:#{@storage.name}/#{data[0]}}\n"
197
+ out << "\\end{figure}\n\n"
198
+ out
199
+ end
200
+ def mOP_FIGURE(data)
201
+ data = Wiki::Encoding::escape(data)
202
+ "\\ref{fig:#{@storage.name}/#{data}}"
203
+ end
204
+
205
+ def mOP_BLOCKQUOTE(data) "\\begin{quote}\n"; end
206
+ def mCP_BLOCKQUOTE(data) "\n\\end{quote}\n\n"; end
207
+
208
+ def mOP_REF(c,current,tree,data)
209
+ @refs << [data[0],"\\bibitem[xxx]{#{data[0].gsub(/\,/,'')}} #{string(c,current,tree,data[1])}"]
210
+ raise ReDel::TagContentSkipError
211
+ end
212
+ def mOP_CITE(data)
213
+ @cites << data[0]
214
+ ref = Wiki::Encoding::escape(data[0])
215
+ "\\cite#{data[1] == "" ? "" : "[#{data[1]}]"}{#{data[0].gsub(/\,/,'')}}"
216
+ end
217
+
218
+ def mOP_FORMULA1(data)
219
+ data
220
+ end
221
+ def mPP_FORMULA2(data)
222
+ unless data[1].nil?
223
+ @formula += 1
224
+ @formulas[data[1]] = [@formula,@strings.sfind('formula') + " " + @formula.to_s]
225
+ end
226
+ end
227
+ def mOP_FORMULA2(data)
228
+ "\\begin{equation}\n #{ReDel::XHTML::unweb(data[0])}#{data[1].nil? ? '' : "\n \\label{#{data[1]}}"}\n\\end{equation}\n"
229
+ end
230
+ def mOP_FORMULA(data)
231
+ "\\ref{#{data}}"
232
+ end
233
+
234
+ def mPP_TABLE(data)
235
+ @tab_count += 1
236
+ @tab_current = "tab:#{@storage.name}/#{data[2].nil? ? @tab_count : data[2][0]}"
237
+ @row_heading[@tab_current] = []
238
+ @cols[@tab_current] = 0
239
+ @rowc = -1
240
+ end
241
+ def mPP_TR(data)
242
+ @rowc += 1
243
+ end
244
+ def mPP_TD(data)
245
+ @row_heading[@tab_current] ||= []
246
+ @row_heading[@tab_current][@rowc] = true if !@row_heading[@tab_current][@rowc] && data[2]
247
+ @cols[@tab_current] += 1 if @rowc == 0
248
+ end
249
+
250
+ def mOP_TABLE(data)
251
+ @tab_count += 1
252
+ @tab_current = "tab:#{@storage.name}/#{data[2].nil? ? @tab_count : data[2][0]}"
253
+ @rowc = 0
254
+ @colc = 0
255
+ @tab_border = true if data[0]
256
+ out = "\\begin{table}\n"
257
+ out << "\\begin{center}\n"
258
+ out << "\\begin{tabular}{#{@tab_border ? "|" : ""}#{("l" + (@tab_border ? "|" : "")) * @cols[@tab_current]}}\n"
259
+ out << "\\hline" if @tab_border
260
+ out
261
+ end
262
+ def mCP_TABLE(c,data)
263
+ out = "\n\\end{tabular}\n"
264
+ out << "\\end{center}\n"
265
+ unless data[2].nil?
266
+ out << "\\caption{#{data[2][1]}}\n" unless data[2] == ""
267
+ out << "\\label{tab:#{@storage.name}/#{data[2][0]}}\n"
268
+ end
269
+ out << "\\end{table}\n\n"
270
+ out
271
+ end
272
+
273
+ def mOP_TR(data) @colc = 0; "\n" end
274
+ def mCP_TR(data)
275
+ out = "\\\\#{@tab_border ? "\n\\hline" : ""}#{@row_heading[@tab_current][@rowc] ? "\n\\hline" : ""}"
276
+ @rowc += 1
277
+ out
278
+ end
279
+ def mOP_TD(data)
280
+ "\\cellcolor{CEWebSHeading}" if data[2]
281
+ end
282
+ def mCP_TD(data)
283
+ @colc += 1
284
+ @colc < @cols[@tab_current] ? " & " : ""
285
+ end
286
+
287
+ def mOP_TAB(data)
288
+ data = Wiki::Encoding::escape(data)
289
+ "\\ref{tab:#{@storage.name}/#{data}}"
290
+ end
291
+ end
292
+
293
+ end
294
+ end
@@ -0,0 +1,19 @@
1
+ module Wiki
2
+ class Parser
3
+
4
+ class ORename < ReDel::Output
5
+ def initialize(storage,from,to)
6
+ @storage = storage
7
+ @from = from
8
+ @to = to
9
+ end
10
+
11
+ def mOP_LINK(data)
12
+ data[0] = @to if data[0] == @from
13
+ "[[" + data[0] + (data[1].nil? ? "" : "|" + data[1])
14
+ end
15
+ def mCP_LINK(data) "]]"; end
16
+ end
17
+
18
+ end
19
+ end