docgenerator 2.1.0 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. checksums.yaml +7 -0
  2. data/examples/creole_example.rb +0 -1
  3. data/examples/creole_example_new_plugin.rb +51 -0
  4. data/examples/creole_example_tabular.rb +3 -1
  5. data/examples/wiki2docgenerator_example.rb +2 -2
  6. data/lib/creole/creole2doc.rb +697 -680
  7. data/lib/creole/creole_characters.rb +90 -26
  8. data/lib/creole/creole_inclusion_and_plugins.rb +25 -43
  9. data/lib/creole/creole_inclusions.rb +87 -75
  10. data/lib/creole/creole_placeholder.rb +87 -89
  11. data/lib/creole/creole_plugins.rb +149 -117
  12. data/lib/creole/creole_tabular.rb +247 -141
  13. data/lib/creole/plugins/todonotes.rb +48 -48
  14. data/lib/docgenerator/characters.rb +106 -8
  15. data/lib/docgenerator/compatibility_v1.rb +7 -1
  16. data/lib/docgenerator/document.rb +34 -19
  17. data/lib/docgenerator/element.rb +1 -0
  18. data/lib/docgenerator/element_meta.rb +1 -1
  19. data/lib/docgenerator/elements.rb +594 -535
  20. data/lib/docgenerator/environments.rb +131 -99
  21. data/lib/docgenerator/index.rb +110 -0
  22. data/lib/docgenerator/lists.rb +2 -1
  23. data/lib/docgenerator/packages/caption.rb +32 -34
  24. data/lib/docgenerator/packages/hyperref.rb +1 -0
  25. data/lib/docgenerator/packages/multicol.rb +3 -2
  26. data/lib/docgenerator/packages/pdfpages.rb +71 -20
  27. data/lib/docgenerator/packages/scrpage2.rb +99 -142
  28. data/lib/docgenerator/packages/url.rb +75 -81
  29. data/lib/docgenerator/sections.rb +98 -98
  30. data/lib/docgenerator/standard.rb +8 -1
  31. data/lib/docgenerator/tabular.rb +44 -25
  32. data/lib/docgenerator/templates/docgenerator_template.yaml +28 -0
  33. data/lib/docgenerator/version.rb +146 -0
  34. data/lib/docgenerator.rb +20 -15
  35. data/meta_test_and_doc/build_doc.rb +39 -10
  36. data/meta_test_and_doc/build_test.rb +34 -12
  37. data/meta_test_and_doc/manpages/characters.rb +452 -20
  38. data/meta_test_and_doc/manpages/elementlist.rb +304 -0
  39. data/meta_test_and_doc/manpages/elements.rb +305 -42
  40. data/meta_test_and_doc/manpages/others.rb +403 -0
  41. data/meta_test_and_doc/manpages/pdfpages.rb +117 -18
  42. data/meta_test_and_doc/manpages/readme.rdoc +3 -1
  43. data/meta_test_and_doc/manpages/scrpage2.rb +0 -80
  44. data/meta_test_and_doc/manpages/tables.rb +6 -6
  45. data/readme.rdoc +11 -120
  46. data/unittest/expected/test_comment.html +1 -0
  47. data/unittest/expected/test_comment.latex +5 -0
  48. data/unittest/expected/test_comment_complex.html +3 -0
  49. data/unittest/expected/test_comment_complex.latex +15 -0
  50. data/unittest/expected_creole/test_creole_characters_all.html +6 -5
  51. data/unittest/expected_creole/test_creole_characters_all.latex +10 -8
  52. data/unittest/expected_creole/test_creole_creole1.0test.latex +5 -5
  53. data/unittest/expected_creole/test_creole_input.normsource +11 -9
  54. data/unittest/expected_creole/test_creole_list_ul.normsource +57 -51
  55. data/unittest/expected_creole/test_creole_list_ulul_without_ul.html +6 -0
  56. data/unittest/expected_creole/test_creole_list_ulul_without_ul.latex +12 -0
  57. data/unittest/expected_creole/test_creole_paragraphs.normsource +12 -10
  58. data/unittest/expected_creole/test_creole_pictures.latex +2 -2
  59. data/unittest/expected_creole/test_creole_pictures_css.latex +2 -2
  60. data/unittest/expected_creole/test_creole_pictures_imgclass.latex +2 -2
  61. data/unittest/expected_creole/test_creole_pictures_width.latex +1 -1
  62. data/unittest/expected_creole/test_creole_tabular.latex +3 -3
  63. data/unittest/expected_creole/test_creole_tabular_creole.latex +2 -2
  64. data/unittest/expected_creole/test_creole_tabular_css.latex +3 -3
  65. data/unittest/expected_creole/test_creole_tabular_row_parameters.latex +22 -0
  66. data/unittest/expected_templates/test_standalone.tex +34 -0
  67. data/unittest/expected_wikimedia/test_wiki_picture.latex +12 -12
  68. data/unittest/unittest_creole.rb +22 -3
  69. data/unittest/unittest_creole_tabular.rb +34 -1
  70. data/unittest/unittest_docgenerator.rb +46 -3
  71. data/unittest/unittest_docgenerator_characters.rb +527 -82
  72. data/unittest/unittest_templates.rb +1 -1
  73. metadata +149 -108
@@ -1,4 +1,4 @@
1
- #encoding: cp1252
1
+ #encoding: utf-8
2
2
  =begin rdoc
3
3
  This is a Creole-to-Docgenerator converter.
4
4
  The Docgenerator-data can be exported as
@@ -24,45 +24,46 @@ Collect the classes to handle Creole-input.
24
24
 
25
25
  More about creole at http://www.wikicreole.org/
26
26
  =end
27
- module Creole
27
+ module Creole
28
28
 
29
29
  =begin rdoc
30
30
  Some class definitions for the Creole-class.
31
31
  =end
32
- class Creole
33
-
34
- #Little structure to store the parsing result.
35
- Creole_line = Struct.new('Creole_line', :type, :content, :add_info)
36
-
37
- #Hash with Characters.
38
- #This characters will be converted into elements.
39
- CHARACTERS = {
40
- '%' => element(:'%'),
41
- '$' => element(:'$'),
42
- '&' => element(:ampersand),
43
- '->' => element(:rightarrow),
44
- '=>' => element(:Rightarrow),
45
- '<-' => element(:leftarrow),
46
- '<=' => element(:Leftarrow),
47
- '_' => element(:underscore),
48
- '' => element(:ldots),
49
- '' => element(:sbquo), # einfaches low-9-Zeichen, U+201A , &#8218;
50
- '' => element(:rsquo), #'zu &#8217;
51
- '' => element(:bdquo), #"auf &#8222;
52
- '' => element(:ldquo), #"zu &#8220;
53
- '' => element(:ndash), # &#8211;
54
- '' => element(:mdash), # &#8211;
55
- }
32
+ class Creole
33
+
34
+ #Little structure to store the parsing result.
35
+ Creole_line = Struct.new('Creole_line', :type, :content, :add_info)
36
+
37
+ #Hash with Characters.
38
+ #This characters will be converted into elements.
39
+ CHARACTERS = {
40
+ '%' => element(:'%'),
41
+ '$' => element(:'$'),
42
+ '&' => element(:ampersand),
43
+ '->' => element(:rightarrow),
44
+ '=>' => element(:Rightarrow),
45
+ '<-' => element(:leftarrow),
46
+ '<=' => element(:Leftarrow),
47
+ '_' => element(:underscore),
48
+ '' => element(:ldots),
49
+ '' => element(:sbquo), # einfaches low-9-Zeichen, U+201A , &#8218;
50
+ '' => element(:rsquo), #'zu &#8217;
51
+ '' => element(:bdquo), #"auf &#8222; #bottom double quote
52
+ '' => element(:ldquo), #"zu &#8220; #left double quote
53
+ '' => element(:rdquo), #right double quote
54
+ '' => element(:ndash), # &#8211;
55
+ '—' => element(:mdash), # &#8211;
56
+ }
56
57
 
57
58
  =begin rdoc
58
59
  Add a quick online-help.
59
60
  =end
60
- def self.help( option = :syntax)
61
- hlp = []
62
- hlp << "==Creole help #{option}"
63
- case option
64
- when :syntax
65
- hlp << <<Syntax
61
+ def self.help( option = :syntax)
62
+ hlp = []
63
+ hlp << "==Creole help #{option}"
64
+ case option
65
+ when :syntax
66
+ hlp << <<Syntax
66
67
  Headings:
