deplate 0.7.3 → 0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (160) hide show
  1. data/AUTHORS.TXT +3 -0
  2. data/CHANGES.TXT +248 -175
  3. data/LICENSE.TXT +0 -0
  4. data/NEWS.TXT +28 -24
  5. data/README.TXT +0 -0
  6. data/TODO.TXT +174 -88
  7. data/VERSION.TXT +1 -1
  8. data/bin/deplate +0 -0
  9. data/bin/deplate.bat +0 -0
  10. data/etc/deplate.ini +91 -3
  11. data/lib/action_view/helpers/deplate.rb +45 -0
  12. data/lib/deplate.rb +6 -1
  13. data/lib/deplate/abstract-class.rb +0 -0
  14. data/lib/deplate/bib.rb +576 -0
  15. data/lib/deplate/builtin.rb +0 -0
  16. data/lib/deplate/cache.rb +55 -5
  17. data/lib/deplate/commands.rb +346 -183
  18. data/lib/deplate/common.rb +209 -48
  19. data/lib/deplate/converter.rb +12 -6
  20. data/lib/deplate/core.rb +777 -378
  21. data/lib/deplate/counters.rb +254 -0
  22. data/lib/deplate/css/article.css +4 -3
  23. data/lib/deplate/css/deplate.css +121 -5
  24. data/lib/deplate/css/heading-navbar.css +0 -0
  25. data/lib/deplate/css/layout-deplate-print.css +0 -0
  26. data/lib/deplate/css/layout-deplate.css +0 -0
  27. data/lib/deplate/css/sans-serif.css +0 -0
  28. data/lib/deplate/css/serif-e.css +0 -0
  29. data/lib/deplate/css/serif-rel.css +0 -0
  30. data/lib/deplate/css/serif.css +9 -3
  31. data/lib/deplate/css/slides.css +0 -0
  32. data/lib/deplate/css/tabbar-left.css +0 -0
  33. data/lib/deplate/css/tabbar-right-ie.css +3 -9
  34. data/lib/deplate/css/tabbar-right.css +51 -18
  35. data/lib/deplate/css/tabbar-top.css +7 -1
  36. data/lib/deplate/css/tabbar.css +0 -0
  37. data/lib/deplate/css/text-sans-serif.css +0 -0
  38. data/lib/deplate/css/text-serif.css +0 -0
  39. data/lib/deplate/define.rb +183 -177
  40. data/lib/deplate/deplate-string.rb +82 -0
  41. data/lib/deplate/docbook.rb +236 -128
  42. data/lib/deplate/elements.rb +584 -417
  43. data/lib/deplate/etc.rb +163 -101
  44. data/lib/deplate/external.rb +42 -11
  45. data/lib/deplate/fmt/dbk-article-4.1.2.rb +0 -0
  46. data/lib/deplate/fmt/dbk-article.rb +0 -0
  47. data/lib/deplate/fmt/dbk-book.rb +0 -0
  48. data/lib/deplate/fmt/dbk-ref.rb +3 -3
  49. data/lib/deplate/fmt/dbk-slides.rb +0 -0
  50. data/lib/deplate/fmt/dbk-snippet.rb +0 -0
  51. data/lib/deplate/fmt/html-snippet.rb +0 -0
  52. data/lib/deplate/fmt/html.rb +783 -550
  53. data/lib/deplate/fmt/htmlsite.rb +192 -199
  54. data/lib/deplate/fmt/htmlslides.rb +0 -0
  55. data/lib/deplate/fmt/htmlwebsite.rb +3 -3
  56. data/lib/deplate/fmt/latex-snippet.rb +0 -0
  57. data/lib/deplate/fmt/latex.rb +242 -83
  58. data/lib/deplate/fmt/null.rb +32 -0
  59. data/lib/deplate/fmt/php.rb +4 -4
  60. data/lib/deplate/fmt/phpsite.rb +6 -5
  61. data/lib/deplate/fmt/plain.rb +160 -106
  62. data/lib/deplate/fmt/template.rb +0 -0
  63. data/lib/deplate/fmt/xhtml10t.rb +0 -0
  64. data/lib/deplate/formatter-snippet.rb +0 -0
  65. data/lib/deplate/formatter.rb +613 -301
  66. data/lib/deplate/input.rb +202 -142
  67. data/lib/deplate/input/deplate-headings.rb +4 -6
  68. data/lib/deplate/input/deplate-restricted.rb +15 -9
  69. data/lib/deplate/input/deplate.rb +2 -4
  70. data/lib/deplate/input/rdoc.rb +39 -38
  71. data/lib/deplate/input/template.rb +0 -0
  72. data/lib/deplate/lib/Makefile.config +29 -0
  73. data/lib/deplate/lib/latex/deplate.sty +54 -0
  74. data/lib/deplate/lib/latex/highlight-extra.sty +0 -0
  75. data/lib/deplate/lib/latex/highlight-typical.sty +0 -0
  76. data/lib/deplate/lib/php/page-comment.inc.php +216 -0
  77. data/lib/deplate/lib/tabmenu.js +0 -0
  78. data/lib/deplate/locale/de.latin1 +155 -17
  79. data/lib/deplate/locale/ru.koi8-r +0 -0
  80. data/lib/deplate/locale/zh_cn.gb2312 +0 -0
  81. data/lib/deplate/macros.rb +133 -82
  82. data/lib/deplate/messages.rb +6 -4
  83. data/lib/deplate/metadata.rb +0 -0
  84. data/lib/deplate/metadata/marshal.rb +0 -0
  85. data/lib/deplate/metadata/xml.rb +0 -0
  86. data/lib/deplate/metadata/yaml.rb +0 -0
  87. data/lib/deplate/mod/anyword.rb +3 -3
  88. data/lib/deplate/mod/babelfish.rb +4 -4
  89. data/lib/deplate/mod/code-gvim.rb +8 -4
  90. data/lib/deplate/mod/code-highlight.rb +3 -3
  91. data/lib/deplate/mod/colored-log.rb +0 -0
  92. data/lib/deplate/mod/de.rb +2 -2
  93. data/lib/deplate/mod/en.rb +0 -0
  94. data/lib/deplate/mod/endnotes.rb +0 -0
  95. data/lib/deplate/mod/fr.rb +0 -0
  96. data/lib/deplate/mod/html-asciimath.rb +0 -0
  97. data/lib/deplate/mod/html-deplate-button.rb +0 -0
  98. data/lib/deplate/mod/html-headings-navbar.rb +5 -13
  99. data/lib/deplate/mod/html-jsmath.rb +39 -0
  100. data/lib/deplate/mod/html-obfuscate-email.rb +3 -3
  101. data/lib/deplate/mod/html-sidebar.rb +0 -0
  102. data/lib/deplate/mod/htmlslides-navbar-fh.rb +3 -3
  103. data/lib/deplate/mod/iconv.rb +0 -0
  104. data/lib/deplate/mod/imgurl.rb +4 -4
  105. data/lib/deplate/mod/inlatex-compound.rb +7 -10
  106. data/lib/deplate/mod/koma.rb +0 -0
  107. data/lib/deplate/mod/latex-emph-table-head.rb +0 -0
  108. data/lib/deplate/mod/latex-styles.rb +7 -4
  109. data/lib/deplate/mod/latex-verbatim-small.rb +0 -0
  110. data/lib/deplate/mod/makefile.rb +23 -7
  111. data/lib/deplate/mod/mark-external-urls.rb +3 -3
  112. data/lib/deplate/mod/markup-1-warn.rb +10 -10
  113. data/lib/deplate/mod/markup-1.rb +0 -0
  114. data/lib/deplate/mod/navbar-png.rb +24 -8
  115. data/lib/deplate/mod/noindent.rb +0 -0
  116. data/lib/deplate/mod/numpara.rb +0 -0
  117. data/lib/deplate/mod/particle-math.rb +4 -4
  118. data/lib/deplate/mod/php-extra.rb +46 -6
  119. data/lib/deplate/mod/pstoedit.rb +0 -0
  120. data/lib/deplate/mod/recode.rb +0 -0
  121. data/lib/deplate/mod/ru_koi8-r.rb +0 -0
  122. data/lib/deplate/mod/smart-dash.rb +26 -0
  123. data/lib/deplate/mod/smiley.rb +69 -7
  124. data/lib/deplate/mod/soffice.rb +0 -0
  125. data/lib/deplate/mod/symbols-latin1.rb +14 -23
  126. data/lib/deplate/mod/symbols-od-utf-8.rb +5 -3
  127. data/lib/deplate/mod/symbols-plain.rb +5 -35
  128. data/lib/deplate/mod/symbols-sgml.rb +8 -9
  129. data/lib/deplate/mod/symbols-utf-8.rb +8 -9
  130. data/lib/deplate/mod/symbols-xml.rb +5 -9
  131. data/lib/deplate/mod/syntax-region-alt.rb +5 -5
  132. data/lib/deplate/mod/utf8.rb +0 -0
  133. data/lib/deplate/mod/validate-html.rb +0 -0
  134. data/lib/deplate/mod/xmlrpc.rb +0 -0
  135. data/lib/deplate/mod/zh-cn-autospace.rb +18 -20
  136. data/lib/deplate/mod/zh-cn.rb +4 -6
  137. data/lib/deplate/nukumi2.rb +71 -0
  138. data/lib/deplate/once-method.rb +0 -0
  139. data/lib/deplate/output.rb +19 -21
  140. data/lib/deplate/particles.rb +178 -116
  141. data/lib/deplate/regions.rb +99 -58
  142. data/lib/deplate/skeletons.rb +122 -0
  143. data/lib/deplate/structured.rb +164 -106
  144. data/lib/deplate/template.rb +67 -43
  145. data/lib/deplate/templates/html-doc.html +0 -0
  146. data/lib/deplate/templates/html-left-tabbar-js.html +0 -0
  147. data/lib/deplate/templates/html-left-tabbar.html +0 -0
  148. data/lib/deplate/templates/html-tabbar-right-pcomments.php +22 -0
  149. data/lib/deplate/templates/html-tabbar-right-step.html +24 -0
  150. data/lib/deplate/templates/html-tabbar-right-table.html +0 -0
  151. data/lib/deplate/templates/html-tabbar-right.html +2 -4
  152. data/lib/deplate/templates/html-tabbar-top.html +0 -9
  153. data/lib/deplate/templates/html-tabbar.html +0 -0
  154. data/lib/deplate/variables.rb +127 -0
  155. data/lib/deplate/wiki-markup.rb +99 -33
  156. data/lib/deplate/xml.rb +18 -18
  157. data/lib/deplate/zh-cn.rb +0 -0
  158. data/lib/ps2ppm.rb +0 -0
  159. data/man/man1/deplate.1 +564 -474
  160. metadata +201 -186
