deplate 0.7.3
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.TXT +26 -0
- data/CHANGES.TXT +177 -0
- data/LICENSE.TXT +340 -0
- data/NEWS.TXT +29 -0
- data/README.TXT +86 -0
- data/TODO.TXT +202 -0
- data/VERSION.TXT +1 -0
- data/bin/deplate +3 -0
- data/bin/deplate.bat +2 -0
- data/etc/deplate.ini +361 -0
- data/lib/deplate.rb +31 -0
- data/lib/deplate/abstract-class.rb +30 -0
- data/lib/deplate/builtin.rb +11 -0
- data/lib/deplate/cache.rb +59 -0
- data/lib/deplate/commands.rb +693 -0
- data/lib/deplate/common.rb +335 -0
- data/lib/deplate/converter.rb +99 -0
- data/lib/deplate/core.rb +2705 -0
- data/lib/deplate/css/article.css +545 -0
- data/lib/deplate/css/deplate.css +699 -0
- data/lib/deplate/css/heading-navbar.css +29 -0
- data/lib/deplate/css/layout-deplate-print.css +540 -0
- data/lib/deplate/css/layout-deplate.css +764 -0
- data/lib/deplate/css/sans-serif.css +160 -0
- data/lib/deplate/css/serif-e.css +170 -0
- data/lib/deplate/css/serif-rel.css +121 -0
- data/lib/deplate/css/serif.css +190 -0
- data/lib/deplate/css/slides.css +11 -0
- data/lib/deplate/css/tabbar-left.css +91 -0
- data/lib/deplate/css/tabbar-right-ie.css +14 -0
- data/lib/deplate/css/tabbar-right.css +118 -0
- data/lib/deplate/css/tabbar-top.css +64 -0
- data/lib/deplate/css/tabbar.css +81 -0
- data/lib/deplate/css/text-sans-serif.css +154 -0
- data/lib/deplate/css/text-serif.css +175 -0
- data/lib/deplate/define.rb +439 -0
- data/lib/deplate/docbook.rb +738 -0
- data/lib/deplate/elements.rb +1355 -0
- data/lib/deplate/etc.rb +199 -0
- data/lib/deplate/external.rb +135 -0
- data/lib/deplate/fmt/dbk-article-4.1.2.rb +21 -0
- data/lib/deplate/fmt/dbk-article.rb +46 -0
- data/lib/deplate/fmt/dbk-book.rb +46 -0
- data/lib/deplate/fmt/dbk-ref.rb +105 -0
- data/lib/deplate/fmt/dbk-slides.rb +47 -0
- data/lib/deplate/fmt/dbk-snippet.rb +21 -0
- data/lib/deplate/fmt/html-snippet.rb +21 -0
- data/lib/deplate/fmt/html.rb +1696 -0
- data/lib/deplate/fmt/htmlsite.rb +419 -0
- data/lib/deplate/fmt/htmlslides.rb +21 -0
- data/lib/deplate/fmt/htmlwebsite.rb +70 -0
- data/lib/deplate/fmt/latex-snippet.rb +22 -0
- data/lib/deplate/fmt/latex.rb +1242 -0
- data/lib/deplate/fmt/php.rb +19 -0
- data/lib/deplate/fmt/phpsite.rb +19 -0
- data/lib/deplate/fmt/plain.rb +598 -0
- data/lib/deplate/fmt/template.rb +34 -0
- data/lib/deplate/fmt/xhtml10t.rb +41 -0
- data/lib/deplate/formatter-snippet.rb +17 -0
- data/lib/deplate/formatter.rb +1210 -0
- data/lib/deplate/input.rb +492 -0
- data/lib/deplate/input/deplate-headings.rb +48 -0
- data/lib/deplate/input/deplate-restricted.rb +70 -0
- data/lib/deplate/input/deplate.rb +28 -0
- data/lib/deplate/input/rdoc.rb +277 -0
- data/lib/deplate/input/template.rb +29 -0
- data/lib/deplate/lib/latex/highlight-extra.sty +15 -0
- data/lib/deplate/lib/latex/highlight-typical.sty +15 -0
- data/lib/deplate/lib/tabmenu.js +146 -0
- data/lib/deplate/locale/de.latin1 +708 -0
- data/lib/deplate/locale/ru.koi8-r +48 -0
- data/lib/deplate/locale/zh_cn.gb2312 +35 -0
- data/lib/deplate/macros.rb +639 -0
- data/lib/deplate/messages.rb +120 -0
- data/lib/deplate/metadata.rb +77 -0
- data/lib/deplate/metadata/marshal.rb +24 -0
- data/lib/deplate/metadata/xml.rb +42 -0
- data/lib/deplate/metadata/yaml.rb +26 -0
- data/lib/deplate/mod/anyword.rb +56 -0
- data/lib/deplate/mod/babelfish.rb +27 -0
- data/lib/deplate/mod/code-gvim.rb +52 -0
- data/lib/deplate/mod/code-highlight.rb +91 -0
- data/lib/deplate/mod/colored-log.rb +17 -0
- data/lib/deplate/mod/de.rb +19 -0
- data/lib/deplate/mod/en.rb +17 -0
- data/lib/deplate/mod/endnotes.rb +60 -0
- data/lib/deplate/mod/fr.rb +46 -0
- data/lib/deplate/mod/html-asciimath.rb +40 -0
- data/lib/deplate/mod/html-deplate-button.rb +15 -0
- data/lib/deplate/mod/html-headings-navbar.rb +39 -0
- data/lib/deplate/mod/html-obfuscate-email.rb +47 -0
- data/lib/deplate/mod/html-sidebar.rb +232 -0
- data/lib/deplate/mod/htmlslides-navbar-fh.rb +32 -0
- data/lib/deplate/mod/iconv.rb +35 -0
- data/lib/deplate/mod/imgurl.rb +30 -0
- data/lib/deplate/mod/inlatex-compound.rb +69 -0
- data/lib/deplate/mod/koma.rb +109 -0
- data/lib/deplate/mod/latex-emph-table-head.rb +38 -0
- data/lib/deplate/mod/latex-styles.rb +461 -0
- data/lib/deplate/mod/latex-verbatim-small.rb +29 -0
- data/lib/deplate/mod/makefile.rb +194 -0
- data/lib/deplate/mod/mark-external-urls.rb +38 -0
- data/lib/deplate/mod/markup-1-warn.rb +37 -0
- data/lib/deplate/mod/markup-1.rb +41 -0
- data/lib/deplate/mod/navbar-png.rb +33 -0
- data/lib/deplate/mod/noindent.rb +32 -0
- data/lib/deplate/mod/numpara.rb +40 -0
- data/lib/deplate/mod/particle-math.rb +34 -0
- data/lib/deplate/mod/php-extra.rb +44 -0
- data/lib/deplate/mod/pstoedit.rb +71 -0
- data/lib/deplate/mod/recode.rb +57 -0
- data/lib/deplate/mod/ru_koi8-r.rb +20 -0
- data/lib/deplate/mod/smiley.rb +50 -0
- data/lib/deplate/mod/soffice.rb +23 -0
- data/lib/deplate/mod/symbols-latin1.rb +58 -0
- data/lib/deplate/mod/symbols-od-utf-8.rb +16 -0
- data/lib/deplate/mod/symbols-plain.rb +58 -0
- data/lib/deplate/mod/symbols-sgml.rb +97 -0
- data/lib/deplate/mod/symbols-utf-8.rb +81 -0
- data/lib/deplate/mod/symbols-xml.rb +34 -0
- data/lib/deplate/mod/syntax-region-alt.rb +37 -0
- data/lib/deplate/mod/utf8.rb +49 -0
- data/lib/deplate/mod/validate-html.rb +35 -0
- data/lib/deplate/mod/xmlrpc.rb +233 -0
- data/lib/deplate/mod/zh-cn-autospace.rb +108 -0
- data/lib/deplate/mod/zh-cn.rb +59 -0
- data/lib/deplate/once-method.rb +44 -0
- data/lib/deplate/output.rb +249 -0
- data/lib/deplate/particles.rb +815 -0
- data/lib/deplate/regions.rb +1076 -0
- data/lib/deplate/structured.rb +763 -0
- data/lib/deplate/template.rb +430 -0
- data/lib/deplate/templates/html-doc.html +28 -0
- data/lib/deplate/templates/html-left-tabbar-js.html +37 -0
- data/lib/deplate/templates/html-left-tabbar.html +31 -0
- data/lib/deplate/templates/html-tabbar-right-table.html +43 -0
- data/lib/deplate/templates/html-tabbar-right.html +23 -0
- data/lib/deplate/templates/html-tabbar-top.html +43 -0
- data/lib/deplate/templates/html-tabbar.html +31 -0
- data/lib/deplate/wiki-markup.rb +117 -0
- data/lib/deplate/xml.rb +109 -0
- data/lib/deplate/zh-cn.rb +59 -0
- data/lib/ps2ppm.rb +239 -0
- data/man/man1/deplate.1 +692 -0
- metadata +210 -0
|
@@ -0,0 +1,815 @@
|
|
|
1
|
+
# particles.rb
|
|
2
|
+
# @Author: Thomas Link (samul AT web.de)
|
|
3
|
+
# @Website: http://deplate.sf.net/
|
|
4
|
+
# @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
|
|
5
|
+
# @Created: 24-M�r-2004.
|
|
6
|
+
# @Last Change: 02-Nov-2005.
|
|
7
|
+
# @Revision: 0.1655
|
|
8
|
+
|
|
9
|
+
require "uri"
|
|
10
|
+
require "deplate/common"
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
# Sub-line level text bits.
|
|
14
|
+
class Deplate::Particle < Deplate::BaseParticle
|
|
15
|
+
# An array of auto-indexed words/strings.
|
|
16
|
+
@@autoindexed = []
|
|
17
|
+
# An array of the default particle classes.
|
|
18
|
+
@@particles = []
|
|
19
|
+
# The regular expression for the default particle classes.
|
|
20
|
+
@@rx = nil
|
|
21
|
+
# Programmatically created particle classes, e.g., indexes,
|
|
22
|
+
# autoindexes etc.
|
|
23
|
+
@@particles_extended = []
|
|
24
|
+
# The rx for @@particles_extended.
|
|
25
|
+
@@rx_extended = nil
|
|
26
|
+
|
|
27
|
+
class << self
|
|
28
|
+
attr :rx
|
|
29
|
+
|
|
30
|
+
def particles
|
|
31
|
+
@@particles
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def rx_particles
|
|
35
|
+
@@rx
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def particles_ext
|
|
39
|
+
@@particles_extended
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def rx_particles_ext
|
|
43
|
+
@@rx_extended
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def match(text)
|
|
47
|
+
return @rx.match(text)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def register_particle(c=self)
|
|
51
|
+
@@particles << c
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Create an auto-indexed word. Arguments:
|
|
55
|
+
# deplate:: An instance of Deplate::Core.
|
|
56
|
+
# idx:: An instance of the Deplate::Core::IndexEntry structure.
|
|
57
|
+
def auto_indexing(deplate, idx)
|
|
58
|
+
if idx
|
|
59
|
+
i = idx.name
|
|
60
|
+
w = idx.synonymes
|
|
61
|
+
name = i.gsub(/\W\|s/) do |x|
|
|
62
|
+
x.unpack('H2' * x.size)
|
|
63
|
+
end
|
|
64
|
+
if !w.any? {|x| @@autoindexed.include?(x)}
|
|
65
|
+
@@autoindexed += w
|
|
66
|
+
aname = %{AutoIndex#{name}}
|
|
67
|
+
if self == Deplate::HyperLink
|
|
68
|
+
rx = Regexp.escape(i).gsub(/\\/, "\\\\")
|
|
69
|
+
rx.gsub!(/"/, %{\\\\"})
|
|
70
|
+
body = <<-EOR
|
|
71
|
+
@rx = %r{^\\b#{rx}\\b}
|
|
72
|
+
def setup
|
|
73
|
+
super
|
|
74
|
+
name = match[0]
|
|
75
|
+
@elt = [@name, @dest, @anchor]
|
|
76
|
+
@idx = [deplate.add_index(self, @name)]
|
|
77
|
+
@deplate.register_metadata(@source,
|
|
78
|
+
'type' => 'index',
|
|
79
|
+
'name' => @name,
|
|
80
|
+
'label' => @idx.label,
|
|
81
|
+
)
|
|
82
|
+
end
|
|
83
|
+
EOR
|
|
84
|
+
else
|
|
85
|
+
idxName = Regexp.escape(i)
|
|
86
|
+
rx = w.collect {|i| Regexp.escape(i)}.join("\\b|\\b")
|
|
87
|
+
rx.gsub!(/"/, %{\\\\"})
|
|
88
|
+
body = <<-EOR
|
|
89
|
+
@rx = %r{^\\b#{rx}\\b}
|
|
90
|
+
def setup
|
|
91
|
+
@idx = @deplate.add_index(self, %{#{idxName}}) if @container
|
|
92
|
+
end
|
|
93
|
+
def process
|
|
94
|
+
if @container
|
|
95
|
+
@elt = plain_text(Deplate::Core.remove_backslashes(@match[0])) +
|
|
96
|
+
format_particle(:format_index, self, @idx)
|
|
97
|
+
else
|
|
98
|
+
@elt = ""
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
EOR
|
|
102
|
+
end
|
|
103
|
+
cls = Deplate::Cache.particle(deplate, body,
|
|
104
|
+
:register => true,
|
|
105
|
+
:extended => true)
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def insert_particle_before(klass)
|
|
111
|
+
idx = @@particles.index(klass) || -1
|
|
112
|
+
@@particles.insert(idx, self)
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
def initialize(deplate, container, context, match, alt, last="", rest="")
|
|
118
|
+
super(deplate, :container => container)
|
|
119
|
+
@level_as_string = container.level_as_string if container
|
|
120
|
+
@context = context
|
|
121
|
+
@match = match
|
|
122
|
+
@last = last
|
|
123
|
+
@rest = rest
|
|
124
|
+
@alt = alt
|
|
125
|
+
setup
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
def setup
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def process
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
# A wrapper class for simple particles that require only minimal
|
|
137
|
+
# processing.
|
|
138
|
+
class Deplate::SimpleParticle < Deplate::Particle
|
|
139
|
+
def setup
|
|
140
|
+
@elt = @deplate.parse(@container, get_text, @alt)
|
|
141
|
+
end
|
|
142
|
+
def get_text
|
|
143
|
+
@match[1]
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
# A pseudo-particle class. Note the following difference: @match holds
|
|
149
|
+
# the plain text as String and not as MatchData.
|
|
150
|
+
class Deplate::Particle::Text < Deplate::Particle
|
|
151
|
+
def process
|
|
152
|
+
@elt = plain_text(@match)
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
# Match characters escaped with a backslash.
|
|
158
|
+
class Deplate::Particle::Escaped < Deplate::Particle
|
|
159
|
+
register_particle
|
|
160
|
+
set_rx /^\\(.)/
|
|
161
|
+
def process
|
|
162
|
+
@elt = plain_text(@match[1], true)
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
# Match emphasized text marked as <tt>__text__</tt>.
|
|
168
|
+
class Deplate::Particle::Emphasize < Deplate::SimpleParticle
|
|
169
|
+
register_particle
|
|
170
|
+
set_rx /^__((\\_|.)+?)__/
|
|
171
|
+
def process
|
|
172
|
+
@elt = @deplate.format_particles(@elt)
|
|
173
|
+
@elt = format_particle(:format_emphasize, self, @elt)
|
|
174
|
+
end
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
# Match code marked as <tt>''text''</tt> (two single quotes).
|
|
179
|
+
class Deplate::Particle::Code < Deplate::Particle
|
|
180
|
+
register_particle
|
|
181
|
+
set_rx(/^''((\\\\|\\'|.)+?)''/)
|
|
182
|
+
|
|
183
|
+
class << self
|
|
184
|
+
# Programmatically markup text as code. Used e.g. for some
|
|
185
|
+
# R-generated tables.
|
|
186
|
+
def markup(text)
|
|
187
|
+
[%{''}, text.gsub("'", "\\\\'"), %{''}].join
|
|
188
|
+
end
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
def process
|
|
192
|
+
text = Deplate::Core.remove_backslashes(get_text)
|
|
193
|
+
@elt = format_particle(:format_code, self, text)
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
def get_text
|
|
197
|
+
@match[1]
|
|
198
|
+
end
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
# Symbols: <-, ->, <=, =>, <~, ~>, <->, <=>, <~>, !=, ~~, ..., --, ==
|
|
203
|
+
# Markers: +++, ###, ???, !!!
|
|
204
|
+
class Deplate::Particle::Symbol < Deplate::Particle
|
|
205
|
+
register_particle
|
|
206
|
+
|
|
207
|
+
# A hash of symbols and method names for formatting this symbol.
|
|
208
|
+
@@symbols_table = {}
|
|
209
|
+
# An array of symbols in order as they were defined -- as ruby
|
|
210
|
+
# eagerly sorts the keys in the @@symbols_table hash. This is used
|
|
211
|
+
# for building the rx.
|
|
212
|
+
@@symbols_keys = []
|
|
213
|
+
|
|
214
|
+
class << self
|
|
215
|
+
# Add a symbol. If val is nil, a general formatter dependent
|
|
216
|
+
# routine will be used.
|
|
217
|
+
def add_symbol(key, val=nil)
|
|
218
|
+
@@symbols_keys << Regexp.escape(key)
|
|
219
|
+
@@symbols_table[key] = val
|
|
220
|
+
end
|
|
221
|
+
|
|
222
|
+
# Build the rx based on @@symbols_keys.
|
|
223
|
+
def setup_rx
|
|
224
|
+
@rx = Regexp.new(%{^(%s)} % @@symbols_keys.join("|"))
|
|
225
|
+
end
|
|
226
|
+
end
|
|
227
|
+
|
|
228
|
+
for i in [
|
|
229
|
+
["<->"],
|
|
230
|
+
["<-" ],
|
|
231
|
+
["->" ],
|
|
232
|
+
["<=>"],
|
|
233
|
+
["<=" ],
|
|
234
|
+
["=>" ],
|
|
235
|
+
["<~>"],
|
|
236
|
+
["<~" ],
|
|
237
|
+
["~>" ],
|
|
238
|
+
["!=" ],
|
|
239
|
+
["~~" ],
|
|
240
|
+
["..."],
|
|
241
|
+
["--" ],
|
|
242
|
+
["==" ],
|
|
243
|
+
["+++"],
|
|
244
|
+
["###"],
|
|
245
|
+
["???"],
|
|
246
|
+
["!!!"],
|
|
247
|
+
[">>>"],
|
|
248
|
+
["<<<"],
|
|
249
|
+
["```", :doublequote_open],
|
|
250
|
+
["`''", :doublequote_close],
|
|
251
|
+
["``", :singlequote_open],
|
|
252
|
+
["`'", :singlequote_close],
|
|
253
|
+
]
|
|
254
|
+
add_symbol(*i)
|
|
255
|
+
end
|
|
256
|
+
setup_rx
|
|
257
|
+
|
|
258
|
+
def process
|
|
259
|
+
sym = @@symbols_table[@match[1]]
|
|
260
|
+
if sym
|
|
261
|
+
@elt = @deplate.formatter.send(sym, self)
|
|
262
|
+
else
|
|
263
|
+
@elt = format_particle(:format_symbol, self, @match[1])
|
|
264
|
+
end
|
|
265
|
+
end
|
|
266
|
+
end
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
class Deplate::Particle::DoubleQuote < Deplate::Particle
|
|
270
|
+
register_particle
|
|
271
|
+
set_rx(/^"/)
|
|
272
|
+
def process
|
|
273
|
+
if @last =~ /(^|[\s({\[])$/
|
|
274
|
+
@elt = format_particle(:doublequote_open, self)
|
|
275
|
+
else
|
|
276
|
+
@elt = format_particle(:doublequote_close, self)
|
|
277
|
+
end
|
|
278
|
+
end
|
|
279
|
+
end
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
class Deplate::Particle::SingleQuote < Deplate::Particle
|
|
283
|
+
register_particle
|
|
284
|
+
set_rx(/^'/)
|
|
285
|
+
def process
|
|
286
|
+
if @last =~ /(^|[\s({\[])$/
|
|
287
|
+
@elt = format_particle(:singlequote_open, self)
|
|
288
|
+
else
|
|
289
|
+
@elt = format_particle(:singlequote_close, self)
|
|
290
|
+
end
|
|
291
|
+
end
|
|
292
|
+
end
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
# Define interwikis.
|
|
296
|
+
module Deplate::InterWiki
|
|
297
|
+
@@interwikis = {}
|
|
298
|
+
Deplate::InterWikiDef = Struct.new("DeplateInterWikiDef", :id, :url, :sfx)
|
|
299
|
+
class << self
|
|
300
|
+
# Add an interwiki definition. E.g.:
|
|
301
|
+
# Deplate::InterWiki.add("DEPLATE", "http://deplate.sf.net/", ".html")
|
|
302
|
+
def add(id, *args)
|
|
303
|
+
@@interwikis[id] = Deplate::InterWikiDef.new(id, *args)
|
|
304
|
+
end
|
|
305
|
+
end
|
|
306
|
+
end
|
|
307
|
+
|
|
308
|
+
|
|
309
|
+
# This class is meant to be subclassed.
|
|
310
|
+
#
|
|
311
|
+
# The class variables @@uc (upper case letters) and @@lc (lower case
|
|
312
|
+
# letters) define the set of characters allowed in wiki names.
|
|
313
|
+
# International users might want to change the default value in their
|
|
314
|
+
# config.rb file.
|
|
315
|
+
class Deplate::HyperLink < Deplate::Particle
|
|
316
|
+
# @@uc = "A-Z"
|
|
317
|
+
# @@lc = "a-z"
|
|
318
|
+
|
|
319
|
+
# Upper case letters in wiki names.
|
|
320
|
+
@@uc = '[:upper:]'
|
|
321
|
+
# Lower case letters in wiki names.
|
|
322
|
+
@@lc = '[:lower:]'
|
|
323
|
+
|
|
324
|
+
# The name of the interwiki, if any.
|
|
325
|
+
# attr :inter
|
|
326
|
+
|
|
327
|
+
class << self
|
|
328
|
+
# Call this method after changing the markup for hyperlinks, e.g.,
|
|
329
|
+
# by changing the set of allowed characters in wiki names.
|
|
330
|
+
def setup(upper=nil, lower=nil)
|
|
331
|
+
@@uc = upper if upper
|
|
332
|
+
@@lc = lower if lower
|
|
333
|
+
@@ac = "[#{@@uc}#{@@lc}][#{@@uc}#{@@lc}_0-9]+"
|
|
334
|
+
@@bc = "[#{@@uc}#{@@lc}_0-9-][#{@@uc}#{@@lc}_0-9-]+"
|
|
335
|
+
Deplate::HyperLink::Extended.setup
|
|
336
|
+
Deplate::HyperLink::Simple.setup
|
|
337
|
+
end
|
|
338
|
+
|
|
339
|
+
# Concatenate url and anchor, if any.
|
|
340
|
+
def url_anchor(url, anchor)
|
|
341
|
+
dest = [url]
|
|
342
|
+
if anchor and !anchor.empty?
|
|
343
|
+
dest << "#" << anchor
|
|
344
|
+
end
|
|
345
|
+
dest.join
|
|
346
|
+
end
|
|
347
|
+
end
|
|
348
|
+
|
|
349
|
+
include Deplate::InterWiki
|
|
350
|
+
|
|
351
|
+
def get_InterWiki(id)
|
|
352
|
+
d = @@interwikis[id]
|
|
353
|
+
Deplate::Core.log(["Unknown InterWiki name", id], :error, @container.source) unless d
|
|
354
|
+
return d
|
|
355
|
+
end
|
|
356
|
+
|
|
357
|
+
def guess_label(dest, anchor)
|
|
358
|
+
src = @container.source.file
|
|
359
|
+
dest = File.expand_path(dest, src ? File.dirname(src) : nil)
|
|
360
|
+
label = anchor || @deplate.file_label(dest)
|
|
361
|
+
# return @deplate.labels[label]
|
|
362
|
+
return label
|
|
363
|
+
end
|
|
364
|
+
|
|
365
|
+
# guess if a wiki name refers to the file at hand (or its included files) or
|
|
366
|
+
# if it's an external reference/URL.
|
|
367
|
+
#
|
|
368
|
+
# +++ the heuristic is fragile and sometimes gives wrong results
|
|
369
|
+
def complete_wiki_ref(inter, name, dest, anchor)
|
|
370
|
+
sfx = @deplate.variables["suffix"]
|
|
371
|
+
sfx = ".%s" % sfx if sfx
|
|
372
|
+
if dest.empty?
|
|
373
|
+
label = guess_label(dest, anchor)
|
|
374
|
+
if label
|
|
375
|
+
dest = @container.output_file_name(:relative => self)
|
|
376
|
+
return :wiki, name, dest, label
|
|
377
|
+
else
|
|
378
|
+
log(["Wiki reference to unknown anchor", "#{dest}##{anchor}"], :error)
|
|
379
|
+
return nil
|
|
380
|
+
end
|
|
381
|
+
elsif @literal
|
|
382
|
+
return :url, name, dest, anchor
|
|
383
|
+
elsif dest =~ /^#/
|
|
384
|
+
# does it "resemble" an url?
|
|
385
|
+
elsif dest =~ Deplate::HyperLink::Url.rx
|
|
386
|
+
# elsif dest =~ URI::REGEXP::ABS_URI
|
|
387
|
+
if !name or name.empty?
|
|
388
|
+
name = dest
|
|
389
|
+
end
|
|
390
|
+
return :url, name, dest, anchor
|
|
391
|
+
# if its an interwiki name, we rely on the interwiki definition, if
|
|
392
|
+
# provided
|
|
393
|
+
elsif inter
|
|
394
|
+
d = get_InterWiki(inter)
|
|
395
|
+
if d
|
|
396
|
+
return :url, name, d.url + @deplate.file_with_suffix(dest, d.sfx), anchor
|
|
397
|
+
end
|
|
398
|
+
# we then check if the file was included
|
|
399
|
+
elsif @deplate.file_included?(dest, File.dirname(@container.source.file || ""), sfx)
|
|
400
|
+
label = guess_label(@deplate.file_with_suffix(dest, sfx), anchor)
|
|
401
|
+
if label
|
|
402
|
+
dest = @container.output_file_name(:label => label)
|
|
403
|
+
else
|
|
404
|
+
dest = ""
|
|
405
|
+
end
|
|
406
|
+
return :wiki, name, dest, label
|
|
407
|
+
end
|
|
408
|
+
# Fallback heuristic
|
|
409
|
+
src = @container.source.file || ""
|
|
410
|
+
dest_sfx = File.extname(dest)
|
|
411
|
+
dest_abs = File.expand_path(dest, File.basename(src))
|
|
412
|
+
dest_is_dir = (File.exist?(dest_abs) and File.stat(dest_abs).directory?)
|
|
413
|
+
if !dest_is_dir and (dest_sfx == "" or dest_sfx == sfx or dest_sfx == File.extname(src))
|
|
414
|
+
dest1 = @deplate.file_with_suffix(dest, @deplate.options.suffix)
|
|
415
|
+
name = dest1 if !dest_sfx.empty? and (name == dest or name == "")
|
|
416
|
+
return :url, name, dest1, anchor
|
|
417
|
+
else
|
|
418
|
+
return :url, name, dest, anchor
|
|
419
|
+
end
|
|
420
|
+
end
|
|
421
|
+
|
|
422
|
+
def indexing(idx)
|
|
423
|
+
idx = idx.compact
|
|
424
|
+
unless @deplate.variables["indexwiki"] == "no" or idx.empty?
|
|
425
|
+
auto = @deplate.variables["autoindex"]
|
|
426
|
+
for i in idx
|
|
427
|
+
Deplate::Particle.auto_indexing(@deplate, i) if auto
|
|
428
|
+
end
|
|
429
|
+
@idx = idx
|
|
430
|
+
else
|
|
431
|
+
@idx = nil
|
|
432
|
+
end
|
|
433
|
+
end
|
|
434
|
+
|
|
435
|
+
def process
|
|
436
|
+
type, name, dest, anchor = complete_wiki_ref(@inter, *@elt)
|
|
437
|
+
if type
|
|
438
|
+
dest.gsub!(/\\/, "/")
|
|
439
|
+
dest = encode_dest(dest)
|
|
440
|
+
anchor = encode_anchor(anchor)
|
|
441
|
+
if dest =~ Deplate::HyperLink::Url.rx
|
|
442
|
+
if dest =~ /^mailto:/
|
|
443
|
+
@styles << "mailto"
|
|
444
|
+
else
|
|
445
|
+
@styles << "remote"
|
|
446
|
+
end
|
|
447
|
+
end
|
|
448
|
+
case type
|
|
449
|
+
when :wiki
|
|
450
|
+
@elt = format_particle(:format_wiki, self, name, dest, anchor)
|
|
451
|
+
when :url
|
|
452
|
+
@elt = format_particle(:format_url, self, name, dest, anchor)
|
|
453
|
+
end
|
|
454
|
+
if @idx
|
|
455
|
+
@idx.collect! do |idx|
|
|
456
|
+
format_particle(:format_index, self, idx)
|
|
457
|
+
end
|
|
458
|
+
@elt += @idx.join
|
|
459
|
+
end
|
|
460
|
+
end
|
|
461
|
+
end
|
|
462
|
+
|
|
463
|
+
protected
|
|
464
|
+
# Escape special characters from path
|
|
465
|
+
def encode_path(path)
|
|
466
|
+
path = path.split(Regexp.new(Regexp.escape(File::SEPARATOR)))
|
|
467
|
+
hd = path[0] =~ /^[a-zA-Z][:|]$/ ? path.shift : nil
|
|
468
|
+
path = [hd, path.collect {|p| URI.escape(p)}].compact
|
|
469
|
+
File.join(*path)
|
|
470
|
+
end
|
|
471
|
+
|
|
472
|
+
def encode_dest(dest)
|
|
473
|
+
if dest =~ /^~/
|
|
474
|
+
return "file://%s" % File.join(ENV["HOME"], encode_path(dest[1..-1]))
|
|
475
|
+
elsif dest =~ Deplate::HyperLink::Url.rx
|
|
476
|
+
# elsif dest =~ URI::REGEXP::ABS_URI
|
|
477
|
+
# if it looks like an url, we assume that it's already properly encoded
|
|
478
|
+
# or should we do some checks?
|
|
479
|
+
# <+TBD+>
|
|
480
|
+
return dest
|
|
481
|
+
else
|
|
482
|
+
return encode_path(dest)
|
|
483
|
+
# dest = ["file://" + File.expand_path(dest)]
|
|
484
|
+
end
|
|
485
|
+
end
|
|
486
|
+
|
|
487
|
+
def encode_anchor(anchor)
|
|
488
|
+
URI.escape(anchor) if anchor
|
|
489
|
+
end
|
|
490
|
+
end
|
|
491
|
+
|
|
492
|
+
|
|
493
|
+
# Match extended wiki names:
|
|
494
|
+
# [[destination]]
|
|
495
|
+
# [[destination][name]]
|
|
496
|
+
# [[destination#anchor][name]]
|
|
497
|
+
# [[#anchor]]
|
|
498
|
+
# [[#anchor][name]]
|
|
499
|
+
class Deplate::HyperLink::Extended < Deplate::HyperLink
|
|
500
|
+
register_particle
|
|
501
|
+
|
|
502
|
+
class << self
|
|
503
|
+
def setup
|
|
504
|
+
# @rx = /^\[\[([^\]#]*)(#(#{@@bc}))?\](\[(.+?)\])?([-!~*]*)\]/
|
|
505
|
+
@rx = /^\[\[([^\]#]*)(#([^\]]*))?\](\[(.+?)\])?([-!~*]*)\]/
|
|
506
|
+
end
|
|
507
|
+
end
|
|
508
|
+
|
|
509
|
+
def setup
|
|
510
|
+
@inter = nil
|
|
511
|
+
@dest = get_destination || ""
|
|
512
|
+
@anchor = get_anchor
|
|
513
|
+
@name = get_name
|
|
514
|
+
@modifier = get_modifier || ""
|
|
515
|
+
unless @modifier.include?("-")
|
|
516
|
+
if @name
|
|
517
|
+
id = @name
|
|
518
|
+
else
|
|
519
|
+
if !@dest or @dest.empty?
|
|
520
|
+
@name = @anchor
|
|
521
|
+
id = @anchor
|
|
522
|
+
else
|
|
523
|
+
@name = @dest
|
|
524
|
+
id = File.basename(@dest)
|
|
525
|
+
end
|
|
526
|
+
end
|
|
527
|
+
idx = [@deplate.add_index(self, id)]
|
|
528
|
+
else
|
|
529
|
+
idx = []
|
|
530
|
+
end
|
|
531
|
+
@idx = indexing(idx)
|
|
532
|
+
@literal = @modifier.include?("!") # || @dest =~ Deplate::HyperLink::Url.rx
|
|
533
|
+
if @modifier.include?('~') and @dest =~ /^\~/
|
|
534
|
+
@dest = File.expand_path(@dest)
|
|
535
|
+
end
|
|
536
|
+
if @modifier.include?('*')
|
|
537
|
+
@args['target'] = '_blank'
|
|
538
|
+
end
|
|
539
|
+
end
|
|
540
|
+
|
|
541
|
+
def get_destination
|
|
542
|
+
@match[1]
|
|
543
|
+
end
|
|
544
|
+
|
|
545
|
+
def get_anchor
|
|
546
|
+
@match[3]
|
|
547
|
+
end
|
|
548
|
+
|
|
549
|
+
def get_name
|
|
550
|
+
@match[5]
|
|
551
|
+
end
|
|
552
|
+
|
|
553
|
+
def get_modifier
|
|
554
|
+
@match[6]
|
|
555
|
+
end
|
|
556
|
+
|
|
557
|
+
def process
|
|
558
|
+
@name = @deplate.parse_and_format(self, @name, false, [
|
|
559
|
+
Deplate::HyperLink::Extended,
|
|
560
|
+
Deplate::HyperLink::Simple,
|
|
561
|
+
Deplate::HyperLink::Url,
|
|
562
|
+
])
|
|
563
|
+
@dest = @deplate.parse_and_format(self, @dest, false, [
|
|
564
|
+
Deplate::HyperLink::Extended,
|
|
565
|
+
Deplate::HyperLink::Simple,
|
|
566
|
+
Deplate::HyperLink::Url,
|
|
567
|
+
])
|
|
568
|
+
# @name = plain_text(Deplate::Core.remove_backslashes(@name))
|
|
569
|
+
@elt = [@name, @dest, @anchor]
|
|
570
|
+
super
|
|
571
|
+
end
|
|
572
|
+
end
|
|
573
|
+
|
|
574
|
+
|
|
575
|
+
# Match simple wiki names.
|
|
576
|
+
#
|
|
577
|
+
# Simple Deplate Names:
|
|
578
|
+
# DeplateName
|
|
579
|
+
# DeplateName#anchor
|
|
580
|
+
#
|
|
581
|
+
# Quoted Deplate Names:
|
|
582
|
+
# [-name-]
|
|
583
|
+
# [-some name-]#there
|
|
584
|
+
#
|
|
585
|
+
# Interdeplate:
|
|
586
|
+
# OTHERDEPLATE::DeplateName
|
|
587
|
+
# OTHERDEPLATE::DeplateName#there
|
|
588
|
+
# OTHERDEPLATE::[-some name-]
|
|
589
|
+
# OTHERDEPLATE::[-some name-]#there
|
|
590
|
+
class Deplate::HyperLink::Simple < Deplate::HyperLink
|
|
591
|
+
register_particle
|
|
592
|
+
|
|
593
|
+
class << self
|
|
594
|
+
def setup
|
|
595
|
+
# @rx = /^((\b[#{@@uc}]+)::)?(\[-(.*?)-\]|\b[#{@@uc}][#{@@lc}]+([#{@@uc}][#{@@lc}0-9]+)+\b)(#(#{@@ac})\b)?/
|
|
596
|
+
@rx = /^(([#{@@uc}]+)::)?(\[-(.*?)-\]|\b[#{@@uc}][#{@@lc}]+([#{@@uc}][#{@@lc}0-9]+)+\b)(#(#{@@ac}))?/
|
|
597
|
+
# @rx = /^(([#{@@uc}]+)::)?(\[-(.*?)-\]|\b[A-Z][#{@@lc}]+([#{@@uc}][#{@@lc}0-9]+)+)(#(#{@@ac}))?(?!#{@@ac})/
|
|
598
|
+
# @rx = /^(([#{@@uc}]+)::)?(\[-(.*?)-\]|\b[#{@@uc}][#{@@lc}]+([#{@@uc}][#{@@lc}0-9]+)+)(#(#{@@ac}))?(?!(#{@@ac}|$))/
|
|
599
|
+
end
|
|
600
|
+
end
|
|
601
|
+
|
|
602
|
+
def setup
|
|
603
|
+
@inter = get_interwiki
|
|
604
|
+
@dest = get_destination
|
|
605
|
+
@anchor = get_anchor
|
|
606
|
+
@literal = nil
|
|
607
|
+
if @dest.empty?
|
|
608
|
+
@name = "#" + @anchor
|
|
609
|
+
else
|
|
610
|
+
@name = @dest
|
|
611
|
+
end
|
|
612
|
+
idx = [@deplate.add_index(self, @name)]
|
|
613
|
+
@idx = indexing(idx)
|
|
614
|
+
end
|
|
615
|
+
|
|
616
|
+
def get_interwiki
|
|
617
|
+
@match[2]
|
|
618
|
+
end
|
|
619
|
+
|
|
620
|
+
def get_destination
|
|
621
|
+
@match[4] || @match[3]
|
|
622
|
+
end
|
|
623
|
+
|
|
624
|
+
def get_anchor
|
|
625
|
+
@match[7]
|
|
626
|
+
end
|
|
627
|
+
|
|
628
|
+
def process
|
|
629
|
+
# @name = @deplate.parse_and_format(self, @name, false)
|
|
630
|
+
@name = plain_text(Deplate::Core.remove_backslashes(@name))
|
|
631
|
+
@elt = [@name, @dest, @anchor]
|
|
632
|
+
super
|
|
633
|
+
end
|
|
634
|
+
end
|
|
635
|
+
|
|
636
|
+
|
|
637
|
+
# Match URLs.
|
|
638
|
+
class Deplate::HyperLink::Url < Deplate::HyperLink
|
|
639
|
+
register_particle
|
|
640
|
+
# We could also try to use URI::REGEXP::ABS_URI
|
|
641
|
+
# @rx = /^((https?|ftps?|nntp|mailto|mailbox):([#{@@uc}#{@@lc}0-9.:%?=&_~@\/\|-]+?))(#([-#{@@uc}#{@@lc}0-9]*))?([.,;:!?)}\]]*\s|$)/
|
|
642
|
+
set_rx(/^((https?|ftps?|nntp|mailto|mailbox|file):(\S+?)(#([-#{@@uc}#{@@lc}0-9]*))?)(?=[.,;:!?)}\]]+\s|\s|$)/)
|
|
643
|
+
|
|
644
|
+
def setup
|
|
645
|
+
@dest = get_destination
|
|
646
|
+
@name = @dest
|
|
647
|
+
@anchor = get_anchor
|
|
648
|
+
@literal = true
|
|
649
|
+
end
|
|
650
|
+
|
|
651
|
+
def get_destination
|
|
652
|
+
# @match[0]
|
|
653
|
+
@match[1]
|
|
654
|
+
end
|
|
655
|
+
|
|
656
|
+
def get_anchor
|
|
657
|
+
# @match[4]
|
|
658
|
+
m = @match[5]
|
|
659
|
+
if m
|
|
660
|
+
rv = m.split(/#/)[1]
|
|
661
|
+
rv
|
|
662
|
+
else
|
|
663
|
+
nil
|
|
664
|
+
end
|
|
665
|
+
end
|
|
666
|
+
|
|
667
|
+
def process
|
|
668
|
+
@name = plain_text(@name)
|
|
669
|
+
@elt = format_particle(:format_url, self, @name, @dest, @anchor)
|
|
670
|
+
end
|
|
671
|
+
end
|
|
672
|
+
|
|
673
|
+
Deplate::HyperLink.setup
|
|
674
|
+
|
|
675
|
+
|
|
676
|
+
# General macro reader. A macro has the form {NAME ARGS: BODY}. Curly
|
|
677
|
+
# braces in the body part have to be escaped with a backslash. ARGS
|
|
678
|
+
# match a series of:
|
|
679
|
+
# * arg!
|
|
680
|
+
# * noArg!
|
|
681
|
+
# * key=value
|
|
682
|
+
# * key="value"
|
|
683
|
+
# * key=(value)
|
|
684
|
+
class Deplate::Particle::Macro < Deplate::Particle
|
|
685
|
+
register_particle
|
|
686
|
+
|
|
687
|
+
# The macro name.
|
|
688
|
+
attr_reader :macro
|
|
689
|
+
|
|
690
|
+
class << self
|
|
691
|
+
# This function builds the rx for the macro reader. The optional
|
|
692
|
+
# argument defines the depth of nested macros for which the
|
|
693
|
+
# regular expression is being built. The default is 5 which should
|
|
694
|
+
# be sufficient due to the primitivity of the macro language.
|
|
695
|
+
def build_rx(depth=5)
|
|
696
|
+
@rx = "\\{(?>\\\\\\{|\\\\\\}|\\\\\\\\|[^{}]+?|#)*\\}"
|
|
697
|
+
@rxr = @rx.gsub("\\", "\\\\\\\\")
|
|
698
|
+
for i in 1..depth
|
|
699
|
+
@rx.gsub!(/#/, @rxr)
|
|
700
|
+
end
|
|
701
|
+
@rx.gsub!(/#/, "[^{}]+?")
|
|
702
|
+
@rx = Regexp.new("^" + @rx)
|
|
703
|
+
end
|
|
704
|
+
end
|
|
705
|
+
|
|
706
|
+
build_rx
|
|
707
|
+
|
|
708
|
+
def setup
|
|
709
|
+
begin
|
|
710
|
+
macro = get_text
|
|
711
|
+
unless macro.empty?
|
|
712
|
+
@macro, args, text = split_name_args(macro)
|
|
713
|
+
if @macro
|
|
714
|
+
@elt = Deplate::Macro.exec(@deplate, @container, @context, @macro, args, @alt, text)
|
|
715
|
+
if @elt
|
|
716
|
+
@args = @elt.args
|
|
717
|
+
else
|
|
718
|
+
args[:match] = @match
|
|
719
|
+
@elt = Deplate::Macro::Unknown.new(@deplate, @container, @context, args, @alt, text)
|
|
720
|
+
end
|
|
721
|
+
@deplate.register_id(@args, @elt)
|
|
722
|
+
else
|
|
723
|
+
Deplate::Core.log(["Malformed macro", @match[0]], :error, @container.source)
|
|
724
|
+
end
|
|
725
|
+
end
|
|
726
|
+
rescue Deplate::DontFormatException
|
|
727
|
+
Deplate::Core.log(["Dropping", @match[0]], nil, @container.source)
|
|
728
|
+
end
|
|
729
|
+
end
|
|
730
|
+
|
|
731
|
+
def get_text
|
|
732
|
+
@match[0][1..-2]
|
|
733
|
+
end
|
|
734
|
+
|
|
735
|
+
def split_name_args(macro)
|
|
736
|
+
m = /^([^a-zA-Z]|[[:alnum:]_]+)(.*)$/.match(macro)
|
|
737
|
+
if m
|
|
738
|
+
macro = m[1]
|
|
739
|
+
if macro =~ /^[^a-zA-Z]/
|
|
740
|
+
text = m[2]
|
|
741
|
+
args = {}
|
|
742
|
+
else
|
|
743
|
+
body = m[2].gsub(/([\\{}])/, '\\\\\\1')
|
|
744
|
+
args, text = @deplate.input.parse_args(m[2], @container)
|
|
745
|
+
end
|
|
746
|
+
[macro, args, text]
|
|
747
|
+
else
|
|
748
|
+
nil
|
|
749
|
+
end
|
|
750
|
+
end
|
|
751
|
+
|
|
752
|
+
def process
|
|
753
|
+
@elt = if @elt then @elt.process else "" end
|
|
754
|
+
end
|
|
755
|
+
end
|
|
756
|
+
|
|
757
|
+
|
|
758
|
+
# Give warnings about misplaced, unbalanced, or not-escaped curly braces.
|
|
759
|
+
class Deplate::Particle::CurlyBrace < Deplate::Particle
|
|
760
|
+
register_particle
|
|
761
|
+
set_rx /^([{}])/
|
|
762
|
+
|
|
763
|
+
def process
|
|
764
|
+
sample_pre = @last[-10..-1]
|
|
765
|
+
sample_post = @rest[0..9]
|
|
766
|
+
Deplate::Core.log(["Curly brace should be preceded by a backslash", "%s>>%s<<%s" % [sample_pre, @match[0], sample_post]], :error, @container.source)
|
|
767
|
+
@elt = plain_text(@match[0], false)
|
|
768
|
+
end
|
|
769
|
+
end
|
|
770
|
+
|
|
771
|
+
|
|
772
|
+
# Match against whitespace. This class is currently only used for
|
|
773
|
+
# template input filter.
|
|
774
|
+
class Deplate::Particle::Whitespace < Deplate::Particle
|
|
775
|
+
set_rx /^\s+/
|
|
776
|
+
|
|
777
|
+
def process
|
|
778
|
+
@elt = @match[0]
|
|
779
|
+
end
|
|
780
|
+
end
|
|
781
|
+
|
|
782
|
+
|
|
783
|
+
# This is a general word class that will some day in the future handle
|
|
784
|
+
# autoidx, index, abbreviation requests.
|
|
785
|
+
# Currently useless.
|
|
786
|
+
class Deplate::Particle::Word < Deplate::Particle
|
|
787
|
+
# register_particle
|
|
788
|
+
set_rx(/^(`?[^[:space:][:punct:]]+)/)
|
|
789
|
+
def process
|
|
790
|
+
word = get_text
|
|
791
|
+
@elt = plain_text(word, false)
|
|
792
|
+
end
|
|
793
|
+
def get_text
|
|
794
|
+
@match[1]
|
|
795
|
+
end
|
|
796
|
+
end
|
|
797
|
+
|
|
798
|
+
|
|
799
|
+
# This class is meant to be subclassed for implementing deprecated-markup
|
|
800
|
+
# warnings as it is done in the markup-1-warn module.
|
|
801
|
+
class Deplate::DeprecatedParticle < Deplate::SimpleParticle
|
|
802
|
+
def process
|
|
803
|
+
Deplate::Core.log(["Deprecated text style", @match[0]], :error, @container.source)
|
|
804
|
+
txt = get_text
|
|
805
|
+
pre, post = get_prepost(@match)
|
|
806
|
+
acc = [
|
|
807
|
+
plain_text(pre.join, false),
|
|
808
|
+
@deplate.format_particles(@elt),
|
|
809
|
+
plain_text(post.join, false)
|
|
810
|
+
]
|
|
811
|
+
@elt = acc.join
|
|
812
|
+
end
|
|
813
|
+
end
|
|
814
|
+
|
|
815
|
+
# vim: ff=unix
|