67
68
  = Level 1 (largest) =
68
69
  == Level 2 ==
@@ -75,18 +76,18 @@ You can close them. If not, the markup end with the paragraph.
75
76
 
76
77
  Links: See Creole.help(:links)
77
78
 
78
- Comming from Wikimedia/wiki2docgenerator? Check Creole.help(:wikimedia)
79
+ Coming from Wikimedia/wiki2docgenerator? Check Creole.help(:wikimedia)
79
80
  Familiar with Creole? Check Creole.help(:creole) for differences.
80
81
  Syntax
81
- when :creole
82
- hlp << <<creole
82
+ when :creole
83
+ hlp << <<creole
83
84
  creole2doc has some special features:
84
85
  *headings allows labels ([key] direct after the =)
85
86
  *line breaks are ignored, the text is wrapped.
86
87
  (you can set it off with option :wrap_at => 0)
87
88
  creole
88
- when :wikimedia
89
- hlp << <<tripfalls
89
+ when :wikimedia
90
+ hlp << <<tripfalls
90
91
  Main Trippfalls when you used wiki2docgenerator before:
91
92
 
92
93
  Lists: You need an empty line after a list.
@@ -94,8 +95,8 @@ Lists: You need an empty line after a list.
94
95
 
95
96
  Text afterwords
96
97
  tripfalls
97
- when :headings
98
- hlp << <<headings
98
+ when :headings
99
+ hlp << <<headings
99
100
  Headings:
100
101
  = Level 1 (largest) =
101
102
  == Level 2 ==
@@ -114,8 +115,8 @@ Headings with label:
114
115
  The content is not parsed.
115
116
  Details see http://www.wikicreole.org/wiki/Headings
116
117
  headings
117
- when :links
118
- hlp << <<links
118
+ when :links
119
+ hlp << <<links
119
120
  Explicit:
