maiku 0.6.1.maiku
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/maruku.rb +141 -0
- data/lib/maruku/attributes.rb +175 -0
- data/lib/maruku/defaults.rb +71 -0
- data/lib/maruku/errors_management.rb +92 -0
- data/lib/maruku/ext/div.rb +133 -0
- data/lib/maruku/ext/math.rb +41 -0
- data/lib/maruku/ext/math/elements.rb +27 -0
- data/lib/maruku/ext/math/latex_fix.rb +12 -0
- data/lib/maruku/ext/math/mathml_engines/blahtex.rb +107 -0
- data/lib/maruku/ext/math/mathml_engines/itex2mml.rb +29 -0
- data/lib/maruku/ext/math/mathml_engines/none.rb +20 -0
- data/lib/maruku/ext/math/mathml_engines/ritex.rb +24 -0
- data/lib/maruku/ext/math/parsing.rb +119 -0
- data/lib/maruku/ext/math/to_html.rb +187 -0
- data/lib/maruku/ext/math/to_latex.rb +26 -0
- data/lib/maruku/helpers.rb +260 -0
- data/lib/maruku/input/charsource.rb +326 -0
- data/lib/maruku/input/extensions.rb +69 -0
- data/lib/maruku/input/html_helper.rb +189 -0
- data/lib/maruku/input/linesource.rb +111 -0
- data/lib/maruku/input/parse_block.rb +616 -0
- data/lib/maruku/input/parse_doc.rb +232 -0
- data/lib/maruku/input/parse_span_better.rb +746 -0
- data/lib/maruku/input/rubypants.rb +225 -0
- data/lib/maruku/input/type_detection.rb +147 -0
- data/lib/maruku/input_textile2/t2_parser.rb +163 -0
- data/lib/maruku/maruku.rb +33 -0
- data/lib/maruku/output/s5/fancy.rb +756 -0
- data/lib/maruku/output/s5/to_s5.rb +138 -0
- data/lib/maruku/output/to_html.rb +991 -0
- data/lib/maruku/output/to_latex.rb +590 -0
- data/lib/maruku/output/to_latex_entities.rb +367 -0
- data/lib/maruku/output/to_latex_strings.rb +64 -0
- data/lib/maruku/output/to_markdown.rb +164 -0
- data/lib/maruku/output/to_s.rb +56 -0
- data/lib/maruku/string_utils.rb +201 -0
- data/lib/maruku/structures.rb +167 -0
- data/lib/maruku/structures_inspect.rb +87 -0
- data/lib/maruku/structures_iterators.rb +61 -0
- data/lib/maruku/textile2.rb +1 -0
- data/lib/maruku/toc.rb +199 -0
- data/lib/maruku/usage/example1.rb +33 -0
- data/lib/maruku/version.rb +39 -0
- metadata +167 -0
@@ -0,0 +1,367 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (C) 2006 Andrea Censi <andrea (at) rubyforge.org>
|
3
|
+
#
|
4
|
+
# This file is part of Maruku.
|
5
|
+
#
|
6
|
+
# Maruku is free software; you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
8
|
+
# the Free Software Foundation; either version 2 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# Maruku is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with Maruku; if not, write to the Free Software
|
18
|
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
19
|
+
#++
|
20
|
+
|
21
|
+
|
22
|
+
require 'rexml/document'
|
23
|
+
|
24
|
+
module MaRuKu; module Out; module Latex
|
25
|
+
|
26
|
+
include REXML
|
27
|
+
|
28
|
+
def to_latex_entity
|
29
|
+
MaRuKu::Out::Latex.need_entity_table
|
30
|
+
|
31
|
+
entity_name = self.entity_name
|
32
|
+
|
33
|
+
entity = ENTITY_TABLE[entity_name]
|
34
|
+
if not entity
|
35
|
+
maruku_error "I don't know how to translate entity '#{entity_name}' "+
|
36
|
+
"to LaTeX."
|
37
|
+
return ""
|
38
|
+
end
|
39
|
+
replace = entity.latex_string
|
40
|
+
|
41
|
+
entity.latex_packages.each do |p|
|
42
|
+
@doc.latex_require_package p
|
43
|
+
end
|
44
|
+
|
45
|
+
# if replace =~ /^\\/
|
46
|
+
# replace = replace + " "
|
47
|
+
# end
|
48
|
+
|
49
|
+
if replace
|
50
|
+
return replace + "{}"
|
51
|
+
else
|
52
|
+
tell_user "Cannot translate entity #{entity_name.inspect} to LaTeX."
|
53
|
+
return entity_name
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
class LatexEntity
|
58
|
+
safe_attr_accessor :html_num, Fixnum
|
59
|
+
safe_attr_accessor :html_entity, String
|
60
|
+
safe_attr_accessor :latex_string, String
|
61
|
+
safe_attr_accessor :latex_packages, Array
|
62
|
+
end
|
63
|
+
|
64
|
+
def Latex.need_entity_table
|
65
|
+
Latex.init_entity_table if ENTITY_TABLE.empty?
|
66
|
+
end
|
67
|
+
|
68
|
+
# create hash @@entity_to_latex
|
69
|
+
def Latex.init_entity_table
|
70
|
+
# $stderr.write "Creating entity table.."
|
71
|
+
# $stderr.flush
|
72
|
+
doc = Document.new XML_TABLE
|
73
|
+
doc.elements.each("//char") do |c|
|
74
|
+
num = c.attributes['num'].to_i
|
75
|
+
name = c.attributes['name']
|
76
|
+
package = c.attributes['package']
|
77
|
+
|
78
|
+
convert = c.attributes['convertTo']
|
79
|
+
convert.gsub!(/@DOUBLEQUOT/,'"')
|
80
|
+
convert.gsub!(/@QUOT/,"'")
|
81
|
+
convert.gsub!(/@GT/,">")
|
82
|
+
convert.gsub!(/@LT/,"<")
|
83
|
+
convert.gsub!(/@AMP/,"&")
|
84
|
+
convert.freeze
|
85
|
+
|
86
|
+
e = LatexEntity.new
|
87
|
+
e.html_num = num
|
88
|
+
e.html_entity = name
|
89
|
+
e.latex_string = convert
|
90
|
+
e.latex_packages = package ? package.split : []
|
91
|
+
|
92
|
+
ENTITY_TABLE[num] = e
|
93
|
+
ENTITY_TABLE[name] = e
|
94
|
+
end
|
95
|
+
# $stderr.puts "..done."
|
96
|
+
end
|
97
|
+
|
98
|
+
ENTITY_TABLE = {}
|
99
|
+
|
100
|
+
# The following is a conversion chart for html elements, courtesy of
|
101
|
+
# text2html
|
102
|
+
|
103
|
+
XML_TABLE ="
|
104
|
+
<chars>
|
105
|
+
<char num='913' name='Alpha' convertTo='$A$' />
|
106
|
+
<char num='914' name='Beta' convertTo='$B$' />
|
107
|
+
<char num='915' name='Gamma' convertTo='$\\Gamma$' />
|
108
|
+
<char num='916' name='Delta' convertTo='$\\Delta$' />
|
109
|
+
<char num='917' name='Epsilon' convertTo='$E$' />
|
110
|
+
<char num='918' name='Zeta' convertTo='$Z$' />
|
111
|
+
<char num='919' name='Eta' convertTo='$H$' />
|
112
|
+
<char num='920' name='Theta' convertTo='$\\Theta$' />
|
113
|
+
<char num='921' name='Iota' convertTo='$I$' />
|
114
|
+
<char num='922' name='Kappa' convertTo='$K$' />
|
115
|
+
<char num='923' name='Lambda' convertTo='$\\Lambda$' />
|
116
|
+
<char num='924' name='Mu' convertTo='$M$' />
|
117
|
+
<char num='925' name='Nu' convertTo='$N$' />
|
118
|
+
<char num='926' name='Xi' convertTo='$\\Xi$' />
|
119
|
+
<char num='927' name='Omicron' convertTo='$O$' />
|
120
|
+
<char num='928' name='Pi' convertTo='$\\Pi$' />
|
121
|
+
<char num='929' name='Rho' convertTo='$P$' />
|
122
|
+
<char num='931' name='Sigma' convertTo='$\\Sigma$' />
|
123
|
+
<char num='932' name='Tau' convertTo='$T$' />
|
124
|
+
<char num='933' name='Upsilon' convertTo='$Y$' />
|
125
|
+
<char num='934' name='Phi' convertTo='$\\Phi$' />
|
126
|
+
<char num='935' name='Chi' convertTo='$X$' />
|
127
|
+
<char num='936' name='Psi' convertTo='$\\Psi$' />
|
128
|
+
<char num='937' name='Omega' convertTo='$\\Omega$' />
|
129
|
+
<char num='945' name='alpha' convertTo='$\\alpha$' />
|
130
|
+
<char num='946' name='beta' convertTo='$\\beta$' />
|
131
|
+
<char num='947' name='gamma' convertTo='$\\gamma$' />
|
132
|
+
<char num='948' name='delta' convertTo='$\\delta$' />
|
133
|
+
<char num='949' name='epsilon' convertTo='$\\epsilon$' />
|
134
|
+
<char num='950' name='zeta' convertTo='$\\zeta$' />
|
135
|
+
<char num='951' name='eta' convertTo='$\\eta$' />
|
136
|
+
<char num='952' name='theta' convertTo='$\\theta$' />
|
137
|
+
<char num='953' name='iota' convertTo='$\\iota$' />
|
138
|
+
<char num='954' name='kappa' convertTo='$\\kappa$' />
|
139
|
+
<char num='955' name='lambda' convertTo='$\\lambda$' />
|
140
|
+
<char num='956' name='mu' convertTo='$\\mu$' />
|
141
|
+
|
142
|
+
<char num='957' name='nu' convertTo='$\\nu$' />
|
143
|
+
<char num='958' name='xi' convertTo='$\\xi$' />
|
144
|
+
<char num='959' name='omicron' convertTo='$o$' />
|
145
|
+
<char num='960' name='pi' convertTo='$\\pi$' />
|
146
|
+
<char num='961' name='rho' convertTo='$\\rho$' />
|
147
|
+
<char num='963' name='sigma' convertTo='$\\sigma$' />
|
148
|
+
<char num='964' name='tau' convertTo='$\\tau$' />
|
149
|
+
<char num='965' name='upsilon' convertTo='$\\upsilon$' />
|
150
|
+
<char num='966' name='phi' convertTo='$\\phi$' />
|
151
|
+
|
152
|
+
<char num='967' name='chi' convertTo='$\\chi$' />
|
153
|
+
<char num='968' name='psi' convertTo='$\\psi$' />
|
154
|
+
<char num='969' name='omega' convertTo='$\\omega$' />
|
155
|
+
<char num='962' name='sigmaf' convertTo='$\\varsigma$' />
|
156
|
+
<char num='977' name='thetasym' convertTo='$\\vartheta$' />
|
157
|
+
<char num='982' name='piv' convertTo='$\\varpi$' />
|
158
|
+
<char num='8230' name='hellip' convertTo='\\ldots' />
|
159
|
+
<char num='8242' name='prime' convertTo='$\\prime$' />
|
160
|
+
<char num='8254' name='oline' convertTo='-' />
|
161
|
+
|
162
|
+
<char num='8260' name='frasl' convertTo='/' />
|
163
|
+
<char num='8472' name='weierp' convertTo='$\\wp$' />
|
164
|
+
<char num='8465' name='image' convertTo='$\\Im$' />
|
165
|
+
<char num='8476' name='real' convertTo='$\\Re$' />
|
166
|
+
<char num='8501' name='alefsym' convertTo='$\\aleph$' />
|
167
|
+
<char num='8226' name='bull' convertTo='$\\bullet$' />
|
168
|
+
<char num='8482' name='trade' convertTo='$^{\\rm TM}$' /> <!-- \texttrademark -->
|
169
|
+
<char num='8592' name='larr' convertTo='$\\leftarrow$' />
|
170
|
+
|
171
|
+
<char num='8594' name='rarr' convertTo='$\\rightarrow$' />
|
172
|
+
<char num='8593' name='uarr' convertTo='$\\uparrow$' />
|
173
|
+
<char num='8595' name='darr' convertTo='$\\downarrow$' />
|
174
|
+
<char num='8596' name='harr' convertTo='$\\leftrightarrow$' />
|
175
|
+
<char num='8629' name='crarr' convertTo='$\\hookleftarrow$' />
|
176
|
+
<char num='8657' name='uArr' convertTo='$\\Uparrow$' />
|
177
|
+
<char num='8659' name='dArr' convertTo='$\\Downarrow$' />
|
178
|
+
<char num='8656' name='lArr' convertTo='$\\Leftarrow$' />
|
179
|
+
<char num='8658' name='rArr' convertTo='$\\Rightarrow$' />
|
180
|
+
|
181
|
+
<char num='8660' name='hArr' convertTo='$\\Leftrightarrow$' />
|
182
|
+
<char num='8704' name='forall' convertTo='$\\forall$' />
|
183
|
+
<char num='8706' name='part' convertTo='$\\partial$' />
|
184
|
+
<char num='8707' name='exist' convertTo='$\\exists$' />
|
185
|
+
<char num='8709' name='empty' convertTo='$\\emptyset$' />
|
186
|
+
<char num='8711' name='nabla' convertTo='$\\nabla$' />
|
187
|
+
<char num='8712' name='isin' convertTo='$\\in$' />
|
188
|
+
<char num='8715' name='ni' convertTo='$\\ni$' />
|
189
|
+
<char num='8713' name='notin' convertTo='$\\notin$' />
|
190
|
+
|
191
|
+
<char num='8721' name='sum' convertTo='$\\sum$' />
|
192
|
+
<char num='8719' name='prod' convertTo='$\\prod$' />
|
193
|
+
<char num='8722' name='minus' convertTo='$-$' />
|
194
|
+
<char num='8727' name='lowast' convertTo='$\\ast$' />
|
195
|
+
<char num='8730' name='radic' convertTo='$\\surd$' />
|
196
|
+
<char num='8733' name='prop' convertTo='$\\propto$' />
|
197
|
+
<char num='8734' name='infin' convertTo='$\\infty$' />
|
198
|
+
<char num='8736' name='ang' convertTo='$\\angle$' />
|
199
|
+
<char num='8743' name='and' convertTo='$\\wedge$' />
|
200
|
+
|
201
|
+
<char num='8744' name='or' convertTo='$\\vee$' />
|
202
|
+
<char num='8745' name='cup' convertTo='$\\cup$' />
|
203
|
+
<char num='8746' name='cap' convertTo='$\\cap$' />
|
204
|
+
<char num='8747' name='int' convertTo='$\\int$' />
|
205
|
+
<char num='8756' name='there4' convertTo='$\\therefore$' package='amssymb' /> <!-- only AMS -->
|
206
|
+
<char num='8764' name='sim' convertTo='$\\sim$' />
|
207
|
+
<char num='8776' name='asymp' convertTo='$\\approx$' />
|
208
|
+
<char num='8773' name='cong' convertTo='$\\cong$' />
|
209
|
+
|
210
|
+
<char num='8800' name='ne' convertTo='$\\neq$' />
|
211
|
+
<char num='8801' name='equiv' convertTo='$\\equiv$' />
|
212
|
+
<char num='8804' name='le' convertTo='$\\leq$' />
|
213
|
+
<char num='8805' name='ge' convertTo='$\\geq$' />
|
214
|
+
<char num='8834' name='sub' convertTo='$\\subset$' />
|
215
|
+
<char num='8835' name='sup' convertTo='$\\supset$' />
|
216
|
+
<!-- <char num='8838' name='sube' convertTo='$\\subseteq$' />-->
|
217
|
+
<char num='8839' name='supe' convertTo='$\\supseteq$' />
|
218
|
+
<!-- <char num='8836' name='nsub' convertTo='$\\nsubset$' /> --><!-- only AMS -->
|
219
|
+
|
220
|
+
<char num='8853' name='oplus' convertTo='$\\oplus$' />
|
221
|
+
<char num='8855' name='otimes' convertTo='$\\otimes$' />
|
222
|
+
<char num='8869' name='perp' convertTo='$\\perp$' />
|
223
|
+
<char num='8901' name='sdot' convertTo='$\\cdot$' />
|
224
|
+
<char num='8968' name='rceil' convertTo='$\\rceil$' />
|
225
|
+
<char num='8969' name='lceil' convertTo='$\\lceil$' />
|
226
|
+
<char num='8970' name='lfloor' convertTo='$\\lfloor$' />
|
227
|
+
<char num='8971' name='rfloor' convertTo='$\\rfloor$' />
|
228
|
+
<char num='9001' name='rang' convertTo='$\\rangle$' />
|
229
|
+
|
230
|
+
<char num='9002' name='lang' convertTo='$\\langle$' />
|
231
|
+
<char num='9674' name='loz' convertTo='$\\lozenge$' package='amssymb' /> <!-- only AMS -->
|
232
|
+
<char num='9824' name='spades' convertTo='$\\spadesuit$' />
|
233
|
+
<char num='9827' name='clubs' convertTo='$\\clubsuit$' />
|
234
|
+
<char num='9829' name='hearts' convertTo='$\\heartsuit$' />
|
235
|
+
<char num='9830' name='diams' convertTo='$\\diamondsuit$' />
|
236
|
+
<char num='38' name='amp' convertTo='\\@AMP' />
|
237
|
+
<!-- <char num='34' name='quot' convertTo='\\@DOUBLEQUOT' /> XXX -->
|
238
|
+
<char num='34' name='quot' convertTo='\"' />
|
239
|
+
<char num='39' name='apos' convertTo=\"'\" />
|
240
|
+
<char num='169' name='copy' convertTo='\\copyright' />
|
241
|
+
|
242
|
+
<char num='60' name='lt' convertTo='$@LT$' />
|
243
|
+
<char num='62' name='gt' convertTo='$@GT$' />
|
244
|
+
<char num='338' name='OElig' convertTo='\\OE' />
|
245
|
+
<char num='339' name='oelig' convertTo='\\oe' />
|
246
|
+
<char num='352' name='Scaron' convertTo='\\v{S}' />
|
247
|
+
<char num='353' name='scaron' convertTo='\\v{s}' />
|
248
|
+
<char num='376' name='Yuml' convertTo='\\\"Y' />
|
249
|
+
<char num='710' name='circ' convertTo='\\textasciicircum' />
|
250
|
+
<char num='732' name='tilde' convertTo='\\textasciitilde' />
|
251
|
+
|
252
|
+
<char num='8211' name='ndash' convertTo='--' />
|
253
|
+
<char num='8212' name='mdash' convertTo='---' />
|
254
|
+
<char num='8216' name='lsquo' convertTo='`' />
|
255
|
+
<char num='8217' name='rsquo' convertTo=\"'\" /> <!-- XXXX -->
|
256
|
+
<char num='8220' name='ldquo' convertTo='``' />
|
257
|
+
<char num='8221' name='rdquo' convertTo=\"''\" /> <!-- XXXX -->
|
258
|
+
<char num='8224' name='dagger' convertTo='\\dag' />
|
259
|
+
<char num='8225' name='Dagger' convertTo='\\ddag' />
|
260
|
+
<char num='8240' name='permil' convertTo='\\permil' package='wasysym' /> <!-- wasysym package -->
|
261
|
+
|
262
|
+
<char num='8364' name='euro' convertTo='\\euro' package='eurosym' /> <!-- eurosym package -->
|
263
|
+
<char num='8249' name='lsaquo' convertTo='\\guilsinglleft' package='aeguill'/>
|
264
|
+
<char num='8250' name='rsaquo' convertTo='\\guilsinglright' package='aeguill' />
|
265
|
+
<!-- <char num='160' name='nbsp' convertTo='\\nolinebreak' />-->
|
266
|
+
<char num='160' name='nbsp' convertTo='~' />
|
267
|
+
<char num='161' name='iexcl' convertTo='\\textexclamdown' />
|
268
|
+
<char num='163' name='pound' convertTo='\\pounds' />
|
269
|
+
<char num='164' name='curren' convertTo='\\currency' package='wasysym' /> <!-- wasysym package -->
|
270
|
+
<char num='165' name='yen' convertTo='\\textyen' package='textcomp'/> <!-- textcomp -->
|
271
|
+
|
272
|
+
<char num='166' name='brvbar' convertTo='\\brokenvert' /> <!-- wasysym -->
|
273
|
+
<char num='167' name='sect' convertTo='\\S' />
|
274
|
+
<char num='171' name='laquo' convertTo='\\guillemotleft' package='aeguill'/>
|
275
|
+
<char num='187' name='raquo' convertTo='\\guillemotright' package='aeguill'/>
|
276
|
+
<char num='174' name='reg' convertTo='\\textregistered' />
|
277
|
+
<char num='170' name='ordf' convertTo='\\textordfeminine' />
|
278
|
+
<char num='172' name='not' convertTo='$\\neg$' />
|
279
|
+
<!-- <char num='176' name='deg' convertTo='$\\degree$' /> --><!-- mathabx -->
|
280
|
+
<char num='176' name='deg' convertTo='\\textdegree' package='textcomp'/>
|
281
|
+
|
282
|
+
<char num='177' name='plusmn' convertTo='$\\pm$' />
|
283
|
+
<char num='180' name='acute' convertTo='@QUOT' />
|
284
|
+
<char num='181' name='micro' convertTo='$\\mu$' />
|
285
|
+
<char num='182' name='para' convertTo='\\P' />
|
286
|
+
<char num='183' name='middot' convertTo='$\\cdot$' />
|
287
|
+
<char num='186' name='ordm' convertTo='\\textordmasculine' />
|
288
|
+
<char num='162' name='cent' convertTo='\\cent' package='wasysym' />
|
289
|
+
<char num='185' name='sup1' convertTo='$^1$' />
|
290
|
+
|
291
|
+
<char num='178' name='sup2' convertTo='$^2$' />
|
292
|
+
<char num='179' name='sup3' convertTo='$^3$' />
|
293
|
+
<char num='189' name='frac12' convertTo='$\\frac{1}{2}$' />
|
294
|
+
<char num='188' name='frac14' convertTo='$\\frac{1}{4}$' />
|
295
|
+
<char num='190' name='frac34' convertTo='$\\frac{3}{4}$' />
|
296
|
+
<char num='192' name='Agrave' convertTo='\\`A' />
|
297
|
+
<char num='193' name='Aacute' convertTo='\\@QUOTA' />
|
298
|
+
<char num='194' name='Acirc' convertTo='\\^A' />
|
299
|
+
<char num='195' name='Atilde' convertTo='\\~A' />
|
300
|
+
|
301
|
+
<char num='196' name='Auml' convertTo='\\@DOUBLEQUOTA' />
|
302
|
+
<char num='197' name='Aring' convertTo='\\AA' />
|
303
|
+
<char num='198' name='AElig' convertTo='\\AE' />
|
304
|
+
<char num='199' name='Ccedil' convertTo='\\c{C}' />
|
305
|
+
<char num='200' name='Egrave' convertTo='\\`E' />
|
306
|
+
<char num='201' name='Eacute' convertTo='\\@QUOTE' />
|
307
|
+
<char num='202' name='Ecirc' convertTo='\\^E' />
|
308
|
+
<char num='203' name='Euml' convertTo='\\@DOUBLEQUOTE' />
|
309
|
+
<char num='204' name='Igrave' convertTo='\\`I' />
|
310
|
+
<char num='205' name='Iacute' convertTo='\\@QUOTI' />
|
311
|
+
<char num='206' name='Icirc' convertTo='\\^I' />
|
312
|
+
<char num='207' name='Iuml' convertTo='\\\"I' />
|
313
|
+
<char num='208' name='ETH' convertTo='$\\eth$' /> <!-- AMS -->
|
314
|
+
<char num='209' name='Ntilde' convertTo='\\~N' />
|
315
|
+
<char num='210' name='Ograve' convertTo='\\`O' />
|
316
|
+
<char num='211' name='Oacute' convertTo='\\@QUOT O' />
|
317
|
+
<char num='212' name='Ocirc' convertTo='\\^O' />
|
318
|
+
<char num='213' name='Otilde' convertTo='\\~O' />
|
319
|
+
<char num='214' name='Ouml' convertTo='\\@DOUBLEQUOTO' />
|
320
|
+
<char num='215' name='times' convertTo='$\\times$' />
|
321
|
+
<char num='216' name='Oslash' convertTo='\\O' />
|
322
|
+
<char num='217' name='Ugrave' convertTo='\\`U' />
|
323
|
+
<char num='218' name='Uacute' convertTo='\\@QUOTU' />
|
324
|
+
<char num='219' name='Ucirc' convertTo='\\^U' />
|
325
|
+
<char num='220' name='Uuml' convertTo='\\@DOUBLEQUOTU' />
|
326
|
+
<char num='221' name='Yacute' convertTo='\\@QUOTY' />
|
327
|
+
<char num='223' name='szlig' convertTo='\\ss' />
|
328
|
+
<char num='224' name='agrave' convertTo='\\`a' />
|
329
|
+
<char num='225' name='aacute' convertTo='\\@QUOTa' />
|
330
|
+
<char num='226' name='acirc' convertTo='\\^a' />
|
331
|
+
<char num='227' name='atilde' convertTo='\\~a' />
|
332
|
+
<char num='228' name='auml' convertTo='\\@DOUBLEQUOTa' />
|
333
|
+
<char num='229' name='aring' convertTo='\\aa' />
|
334
|
+
<char num='230' name='aelig' convertTo='\\ae' />
|
335
|
+
<char num='231' name='ccedil' convertTo='\\c{c}' />
|
336
|
+
<char num='232' name='egrave' convertTo='\\`e' />
|
337
|
+
<char num='233' name='eacute' convertTo='\\@QUOTe' />
|
338
|
+
<char num='234' name='ecirc' convertTo='\\^e' />
|
339
|
+
<char num='235' name='euml' convertTo='\\@DOUBLEQUOTe' />
|
340
|
+
<char num='236' name='igrave' convertTo='\\`i' />
|
341
|
+
<char num='237' name='iacute' convertTo='\\@QUOTi' />
|
342
|
+
<char num='238' name='icirc' convertTo='\\^i' />
|
343
|
+
<char num='239' name='iuml' convertTo='\\@DOUBLEQUOTi' />
|
344
|
+
<char num='240' name='eth' convertTo='$\\eth$' package='amssymb'/> <!-- -->
|
345
|
+
<char num='241' name='ntilde' convertTo='\\~n' />
|
346
|
+
<char num='242' name='ograve' convertTo='\\`o' />
|
347
|
+
<char num='243' name='oacute' convertTo='\\@QUOTo' />
|
348
|
+
<char num='244' name='ocirc' convertTo='\\^o' />
|
349
|
+
<char num='245' name='otilde' convertTo='\\~o' />
|
350
|
+
<char num='246' name='ouml' convertTo='\\@DOUBLEQUOTo' />
|
351
|
+
<!-- <char num='247' name='divide' convertTo='$\\divide$' /> -->
|
352
|
+
<char num='248' name='oslash' convertTo='\\o' />
|
353
|
+
<char num='249' name='ugrave' convertTo='\\`u' />
|
354
|
+
<char num='250' name='uacute' convertTo='\\@QUOTu' />
|
355
|
+
<char num='251' name='ucirc' convertTo='\\^u' />
|
356
|
+
<char num='252' name='uuml' convertTo='\\@DOUBLEQUOTu' />
|
357
|
+
<char num='253' name='yacute' convertTo='\\@QUOTy' />
|
358
|
+
|
359
|
+
<char num='255' name='yuml' convertTo='\\@DOUBLEQUOTy' />
|
360
|
+
|
361
|
+
<char num='222' name='THORN' convertTo='\\Thorn' package='wasysym' />
|
362
|
+
<char num='254' name='thorn' convertTo='\\thorn' package='wasysym' />
|
363
|
+
</chars>"
|
364
|
+
|
365
|
+
|
366
|
+
end end end
|
367
|
+
|
@@ -0,0 +1,64 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (C) 2006 Andrea Censi <andrea (at) rubyforge.org>
|
3
|
+
#
|
4
|
+
# This file is part of Maruku.
|
5
|
+
#
|
6
|
+
# Maruku is free software; you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
8
|
+
# the Free Software Foundation; either version 2 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# Maruku is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with Maruku; if not, write to the Free Software
|
18
|
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
19
|
+
#++
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
class String
|
24
|
+
|
25
|
+
# These are TeX's special characters
|
26
|
+
LATEX_ADD_SLASH = [ ?{, ?}, ?$, ?&, ?#, ?_, ?%]
|
27
|
+
|
28
|
+
# These, we transform to {\tt \char<ascii code>}
|
29
|
+
LATEX_TO_CHARCODE = [ ?^, ?~, ?>,?<]
|
30
|
+
|
31
|
+
def escape_to_latex(s)
|
32
|
+
s2 = ""
|
33
|
+
s.each_byte do |b|
|
34
|
+
if LATEX_TO_CHARCODE.include? b
|
35
|
+
s2 += "{\\tt \\char#{b}}"
|
36
|
+
elsif LATEX_ADD_SLASH.include? b
|
37
|
+
s2 << ?\\ << b
|
38
|
+
elsif b == ?\\
|
39
|
+
# there is no backslash in cmr10 fonts
|
40
|
+
s2 += "$\\backslash$"
|
41
|
+
else
|
42
|
+
s2 << b
|
43
|
+
end
|
44
|
+
end
|
45
|
+
s2
|
46
|
+
end
|
47
|
+
|
48
|
+
# escapes special characters
|
49
|
+
def to_latex
|
50
|
+
s = escape_to_latex(self)
|
51
|
+
OtherGoodies.each do |k, v|
|
52
|
+
s.gsub!(k, v)
|
53
|
+
end
|
54
|
+
s
|
55
|
+
end
|
56
|
+
|
57
|
+
# other things that are good on the eyes
|
58
|
+
OtherGoodies = {
|
59
|
+
/(\s)LaTeX/ => '\1\\LaTeX\\xspace ', # XXX not if already \LaTeX
|
60
|
+
# 'HTML' => '\\textsc{html}\\xspace ',
|
61
|
+
# 'PDF' => '\\textsc{pdf}\\xspace '
|
62
|
+
}
|
63
|
+
|
64
|
+
end
|
@@ -0,0 +1,164 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (C) 2006 Andrea Censi <andrea (at) rubyforge.org>
|
3
|
+
#
|
4
|
+
# This file is part of Maruku.
|
5
|
+
#
|
6
|
+
# Maruku is free software; you can redistribute it and/or modify
|
7
|
+
# it under the terms of the GNU General Public License as published by
|
8
|
+
# the Free Software Foundation; either version 2 of the License, or
|
9
|
+
# (at your option) any later version.
|
10
|
+
#
|
11
|
+
# Maruku is distributed in the hope that it will be useful,
|
12
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
+
# GNU General Public License for more details.
|
15
|
+
#
|
16
|
+
# You should have received a copy of the GNU General Public License
|
17
|
+
# along with Maruku; if not, write to the Free Software
|
18
|
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
19
|
+
#++
|
20
|
+
|
21
|
+
|
22
|
+
class String
|
23
|
+
# XXX: markdown escaping
|
24
|
+
def to_md(c=nil)
|
25
|
+
to_s
|
26
|
+
end
|
27
|
+
|
28
|
+
# " andrea censi " => [" andrea ", "censi "]
|
29
|
+
def mysplit
|
30
|
+
split.map{|x| x+" "}
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
module MaRuKu; module Out; module Markdown
|
36
|
+
|
37
|
+
DefaultLineLength = 40
|
38
|
+
|
39
|
+
def to_md(context={})
|
40
|
+
children_to_md(context)
|
41
|
+
end
|
42
|
+
|
43
|
+
def to_md_paragraph(context)
|
44
|
+
line_length = context[:line_length] || DefaultLineLength
|
45
|
+
wrap(@children, line_length, context)+"\n"
|
46
|
+
end
|
47
|
+
|
48
|
+
def to_md_li_span(context)
|
49
|
+
len = (context[:line_length] || DefaultLineLength) - 2
|
50
|
+
s = add_tabs(wrap(@children, len-2, context), 1, ' ')
|
51
|
+
s[0] = ?*
|
52
|
+
s + "\n"
|
53
|
+
end
|
54
|
+
|
55
|
+
def to_md_abbr_def(context)
|
56
|
+
"*[#{self.abbr}]: #{self.text}\n"
|
57
|
+
end
|
58
|
+
|
59
|
+
def to_md_ol(context)
|
60
|
+
len = (context[:line_length] || DefaultLineLength) - 2
|
61
|
+
md = ""
|
62
|
+
self.children.each_with_index do |li, i|
|
63
|
+
s = add_tabs(w=wrap(li.children, len-2, context), 1, ' ')+"\n"
|
64
|
+
s[0,4] = "#{i+1}. "[0,4]
|
65
|
+
# puts w.inspect
|
66
|
+
md += s
|
67
|
+
end
|
68
|
+
md + "\n"
|
69
|
+
end
|
70
|
+
|
71
|
+
def to_md_ul(context)
|
72
|
+
len = (context[:line_length] || DefaultLineLength) - 2
|
73
|
+
md = ""
|
74
|
+
self.children.each_with_index do |li, i|
|
75
|
+
w = wrap(li.children, len-2, context)
|
76
|
+
# puts "W: "+ w.inspect
|
77
|
+
s = add_indent(w)
|
78
|
+
# puts "S: " +s.inspect
|
79
|
+
s[0,1] = "-"
|
80
|
+
md += s
|
81
|
+
end
|
82
|
+
md + "\n"
|
83
|
+
end
|
84
|
+
|
85
|
+
def add_indent(s,char=" ")
|
86
|
+
t = s.split("\n").map{|x| char+x }.join("\n")
|
87
|
+
s << ?\n if t[-1] == ?\n
|
88
|
+
s
|
89
|
+
end
|
90
|
+
|
91
|
+
# Convert each child to html
|
92
|
+
def children_to_md(context)
|
93
|
+
array_to_md(@children, context)
|
94
|
+
end
|
95
|
+
|
96
|
+
def wrap(array, line_length, context)
|
97
|
+
out = ""
|
98
|
+
line = ""
|
99
|
+
array.each do |c|
|
100
|
+
if c.kind_of?(MDElement) && c.node_type == :linebreak
|
101
|
+
out << line.strip << " \n"; line="";
|
102
|
+
next
|
103
|
+
end
|
104
|
+
|
105
|
+
pieces =
|
106
|
+
if c.kind_of? String
|
107
|
+
c.to_md.mysplit
|
108
|
+
else
|
109
|
+
[c.to_md(context)].flatten
|
110
|
+
end
|
111
|
+
|
112
|
+
# puts "Pieces: #{pieces.inspect}"
|
113
|
+
pieces.each do |p|
|
114
|
+
if p.size + line.size > line_length
|
115
|
+
out << line.strip << "\n";
|
116
|
+
line = ""
|
117
|
+
end
|
118
|
+
line << p
|
119
|
+
end
|
120
|
+
end
|
121
|
+
out << line.strip << "\n" if line.size > 0
|
122
|
+
out << ?\n if not out[-1] == ?\n
|
123
|
+
out
|
124
|
+
end
|
125
|
+
|
126
|
+
|
127
|
+
def array_to_md(array, context, join_char='')
|
128
|
+
e = []
|
129
|
+
array.each do |c|
|
130
|
+
method = c.kind_of?(MDElement) ?
|
131
|
+
"to_md_#{c.node_type}" : "to_md"
|
132
|
+
|
133
|
+
if not c.respond_to?(method)
|
134
|
+
#raise "Object does not answer to #{method}: #{c.class} #{c.inspect[0,100]}"
|
135
|
+
# tell_user "Using default for #{c.node_type}"
|
136
|
+
method = 'to_md'
|
137
|
+
end
|
138
|
+
|
139
|
+
# puts "#{c.inspect} created with method #{method}"
|
140
|
+
h = c.send(method, context)
|
141
|
+
|
142
|
+
if h.nil?
|
143
|
+
raise "Nil md for #{c.inspect} created with method #{method}"
|
144
|
+
end
|
145
|
+
|
146
|
+
if h.kind_of?Array
|
147
|
+
e = e + h
|
148
|
+
else
|
149
|
+
e << h
|
150
|
+
end
|
151
|
+
end
|
152
|
+
e.join(join_char)
|
153
|
+
end
|
154
|
+
|
155
|
+
end end end
|
156
|
+
|
157
|
+
module MaRuKu; class MDDocument
|
158
|
+
alias old_md to_md
|
159
|
+
def to_md(context={})
|
160
|
+
s = old_md(context)
|
161
|
+
# puts s
|
162
|
+
s
|
163
|
+
end
|
164
|
+
end end
|