@@ -3,14 +3,15 @@
3
3
  # @Website: http://deplate.sf.net/
4
4
  # @License: GPL (see http://www.gnu.org/licenses/gpl.txt)
5
5
  # @Created: 26-M�r-2004.
6
- # @Last Change: 02-Nov-2005.
7
- # @Revision: 0.3718
6
+ # @Last Change: 07-Jun-2006.
7
+ # @Revision: 0.4285
8
8
 
9
+ require "deplate/abstract-class"
9
10
 
10
11
  class Deplate::DontFormatException < Exception
11
12
  end
12
13
 
13
- Deplate::CaptionDef = Struct.new('DeplateCaptionDef', :elt, :args)
14
+ Deplate::CaptionDef = Struct.new('DeplateCaptionDef', :elt, :args, :source)
14
15
 
15
16
  # Deplate::Elements are text entities at line or paragraph level.
16
17
  class Deplate::Element < Deplate::BaseElement
@@ -18,15 +19,16 @@ class Deplate::Element < Deplate::BaseElement
18
19
 
19
20
  @@accumulate_pre = {}
20
21
  @@accumulate_post = {}
21
-
22
+
22
23
  #### attached labels
23
24
  attr_accessor :label
24
25
  #### an attached caption (for Table etc.)
25
- attr_accessor :caption, :captionOptions
26
+ attr_reader :caption
27
+ attr_accessor :captionOptions
26
28
  #### is this element in one-line format?
27
29
  attr_accessor :multiliner
28
30
  #### end pattern
29
- attr_reader :endRx
31
+ attr_reader :endRx
30
32
  #### the element's level of indentation or whatever
31
33
  attr_accessor :level_heading, :top_heading_idx
32
34
  #### an array of deferred formatting blocks
@@ -37,22 +39,19 @@ class Deplate::Element < Deplate::BaseElement
37
39
  attr_accessor :registered_metadata
38
40
 
39
41
  attr_reader :line_cont
42
+ attr_reader :embedable
40
43
 
41
44
  # class methods & variables
42
45
  class << self
43
- # the regular expression for this class
44
- attr_reader :rx
45
- attr_reader :labelling
46
-
47
46
  def match(text)
48
- return @rx.match(text)
47
+ return self.rx.match(text)
49
48
  end
50
49
 
51
50
  def elements
52
51
  return @@elements
53
52
  end
54
53
 
55
- def is_volatile?(match)
54
+ def is_volatile?(match, input)
56
55
  false
57
56
  end
58
57
 
@@ -60,14 +59,6 @@ class Deplate::Element < Deplate::BaseElement
60
59
  @@elements << c
61
60
  end
62
61
 
63
- def set_labelling(val=true)
64
- @labelling = val
65
- end
66
-
67
- def set_name(name)
68
- @name=name
69
- end
70
-
71
62
  def accumulate(src, array, deplate, text, match, *args)
72
63
  Deplate::Core.log(["New element", self.name, text], :debug)
73
64
  e = self.new(deplate, src, text, match, *args)
@@ -90,10 +81,21 @@ class Deplate::Element < Deplate::BaseElement
90
81
  @@accumulate_post[klass] = hooks
91
82
  end
92
83
 
93
- def do_accumulate(src, array, deplate, *args)
94
- run_accumulation_hooks(@@accumulate_pre[self], src, array, deplate, *args)
95
- accumulate(src, array, deplate, *args)
96
- run_accumulation_hooks(@@accumulate_post[self], src, array, deplate, *args)
84
+ def do_accumulate(src, array, deplate, text, *args)
85
+ run_accumulation_hooks(@@accumulate_pre[self], src, array, deplate, text, *args)
86
+ top = array.last
87
+ accumulate(src, array, deplate, text, *args)
88
+ indentation = text.gsub(/^(\s*).*$/, '\\1')
89
+ shiftwidth = deplate.variables['tabWidth']
90
+ shiftwidth = shiftwidth ? shiftwidth.to_i : 4
91
+ indent_level = indentation.size / shiftwidth
92
+ i = -1
93
+ while ((e = array[i]) and (!top or e != top))
94
+ e.indentation = indentation
95
+ e.indentation_level = indent_level
96
+ i -= 1
97
+ end
98
+ run_accumulation_hooks(@@accumulate_post[self], src, array, deplate, text, *args)
97
99
  end
98
100
 
99
101
  def run_accumulation_hooks(all_hooks, src, array, deplate, *args)
@@ -113,18 +115,20 @@ class Deplate::Element < Deplate::BaseElement
113
115
 
114
116
  def get_date(arg, args)
115
117
  case arg
116
- when "now"
118
+ when 'now', '', nil
117
119
  return Time.new.asctime
118
- when "time"
119
- return Time.new.strftime("%X")
120
- when "today"
121
- return Time.new.strftime("%d. %b %Y")
122
- when "month"
123
- return Time.new.strftime("%B %Y")
124
- when "year"
125
- return Time.new.strftime("%Y")
126
- when "", nil
127
- return ""
120
+ when 'time'
121
+ return Time.new.strftime('%X')
122
+ when 'today'
123
+ return Time.new.strftime('%d. %b %Y')
124
+ when 'month'
125
+ return Time.new.strftime('%B %Y')
126
+ when 'year'
127
+ return Time.new.strftime('%Y')
128
+ when 'none', 'nil'
129
+ return ''
130
+ # when '', nil
131
+ # return ''
128
132
  else
129
133
  return Time.new.strftime(arg)
130
134
  end
@@ -133,19 +137,24 @@ class Deplate::Element < Deplate::BaseElement
133
137
 
134
138
  def initialize(deplate, src, text, match, *args)
135
139
  super(deplate)
140
+ @multiliner = false
136
141
  @source = src
137
142
  @text = text