120
121
  * [[http://ruby.lickert.net/docgenerator]]
121
122
  * [[http://ruby.lickert.net/docgenerator|Details on docgenerator.rb]]
@@ -123,8 +124,8 @@ Explicit:
123
124
  Implicit:
124
125
  * http://ruby.lickert.net/docgenerator
125
126
  links
126
- when :tabular
127
- hlp << <<tabular
127
+ when :tabular
128
+ hlp << <<tabular
128
129
  Wikimedia-like syntax:
129
130
  <<<tabular
130
131
  |!columns=3
@@ -142,21 +143,21 @@ Wikimedia-like syntax:
142
143
  |three
143
144
  >>>
144
145
  tabular
145
- else
146
- hlp << "Undefined help for #{option.inspect}"
147
- end
148
- return hlp.join("\n")
149
- end
150
- end #Creole
146
+ else
147
+ hlp << "Undefined help for #{option.inspect}"
148
+ end
149
+ return hlp.join("\n")
150
+ end
151
+ end #Creole
151
152
 
152
- #Load sub-classes.
153
- #~ Dir.chdir(File.dirname(__FILE__)){
154
- require_relative 'creole_placeholder.rb'
155
- require_relative 'creole_tabular.rb'
156
- require_relative 'creole_inclusion_and_plugins.rb'
157
- #~ begin require 'privat/creole_affiliate.rb'; rescue LoadError; end #Just some privat extension
153
+ #Load sub-classes.
154
+ #~ Dir.chdir(File.dirname(__FILE__)){
155
+ require_relative 'creole_placeholder.rb'
156
+ require_relative 'creole_tabular.rb'
157
+ require_relative 'creole_inclusion_and_plugins.rb'
158
+ #~ begin require 'privat/creole_affiliate.rb'; rescue LoadError; end #Just some privat extension
158
159
 
159
- require 'log4r'
160
+ require 'log4r'
160
161
 
161
162
  =begin rdoc
162
163
  Build a document.
@@ -167,7 +168,7 @@ multiple HTML (corresponding to pages).
167
168
 
168
169
  HTML-pagebreak could be forced with ======== or something similar.
169
170
  =end
170
- class Creole_document
171
+ class Creole_document
171
172
 
172
173
  =begin rdoc
173
174
  Define a creole document. The settings are forwarded to Document#new()
@@ -177,65 +178,63 @@ Some settings are used only directly in Creole_document.
177
178
  - :content: Wiki-text. Same as Creole_document#<<
178
179
  - :logname: Name for Creole#log
179
180
  =end
180
- def initialize( settings = {} )
181
- @with_toc = settings[:with_toc ]
182
- settings.delete(:with_toc) #Avoid error message in Document.new
183
- settings[:logname] ||= 'CreoleDoc' #Just a name for easier debugging/logging
184
-
185
- @creole = Creole.new(
186
- #Get content if available and delete setting to avoid error message in Document.new
187
- :logname => settings.delete(:logname), #for logger
188
- :content => settings.delete(:content),
189
- :ignore => settings.delete(:ignore),
190
- :targetdir => settings.delete(:targetdir)
191
- )
192
- #fixme/ideen parameter
193
- #preamble -> vor wiki-texten
194
- #post -> nach wiki-texten
195
- #plugins/inclusions
196
- #replacements (schon teil von document?)
197
-
198
- @doc = Document.new(settings)
199
-
200
- @doc.runtex = settings[:runtex] if settings[:runtex]
201
-
202
- @log = @doc.log
203
-
204
- @doc.body << creole
205
-
206
- end
207
- #The related document
208
- attr_reader :doc
209
- #The related creole-object
210
- attr_reader :creole
211
- #Add content to the wiki.
212
- def << (content)
213
- @creole << content
214
- end
181
+ def initialize( settings = {} )
182
+ @with_toc = settings[:with_toc ]
183
+ settings.delete(:with_toc) #Avoid error message in Document.new
184
+ settings[:logname] ||= 'CreoleDoc' #Just a name for easier debugging/logging
185
+
186
+ @creole = Creole.new(
187
+ #Get content if available and delete setting to avoid error message in Document.new
188
+ :logname => settings.delete(:logname), #for logger
189
+ :content => settings.delete(:content),
190
+ :ignore => settings.delete(:ignore),
191
+ :targetdir => settings.delete(:targetdir)
192
+ )
193
+ #fixme/ideen parameter
194
+ #preamble -> vor wiki-texten
195
+ #post -> nach wiki-texten
196
+
197
+ @doc = Document.new(settings)
198
+
199
+ @doc.runtex = settings[:runtex] if settings[:runtex]
200
+
201
+ @log = @doc.log
202
+
203
+ @doc.body << creole
204
+
205
+ end
206
+ #The related document
207
+ attr_reader :doc
208
+ #The related creole-object
209
+ attr_reader :creole
210
+ #Add content to the wiki.
211
+ def << (content)
212
+ @creole << content
213
+ end
215
214
  =begin rdoc
216
215
  Save the creole document.
217
216
 
218
217
  If requested, the tableofcontents is added.
219
218
  The first Creole_document#save decides, which variant is added (html/tex)
220
219
  =end
221
- def save( filename, options = {} )
222
- if @with_toc
223
- @doc.body.insertbefore(creole, element(:htmlonly,{}, creole.toc(:level => @with_toc )))
224
- @doc.body.insertbefore(creole, element(:latexonly,{},element(:tableofcontents).cr))
225
- case @with_toc
226
- when Numeric
227
- @doc.head << element(:latexonly,{},"\\setcounter{tocdepth}{#{@with_toc}}\n")
228
- end
229
- @with_toc = false #Add it only once
230
- end #@with_toc
231
-
232
- @doc.save(filename, options )
233
- end
234
- #Use runtex if available.
235
- def runtex=(option)
236
- @doc.runtex = option
237
- end
238
- end
220
+ def save( filename, options = {} )
221
+ if @with_toc
222
+ @doc.body.insertbefore(creole, element(:htmlonly,{}, creole.toc(:level => @with_toc )))
223
+ @doc.body.insertbefore(creole, element(:latexonly,{},element(:tableofcontents).cr))
224
+ case @with_toc
225
+ when Numeric
226
+ @doc.head << element(:latexonly,{},"\\setcounter{tocdepth}{#{@with_toc}}\n")
227
+ end
228
+ @with_toc = false #Add it only once
229
+ end #@with_toc
230
+
231
+ @doc.save(filename, options )
232
+ end
233
+ #Use runtex if available.
234
+ def runtex=(option)
235
+ @doc.runtex = option
236
+ end
237
+ end
239
238
  =begin rdoc
240
239
  Creole is a standard wiki-syntax for wikitexts.
241
240
  Definition see http://www.wikicreole.org
@@ -248,98 +247,112 @@ This class gets a creole-text and translate it to elements of the docgenerator,
248
247
  they can be used by Document or directly like Element#to_doc.
249
248
 
250
249
  Example:
251
- wiki = Creole.new()
252
- wiki << <<txt
253
- =Test document
254
- This is a little test text with **bold** and //italic// text.
255
- txt
256
- wiki.to_latex()
250
+ wiki = Creole.new()
251
+ wiki << <<txt
252
+ =Test document
253
+ This is a little test text with **bold** and //italic// text.
254
+ txt
255
+ wiki.to_latex()
257
256
 
258
257
  Often I use it in combination with "Here"-Documents with __END__:
259
258
 
260
- require 'creole/creole2doc'
261
-
262
- doc = Creole_document.new()
263
- doc << DATA
264
- doc.save('test.html')
265
- __END__
266
- Content
259
+ require 'creole/creole2doc'
260
+
261
+ doc = Creole_document.new()
262
+ doc << DATA
263
+ doc.save('test.html')
264
+ __ END__
265
+ Content
266
+ --
267
+ Im Code beispiel steht __<space>END__
268
+ Würde dort __END__ stehen, hätte rdoc einen Fehler.
269
+ ++
267
270
  =end
268
- class Creole
271
+ class Creole
272
+ class << Creole
273
+ #Define a default for targetdir-option in Creole.new.
274
+ attr_accessor :targetdir
275
+ end
276
+
269
277
  =begin rdoc
270
278
  Define the Creole-object.
271
279
 
272
280
  Options:
273
- - :log => Logger to catch information.
274
- Alternativ you have access to the default logger via Creole#log
275
- - :targetdir => directory, where you want to save the result.
276
- This directory is important for checks for internal links.
277
- - :ignore: A regex describing parts to be ignored during text parsing. e.g. /^#~.*$/ for usage with scite.
278
- - :encoding: The encoding used for creole.
281
+ * :log => Logger to catch information.
282
+
283
+ Alternativ you have access to the default logger via Creole#log
284
+ * :targetdir => directory, where you want to save the result.
285
+
286
+ This directory is important for checks for internal links.
287
+
288
+ You may change the default '.' with
289
+ Docgenerator::Creole::Creole.targetdir = 'mysubdir'
290
+ * :ignore: A regex describing parts to be ignored during text parsing. e.g. /^#~.*$/ for usage with scite.
291
+ * :encoding: The encoding used for creole.
279
292
  Default is UTF-8
280
293
  =end
281
- def initialize( options = {} )
282
- @options = {
283
- :logname => 'Creole', #Just a name for easier debugging/logging
284
- :targetdir => '.',
285
- :wrap_at => 75, #Default line wrapping
286
- #~ :parsetest => false #Make an immediate test for parsing #fixme
287
- #~ :placeholders =
288
- #Definition how to handle the sectioning.
289
- :title_levels => {
290
- 0 => nil,
291
- 1 => :h1,
292
- 2 => :h2,
293
- 3 => :h3,
294
- 4 => :h4,
295
- 5 => :h5,
296
- 6 => :h6,
297
- },
298
- :ignore => nil, #Define a "local" comment, e.g /^#~.*$/
299
- :encoding => __ENCODING__,
300
- }.update(options)
301
- @placeholders = Placeholders::Collection.dup
302
- @inclusions = Inclusions::Collection.dup
303
- @plugins = Plugins::Collection.dup
304
-
305
- #Store the given source text
306
- @source = []
307
- #Store the pre-parsed content
308
- @normsource = []
309
- @toc = [] #Collection of all heading lines
310
- @footnotegroups = {} #Collection of footnote groups
311
-
312
- @targetdir = @options[:targetdir] if @options[:targetdir]
313
-
314
- @log = @options[:log]
315
- @log = Log4r::Logger.new(@options[:logname], Log4r::INFO) unless @log
316
- @log.outputters = Log4r::StdoutOutputter.new('log_stdout') if @log.outputters.empty?
317
-
318
- @creation_caller = caller.first
319
- self << @options[:content] if @options[:content]
320
- end
321
-
322
- #Hash with placeholders.
323
- #
324
- #Placeholders are used with <<<'name'.
325
- #This accessor is needed to add more placeholders for specific wikis.
326
- #Default: Creole::Placeholders
327
- attr_reader :placeholders
328
- attr_reader :options
329
-
330
- #Hash with inclusions.
331
- #This accessor is needed to add more inclusions for specific wikis.
332
- #Default: Creole::Inclusions
333
- attr_reader :inclusions
334
- #Hash with all plugins
335
- #This accessor is needed to add more plugins for specific wikis.
336
- #Default: Creole::Plugins
337
- attr_reader :plugins
338
- #All footnotegroups of the wiki
339
- attr_reader :footnotegroups
340
-
341
- #Error Class
342
- class InputError < ArgumentError; end
294
+ def initialize( options = {} )
295
+ @options = {
296
+ :logname => 'Creole', #Just a name for easier debugging/logging
297
+ :targetdir => self.class.targetdir || '.',
298
+ :wrap_at => 75, #Default line wrapping
299
+ #~ :parsetest => false #Make an immediate test for parsing #fixme
300
+ #~ :placeholders =
301
+ #Definition how to handle the sectioning.
302
+ :title_levels => {
303
+ 0 => nil,
304
+ 1 => :h1,
305
+ 2 => :h2,
306
+ 3 => :h3,
307
+ 4 => :h4,
308
+ 5 => :h5,
309
+ 6 => :h6,
310
+ },
311
+ :ignore => nil, #Define a "local" comment, e.g /^#~.*$/
312
+ :encoding => __ENCODING__,
313
+ }.update(options)
314
+ @placeholders = Placeholders::Collection.dup
315
+ @inclusions = Inclusions::Collection.dup
316
+ @plugins = Plugins::Collection.dup
317
+
318
+ #Store the given source text
319
+ @source = []
320
+ #Store the pre-parsed content
321
+ @normsource = []
322
+ @toc = [] #Collection of all heading lines
323
+ @footnotegroups = {} #Collection of footnote groups
324
+
325
+ @targetdir = @options[:targetdir] if @options[:targetdir]
326
+
327
+ @log = @options[:log]
328
+ @log = Log4r::Logger.new(@options[:logname], Log4r::INFO) unless @log
329
+ @log.outputters = Log4r::StdoutOutputter.new('log_stdout') if @log.outputters.empty?
330
+
331
+ @creation_caller = caller.first
332
+ self << @options[:content] if @options[:content]
333
+ end
334
+
335
+ #Hash with placeholders.
336
+ #
337
+ #Placeholders are used with <<<'name'.
338
+ #This accessor is needed to add more placeholders for specific wikis.
339
+ #Default: Creole::Placeholders
340
+ attr_reader :placeholders
341
+ attr_reader :options
342
+
343
+ #Hash with inclusions.
344
+ #This accessor is needed to add more inclusions for specific wikis.
345
+ #Default: Creole::Inclusions
346
+ attr_reader :inclusions
347
+ #Hash with all plugins
348
+ #This accessor is needed to add more plugins for specific wikis.
349
+ #Default: Creole::Plugins
350
+ attr_reader :plugins
351
+ #All footnotegroups of the wiki
352
+ attr_reader :footnotegroups
353
+
354
+ #Error Class
355
+ class InputError < ArgumentError; end
343
356
  =begin rdoc
344
357
  Get some content.
345
358
  Strings are taken like strings.
@@ -351,246 +364,248 @@ In case of ruby scripts, the part after __END__ is used as input.
351
364
  Content added with << starts always with a new paragraph, but it may contain
352
365
  multiple paragraphs, lists...
353
366
  =end
354
- def << ( input )
355
- case input
356
- when String
357
- source = input
358
- when Array
359
- #Items of the array are handled like single lines.
360
- #The chomp avoid double \n (the array items may already have their own newlines).
361
- source = input.map{|item| item.chomp}.join("\n") #ohne doppelte xx
362
- when File
363
- #If file is a ruby script, then use the wiki-code after __END__
364
- #
365
- #Often scripts contains there own text content after __END__.
366
- #So we have to catch, if << is called with DATA
367
- if /\.rb\Z/ =~ input.path and $0 != input.path
368
- @log.info("Take content of #{input.inspect} after __END__") if @log.info?
367
+ def << ( input )
368
+ case input
369
+ when String
370
+ source = input
371
+ when Array
372
+ #Items of the array are handled like single lines.
373
+ #The chomp avoid double \n (the array items may already have their own newlines).
374
+ source = input.map{|item| item.chomp}.join("\n") #ohne doppelte xx
375
+ when File
376
+ #If file is a ruby script, then use the wiki-code after __END__
377
+ #
378
+ #Often scripts contains there own text content after __END__.
379
+ #So we have to catch, if << is called with DATA
380
+ if /\.rb\Z/ =~ input.path and $0 != input.path
381
+ @log.info("Take content of #{input.inspect} after __END__") if @log.info?
382
+ begin
383
+ line = input.readline while line != "__END__\n"
384
+ rescue EOFError
385
+ @log.error("No __END__ found in #{input.inspect}") if @log.error?
386
+ end
387
+ end
388
+ #Read the code
389
+ source = input.readlines.join
390
+ else
391
+ raise InputError, "Don't know, how to handle #{input.class} in Creole#<<"
392
+ end
369
393
  begin
370
- line = input.readline while line != "__END__\n"
371
- rescue EOFError
372
- @log.error("No __END__ found in #{input.inspect}") if @log.error?
373
- end
374
- end
375
- #Read the code
376
- source = input.readlines.join
377
- else
378
- raise InputError, "Don't know, how to handle #{input.class} in Creole#<<"
379
- end
380
- begin
381
- source_enc = source.encode(@options[:encoding])
382
- rescue Encoding::UndefinedConversionError => err
383
- @log.warn("Encoding conversion error <#{err}>") if @log.warn?
384
- source_enc = source.encode(@options[:encoding], :undef => :replace)
385
- end
386
- @source << source_enc
387
- #Parse the given source.
388
- #This is done immediate, so you have a chance to localize the line, where an error occurs.
389
- #(Some errors are reported later during to_doc).
390
- #fixme: option to parse immediate at << or later
391
- #immediate_parse => true...
392
- @normsource.push( *parse( source_enc ) )
393
- end #<< ( input )
394
+ source_enc = source.encode(@options[:encoding])
395
+ rescue Encoding::UndefinedConversionError => err
396
+ @log.warn("Encoding conversion error <#{err}>") if @log.warn?
397
+ source_enc = source.encode(@options[:encoding], :undef => :replace)
398
+ end
399
+ @source << source_enc
400
+ #Parse the given source.
401
+ #This is done immediate, so you have a chance to localize the line, where an error occurs.
402
+ #(Some errors are reported later during to_doc).
403
+ #fixme: option to parse immediate at << or later
404
+ #immediate_parse => true...
405
+ @normsource.push( *parse( source_enc ) )
406
+ end #<< ( input )
394
407
  =begin rdoc
395
408
  Parse the given creole code and build a "normalized source"
396
409
  =end
397
- def parse( source = @source )
398
-
399
- normsource = []
400
- statusflag = nil #Variable to store the actual status. nil = nothing special.
401
- normsource << Creole_line.new(:dummy)
402
-
403
- if ! source.respond_to?(:each_with_index)
404
- #Ruby 1.9 removed each from String
405
- if source.respond_to? :each_line
406
- source = source.each_line
407
- else
408
- @log.fatal("Unable to parse #{source.class}: #{source.inspect}" ) if @log.fatal?
409
- return normsource
410
- end
411
- end
412
-
413
-
414
- #
415
- #Check code line by line
416
- #
417
- source.each_with_index{|line, lineno|
418
- #Check special status
419
- case statusflag
420
- when nil #Nothing to do
421
- when :pre
422
- line =~ /\}\}\}/ ? statusflag = nil : normsource.last.content << line
423
- next
424
- when :placeholder
425
- if line =~ /^>>>$/
426
- statusflag = nil
427
- normsource.last.content.close
410
+ def parse( source = @source )
411
+
412
+ normsource = []
413
+ statusflag = nil #Variable to store the actual status. nil = nothing special.
414
+ normsource << Creole_line.new(:dummy)
415
+
416
+ if ! source.respond_to?(:each_with_index)
417
+ #Ruby 1.9 removed each from String
418
+ if source.respond_to? :each_line
419
+ source = source.each_line
428
420
  else
429
- normsource.last.content << line
421
+ @log.fatal("Unable to parse #{source.class}: #{source.inspect}" ) if @log.fatal?
422
+ return normsource
430
423
  end
431
- next
432
- else
433
- @log.fatal("Undefind status #{statusflag}: #{line.inspect}" ) if @log.fatal?
434
- end #statusflag
435
-
436
- #
437
- #Parse the wiki text on line level (main structure)
438
- case line
439
- #Skip this line, if it correspond to a special comment-pattern.
440
- #Can be used for application-specific comments.
424
+ end
425
+
426
+
441
427
  #
442
- #Example:
443
- # :ignore => /^#~.*$/
444
- #This comment is created by scite using Ctrl-Q (for ruby-scripts).
445
- when @options[:ignore]
446
- @log.info("Found comment #{$1} : #{line.inspect}" ) if @log.info?
447
- #Headings
448
- #http://www.wikicreole.org/wiki/Headings
428
+ #Check code line by line
449
429
  #
450
- #Modification of standard: Labels are possible.
451
- when /^(=+)(?:\[(.*)\])?(.+?)(=*)\s*$/
452
- normsource << Creole_line.new(:title, $3, :level => $1.size, :label => $2 )
453
- @toc << normsource.last
454
- #Creole doesn't need a trailing ===, but when it is ther, it should be correct
455
- if $1.size != $4.size and $4.size > 0
456
- @log.warn("Heading problem #{$1} doesn't match <#{$4}>: #{line.inspect}" ) if @log.warn?
457
- end
458
- if $~.post_match !~ /\s*/
459
- @log.warn("Ignore text #{$~.post_match.inspect} after title <#{line.inspect}>" ) if @log.warn?
460
- end
461
- #And close the actual level
462
- #See unit test test_creole_mix_titles_list
463
- normsource << Creole_line.new(:dummy )
464
- #Empty line
465
- when /^\s*$/
466
- normsource << Creole_line.new(:dummy )
467
- when /^----\s*$/
468
- normsource << Creole_line.new(:hr )
469
- #List entry
470
- when /^\s*((\*|\#)+)/
471
- normsource << Creole_line.new(:list, $~.post_match, :listtype => $1 )
472
- #Tabular
473
- when /^\|/
474
- #fixme tab soll in par...
475
- #~ normsource.last << Creole_line.new(:placeholder,
476
- #~ ... unless anpassen...
477
- normsource << Creole_line.new(:placeholder,
478
- @placeholders['creole_tabular'].new(self),
479
- :start => lineno
480
- ) unless normsource.last.content.is_a?(Creole_tab)
481
- normsource.last.content << line
482
- #http://www.wikicreole.org/wiki/PreformattedAndNowiki
483
- when /^\{\{\{\s*$/ #Kind of verbatim
484
- normsource << Creole_line.new(:pre, [], :start => lineno )
485
- statusflag = :pre
486
- #~ when /^<<<(.*)\|?(.*?)/ #fixme options for placeholders?
487
- when /^<<<(.*)/
488
- ph, par = $1.split(/\|/,2)
489
- placeholder = @placeholders[ph].new(self, par)
490
- if placeholder.instance_of?(Placeholders::Dummy)
491
- @log.warn("Unknown placeholder #{ph.inspect} used in line #{lineno}" ) if @log.warn?
492
- end
493
- normsource << Creole_line.new(:placeholder, placeholder, :start => lineno )
494
- statusflag = :placeholder
495
- else
496
- case normsource.last.type
497
- when :par, :list
430
+ source.each_with_index{|line, lineno|
431
+ #Check special status
432
+ case statusflag
433
+ when nil #Nothing to do
434
+ when :pre
435
+ line =~ /\}\}\}/ ? statusflag = nil : normsource.last.content << line
436
+ next
437
+ when :placeholder
438
+ #~ if line =~ /^>>>$/ #did not catch each system specific line end.
439
+ if line =~ /^>>>(\r\n?|\n)/
440
+ statusflag = nil
441
+ normsource.last.content.close
442
+ else
443
+ normsource.last.content << line
444
+ end
445
+ next
446
+ else
447
+ @log.fatal("Undefinded status #{statusflag}: #{line.inspect}" ) if @log.fatal?
448
+ end #statusflag
449
+
450
+ #
451
+ #Parse the wiki text on line level (main structure)
452
+ case line
453
+ #Skip this line, if it correspond to a special comment-pattern.
454
+ #Can be used for application-specific comments.
455
+ #
456
+ #Example:
457
+ # :ignore => /^(#~.*)$/
458
+ #This comment is created by scite using Ctrl-Q (for ruby-scripts).
459
+ when @options[:ignore]
460
+ @log.info("Found comment in line %2i: %s" % [
461
+ lineno, #line.inspect
462
+ [$~.pre_match, '<<', $1, '>>', $~.post_match].join.strip,
463
+ ]) if @log.info?
464
+ #Headings
465
+ #http://www.wikicreole.org/wiki/Headings
466
+ #
467
+ #Modification of standard: Labels are possible.
468
+ when /^(=+)(?:\[(.*)\])?(.+?)(=*)\s*$/
469
+ normsource << Creole_line.new(:title, $3, :level => $1.size, :label => $2 )
470
+ @toc << normsource.last
471
+ #Creole doesn't need a trailing ===, but when it is ther, it should be correct
472
+ if $1.size != $4.size and $4.size > 0
473
+ @log.warn("Heading problem #{$1} doesn't match <#{$4}>: #{line.inspect}" ) if @log.warn?
474
+ end
475
+ if $~.post_match !~ /\s*/
476
+ @log.warn("Ignore text #{$~.post_match.inspect} after title <#{line.inspect}>" ) if @log.warn?
477
+ end
478
+ #And close the actual level
479
+ #See unit test test_creole_mix_titles_list
480
+ normsource << Creole_line.new(:dummy )
481
+ #Empty line
482
+ when /^\s*$/
483
+ normsource << Creole_line.new(:dummy )
484
+ when /^----\s*$/
485
+ normsource << Creole_line.new(:hr )
486
+ #List entry
487
+ when /^\s*((\*|\#)+)/
488
+ normsource << Creole_line.new(:list, $~.post_match, :listtype => $1 )
489
+ #Tabular
490
+ when /^\|/
491
+ #fixme tab soll in par...
492
+ #~ normsource.last << Creole_line.new(:placeholder,
493
+ #~ ... unless anpassen...
494
+ normsource << Creole_line.new(:placeholder,
495
+ @placeholders['creole_tabular'].new(self),
496
+ :start => lineno
497
+ ) unless normsource.last.content.is_a?(Creole_tab)
498
498
  normsource.last.content << line
499
+ #http://www.wikicreole.org/wiki/PreformattedAndNowiki
500
+ when /^\{\{\{\s*$/ #Kind of verbatim
501
+ normsource << Creole_line.new(:pre, [], :start => lineno )
502
+ statusflag = :pre
503
+ #~ when /^<<<(.*)\|?(.*?)/ #fixme options for placeholders?
504
+ when /^<<<(.*)/
505
+ ph, par = $1.split(/\|/,2)
506
+ placeholder = @placeholders[ph].new(self, par)
507
+ if placeholder.instance_of?(Placeholders::Dummy)
508
+ @log.warn("Unknown placeholder #{ph.inspect} used in line #{lineno}" ) if @log.warn?
509
+ end
510
+ normsource << Creole_line.new(:placeholder, placeholder, :start => lineno )
511
+ statusflag = :placeholder
499
512
  else
500
- normsource << Creole_line.new(:par, line )
501
- end
502
- end
503
- }
504
- case statusflag
505
- when nil #ok
506
- when :pre
507
- @log.warn("Unclosed verbatim found (start at #{normsource.last.add_info[:start]})" ) if @log.warn?
508
- #~ raise ''
509
- when :placeholder
510
- @log.warn("Unclosed placeholder #{normsource.last.type} (start at #{normsource.last.add_info[:start]})" ) if @log.warn?
511
- else
512
- @log.warn("Wiki ends with status #{statusflag.inspect}" ) if @log.warn?
513
- end
514
- return normsource
515
- end #parse
516
- #Logger to collect messages.
517
- attr_reader :log
518
- #Returns the source as it was received
519
- attr_reader :source
520
- #The pre-parsed content.
521
- attr_reader :normsource
522
- #Directory for the target.
523
- #Can be used to check internal links (images, local files...)
524
- attr_reader :targetdir
525
- #Wrap some text after this lines.
526
- #See http://forum.ruby-portal.de/viewtopic.php?t=3844
527
- #
513
+ case normsource.last.type
514
+ when :par, :list
515
+ normsource.last.content << line
516
+ else
517
+ normsource << Creole_line.new(:par, line )
518
+ end
519
+ end
520
+ }
521
+ case statusflag
522
+ when nil #ok
523
+ when :pre
524
+ @log.warn("Unclosed verbatim found (start at #{normsource.last.add_info[:start]})" ) if @log.warn?
525
+ #~ raise ''
526
+ when :placeholder
527
+ #One possible source: Regexp $ is system specific.
528
+ @log.warn("Unclosed placeholder #{normsource.last.type} (start at #{normsource.last.add_info[:start]})" ) if @log.warn?
529
+ else
530
+ @log.warn("Wiki ends with status #{statusflag.inspect}" ) if @log.warn?
531
+ end
532
+ return normsource
533
+ end #parse
534
+ #Logger to collect messages.
535
+ attr_reader :log
536
+ #Returns the source as it was received
537
+ attr_reader :source
538
+ #The pre-parsed content.
539
+ attr_reader :normsource
540
+ #Directory for the target.
541
+ #Can be used to check internal links (images, local files...)
542
+ attr_reader :targetdir
528
543
 
529
544
  =begin rdoc
530
545
  Return a table of contents as a list.
531
546
  =end
532
- def toc( i_options = {})
533
- options = {
534
- :listtype => :ul,
535
- :level => 4,
536
- #~ :startlevel => 1,
537
- }.update(i_options)
538
-
539
- if ! options[:level].is_a?(Fixnum)
540
- @log.error("Toc: toclevel is no number but '#{options[:level].inspect}'. Set 4") if @log.error?
541
- options[:level] = 4
542
- end
547
+ def toc( i_options = {})
548
+ options = {
549
+ :listtype => :ul,
550
+ :level => 4,
551
+ #~ :startlevel => 1,
552
+ }.update(i_options)
553
+
554
+ if ! options[:level].is_a?(Fixnum)
555
+ @log.error("Toc: toclevel is no number but '#{options[:level].inspect}'. Set 4") if @log.error?
556
+ options[:level] = 4
557
+ end
543
558
 
544
559
 
545
- toclist = []
546
- toclabel = [0] #help variable to construct labels
547
- listtype = '*'
548
- case options[:listtype]
549
- when '*', :ul, :itemize
560
+ toclist = []
561
+ toclabel = [0] #help variable to construct labels
550
562
  listtype = '*'
551
- when '#', :ol, :enumerate
552
- listtype = '#'
553
- else
554
- @log.error("Toc: Unknown listtype #{options[:listtype]}") if @log.error?
555
- end
556
-
557
- @toc.each{|tocentry|
558
- level = tocentry.add_info[:level]
559
- #Skip deeper levels then wanted.
560
- next if level > options[:level]
561
-
562
- #Build the label
563
- if level > toclabel.size
564
- toclabel << 0
565
- elsif level < toclabel.size
566
- toclabel.pop
567
- end
568
- #Happens if there is a jump gap on section levels (subsubsection inside section without subsection)
569
- if ! toclabel[level-1]
570
- @log.warn("Missing toclevel for <#{tocentry.content}> #{tocentry.add_info.inspect}")
571
- #add dummy level
572
- toclabel << 0
573
- toclist << "#{listtype * ( level - 1)} ---"
574
- end
575
- toclabel[level-1] = toclabel[level-1] + 1
576
-
577
- #Check if there was already a label.
578
- #If yes: use it. If not: build a new one with the help of toclabel.
579
- if tocentry.add_info[:label]
580
- label = tocentry.add_info[:label]
581
- else
582
- label = tocentry.add_info[:label] = toclabel.join('-')
563
+ case options[:listtype]
564
+ when '*', :ul, :itemize
565
+ listtype = '*'
566
+ when '#', :ol, :enumerate
567
+ listtype = '#'
568
+ else
569
+ @log.error("Toc: Unknown listtype #{options[:listtype]}") if @log.error?
583
570
  end
584
571
 
585
- #Feature to create the toc if higher levels are missing /start at h3...)
586
- #~ if level < options[:startlevel]
587
- #~ @log.warn( "toc: TOC starts not at #{options[:startlevel]}, but level #{level}" ) if @log.warn?
588
- #~ next
589
- #~ end
590
-
591
- toclist << "#{listtype * level}[[##{label}|#{tocentry.content}]]"
592
- }
593
- toclist = <<toc
572
+ @toc.each{|tocentry|
573
+ level = tocentry.add_info[:level]
574
+ #Skip deeper levels then wanted.
575
+ next if level > options[:level]
576
+
577
+ #Build the label
578
+ if level > toclabel.size
579
+ toclabel << 0
580
+ elsif level < toclabel.size
581
+ toclabel.pop
582
+ end
583
+ #Happens if there is a jump gap on section levels (subsubsection inside section without subsection)
584
+ if ! toclabel[level-1]
585
+ @log.warn("Missing toclevel for <#{tocentry.content}> #{tocentry.add_info.inspect}")
586
+ #add dummy level
587
+ toclabel << 0
588
+ toclist << "#{listtype * ( level - 1)} ---"
589
+ end
590
+ toclabel[level-1] = toclabel[level-1] + 1
591
+
592
+ #Check if there was already a label.
593
+ #If yes: use it. If not: build a new one with the help of toclabel.
594
+ if tocentry.add_info[:label]
595
+ label = tocentry.add_info[:label]
596
+ else
597
+ label = tocentry.add_info[:label] = toclabel.join('-')
598
+ end
599
+
600
+ #Feature to create the toc if higher levels are missing /start at h3...)
601
+ #~ if level < options[:startlevel]
602
+ #~ @log.warn( "toc: TOC starts not at #{options[:startlevel]}, but level #{level}" ) if @log.warn?
603
+ #~ next
604
+ #~ end
605
+
606
+ toclist << "#{listtype * level}[[##{label}|#{tocentry.content}]]"
607
+ }
608
+ toclist = <<toc
594
609
  <<<html
595
610
  <div class = 'toc'>
596
611
  >>>
@@ -600,8 +615,8 @@ Return a table of contents as a list.
600
615
  >>>
601
616
  toc
602
617
 
603
- return Creole.new( :content => toclist, :log => @log )
604
- end #toc
618
+ return Creole.new( :content => toclist, :log => @log )
619
+ end #toc
605
620
  =begin rdoc
606
621
  Wrapping mechanism for texts.
607
622
 
@@ -610,251 +625,253 @@ Don't do anything, if line_width is 0.
610
625
  See also http://stackoverflow.com/questions/7548968/format-output-to-40-characters-long-per-line/7549032#7549032
611
626
  and http://forum.ruby-portal.de/viewtopic.php?t=3844&p=24578
612
627
  =end
613
- def word_wrap(text, line_width = @options[:wrap_at] )
614
- return text if line_width <= 0
615
- text.gsub(/\n/, ' ').gsub(/(.{1,#{line_width}})(\s+|$)/, "\\1\n").strip
616
- end
628
+ def word_wrap(text, line_width = @options[:wrap_at] )
629
+ return text if line_width <= 0
630
+ text.gsub(/\n/, ' ').gsub(/(.{1,#{line_width}})(\s+|$)/, "\\1\n").strip
631
+ end
617
632
  =begin rdoc
618
633
  Prepare document.
619
634
  =end
620
- def to_doc( target, options = {} )
621
- options[:log] = @log unless options[:log]
622
- #
623
- #Delete again all footnotegroups.
624
- #Else you get footnotes doubled.
625
- @footnotegroups = {} #Collection of footnote groups
626
- return normsource2elements( @normsource, options ).to_doc(target, options)
627
- end #to_doc
635
+ def to_doc( target, options = {} )
636
+ options[:log] = @log unless options[:log]
637
+ #
638
+ #Delete again all footnotegroups.
639
+ #Else you get footnotes doubled.
640
+ @footnotegroups = {} #Collection of footnote groups
641
+ return normsource2elements( @normsource, options ).to_doc(target, options)
642
+ end #to_doc
628
643
  =begin rdoc
629
644
  Take the given normsource and build a list of elements.
630
645
  Used by
631
646
  - Creole#to_doc
632
647
  - Creole_ruby#to_doc
633
648
  =end
634
- def normsource2elements( normsource, options )
635
- doc = []
636
- elements = {} #little collector for lists
637
- normsource.each{|line|
638
- case line.type
639
- when :dummy
640
- elements = {}
641
- #Here we define the sectioning.
642
- #line.add_info[:level] contains the number of = from the wiki.
643
- #
644
- when :title
645
-
646
- doc << element(@options[:title_levels][line.add_info[:level]], {
647
- :id => line.add_info[:label]
648
- #inline or not?
649
- #Required for filenames with _
650
- #But: http://www.wikicreole.org/wiki/Headings says no.
651
- #Make decision depending on a setting?
652
- }, line.content ).cr
653
- #~ }, inline(line.content, options ) ).cr
654
- when :list
655
- key = line.add_info[:listtype]
656
- if ! elements[key]
657
- case key[-1,1]
658
- when '*'; elements[key] = element(:ul).cR
659
- when '#'; elements[key] = element(:ol).cR
660
- else
661
- options[:log].error("Undefined listtype #{key[-1,1]}") if options[:log].error?
662
- end
663
- if key.size == 1 #new list, add to document
664
- doc << elements[key]
665
- elsif parent_list = elements[key[0,key.size-1]] #new sublist, add to "parent"
666
- parent_list << element(:li).cr unless parent_list.content.last.is_a?(:li)
667
- parent_list.content.last << elements[key]
668
- else #sublist without parent.
669
- options[:log].error("List #{key} with missing sublist") if options[:log].error?
670
- end
649
+ def normsource2elements( normsource, options )
650
+ doc = []
651
+ elements = {} #little collector for lists
652
+ normsource.each{|line|
653
+ case line.type
654
+ when :dummy
655
+ elements = {}
656
+ #Here we define the sectioning.
657
+ #line.add_info[:level] contains the number of = from the wiki.
658
+ #
659
+ when :title
660
+
661
+ doc << element(@options[:title_levels][line.add_info[:level]], {
662
+ :id => line.add_info[:label]
663
+ #inline or not?
664
+ #Required for filenames with _
665
+ #But: http://www.wikicreole.org/wiki/Headings says no.
666
+ #Make decision depending on a setting?
667
+ }, line.content ).cr
668
+ #~ }, inline(line.content, options ) ).cr
669
+ when :list
670
+ key = line.add_info[:listtype]
671
+ if ! elements[key]
672
+ case key[-1,1]
673
+ when '*'; elements[key] = element(:ul).cR
674
+ when '#'; elements[key] = element(:ol).cR
675
+ else
676
+ options[:log].error("Undefined listtype #{key[-1,1]}") if options[:log].error?
677
+ end
678
+ if key.size == 1 #new list, add to document
679
+ doc << elements[key]
680
+ elsif parent_list = elements[key[0,key.size-1]] #new sublist, add to "parent"
681
+ parent_list << element(:li).cr unless parent_list.content.last.is_a?(:li)
682
+ parent_list.content.last << elements[key]
683
+ else #sublist without parent.
684
+ options[:log].error("List #{key} with missing superlist") if options[:log].error?
685
+ doc << element(:comment,{},'Sublist without superlist - move on top level').cr #add pending list on top level.
686
+ doc << elements[key] #add pending list on top level.
687
+ end
688
+ end
689
+ elements.each{|ekey, list|
690
+ case ekey
691
+ when key
692
+ list << element(:li,{}, inline(line.content, options) ).cr
693
+ else
694
+ elements.delete(ekey) if ekey.size >= key.size
695
+ end
696
+ }
697
+ when :pre
698
+ doc << element(:verbatim, {}, line.content ).cR
699
+ when :hr
700
+ doc << element(:hr).cr
701
+ when :placeholder
702
+ doc << line.content
703
+ when :par
704
+ doc << element(:par, {}, inline(line.content, options)).cR
705
+ else
706
+ options[:log].error("Wrong line type #{ line.type.inspect }") if options[:log].error?
671
707
  end
672
- elements.each{|ekey, list|
673
- case ekey
674
- when key
675
- list << element(:li,{}, inline(line.content, options) ).cr
676
- else
677
- elements.delete(ekey) if ekey.size >= key.size
678
- end
679
- }
680
- when :pre
681
- doc << element(:verbatim, {}, line.content ).cR
682
- when :hr
683
- doc << element(:hr).cr
684
- when :placeholder
685
- doc << line.content
686
- when :par
687
- doc << element(:par, {}, inline(line.content, options)).cR
688
- else
689
- options[:log].error("Wrong line type #{ line.type.inspect }") if options[:log].error?
690
- end
691
- }
692
-
693
- return doc
694
- end #to_doc_internal
708
+ }
709
+
710
+ return doc
711
+ end #to_doc_internal
695
712
  =begin rdoc
696
713
  Parse the inline text.
697
714
 
698
715
  Options is a Hash and may contain:
699
716
  * :log (default: @log)
700
717
  =end
701
- def inline( text, options )
702
-
703
- raise ArgumentError, "Creole#inline: Options no Hash" unless options.is_a?(Hash)
704
- options[:log] = @log unless options[:log]
705
- options[:plugins] = @plugins unless options[:plugins]
706
- options[:inclusions] = @inclusions unless options[:inclusions]
707
-
708
- res = [] #result
709
- stack = [] #
710
-
711
- #~ http_regex =
712
- #fixme: Only once to reduce runtime
713
- splitregex = Regexp.new(
714
- '(' + [
715
- '\[\[.+?\]\]', # [[...links]]
716
- 'http:\/\/.+?(\s|\Z)', #including the next space!!
717
- '\*\*', #bold
718
- '\/\/', #emph
719
- '\\\\\\\\', #newline
720
- '\{\{\{.*?\}\}\}', #inline verbatim
721
- '\{\{.*?\}\}', #images/inclusion
722
- '<<.*?>>', #Plugins
723
- CHARACTERS.keys.join('|')
724
- ].join('|') + ')'
725
- )
726
- #Splitt along 'active' elements.
727
- #~ @options[:wrap_at]
728
- #~ text.gsub(/\n/, ' ').split(splitregex).each{|el|
729
- text.split(splitregex).each{|el|
730
- case el
731
- when '**' #bold
732
- if stack.last.is_a?(:textbf)
733
- stack.pop #leave bold area
734
- else
735
- stack << newel = element(:textbf) #enter bold area
736
- if stack.size > 1
737
- stack[-2] << newel
738
- else
739
- res << newel
740
- end
741
- end
742
- when '//' #italic
743
- if stack.last.is_a?(:emph)
744
- stack.pop #leave italic area
745
- else
746
- stack << newel = element(:emph) #enter italic area
747
- if stack.size > 1
748
- stack[-2] << newel
749
- else
750
- res << newel
718
+ def inline( text, options )
719
+
720
+ raise ArgumentError, "Creole#inline: Options no Hash" unless options.is_a?(Hash)
721
+ options[:log] = @log unless options[:log]
722
+ options[:plugins] = @plugins unless options[:plugins]
723
+ options[:inclusions] = @inclusions unless options[:inclusions]
724
+
725
+ res = [] #result
726
+ stack = [] #
727
+
728
+ #~ http_regex =
729
+ #fixme: Only once to reduce runtime
730
+ splitregex = Regexp.new(
731
+ '(' + [
732
+ '\[\[.+?\]\]', # [[...links]]
733
+ 'https?:\/\/.+?(\s|\Z)', #including the next space!!
734
+ '\*\*', #bold
735
+ '\/\/', #emph
736
+ '\\\\\\\\', #newline
737
+ '\{\{\{.*?\}\}\}', #inline verbatim
738
+ '\{\{.*?\}\}', #images/inclusion
739
+ '<<.*?>>', #Plugins
740
+ CHARACTERS.keys.join('|')
741
+ ].join('|') + ')'
742
+ )
743
+ #Splitt along 'active' elements.
744
+ #~ @options[:wrap_at]
745
+ #~ text.gsub(/\n/, ' ').split(splitregex).each{|el|
746
+ text.split(splitregex).each{|el|
747
+ case el
748
+ when '**' #bold
749
+ if stack.last.is_a?(:textbf)
750
+ stack.pop #leave bold area
751
+ else
752
+ stack << newel = element(:textbf) #enter bold area
753
+ if stack.size > 1
754
+ stack[-2] << newel
755
+ else
756
+ res << newel
757
+ end
758
+ end
759
+ when '//' #italic
760
+ if stack.last.is_a?(:emph)
761
+ stack.pop #leave italic area
762
+ else
763
+ stack << newel = element(:emph) #enter italic area
764
+ if stack.size > 1
765
+ stack[-2] << newel
766
+ else
767
+ res << newel
768
+ end
769
+ end
770
+ when '\\\\' #newline
771
+ ( stack.last ? stack.last : res ) << element(:newline).cr
772
+ #Something like [[http:...]]
773
+ when %r{^\[\[(.+?)(?:\|(.*?))?\]\]} #Link
774
+ link = $1
775
+ linktext = $2 ? $2 : $1
776
+ case link
777
+ when /^(https?|ftp):\/\/.+?/
778
+ link = link
779
+ #local file via file://...
780
+ when /^(file):\/\/(.+)/
781
+ link = link
782
+ check_link_existence( $2, options[:log] )
783
+ when /^\./, /\S:[\\\/]/ #lokal file
784
+ link = link
785
+ check_link_existence( link, options[:log] )
786
+ when /^#/ #internal link
787
+ link = link
788
+ #fixme tex?
789
+ else #internal link
790
+ #This is normally the wiki-links.
791
+ #But this is no wiki, it's a documentgenerator with wiki syntax.
792
+ options[:log].warn("Unclear link <#{el}> #{self.inspect}") if options[:log].warn?
793
+ link = link
794
+ end
795
+ if link == linktext #Avoid replacement of // inside linktext
796
+ href = element(:a, {:href=>link}, linktext )
797
+ else
798
+ href = element(:a, {:href=>link}, inline(linktext, options) )
799
+ end
800
+ if stack.last
801
+ stack.last << href
802
+ else
803
+ res << href
804
+ end
805
+ #All links should be catched before
806
+ when %r{\[\[(.*)\]\]}
807
+ options[:log].error("Lost link <#{el}>") if options[:log].error?
808
+ #fixme: there are obsolete 2 additional spaces in the result.
809
+ when /^http/ #implicit link
810
+ #~ href = element(:a, {:href=>el.strip}, el.strip ) #This makes problems with TeX (unmasked _,%...)
811
+ href = element(:url, {}, el.strip )
812
+ el =~ /(\s|\Z)$/ #get the end-space/newline if available
813
+ endspace = ( $1.empty? ? nil : $1 )
814
+ if stack.last
815
+ stack.last << href
816
+ #~ stack.last << last_char #add again the
817
+ else
818
+ res << href
819
+ #~ res << last_char #add again the end-space/newline
820
+ end
821
+ #No-wiki inline: {{{text}}}
822
+ when /\{\{\{(.*)\}\}\}/
823
+ if stack.last
824
+ stack.last << element(:verb,{},$1)
825
+ else
826
+ res << element(:verb,{},$1)
827
+ end
828
+ #Inclusion
829
+ #creole2doc implements a general inclusion.
830
+ #Main usage are pictures/images ({{picname|alt}}),
831
+ #but it can be more...
832
+ #
833
+ #Available inclusions are defined in Creole::Inclusions resp. Creole#inclusions,
834
+ when /\{\{(.+?)(?:\|(.*))?\}\}/
835
+ if stack.last
836
+ stack.last << inclusion_or_plugin($1, $2, options[:inclusions])
837
+ else
838
+ res << inclusion_or_plugin($1, $2, options[:inclusions])
839
+ end
840
+ #Plugin
841
+ #Used like Inclusions.
842
+ #
843
+ #available plugins are defined in Creole::Plugins resp. Creole#plugins
844
+ when /<<(.+?)(?:\|(.*))?>>/
845
+ if stack.last
846
+ stack.last << inclusion_or_plugin($1, $2, options[:plugins])
847
+ else
848
+ res << inclusion_or_plugin($1, $2, options[:plugins])
849
+ end
850
+ #No special wiki command. The text is "normal" text.
851
+ else #text to add
852
+ #Replace characters.
853
+ if CHARACTERS[el]
854
+ insertion = CHARACTERS[el]
855
+ startspace = endspace = nil
856
+ else
857
+ startspace = ( el[0,1] =~ /\s/ )
858
+ endspace = ( el[-1,1] =~ /\s/ )
859
+ insertion = word_wrap( el ) #wrap content
860
+ end
861
+ if stack.last
862
+ stack.last << insertion
863
+ #This adds some obsolete spaces in case of newlines at the end.
864
+ #But if I compare with ' ', then words will be concatenated without separator.
865
+ stack.last << ' ' if endspace
866
+ else #Just some text without any format
867
+ res << ' ' if startspace #Keep space
868
+ res << insertion
869
+ res << ' ' if endspace #Keep space
870
+ end
751
871
  end
752
- end
753
- when '\\\\' #newline
754
- ( stack.last ? stack.last : res ) << element(:newline).cr
755
- #Something like [[http:...]]
756
- when %r{^\[\[(.+?)(?:\|(.*?))?\]\]} #Link
757
- link = $1
758
- linktext = $2 ? $2 : $1
759
- case link
760
- when /^(https?|ftp):\/\/.+?/
761
- link = link
762
- #local file via file://...
763
- when /^(file):\/\/(.+)/
764
- link = link
765
- check_link_existence( $2, options[:log] )
766
- when /^\./, /\S:[\\\/]/ #lokal file
767
- link = link
768
- check_link_existence( link, options[:log] )
769
- when /^#/ #internal link
770
- link = link
771
- #fixme tex?
772
- else #internal link
773
- #This is normally the wiki-links.
774
- #But this is no wiki, it's a documentgenerator with wiki syntax.
775
- options[:log].warn("Unclear link <#{el}> #{self.inspect}") if options[:log].warn?
776
- link = link
777
- end
778
- if link == linktext #Avoid replacement of // inside linktext
779
- href = element(:a, {:href=>link}, linktext )
780
- else
781
- href = element(:a, {:href=>link}, inline(linktext, options) )
782
- end
783
- if stack.last
784
- stack.last << href
785
- else
786
- res << href
787
- end
788
- #All links should be catched before
789
- when %r{\[\[(.*)\]\]}
790
- options[:log].error("Lost link <#{el}>") if options[:log].error?
791
- #fixme: there are obsolete 2 additional spaces in the result.
792
- when /^http/ #implicit link
793
- #~ href = element(:a, {:href=>el.strip}, el.strip ) #This makes problems with TeX (unmasked _,%...)
794
- href = element(:url, {}, el.strip )
795
- el =~ /(\s|\Z)$/ #get the end-space/newline if available
796
- endspace = ( $1.empty? ? nil : $1 )
797
- if stack.last
798
- stack.last << href
799
- #~ stack.last << last_char #add again the
800
- else
801
- res << href
802
- #~ res << last_char #add again the end-space/newline
803
- end
804
- #No-wiki inline: {{{text}}}
805
- when /\{\{\{(.*)\}\}\}/
806
- if stack.last
807
- stack.last << element(:verb,{},$1)
808
- else
809
- res << element(:verb,{},$1)
810
- end
811
- #Inclusion
812
- #creole2doc implements a general inclusion.
813
- #Main usage are pictures/images ({{picname|alt}}),
814
- #but it can be more...
815
- #
816
- #Available inclusions are defined in Creole::Inclusions resp. Creole#inclusions,
817
- when /\{\{(.+?)(?:\|(.*))?\}\}/
818
- if stack.last
819
- stack.last << inclusion_or_plugin($1, $2, options[:inclusions])
820
- else
821
- res << inclusion_or_plugin($1, $2, options[:inclusions])
822
- end
823
- #Plugin
824
- #Used like Inclusions.
825
- #
826
- #available plugins are defined in Creole::Plugins resp. Creole#plugins
827
- when /<<(.+?)(?:\|(.*))?>>/
828
- if stack.last
829
- stack.last << inclusion_or_plugin($1, $2, options[:plugins])
830
- else
831
- res << inclusion_or_plugin($1, $2, options[:plugins])
832
- end
833
- #No special wiki command. The text is "normal" text.
834
- else #text to add
835
- #Replace characters.
836
- if CHARACTERS[el]
837
- insertion = CHARACTERS[el]
838
- startspace = endspace = nil
839
- else
840
- startspace = ( el[0,1] =~ /\s/ )
841
- endspace = ( el[-1,1] =~ /\s/ )
842
- insertion = word_wrap( el ) #wrap content
843
- end
844
- if stack.last
845
- stack.last << insertion
846
- #This adds some obsolete spaces in case of newlines at the end.
847
- #But if I compare with ' ', then words will be concatenated without separator.
848
- stack.last << ' ' if endspace
849
- else #Just some text without any format
850
- res << ' ' if startspace #Keep space
851
- res << insertion
852
- res << ' ' if endspace #Keep space
853
- end
854
- end
855
- }
856
- res
857
- end #inline
872
+ }
873
+ res
874
+ end #inline
858
875
  =begin rdoc
859
876
  Inclusion or Plugin.
860
877
  creole2doc implements a general inclusion.
@@ -863,24 +880,24 @@ but it can be more...
863
880
 
864
881
  The last paramter contains a hash with the supported inclusions/plugins.
865
882
  =end
866
- def inclusion_or_plugin( link, p_additions, inclusions )
867
-
868
- addition, additions = nil
869
- #Splitt additions at |
870
- if p_additions
871
- addition, *additions = p_additions.split(/\|/)
872
- end
883
+ def inclusion_or_plugin( link, p_additions, inclusions )
884
+
885
+ addition, additions = nil
886
+ #Splitt additions at |
887
+ if p_additions
888
+ addition, *additions = p_additions.split(/\|/)
889
+ end
873
890
 
874
- inclusion = inclusions[link]
875
- #check inclusion.ancestors?
876
- #~ if inclusion.superclass != Creole_inclusion_and_plugin
877
- if inclusion.is_a?(Creole_inclusion_and_plugin)
878
- @log.error( "Wrong inclusion/plugin definition for #{link} (#{inclusion.inspect}, expected #{inclusions.default.superclass})") if @log.error?
879
- return nil
880
- end
881
- ip = inclusion.new( link, addition, additions, self )
882
- return ip
883
- end #inclusion
891
+ inclusion = inclusions[link]
892
+ #check inclusion.ancestors?
893
+ #~ if inclusion.superclass != Creole_inclusion_and_plugin
894
+ if inclusion.is_a?(Creole_inclusion_and_plugin)
895
+ @log.error( "Wrong inclusion/plugin definition for #{link} (#{inclusion.inspect}, expected #{inclusions.default.superclass})") if @log.error?
896
+ return nil
897
+ end
898
+ ip = inclusion.new( link, addition, additions, self )
899
+ return ip
900
+ end #inclusion
884
901
  =begin rdoc
885
902
  Check for links and pictures if the target exist.
886
903
 
@@ -889,27 +906,27 @@ Relative pathes are searched from @options[:targetdir] (default '.').
889
906
 
890
907
  Different locations are not supported (e.g. to implement LaTeXs \graphicspath)
891
908
  =end
892
- def check_link_existence( filename, log )
893
- case filename
894
- when /^.:/#absolute DOS-path (e.g. c:\...)
895
- path = filename.dup
896
- else #relative path
897
- path = "#{@options[:targetdir]}/#{filename}".sub(/^\//, '')
898
- end
899
- path.sub!(/(\.html?)#.*$/, '\1') #Don't check anchor inside html
900
- if ! File.exist?(path)
901
- log.warn("Reference not found: <#{filename}> (looking at <#{path}>)") if log.warn?
902
- #~ log.debug("Reference not found: <#{path}>") if log.debug?
903
- fpath = File.expand_path("#{Dir.pwd}/#{path}")
904
- log.debug("Reference not found: <#{fpath}>") if log.debug?
905
- end
906
- end #check_link_existence
909
+ def check_link_existence( filename, log )
910
+ case filename
911
+ when /^.:/#absolute DOS-path (e.g. c:\...)
912
+ path = filename.dup
913
+ else #relative path
914
+ path = "#{@options[:targetdir]}/#{filename}".sub(/^\//, '')
915
+ end
916
+ path.sub!(/(\.html?)#.*$/, '\1') #Don't check anchor inside html
917
+ if ! File.exist?(path)
918
+ log.warn("Reference not found: <#{filename}> (looking at <#{path}>)") if log.warn?
919
+ #~ log.debug("Reference not found: <#{path}>") if log.debug?
920
+ fpath = File.expand_path("#{Dir.pwd}/#{path}")
921
+ log.debug("Reference not found: <#{fpath}>") if log.debug?
922
+ end
923
+ end #check_link_existence
907
924
 
908
- def inspect()
909
- "<#{self.class} (created #{@creation_caller})>"
910
- end
911
- end #Creole
912
- end #module Creole
925
+ def inspect()
926
+ "<#{self.class} (created #{@creation_caller})>"
927
+ end
928
+ end #Creole
929
+ end #module Creole
913
930
  end #module Docgenerator
914
931
 
915
932