138
143
  @match = match
139
144
  @endRx = nil
140
145
  @fmx = nil
141
146
  @label = []
142
- @collapse = nil
147
+ @collapse = false
143
148
  @caption = nil
144
149
  @container = nil
145
150
  @line_cont = true
151
+ @embedable = true
146
152
  @postponed_format = []
147
153
  @postponed_preformat = []
148
154
  @registered_metadata = []
155
+
156
+ @level = get_level if respond_to?(:get_level)
157
+ @accum = respond_to?(:get_text) ? [get_text] : []
149
158
 
150
159
  set_instance_top
151
160
 
@@ -177,9 +186,9 @@ class Deplate::Element < Deplate::BaseElement
177
186
  if lab
178
187
  for l in lab.compact
179
188
  # or @deplate.label_aliases.include?(l)
180
- unless @label.include?(l)
189
+ if anyway or !@label.include?(l)
181
190
  @label << l
182
- @deplate.add_label(self, l, @level_as_string, :anyway => anyway)
191
+ @deplate.add_label(self, l, level_as_string, :anyway => anyway)
183
192
  end
184
193
  end
185
194
  end
@@ -210,8 +219,10 @@ class Deplate::Element < Deplate::BaseElement
210
219
  @accum << line
211
220
  end
212
221
 
213
- def to_be_continued?(line)
214
- return @multiliner
222
+ def_abstract :push_match
223
+
224
+ def to_be_continued?(line, klass, match)
225
+ klass.nil? && @multiliner
215
226
  end
216
227
 
217
228
  # compile the accumulated lines in @accum & put the result into @elt
@@ -229,33 +240,42 @@ class Deplate::Element < Deplate::BaseElement
229
240
  if @deplate.options.keep_whitespace
230
241
  return accum.join("\n")
231
242
  else
232
- return accum.join(" ")
243
+ return accum.collect {|l| l.strip}.join(' ')
233
244
  end
234
245
  end
235
246
 
236
247
  def process
237
248
  process_etc
238
249
  process_particles do |e|
239
- if e.kind_of?(String)
240
- ### <+TBD+> This actually is more of an error and shouldn't be
241
- e
242
- else
243
- rv = e.collect do |p|
250
+ printable_particles(e)
251
+ end
252
+ return self
253
+ end
254
+
255
+ def printable_particles(e)
256
+ if e.kind_of?(String)
257
+ ### <+TBD+> This actually is more of an error and shouldn't be
258
+ e
259
+ else
260
+ rv = e.collect do |p|
261
+ case p
262
+ when Array
263
+ printable_particles(p)
264
+ else
244
265
  # <+TBD+> begin
245
266
  # p.container = self
246
267
  p.process
247
268
  # rescue Exception => e
248
- # puts e.backtrace.join("\n")
249
- # raise
269
+ # puts e.backtrace.join("\n")
270
+ # raise
250
271
  # end
251
272
  p.elt
252
273
  end
253
- @deplate.join_particles(rv)
254
274
  end
275
+ @deplate.join_particles(rv)
255
276
  end
256
- return self
257
277
  end
258
-
278
+
259
279
  def print
260
280
  unless @args['swallow']
261
281
  for block in @postponed_preformat
@@ -271,7 +291,18 @@ class Deplate::Element < Deplate::BaseElement
271
291
  def format_current(formatting_method=nil)
272
292
  formatting_method ||= self.class.formatter
273
293
  if formatting_method
274
- elt = format_element(formatting_method, self)
294
+ case formatting_method
295
+ when Array
296
+ for fm in formatting_method
297
+ @elt = format_element(fm, self)
298
+ end
299
+ elt = @elt
300
+ when Symbol
301
+ elt = format_element(formatting_method, self)
302
+ else
303
+ log(['Internal error', 'format_current', self.class.name, formatting_method],
304
+ :error)
305
+ end
275
306
  elsif self.respond_to?(:format_special)
276
307
  elt = format_special
277
308
  else
@@ -308,12 +339,12 @@ class Deplate::Element < Deplate::BaseElement
308
339
 
309
340
  def label_accum(out, formatting_method)
310
341
  fmt = @deplate.formatter
311
- if fmt.label_once.include?(formatting_method)
342
+ if formatting_method and fmt.label_once.include?(formatting_method)
312
343
  l = format_element(:format_label, self, :once)
313
344
  out.unshift(l) unless l.empty?
314
345
  elsif fmt.label_delegate.include?(formatting_method)
315
346
  else
316
- case label_mode || fmt.label_mode
347
+ case self.label_mode || fmt.label_mode
317
348
  when :once
318
349
  l = format_element(:format_label, self, :once)
319
350
  out.unshift(l) unless l.empty?
@@ -323,7 +354,7 @@ class Deplate::Element < Deplate::BaseElement
323
354
  when :after
324
355
  l = format_element(:format_label, self, :after)
325
356
  out.push(l) unless l.empty?
326
- when :delegate, :self
357
+ when :delegate, :self, :none
327
358
  else
328
359
  lb = format_element(:format_label, self, :before)
329
360
  la = format_element(:format_label, self, :after)
@@ -350,18 +381,63 @@ class Deplate::Element < Deplate::BaseElement
350
381
  end
351
382
 
352
383
  def register_caption
353
- log(["Can't attach caption to", self.class.name], :error)
384
+ # log(["Can't attach caption to", self.class.name], :error)
385
+ end
386
+
387
+ def set_caption(captiondef, quiet=false)
388
+ if @caption
389
+ log('Element already has a caption', :error) unless quiet
390
+ else
391
+ self.level_as_string = @deplate.get_current_heading
392
+ captiondef.elt = @deplate.parse_with_source(captiondef.source,
393
+ captiondef.elt,
394
+ false)
395
+ @caption = captiondef
396
+ if respond_to?(:register_caption)
397
+ register_caption
398
+ end
399
+ end
354
400
  end
355
401
 
356
402
  def to_plain_text
357
403
  @accum.join("\n")
358
404
  end
405
+
406
+ def element_caption
407
+ @caption ? @caption.elt : elt_as_caption
408
+ end
359
409
 
410
+ def elt_as_caption
411
+ @elt
412
+ end
413
+
414
+ def register_in_listing(list, args={})
415
+ @deplate.options.listings.push(list, self)
416
+
417
+ en = @deplate.options.listings.get_prop(list, 'entity') || list
418
+ # nn = @deplate.get_numbering_mode(en, 2)
419
+ # nn = nil if nn == 0
420
+ cn = @deplate.options.listings.get_prop(list, 'counter') || list
421
+ # self.level_as_string = @deplate.options.counters.increase(cn, :to_s => true, :level => nn)
422
+ self.level_as_string = @deplate.options.counters.increase(cn, :to_s => true)
423
+ prefix = @deplate.options.listings.get_prop(list, 'prefix') || list
424
+ label = @deplate.elt_label(prefix, level_as_string)
425
+ @label << label
426
+ @args[:id] ||= label
427
+
428
+ @registered_metadata << @deplate.get_metadata(@source,
429
+ 'type' => list,
430
+ 'name' => element_caption,
431
+ 'id' => get_id
432
+ )
433
+ end
434
+
360
435
  protected
361
436
  def process_etc
362
- if !@caption and @args["caption"]
363
- caption = @deplate.parse(self, @args["caption"])
364
- @caption = Deplate::CaptionDef.new(caption, @args)
437
+ if !@caption and @args['caption']
438
+ log(['DEBUG: Too late: Add caption', @args['caption']], :error)
439
+ caption = @deplate.parse(self, @args['caption'])
440
+ set_caption(Deplate::CaptionDef.new(caption, @args, @source))
365
441
  end
366
442
  if defined?(@caption) && @caption
367
443
  elt = @caption.elt.collect {|p| p.process; p.elt}
@@ -376,19 +452,32 @@ class Deplate::Element < Deplate::BaseElement
376
452
  end
377
453
 
378
454
  def unify_props(other)
379
- put_label(other.label, true)
455
+ if !level_as_string and other.level_as_string
456
+ self.level_as_string = other.level_as_string
457
+ end
458
+ l = [other.args['id'], other.args[:id], *other.label]
459
+ l.compact!
460
+ l.uniq!
461
+ put_label(l, true)
380
462
  @args.update(other.args)
463
+ # p "DBG", self.class, other.class, @args.keys, other.args.keys
381
464
  @level ||= other.level
382
- @caption ||= other.caption
383
- @captionOptions ||= other.captionOptions
384
465
  @source.begin ||= other.source.begin
385
466
  @source.end = other.source.end if other.source.end
467
+ @indentation ||= other.indentation
468
+ @indentation_level ||= other.indentation_level
469
+ @captionOptions ||= other.captionOptions
470
+ if !@caption
471
+ cap = @args['caption']
472
+ if cap
473
+ set_caption(Deplate::CaptionDef.new(cap, @args, @source))
474
+ elsif other.caption
475
+ @caption = other.caption
476
+ end
477
+ end
386
478
  if other.styles
387
479
  update_styles(other.styles)
388
480
  end
389
- if !level_as_string and other.level_as_string
390
- self.level_as_string = other.level_as_string
391
- end
392
481
  end
393
482
 
394
483
  def unify_elt(other)
@@ -401,7 +490,8 @@ class Deplate::Element < Deplate::BaseElement
401
490
 
402
491
  def container=(element)
403
492
  @container = element
404
- @args = element.args
493
+ # @args = element.args
494
+ @args.update(element.args)
405
495
  @postponed_format = element.postponed_format
406
496
  @postponed_preformat = element.postponed_preformat
407
497
  end
@@ -433,86 +523,305 @@ class Deplate::Element < Deplate::BaseElement
433
523
  if @elt
434
524
  @elt = (@elt.collect(&block)).join
435
525
  else
436
- log(["Internal error: no @elt", self.class], :error)
526
+ log(["Internal error: No @elt", self.class], :error)
437
527
  @elt = ""
438
528
  end
439
529
  end
440
530
  alias process_elements process_particles
441
531
 
442
532
  def register_figure
443
- @deplate.table_of_figures << self
444
- @deplate.current_figure += 1
445
- @level_as_string = [@deplate.current_heading[0], @deplate.current_figure].join(".")
446
- @label << @deplate.elt_label("fig", @level_as_string)
533
+ register_in_listing('lof')
447
534
  end
448
535
 
449
536
  def register_table
450
- @deplate.table_of_tables << self
451
- @deplate.current_table += 1
452
- @level_as_string = [@deplate.current_heading[0], @deplate.current_table].join(".")
453
- @label << @deplate.elt_label("tab", @level_as_string)
537
+ register_in_listing('lot')
454
538
  end
455
539
  end
456
540
 
541
+
457
542
  class Deplate::Element::Comment < Deplate::Element
458
543
  register_element
459
- set_rx(/^\s*(%+)[ \t]*(.*)$/)
460
-
544
+ set_rx(/^\s*(%+)[[:blank:]]*(.*)$/)
545
+ def_get :level, lambda {@match[1].size}
546
+ def_get :text, 2
547
+
461
548
  # disappear
462
549
  def self.accumulate(src, array, deplate, text, match)
463
550
  Deplate::Core.log(["Hide comment", text], :debug)
464
551
  end
465
552
 
466
553
  def setup
467
- @multiliner = false
554
+ @collapse = true
555
+ end
556
+ end
557
+
558
+
559
+ class Deplate::Element::Note < Deplate::Element
560
+ register_element
561
+ set_formatter :format_note
562
+ set_rx(/^([[:blank:]]+)([#!?+]{3,3})\s+(.*)$/)
563
+ def_get :level, lambda {expand_tab(@match[1]).size}
564
+ def_get :marker, lambda {@match[2][0..0]}
565
+ def_get :text, 3
566
+
567
+ attr_reader :marker
568
+
569
+ def setup
570
+ @multiliner = true
571
+ @marker = get_marker
572
+ end
573
+
574
+ def to_be_continued?(line, klass, match)
575
+ indent = get_indent(line).size
576
+ return indent >= @level
577
+ end
578
+ end
579
+
580
+
581
+ Deplate::ListItem = Struct.new('DeplateListItem', :item, :body, :listtype, :type,
582
+ :level, :max, :explicit, :label, :style, :opts,
583
+ :preformatted)
584
+
585
+ class Deplate::List < Deplate::Element
586
+ set_formatter :format_list
587
+ class_attribute :listtype
588
+ # class_attribute :not_embedable, []
589
+
590
+ def_get :opts
591
+ def_get :level, lambda {expand_tab(@match[2]).size}
592
+ def_get :level_max, lambda {expand_tab(@match[1]).size}
593
+ def_get :item, 3
594
+ def_get :text, 4
595
+
596
+ attr_reader :levelRange, :item, :oitem
597
+
598
+ def setup
599
+ @multiliner = true
468
600
  @collapse = true
469
- @level = get_level
470
- @accum = [get_text]
601
+ @itemopts = get_opts
602
+ if self.instance_of?(Deplate::List::Description)
603
+ @levelMax = @level + (@deplate.variables["tabwidth"] || 4)
604
+ else
605
+ @levelMax = get_level_max
606
+ end
607
+ @oitem = @item = get_item
471
608
  end
472
609
 
473
- def get_level
474
- @match[1].size
610
+ def collapsable?(other)
611
+ if other.kind_of?(Deplate::List)
612
+ return true
613
+ elsif other.kind_of?(Deplate::Element::Paragraph)
614
+ return @elt.find do |i|
615
+ continuation_level_ok?(other.level, i.level, i.max)
616
+ end
617
+ elsif other.kind_of?(Deplate::Element::Whitespace)
618
+ return true
619
+ elsif indentation_level_ok?(other) and other.embedable
620
+ # and !self.class.not_embedable.include?(other.class)
621
+ return true
622
+ else
623
+ return false
624
+ end
625
+ end
626
+
627
+ def unify_now(other)
628
+ if other.kind_of?(Deplate::Element::Paragraph)
629
+ @elt << Deplate::ListItem.new([], other.elt.flatten, @elt.last.listtype,
630
+ "Paragraph", other.level, other.level,
631
+ other.is_explicit?, other.label,
632
+ other.class.name)
633
+ other.label = []
634
+ unify_props(other)
635
+ elsif other.kind_of?(Deplate::Element::Whitespace)
636
+ elsif other.kind_of?(Deplate::List)
637
+ super
638
+ else
639
+ e = @elt.last
640
+ unless e.type == 'Container' and e.body.unify(other)
641
+ # unify_props(other)
642
+ l = other.level
643
+ unless l
644
+ l = e.level if e
645
+ l ||= level
646
+ end
647
+ @elt << Deplate::ListItem.new([], other, @elt.last.listtype,
648
+ "Container", l, l,
649
+ other.is_explicit?, other.label,
650
+ other.class.name)
651
+ end
652
+ end
475
653
  end
476
654
 
477
- def get_text
478
- @match[2]
655
+ def to_be_continued?(line, klass, match)
656
+ linelevel = get_indent(line).size
657
+ klass.nil? && continuation_level_ok?(linelevel, @level, @levelMax)
658
+ end
659
+
660
+ def continuation_level_ok?(otherLevel, thisLevel, thisMaxLevel)
661
+ # return thisLevel <= otherLevel && otherLevel <= thisMaxLevel
662
+ return thisLevel <= otherLevel
663
+ end
664
+
665
+ def indentation_level_ok?(other)
666
+ return indentation <= other.indentation
667
+ end
668
+
669
+ def finish
670
+ finish_item
671
+ finish_elt
672
+ @label = []
673
+ return self
674
+ end
675
+
676
+ def finish_item
677
+ @item = @deplate.parse(self, @item)
678
+ end
679
+
680
+ def finish_elt
681
+ accum = @deplate.parse(self, @accum.join(" "))
682
+ type = self.class.listtype
683
+ @elt = [Deplate::ListItem.new(@item, accum, type, type, @level,
684
+ @levelMax, is_explicit?, @label,
685
+ type, @itemopts)]
686
+ end
687
+
688
+ def process_particles(&block)
689
+ @elt.each do |e|
690
+ e.item = block.call(e.item)
691
+ case e.type
692
+ when 'Container'
693
+ # <+TBD+> This doesn't work for all elements (e.g.
694
+ # volatile elements)
695
+ # e.body.process_particles(&block)
696
+ e.body = e.body.process
697
+ else
698
+ e.body = block.call(e.body)
699
+ end
700
+ end
701
+ end
702
+ end
703
+
704
+
705
+ class Deplate::List::Ordered < Deplate::List
706
+ register_element
707
+ set_rx(/^(([[:blank:]]+)([0-9]+\.|[#\@?]\.?|[a-zA-Z?]\.)[[:blank:]]+)(.+)$/)
708
+ self.listtype = "Ordered"
709
+
710
+ def is_explicit?
711
+ if @oitem =~ /^[0-9a-zA-Z]+\.$/
712
+ return true
713
+ else
714
+ return false
715
+ end
716
+ end
717
+ end
718
+
719
+
720
+ class Deplate::List::Itemize < Deplate::List
721
+ register_element
722
+ set_rx(/^(([[:blank:]]+)([-�+*])[[:blank:]]+)(.+)$/)
723
+ self.listtype = "Itemize"
724
+ end
725
+
726
+
727
+ class Deplate::List::Description < Deplate::List
728
+ register_element
729
+ set_rx(/^(([[:blank:]]+)(.+?)[[:blank:]]+::[[:blank:]])(.*)$/)
730
+ self.listtype = "Description"
731
+ end
732
+
733
+
734
+ class Deplate::List::Task < Deplate::List
735
+ register_element
736
+ set_rx(/^(([[:blank:]]+)#(([0-9][A-Z]?|[A-Z][0-9]?)[[:blank:]]+(_|x|x?[0-9-]+%?)|(_|x|x?[0-9-]+%?)[[:blank:]]+([0-9][A-Z]?|[A-Z][0-9]?)))[[:blank:]]+(.*)$/)
737
+ self.listtype = 'Task'
738
+ def_get :item, lambda {[@itemopts[:priority], @itemopts[:category]].join}
739
+ def_get :text, 8
740
+
741
+ attr_accessor :task
742
+
743
+ def finish_item
744
+ # @item = @deplate.parse(self, @item)
745
+ end
746
+
747
+ def get_opts
748
+ if defined?(@task) and @task
749
+ return @task
750
+ end
751
+
752
+ item = @match[3]
753
+ rv = {}
754
+ type, due = item.split(/\s+/)
755
+ if type =~ /^(_|x|x?[\d-]+%?)$/
756
+ type, due = due, type
757
+ end
758
+
759
+ if type =~ /^([0-9])([A-Z]?)$/
760
+ rv[:priority] = $1
761
+ rv[:category] = $2 unless $2.empty?
762
+ elsif type =~ /^([A-Z])([0-9]?)$/
763
+ rv[:priority] = $2
764
+ rv[:category] = $1 unless $1.empty?
765
+ else
766
+ log(['Invalid task item', item], :error)
767
+ end
768
+
769
+ if due =~ /^\s*x/
770
+ rv[:done] = true
771
+ end
772
+ if due =~ /^\s*x?([0-9-]+%?)/
773
+ # rv[:due] = ParseDate::parsedate($1, true)
774
+ rv[:due] = $1
775
+ end
776
+
777
+ rv
479
778
  end
480
779
  end
481
780
 
781
+
482
782
  class Deplate::Element::Region < Deplate::Element
483
783
  register_element
484
784
  set_rx(/^(\s*)#([A-Z]([a-z][A-Za-z]*)?)\b(.*)(\<\<(.+)|:)\s*$/)
485
- @rxi_name = 2
486
- @rxi_args = 4
487
- @rxi_endrx = 6
488
- @rxi_indent = 1
489
785
 
490
- attr_reader :specified, :regNote, :name
786
+ class_attribute :rxi_indent, 1
787
+ class_attribute :rxi_name, 2
788
+ class_attribute :rxi_args, 4
789
+ class_attribute :rxi_endrx, 6
491
790
 
492
- class << self
493
- attr_reader :rxi_name, :rxi_args, :rxi_endrx, :rxi_indent
791
+ def_get :name, lambda {@match[self.class.rxi_name]}
792
+ def_get :args, lambda {@match[self.class.rxi_args]}
793
+ def_get :indent, lambda {@match[self.class.rxi_indent]}
794
+ def_get :endrx, lambda {
795
+ i = self.class.rxi_endrx
796
+ if @match[i - 1] == ":"
797
+ /^(#{get_indent})?#End\s*$/
798
+ else
799
+ erx = @match[i]
800
+ if erx
801
+ /^(#{get_indent})?#{Regexp.escape(erx)}\s*$/
802
+ end
803
+ end
804
+ }
494
805
 
806
+ class << self
495
807
  def pseudo_match(args)
496
- [
497
- nil,
498
- args[:indent], #1
499
- args[:name], #2
500
- nil, #3
501
- args[:args], #4
502
- nil, #5
503
- args[:endrx], #6
504
- ]
808
+ rv = []
809
+ rv[rxi_indent] = args[:indent]
810
+ rv[rxi_args] = args[:args]
811
+ rv[rxi_name] = args[:name]
812
+ rv[rxi_endrx] = args[:endrx]
813
+ rv
505
814
  end
506
815
  end
816
+
817
+ attr_reader :specified, :regNote, :name
507
818
 
508
819
  def setup(name=nil)
509
820
  @multiliner = true
510
821
  @endRx = get_endrx
511
- @accum = []
512
822
  @name = name || get_name
513
823
  begin
514
824
  @args, @regNote = @deplate.input.parse_args(get_args)
515
- @collapse = false
516
825
  region = @deplate.input.regions[@name]
517
826
  unless region
518
827
  if @deplate.formatter.matches?(@name)
@@ -529,96 +838,37 @@ class Deplate::Element::Region < Deplate::Element
529
838
  region = Deplate::Regions::UNKNOWN
530
839
  end
531
840
  @specified = region.new(@deplate, @source, @text, @match, self)
532
- @specified.indent = get_indent
533
841
  @line_cont = region.line_cont
534
842
  # @deplate.register_id(@args, @specified)
535
843
  @deplate.register_id(@args, self)
536
844
  end
537
845
 
538
- def get_name
539
- @match[self.class.rxi_name]
540
- end
541
-
542
- def get_args
543
- @match[self.class.rxi_args]
544
- end
545
-
546
- def get_endrx
547
- i = self.class.rxi_endrx
548
- if @match[i - 1] == ":"
549
- /^(#{get_indent})?#End\s*$/
550
- else
551
- erx = @match[i]
552
- if erx
553
- /^(#{get_indent})?#{Regexp.escape(erx)}\s*$/
554
- end
555
- end
556
- end
557
-
558
- def get_indent
559
- @match[self.class.rxi_indent]
560
- end
561
-
562
846
  def finish
847
+ update_region
563
848
  return @specified.finish
564
849
  end
565
- end
566
850
 
567
- class Deplate::Element::Clip < Deplate::BaseElement
568
- attr_reader :is_template
569
- # attr_accessor :prototype
570
-
571
- def initialize(acc, deplate, source)
572
- super(deplate)
573
- @acc = acc
574
- @elt = nil
575
- @source = source
576
- @invoker = nil
577
- @is_template = false
578
- @prototype = nil
851
+ def finished?
852
+ @specified.finished?
579
853
  end
580
854
 
581
- def process
582
- unless @prototype
583
- @prototype = @acc.first
584
- @prototype.args.update(@args) if @prototype
585
- end
586
- unless @elt
587
- @elt = @acc.collect{|p| p.process; p.elt}
588
- @elt = @deplate.join_particles(@elt)
589
- end
590
- return self
591
- end
592
-
593
- def format_clip(invoker, expected)
594
- unless @elt
595
- log("We shouldn't be here. If you can track down when this happens, please send an example to the author.", :anyway)
596
- process
597
- end
598
- if @elt
599
- @prototype.match_expected(expected, invoker)
600
- else
601
- log("Clip is nil, which is quite strange and most likely deplate's error but as I haven't had the time yet to track this down this error still occurs.", :error)
602
- end
603
- @elt
604
- end
605
-
606
- def print
607
- output(@elt)
855
+ def update_region
856
+ @specified.indentation = indentation
857
+ @specified.indent = get_indent
608
858
  end
609
859
  end
610
860
 
861
+
611
862
  class Deplate::Element::Command < Deplate::Element
612
863
  register_element
613
- set_rx /^\s*#([A-Z]+)((\s[^:]+)?(:\s*(.+?)\s*)?)$/
864
+ set_rx(/^\s*#([A-Z]+)((\s[^:]+)?(:\s*(.+?)\s*)?)$/)
614
865
  attr :name
615
866
 
616
867
  class << self
617
- def is_volatile?(match)
618
- case match[1]
619
- when "IDX", "NOIDX", "DONTIDX", "AUTOIDX", "DOC", "OPT", "AUTHOR",
620
- "TITLE", "DATE", "ABBREV"
621
- true
868
+ def is_volatile?(match, input)
869
+ cmd = input.commands[match[1]]
870
+ if cmd
871
+ cmd.volatile
622
872
  else
623
873
  false
624
874
  end
@@ -626,15 +876,15 @@ class Deplate::Element::Command < Deplate::Element
626
876
 
627
877
  def accumulate(src, array, deplate, text, match)
628
878
  cmd = match[1]
629
- Deplate::Core.log(["Command", cmd, text], :debug)
879
+ Deplate::Core.log(['Command', cmd, text], :debug)
630
880
  begin
631
881
  args, text = deplate.input.parse_args(match[2])
632
882
  case cmd
633
- when "IF"
883
+ when 'IF'
634
884
  deplate.switches << !check_switch(deplate, text)
635
- when "ELSEIF"
885
+ when 'ELSEIF'
636
886
  if deplate.switches.empty?
637
- Deplate::Core.log(["ELSEIF without IF", cmd, match[0]], :error, src)
887
+ Deplate::Core.log(['ELSEIF without IF', cmd, match[0]], :error, src)
638
888
  else
639
889
  case deplate.switches.last
640
890
  when :skip
@@ -646,9 +896,9 @@ class Deplate::Element::Command < Deplate::Element
646
896
  deplate.switches << :skip
647
897
  end
648
898
  end
649
- when "ELSE"
899
+ when 'ELSE'
650
900
  if deplate.switches.empty?
651
- Deplate::Core.log(["ELSE without IF", cmd, match[0]], :error, src)
901
+ Deplate::Core.log(['ELSE without IF', cmd, match[0]], :error, src)
652
902
  else
653
903
  case deplate.switches.last
654
904
  when :skip
@@ -659,9 +909,9 @@ class Deplate::Element::Command < Deplate::Element
659
909
  deplate.switches << :skip
660
910
  end
661
911
  end
662
- when "ENDIF"
912
+ when 'ENDIF'
663
913
  if deplate.switches.empty?
664
- Deplate::Core.log(["ENDIF without IF", cmd, match[0]], :error, src)
914
+ Deplate::Core.log(['ENDIF without IF', cmd, match[0]], :error, src)
665
915
  else
666
916
  deplate.switches.pop
667
917
  end
@@ -671,12 +921,12 @@ class Deplate::Element::Command < Deplate::Element
671
921
  if cc
672
922
  cc.do_accumulate(src, array, deplate, text, match, args, cmd)
673
923
  else
674
- Deplate::Core.log(["Unknown command", cmd, match[0]], :error, src)
924
+ Deplate::Core.log(['Unknown command', cmd, match[0]], :error, src)
675
925
  end
676
926
  end
677
927
  end
678
928
  rescue Deplate::DontFormatException
679
- Deplate::Core.log(["Dropping", match[0]], nil, src)
929
+ Deplate::Core.log(['Dropping', match[0]], nil, src)
680
930
  end
681
931
  end
682
932
 
@@ -694,24 +944,38 @@ class Deplate::Element::Command < Deplate::Element
694
944
  end
695
945
  val = m[4]
696
946
  op = val ? m[3] : m[2]
697
- if op == "!"
698
- return get_var_or_option(deplate, var)
947
+ case val
948
+ when 'true'
949
+ val = true
950
+ when 'false'
951
+ val = false
952
+ when nil
953
+ else
954
+ val = Deplate::Core.remove_backslashes(val.strip)
955
+ end
956
+ if op == '!'
957
+ switch = get_var_or_option(deplate, var)
958
+ if negate
959
+ return !switch
960
+ else
961
+ return switch
962
+ end
699
963
  else
700
964
  case op
701
- when "==", "!="
965
+ when '==', '!='
702
966
  compare = Proc.new {|a, b| a == b}
703
- when "=~", "!=~"
967
+ when '=~', '!=~'
704
968
  compare = Proc.new {|a, b| a =~ Regexp.new(b)}
705
969
  else
706
- raise "Internal error"
970
+ raise 'Internal error'
707
971
  end
708
972
  case var
709
- when "fmt"
973
+ when 'fmt'
710
974
  switch = compare.call(deplate.formatter.formatter_name, val)
711
975
  else
712
976
  switch = compare.call(get_var_or_option(deplate, var), val)
713
977
  end
714
- if op[0..0] == "!" or negate
978
+ if op[0..0] == '!' or negate
715
979
  return !switch
716
980
  else
717
981
  return switch
@@ -720,7 +984,7 @@ class Deplate::Element::Command < Deplate::Element
720
984
  elsif text =~ /^\w+$/
721
985
  return get_var_or_option(deplate, text)
722
986
  else
723
- Deplate::Core.log(["Malformed condition", text], :error)
987
+ Deplate::Core.log(['Malformed condition', text], :error)
724
988
  return true
725
989
  end
726
990
  end
@@ -731,181 +995,21 @@ class Deplate::Element::Command < Deplate::Element
731
995
  elsif deplate.options.allow.include?(':') && key =~ /^:(.*)$/
732
996
  return deplate.options.send($1)
733
997
  end
734
- Deplate::Core.log(["Unknown variable or option", key])
998
+ Deplate::Core.log(['Unknown variable or option', key])
735
999
  return nil
736
1000
  end
737
1001
  end
738
1002
  end
739
1003
 
740
- class Deplate::Element::Note < Deplate::Element
741
- register_element
742
- set_formatter :format_note
743
- set_rx /^([ \t]+)([#!?+]{3,3})\s+(.*)$/
744
-
745
- attr_reader :marker
746
-
747
- def setup
748
- @multiliner = true
749
- @collapse = false
750
- @level = get_level
751
- @marker = get_marker
752
- @accum = [get_text]
753
- end
754
-
755
- def to_be_continued?(line)
756
- indent = get_indent(line).size
757
- return indent >= @level
758
- end
759
-
760
- def get_level
761
- expand_tab(@match[1]).size
762
- end
763
-
764
- def get_marker
765
- @match[2][0..0]
766
- end
767
-
768
- def get_text
769
- @match[3]
770
- end
771
- end
772
-
773
- Deplate::ListItem = Struct.new("DeplateListItem", :item, :body, :listtype, :type,
774
- :level, :max, :explicit, :label, :style)
775
-
776
- class Deplate::List < Deplate::Element
777
- set_formatter :format_list
778
- set_labelling
779
-
780
- attr_reader :levelRange, :item, :oitem
781
-
782
- class << self
783
- attr :name
784
- end
785
-
786
- def setup
787
- @multiliner = true
788
- @collapse = true
789
- @level = get_level
790
- if self.instance_of?(Deplate::List::Description)
791
- @levelMax = @level + (@deplate.variables["tabwidth"] || 4)
792
- else
793
- @levelMax = get_level_max
794
- end
795
- @oitem = @item = get_item
796
- @accum = [get_text]
797
- end
798
-
799
- def get_level
800
- expand_tab(@match[2]).size
801
- end
802
-
803
- def get_level_max
804
- expand_tab(@match[1]).size
805
- end
806
-
807
- def get_item
808
- @match[3]
809
- end
810
-
811
- def get_text
812
- @match[4]
813
- end
814
-
815
- def collapsable?(other)
816
- if other.kind_of?(Deplate::List)
817
- return true
818
- elsif other.kind_of?(Deplate::Element::Paragraph)
819
- return @elt.find do |i|
820
- continuation_level_ok?(other.level, i.level, i.max)
821
- end
822
- elsif other.kind_of?(Deplate::Element::Whitespace)
823
- return true
824
- else
825
- return false
826
- end
827
- end
828
-
829
- def unify_now(other)
830
- if other.kind_of?(Deplate::Element::Paragraph)
831
- @elt << Deplate::ListItem.new([], other.elt.flatten, @elt.last.listtype,
832
- "Paragraph", other.level, other.level,
833
- other.is_explicit?, other.label)
834
- other.label = []
835
- unify_props(other)
836
- elsif other.kind_of?(Deplate::Element::Whitespace)
837
- else
838
- super
839
- end
840
- end
841
-
842
- def to_be_continued?(line)
843
- linelevel = get_indent(line).size
844
- return continuation_level_ok?(linelevel, @level, @levelMax)
845
- end
846
-
847
- def continuation_level_ok?(otherLevel, thisLevel, thisMaxLevel)
848
- # return thisLevel <= otherLevel && otherLevel <= thisMaxLevel
849
- return thisLevel <= otherLevel
850
- end
851
-
852
- def finish
853
- @item = @deplate.parse(self, @item)
854
- accum = @deplate.parse(self, @accum.join(" "))
855
- name = self.class.name
856
- @elt = [Deplate::ListItem.new(@item, accum, name, name, @level,
857
- @levelMax, is_explicit?, @label)]
858
- @label = []
859
- return self
860
- end
861
-
862
- def process_particles(&block)
863
- @elt.each do |e|
864
- e.item = block.call(e.item)
865
- e.body = block.call(e.body)
866
- end
867
- end
868
- end
869
-
870
- class Deplate::List::Numbered < Deplate::List
871
- register_element
872
- set_formatter :format_list
873
- set_rx /^(([ \t]+)([0-9]+\.|[#\@?]\.?|[a-zA-Z?]\.)[ \t]+)(.+)$/
874
- set_name "Numbered"
875
-
876
- def is_explicit?
877
- if @oitem =~ /^[0-9a-zA-Z]+\.$/
878
- return true
879
- else
880
- return false
881
- end
882
- end
883
- end
884
-
885
- class Deplate::List::Itemize < Deplate::List
886
- register_element
887
- set_formatter :format_list
888
- set_rx /^(([ \t]+)([-�+*])[ \t]+)(.+)$/
889
- set_name "Itemize"
890
- end
891
-
892
- class Deplate::List::Description < Deplate::List
893
- register_element
894
- set_formatter :format_list
895
- set_rx /^(([ \t]+)(.+?)[ \t]+::[ \t])(.*)$/
896
- set_name "Description"
897
- end
898
-
899
-
900
1004
 
901
1005
  class Deplate::Element::Table < Deplate::Element
902
1006
  register_element
903
1007
  set_formatter :format_table
904
- set_rx /^(\|\|?)([ \t]+.+[ \t]+)\1$/
1008
+ set_rx(/^\s*(\|\|?)([[:blank:]]+.+[[:blank:]]+)\1\s*$/)
905
1009
 
906
- TableRow = Struct.new("DeplateTableRow", :high, :cols, :head, :foot, :is_ruler,
1010
+ TableRow = Struct.new('DeplateTableRow', :high, :cols, :head, :foot, :is_ruler,
907
1011
  :from_top, :from_bottom)
908
- TableCell = Struct.new("DeplateTableCell", :cell,
1012
+ TableCell = Struct.new('DeplateTableCell', :cell,
909
1013
  :x, :y, :from_right, :from_bottom,
910
1014
  :high, :head, :foot,
911
1015
  :span_x, :span_y, :row)
@@ -914,7 +1018,7 @@ class Deplate::Element::Table < Deplate::Element
914
1018
  :contains_footnotes, :printed_header
915
1019
 
916
1020
  def setup
917
- @multiliner = false
1021
+ @multiliner = :match
918
1022
  @collapse = true
919
1023
  high = get_highlight
920
1024
  cols = get_cols
@@ -925,12 +1029,23 @@ class Deplate::Element::Table < Deplate::Element
925
1029
  @contains_footnotes = false
926
1030
  end
927
1031
 
928
- def get_highlight
929
- @match[1].size == 2
1032
+ def to_be_continued?(line, klass, match)
1033
+ klass == self.class
1034
+ end
1035
+
1036
+ def push_match(match)
1037
+ high = get_highlight(match)
1038
+ cols = get_cols(match)
1039
+ cols.collect! {|t| t.strip}
1040
+ @accum << TableRow.new(high, cols)
1041
+ end
1042
+
1043
+ def get_highlight(match=@match)
1044
+ match[1].size == 2
930
1045
  end
931
1046
 
932
- def get_cols
933
- @match[2].split(/[ \t]\|\|?[ \t]/)
1047
+ def get_cols(match=@match)
1048
+ match[2].split(/[[:blank:]]\|\|?[[:blank:]]/)
934
1049
  end
935
1050
 
936
1051
  def unify_now(other)
@@ -1078,18 +1193,25 @@ class Deplate::Element::Table < Deplate::Element
1078
1193
  end
1079
1194
  end
1080
1195
 
1196
+ def unify_props(other)
1197
+ super
1198
+ end
1199
+
1081
1200
  def register_caption
1082
1201
  register_table
1083
1202
  end
1084
1203
  end
1085
1204
 
1205
+
1086
1206
  class Deplate::Element::Heading < Deplate::Element
1087
1207
  attr_accessor :first_top, :last_top, :top_index, :abstract
1088
1208
  attr_writer :destination
1089
1209
 
1090
1210
  register_element
1091
1211
  set_formatter :format_heading
1092
- set_rx /^(\*+)[ \t]+(.*?)$/
1212
+ set_rx(/^(\*+)[[:blank:]]+(.*?)$/)
1213
+ def_get :level, lambda {@match[1].size}
1214
+ def_get :text, 2
1093
1215
 
1094
1216
  class << self
1095
1217
  def accumulate(src, array, deplate, text, match)
@@ -1109,15 +1231,10 @@ class Deplate::Element::Heading < Deplate::Element
1109
1231
  end
1110
1232
 
1111
1233
  def set_instance_top
1112
- @level = get_level
1113
1234
  ls = @deplate.variables["levelshift"]
1114
1235
  if ls
1115
1236
  @level += ls.to_i
1116
1237
  end
1117
- if is_top_heading?
1118
- @deplate.current_table = 0
1119
- @deplate.current_figure = 0
1120
- end
1121
1238
  @deplate.increase_current_heading(@level)
1122
1239
  super
1123
1240
  end
@@ -1125,28 +1242,18 @@ class Deplate::Element::Heading < Deplate::Element
1125
1242
  def setup
1126
1243
  @first_top = false
1127
1244
  @last_top = false
1128
- @multiliner = false
1129
- @collapse = false
1130
1245
  @abstract = nil
1131
- @accum = [get_text]
1132
- @args[:id] = @deplate.elt_label("hd", @level_as_string)
1133
1246
  @destination = @deplate.output.destination
1134
1247
  @top_index = [0, 0]
1135
- @deplate.table_of_contents << self
1248
+ @args[:id] = @deplate.elt_label('hd', level_as_string)
1249
+ @deplate.options.listings.push('toc', self)
1250
+ # register_in_listing('toc')
1136
1251
  @deplate.headings[@level_heading] = self
1137
1252
  update_args
1138
1253
  end
1139
1254
 
1140
- def get_level
1141
- @match[1].size
1142
- end
1143
-
1144
- def get_text
1145
- @match[2]
1146
- end
1147
-
1148
1255
  def is_top_heading?
1149
- @level == 1
1256
+ @level <= @deplate.options.split_level
1150
1257
  end
1151
1258
 
1152
1259
  def update_options(args)
@@ -1166,7 +1273,24 @@ class Deplate::Element::Heading < Deplate::Element
1166
1273
  end
1167
1274
 
1168
1275
  def process
1169
- rv = super
1276
+ rv = super
1277
+ url = @args['url']
1278
+ hh = @deplate.variables['hyperHeading']
1279
+ if url and hh
1280
+ if hh == 'full'
1281
+ # <+TBD+> Extract invalid tags and move them add them to the
1282
+ # end of the result (but this has to be done by the
1283
+ # formatter, so well ...)
1284
+ rv.elt = @deplate.formatter.format_particle(:format_url, rv, rv.elt, url, nil)
1285
+ else
1286
+ button = @deplate.variables['hyperHeadingButton'] ||
1287
+ @deplate.parse_and_format_without_wikinames(self,
1288
+ # '{img alt="=>": hyperHeading}',
1289
+ '=>',
1290
+ false)
1291
+ rv.elt += @deplate.formatter.format_particle(:format_url, rv, button, url, nil)
1292
+ end
1293
+ end
1170
1294
  if rv.is_top_heading?
1171
1295
  @deplate.options.heading_names[@top_heading_idx] = rv.elt
1172
1296
  if @deplate.variables['subToC']
@@ -1174,7 +1298,7 @@ class Deplate::Element::Heading < Deplate::Element
1174
1298
  match = []
1175
1299
  toc = Deplate::Command::LIST.new(@deplate, @source, 'toc', match, args, 'LIST')
1176
1300
  toc.level = @level
1177
- toc.level_as_string = @level_as_string
1301
+ toc.level_as_string = level_as_string
1178
1302
  rv = [rv, toc.finish.process].compact.flatten
1179
1303
  end
1180
1304
  end
@@ -1197,49 +1321,48 @@ class Deplate::Element::Heading < Deplate::Element
1197
1321
  end
1198
1322
 
1199
1323
  def description
1200
- if @args['shortcaption']
1201
- @args['shortcaption']
1202
- elsif @caption
1203
- @caption.elt
1204
- else
1205
- @elt
1206
- end
1324
+ desc = if @args['shortcaption']
1325
+ @args['shortcaption']
1326
+ elsif @caption
1327
+ @caption.elt
1328
+ else
1329
+ @elt
1330
+ end
1331
+ printable_particles(desc)
1207
1332
  end
1208
1333
 
1209
1334
  def register_caption
1210
- @deplate.table_of_contents << self
1211
- @label << @deplate.elt_label('hd', @level_as_string)
1335
+ @deplate.options.listings.push('toc', self)
1336
+ @label << @deplate.elt_label('hd', level_as_string)
1212
1337
  end
1213
1338
  end
1214
1339
 
1340
+
1215
1341
  class Deplate::Element::Break < Deplate::Element
1216
1342
  register_element
1217
1343
  set_formatter :format_break
1218
- set_rx /^\s*-{2,}8\<-{2,}\s*$/
1219
-
1220
- def setup
1221
- @multiliner = false
1222
- @collapse = false
1223
- @accum = []
1224
- end
1344
+ set_rx(/^\s*-{2,}8\<-{2,}\s*$/)
1225
1345
  end
1226
1346
 
1347
+
1227
1348
  # An anchor is not a proper element, but is attached to the preceding one
1228
1349
  class Deplate::Element::Anchor < Deplate::Element
1229
1350
  register_element
1230
1351
  set_formatter :format_anchor
1231
- set_rx /^\s*%?#([a-z][a-zA-Z0-9:_-]+).*$/
1352
+ set_rx(/^\s*%?#([a-z][a-zA-Z0-9:_-]+)(.*)$/)
1232
1353
 
1233
1354
  class << self
1234
1355
  def accumulate(src, array, deplate, text, match)
1235
1356
  i = 0
1236
1357
  l = get_text(match)
1237
1358
  Deplate::Core.log(['New anchor', l], :debug)
1359
+ r = get_rest(match)
1360
+ if r and !r.empty?
1361
+ Deplate::Core.log(['Deprecated: Text after anchor', r], :error, src)
1362
+ end
1238
1363
  last = array.last
1239
1364
  if last and last.can_be_labelled
1240
1365
  last.put_label([l])
1241
- # last.args["label"] ||= l
1242
- deplate.labels_named << l
1243
1366
  else
1244
1367
  Deplate::Core.log(["Defer label", l], nil, src)
1245
1368
  deplate.labels_floating << l
@@ -1250,7 +1373,11 @@ class Deplate::Element::Anchor < Deplate::Element
1250
1373
  match[1]
1251
1374
  end
1252
1375
 
1253
- def is_volatile?(match)
1376
+ def get_rest(match)
1377
+ match[2]
1378
+ end
1379
+
1380
+ def is_volatile?(match, input)
1254
1381
  true
1255
1382
  end
1256
1383
  end
@@ -1264,10 +1391,12 @@ class Deplate::Element::Anchor < Deplate::Element
1264
1391
  end
1265
1392
  end
1266
1393
 
1394
+
1267
1395
  # just disappear
1268
1396
  class Deplate::Element::Whitespace < Deplate::Element
1269
1397
  register_element
1270
- set_rx /^\s*$/
1398
+ set_rx(/^\s*$/)
1399
+ def_get :text, lambda {@text}
1271
1400
 
1272
1401
  class << self
1273
1402
  def accumulate(src, array, deplate, text, match)
@@ -1284,9 +1413,7 @@ class Deplate::Element::Whitespace < Deplate::Element
1284
1413
  end
1285
1414
 
1286
1415
  def setup(kw)
1287
- @multiliner = false
1288
- @collapse = true
1289
- @accum = [@text]
1416
+ @collapse = true
1290
1417
  @can_be_labelled = false
1291
1418
  @keep_whitespace = kw
1292
1419
  end
@@ -1308,9 +1435,8 @@ class Deplate::Element::PotentialPageBreak < Deplate::Element
1308
1435
  set_formatter :format_PAGEBREAK
1309
1436
  attr_accessor :enabled
1310
1437
 
1311
- def initialize(*args)
1438
+ def setup
1312
1439
  @enabled = false
1313
- super
1314
1440
  end
1315
1441
 
1316
1442
  def process
@@ -1327,29 +1453,70 @@ end
1327
1453
  # matches
1328
1454
  class Deplate::Element::Paragraph < Deplate::Element
1329
1455
  set_formatter :format_paragraph
1330
- set_rx /^([ \t]*)(.+)[ \t]*$/
1456
+ set_rx(/^([[:blank:]]*)(.+)[[:blank:]]*$/)
1457
+ def_get :level, lambda {get_indent(@match[1]).size}
1458
+ def_get :text, lambda {@deplate.options.keep_whitespace ? @match[0] : @match[2]}
1331
1459
 
1332
1460
  class << self
1333
1461
  def from_text(deplate, src, text)
1334
- m = @rx.match(text)
1462
+ m = self.rx.match(text)
1335
1463
  self.new(deplate, src, text, m)
1336
1464
  end
1337
1465
  end
1338
1466
 
1339
1467
  def setup
1340
1468
  @multiliner = true
1341
- @collapse = false
1342
- @level = get_level
1343
- @accum = [get_text]
1344
1469
  end
1470
+ end
1471
+
1345
1472
 
1346
- def get_level
1347
- get_indent(@match[1]).size
1473
+ class Deplate::Element::Clip < Deplate::BaseElement
1474
+ attr_reader :is_template
1475
+ # attr_accessor :prototype
1476
+
1477
+ def initialize(acc, deplate, source)
1478
+ super(deplate)
1479
+ @acc = acc
1480
+ @elt = nil
1481
+ @source = source
1482
+ @invoker = nil
1483
+ @is_template = false
1484
+ @prototype = nil
1348
1485
  end
1349
1486
 
1350
- def get_text
1351
- @deplate.options.keep_whitespace ? @match[0] : @match[2]
1487
+ def process
1488
+ unless @prototype
1489
+ @prototype = @acc.first
1490
+ @prototype.args.update(@args) if @prototype
1491
+ end
1492
+ unless @elt
1493
+ @elt = @acc.collect{|p| p.process; p.elt}
1494
+ @elt = @deplate.join_particles(@elt)
1495
+ end
1496
+ return self
1497
+ end
1498
+
1499
+ def format_clip(invoker, expected)
1500
+ unless @elt
1501
+ log("We shouldn't be here. If you can track down when this happens, please send an example to the author.", :anyway)
1502
+ process
1503
+ end
1504
+ if @elt
1505
+ if @prototype
1506
+ @prototype.match_expected(expected, invoker)
1507
+ elsif @elt =~ /\S/
1508
+ log(['Internal error', 'prototype=nil', @elt], :error)
1509
+ end
1510
+ else
1511
+ log("Clip is nil, which is quite strange and most likely deplate's error but as I haven't had the time yet to track this down this error still occurs.", :error)
1512
+ end
1513
+ @elt
1514
+ end
1515
+
1516
+ def print
1517
+ output(@elt)
1352
1518
  end
1353
1519
  end
1354
1520
 
1521
+
1355
1522
  # vim: ff=unix