docgenerator 1.0.4 → 1.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 (231) hide show
  1. data/lib/creole/creole2doc.rb +777 -0
  2. data/lib/creole/creole_inclusion_and_plugins.rb +236 -0
  3. data/lib/creole/creole_placeholder.rb +74 -0
  4. data/lib/creole/creole_tabular.rb +170 -0
  5. data/lib/docgenerator.rb +15 -6
  6. data/lib/docgenerator_attribute.rb +2 -2
  7. data/lib/docgenerator_characters.rb +20 -4
  8. data/lib/docgenerator_document.rb +132 -42
  9. data/lib/docgenerator_element.rb +531 -524
  10. data/lib/docgenerator_elements.rb +408 -399
  11. data/lib/docgenerator_environments.rb +28 -2
  12. data/lib/docgenerator_footnote.rb +72 -79
  13. data/lib/docgenerator_sections.rb +1 -1
  14. data/lib/docgenerator_tabular.rb +8 -3
  15. data/lib/packages/docgenerator_beamer.rb +253 -0
  16. data/lib/packages/docgenerator_scrlettr2.rb +53 -9
  17. data/lib/templates/docgenerator_template_css.rb +4 -0
  18. data/lib/wiki2doc/wiki2docgenerator.rb +1087 -970
  19. data/lib/yaml2presentation/yaml2presentation.rb +1091 -0
  20. data/self_docgenerator.rb +8 -6
  21. data/unittest/Red_Flower.jpg +0 -0
  22. data/unittest/creole1.0test.txt +128 -0
  23. data/unittest/expected/beamer_01_doc.html +1 -1
  24. data/unittest/expected/beamer_02_doc.html +1 -1
  25. data/unittest/expected/beamer_doc_html_overview_with_detailpic_and_text_doc.html +34 -0
  26. data/unittest/expected/beamer_doc_html_overview_with_detailpic_doc.html +34 -0
  27. data/unittest/expected/beamer_doc_key_doc.html +1 -1
  28. data/unittest/expected/beamer_doc_note_doc.html +1 -1
  29. data/unittest/expected/beamer_doc_pic_bottom_doc.html +1 -1
  30. data/unittest/expected/beamer_doc_pic_doc.html +1 -1
  31. data/unittest/expected/beamer_doc_pic_left_doc.html +1 -1
  32. data/unittest/expected/beamer_doc_pic_right_doc.html +1 -1
  33. data/unittest/expected/beamer_doc_pic_top_doc.html +1 -1
  34. data/unittest/expected/test_footnote.html +2 -2
  35. data/unittest/expected/test_footnote.latex +1 -1
  36. data/unittest/expected/test_footnote_group.html +3 -3
  37. data/unittest/expected/test_footnote_group.latex +2 -2
  38. data/unittest/expected_creole/test_creole.html +3 -0
  39. data/unittest/expected_creole/test_creole_characters_all.html +10 -0
  40. data/unittest/expected_creole/test_creole_characters_all.latex +20 -0
  41. data/unittest/expected_creole/test_creole_characters_special.html +10 -0
  42. data/unittest/expected_creole/test_creole_characters_special.latex +18 -0
  43. data/unittest/expected_creole/test_creole_countdown.html +3 -0
  44. data/unittest/expected_creole/test_creole_countdown.latex +4 -0
  45. data/unittest/expected_creole/test_creole_creole1.0test.html +182 -0
  46. data/unittest/expected_creole/test_creole_creole1.0test.latex +253 -0
  47. data/unittest/expected_creole/test_creole_creole1.0test.text +160 -0
  48. data/unittest/expected_creole/test_creole_footnotes.html +9 -0
  49. data/unittest/expected_creole/test_creole_footnotes.latex +14 -0
  50. data/unittest/expected_creole/test_creole_footnotes_label.html +9 -0
  51. data/unittest/expected_creole/test_creole_headings.html +17 -0
  52. data/unittest/expected_creole/test_creole_headings.latex +19 -0
  53. data/unittest/expected_creole/test_creole_headings.text +48 -0
  54. data/unittest/expected_creole/test_creole_headings.wiki +37 -0
  55. data/unittest/expected_creole/test_creole_hr.html +7 -0
  56. data/unittest/expected_creole/test_creole_hr.latex +9 -0
  57. data/unittest/expected_creole/test_creole_hr.text +4 -0
  58. data/unittest/expected_creole/test_creole_inline.html +3 -0
  59. data/unittest/expected_creole/test_creole_inline.latex +4 -0
  60. data/unittest/expected_creole/test_creole_inline.text +2 -0
  61. data/unittest/expected_creole/test_creole_inline_ruby.html +12 -0
  62. data/unittest/expected_creole/test_creole_inline_ruby.latex +20 -0
  63. data/unittest/expected_creole/test_creole_inline_ruby_raw.html +6 -0
  64. data/unittest/expected_creole/test_creole_inline_ruby_raw.latex +8 -0
  65. data/unittest/expected_creole/test_creole_input.normsource +23 -0
  66. data/unittest/expected_creole/test_creole_label.html +12 -0
  67. data/unittest/expected_creole/test_creole_label.latex +15 -0
  68. data/unittest/expected_creole/test_creole_line_break.html +6 -0
  69. data/unittest/expected_creole/test_creole_line_break.latex +8 -0
  70. data/unittest/expected_creole/test_creole_links_explicit_internal.html +6 -0
  71. data/unittest/expected_creole/test_creole_links_explicit_internal.text +4 -0
  72. data/unittest/expected_creole/test_creole_links_explicit_with_em.html +3 -0
  73. data/unittest/expected_creole/test_creole_links_explicit_with_em.latex +4 -0
  74. data/unittest/expected_creole/test_creole_links_explicit_with_em.text +2 -0
  75. data/unittest/expected_creole/test_creole_links_external.html +6 -0
  76. data/unittest/expected_creole/test_creole_links_external.latex +8 -0
  77. data/unittest/expected_creole/test_creole_links_external.text +4 -0
  78. data/unittest/expected_creole/test_creole_links_external_implicit.html +9 -0
  79. data/unittest/expected_creole/test_creole_links_external_implicit.latex +12 -0
  80. data/unittest/expected_creole/test_creole_links_external_implicit.text +6 -0
  81. data/unittest/expected_creole/test_creole_links_file.html +6 -0
  82. data/unittest/expected_creole/test_creole_links_file.latex +8 -0
  83. data/unittest/expected_creole/test_creole_links_file.text +4 -0
  84. data/unittest/expected_creole/test_creole_list_ol.html +12 -0
  85. data/unittest/expected_creole/test_creole_list_ol.latex +22 -0
  86. data/unittest/expected_creole/test_creole_list_ol_after_ul.html +12 -0
  87. data/unittest/expected_creole/test_creole_list_ol_after_ul.latex +20 -0
  88. data/unittest/expected_creole/test_creole_list_ol_after_ul.text +6 -0
  89. data/unittest/expected_creole/test_creole_list_ol_ul.html +15 -0
  90. data/unittest/expected_creole/test_creole_list_ol_ul.latex +26 -0
  91. data/unittest/expected_creole/test_creole_list_ul.html +22 -0
  92. data/unittest/expected_creole/test_creole_list_ul.latex +40 -0
  93. data/unittest/expected_creole/test_creole_list_ul.normsource +83 -0
  94. data/unittest/expected_creole/test_creole_list_ul_too_much.html +24 -0
  95. data/unittest/expected_creole/test_creole_list_ul_too_much.latex +44 -0
  96. data/unittest/expected_creole/test_creole_newline.html +9 -0
  97. data/unittest/expected_creole/test_creole_newline.latex +11 -0
  98. data/unittest/expected_creole/test_creole_newline.text +7 -0
  99. data/unittest/expected_creole/test_creole_paragraphs.html +6 -0
  100. data/unittest/expected_creole/test_creole_paragraphs.latex +8 -0
  101. data/unittest/expected_creole/test_creole_paragraphs.normsource +27 -0
  102. data/unittest/expected_creole/test_creole_paragraphs.text +4 -0
  103. data/unittest/expected_creole/test_creole_paragraphs.wiki +4 -0
  104. data/unittest/expected_creole/test_creole_paragraphs_wrap.html +5 -0
  105. data/unittest/expected_creole/test_creole_paragraphs_wrap.latex +6 -0
  106. data/unittest/expected_creole/test_creole_paragraphs_wrap.text +4 -0
  107. data/unittest/expected_creole/test_creole_paragraphs_wrap.wiki +4 -0
  108. data/unittest/expected_creole/test_creole_paragraphs_wrap0.html +9 -0
  109. data/unittest/expected_creole/test_creole_paragraphs_wrap0.latex +11 -0
  110. data/unittest/expected_creole/test_creole_paragraphs_wrap0.text +7 -0
  111. data/unittest/expected_creole/test_creole_paragraphs_wrap0.wiki +7 -0
  112. data/unittest/expected_creole/test_creole_paragraphs_wrap60.html +5 -0
  113. data/unittest/expected_creole/test_creole_paragraphs_wrap60.latex +6 -0
  114. data/unittest/expected_creole/test_creole_paragraphs_wrap60.text +4 -0
  115. data/unittest/expected_creole/test_creole_paragraphs_wrap60.wiki +4 -0
  116. data/unittest/expected_creole/test_creole_picture_link.html +6 -0
  117. data/unittest/expected_creole/test_creole_pictures.html +10 -0
  118. data/unittest/expected_creole/test_creole_pictures.latex +13 -0
  119. data/unittest/expected_creole/test_creole_pictures_css.html +3 -0
  120. data/unittest/expected_creole/test_creole_pictures_css.latex +4 -0
  121. data/unittest/expected_creole/test_creole_pictures_imgclass.html +6 -0
  122. data/unittest/expected_creole/test_creole_pictures_imgclass.latex +8 -0
  123. data/unittest/expected_creole/test_creole_placeholders_html.html +7 -0
  124. data/unittest/expected_creole/test_creole_placeholders_html.latex +8 -0
  125. data/unittest/expected_creole/test_creole_placeholders_html.text +4 -0
  126. data/unittest/expected_creole/test_creole_placeholders_latex.html +6 -0
  127. data/unittest/expected_creole/test_creole_placeholders_latex.latex +9 -0
  128. data/unittest/expected_creole/test_creole_placeholders_latex.text +4 -0
  129. data/unittest/expected_creole/test_creole_tabular.html +20 -0
  130. data/unittest/expected_creole/test_creole_tabular.latex +22 -0
  131. data/unittest/expected_creole/test_creole_tabular_creole.html +18 -0
  132. data/unittest/expected_creole/test_creole_tabular_creole.latex +19 -0
  133. data/unittest/expected_creole/test_creole_tabular_css.html +20 -0
  134. data/unittest/expected_creole/test_creole_tabular_css.latex +22 -0
  135. data/unittest/expected_creole/test_creole_toc.html +11 -0
  136. data/unittest/expected_creole/test_creole_toc.latex +22 -0
  137. data/unittest/expected_creole/test_creole_toc.text +4 -0
  138. data/unittest/expected_creole/test_creole_toc_text.html +5 -0
  139. data/unittest/expected_creole/test_creole_toc_text.latex +5 -0
  140. data/unittest/expected_creole/test_creole_ul_multiple_line.html +7 -0
  141. data/unittest/expected_creole/test_creole_ul_multiple_line.latex +14 -0
  142. data/unittest/expected_creole/test_creole_ul_with_blank.html +11 -0
  143. data/unittest/expected_creole/test_creole_ul_with_blank.latex +20 -0
  144. data/unittest/expected_creole/test_creole_ul_with_bold.creole +0 -0
  145. data/unittest/expected_creole/test_creole_ul_with_bold.html +11 -0
  146. data/unittest/expected_creole/test_creole_ul_with_bold.latex +18 -0
  147. data/unittest/expected_creole/test_creole_ul_with_bold.text +7 -0
  148. data/unittest/expected_creole/test_creole_verbatim.html +25 -0
  149. data/unittest/expected_creole/test_creole_verbatim.latex +33 -0
  150. data/unittest/expected_creole/test_creole_verbatim.text +17 -0
  151. data/unittest/expected_creole/test_creole_verbatim_inline.html +6 -0
  152. data/unittest/expected_creole/test_creole_verbatim_inline.latex +8 -0
  153. data/unittest/expected_creole/test_creole_verbatim_inline_at_start.html +6 -0
  154. data/unittest/expected_creole/test_creole_verbatim_inline_at_start.latex +8 -0
  155. data/unittest/expected_privat/test_creole_test_document.html +6 -0
  156. data/unittest/{expected → expected_wiki}/test_wiki.html +0 -0
  157. data/unittest/{expected → expected_wiki}/test_wiki.latex +0 -0
  158. data/unittest/{expected → expected_wiki}/test_wiki.text +0 -0
  159. data/unittest/{expected → expected_wiki}/test_wiki.wiki +0 -0
  160. data/unittest/{expected → expected_wiki}/test_wiki_amazon.html +0 -0
  161. data/unittest/{expected → expected_wiki}/test_wiki_description.html +0 -0
  162. data/unittest/{expected → expected_wiki}/test_wiki_description.latex +0 -0
  163. data/unittest/{expected → expected_wiki}/test_wiki_description.text +0 -0
  164. data/unittest/{expected → expected_wiki}/test_wiki_description.wiki +0 -0
  165. data/unittest/expected_wiki/test_wiki_footnote.html +8 -0
  166. data/unittest/expected_wiki/test_wiki_footnote.latex +17 -0
  167. data/unittest/{expected → expected_wiki}/test_wiki_footnote.text +2 -4
  168. data/unittest/expected_wiki/test_wiki_footnote.wiki +10 -0
  169. data/unittest/expected_wiki/test_wiki_footnote_2.html +8 -0
  170. data/unittest/expected_wiki/test_wiki_footnote_groupid.html +21 -0
  171. data/unittest/{expected → expected_wiki}/test_wiki_html_code.html +0 -0
  172. data/unittest/{expected → expected_wiki}/test_wiki_html_code.latex +0 -0
  173. data/unittest/{expected → expected_wiki}/test_wiki_html_code.text +0 -0
  174. data/unittest/{expected → expected_wiki}/test_wiki_html_code.wiki +0 -0
  175. data/unittest/{expected → expected_wiki}/test_wiki_inline.html +0 -0
  176. data/unittest/{expected → expected_wiki}/test_wiki_inline.latex +0 -0
  177. data/unittest/{expected → expected_wiki}/test_wiki_inline.text +0 -0
  178. data/unittest/{expected → expected_wiki}/test_wiki_inline.wiki +0 -0
  179. data/unittest/{expected → expected_wiki}/test_wiki_label.html +0 -0
  180. data/unittest/{expected → expected_wiki}/test_wiki_link.html +0 -0
  181. data/unittest/{expected → expected_wiki}/test_wiki_link.latex +0 -0
  182. data/unittest/{expected → expected_wiki}/test_wiki_link.log +0 -0
  183. data/unittest/{expected → expected_wiki}/test_wiki_link.wiki +0 -0
  184. data/unittest/{expected → expected_wiki}/test_wiki_list_ol.html +0 -0
  185. data/unittest/{expected → expected_wiki}/test_wiki_list_ol.latex +0 -0
  186. data/unittest/{expected → expected_wiki}/test_wiki_list_ol.text +0 -0
  187. data/unittest/{expected → expected_wiki}/test_wiki_list_ol.wiki +0 -0
  188. data/unittest/{expected → expected_wiki}/test_wiki_list_ol_after_ul.html +0 -0
  189. data/unittest/{expected → expected_wiki}/test_wiki_list_ol_after_ul.latex +0 -0
  190. data/unittest/{expected → expected_wiki}/test_wiki_list_ol_after_ul.text +0 -0
  191. data/unittest/{expected → expected_wiki}/test_wiki_list_ol_after_ul.wiki +0 -0
  192. data/unittest/{expected → expected_wiki}/test_wiki_list_ol_ul.html +0 -0
  193. data/unittest/{expected → expected_wiki}/test_wiki_list_ol_ul.latex +0 -0
  194. data/unittest/{expected → expected_wiki}/test_wiki_list_ol_ul.text +0 -0
  195. data/unittest/{expected → expected_wiki}/test_wiki_list_ol_ul.wiki +0 -0
  196. data/unittest/{expected → expected_wiki}/test_wiki_list_ul.html +0 -0
  197. data/unittest/{expected → expected_wiki}/test_wiki_list_ul.latex +0 -0
  198. data/unittest/{expected → expected_wiki}/test_wiki_list_ul.text +0 -0
  199. data/unittest/{expected → expected_wiki}/test_wiki_list_ul.wiki +0 -0
  200. data/unittest/{expected → expected_wiki}/test_wiki_list_ul_too_much.html +0 -0
  201. data/unittest/{expected → expected_wiki}/test_wiki_list_ul_too_much.latex +0 -0
  202. data/unittest/{expected → expected_wiki}/test_wiki_list_ul_too_much.text +0 -0
  203. data/unittest/{expected → expected_wiki}/test_wiki_list_ul_too_much.wiki +0 -0
  204. data/unittest/{expected → expected_wiki}/test_wiki_picture.html +0 -0
  205. data/unittest/{expected → expected_wiki}/test_wiki_picture.latex +0 -0
  206. data/unittest/{expected → expected_wiki}/test_wiki_picture_thumb.html +0 -0
  207. data/unittest/{expected → expected_wiki}/test_wiki_tab1.html +0 -0
  208. data/unittest/{expected → expected_wiki}/test_wiki_tab1.latex +0 -0
  209. data/unittest/{expected → expected_wiki}/test_wiki_tab1.wiki +0 -0
  210. data/unittest/{expected → expected_wiki}/test_wiki_textformatting.html +0 -0
  211. data/unittest/{expected → expected_wiki}/test_wiki_textformatting.latex +0 -0
  212. data/unittest/{expected → expected_wiki}/test_wiki_textformatting.text +0 -0
  213. data/unittest/{expected → expected_wiki}/test_wiki_textformatting.wiki +0 -0
  214. data/unittest/{expected → expected_wiki}/test_wiki_toc.html +0 -0
  215. data/unittest/{expected → expected_wiki}/test_wiki_toc.latex +0 -0
  216. data/unittest/{expected → expected_wiki}/test_wiki_toc.text +0 -0
  217. data/unittest/{expected → expected_wiki}/test_wiki_toc.wiki +0 -0
  218. data/unittest/{expected → expected_wiki}/test_wiki_ul_multiple_line.html +0 -0
  219. data/unittest/{expected → expected_wiki}/test_wiki_ul_multiple_line.latex +0 -0
  220. data/unittest/{expected → expected_wiki}/test_wiki_ul_multiple_line.text +0 -0
  221. data/unittest/{expected → expected_wiki}/test_wiki_ul_multiple_line.wiki +0 -0
  222. data/unittest/test_docgenerator.rb +1 -2
  223. data/unittest/unittest_creole2doc.rb +1024 -0
  224. data/unittest/unittest_docgenerator.rb +17 -8
  225. data/unittest/unittest_wiki2doc.rb +92 -88
  226. data/unittest/unittest_yaml2pres.rb +336 -0
  227. metadata +202 -70
  228. data/unittest/expected/test_wiki_footnote.html +0 -8
  229. data/unittest/expected/test_wiki_footnote.latex +0 -15
  230. data/unittest/expected/test_wiki_footnote.wiki +0 -12
  231. data/unittest/expected/test_wiki_footnote_groupid.html +0 -21
@@ -28,243 +28,243 @@ end
28
28
  #The proc contains three block-parameter: The match-element, the Wikitext-object and the logger-object.
29
29
  Wikireg = Struct.new( 'WikiReg', :rule, :regex, :proc )
30
30
  class Wikireg
31
- @@give_message = true
32
- def self.give_message=(val); @@give_message = val; end
33
- def self.give_message?(); return @@give_message; end
31
+ @@give_message = true
32
+ def self.give_message=(val); @@give_message = val; end
33
+ def self.give_message?(); return @@give_message; end
34
34
  end
35
35
 
36
36
  #Constant with all Standard-replacemnts of Wikis.
37
37
  #Each replacement should also convert the part before and after the match.
38
38
  WIKI_INLINE_REPLACEMENTS = [
39
- #[[Bild:Dateiname|Zusatzinfos|Beschreibung]]
40
- #Zusatzinfos:
41
- # -left
42
- # -right
43
- Wikireg.new(:bild, /\[\[Bild:(.*?)\]\]/,
44
- Proc.new{|m, oo, log|
45
- parameter = m[1].split('|')
46
- [ oo.inline(m.pre_match, log),
47
- oo.wiki_bild( parameter.first, parameter[1..-1], log),
48
- oo.inline(m.post_match, log),
49
- ]
50
- } ),
51
- Wikireg.new(:file, /\[\[File:(.*)\]\]/,
52
- Proc.new{|m, oo, log|
53
- parameter = m[1].split('|')
54
- filename = parameter[0]
55
- if parameter.size > 1
56
- txt = "#{parameter.last}"
57
- else
58
- txt = File.basename(filename)
59
- end
60
- if Wikireg.give_message? and ! File.exist?(filename)
61
- log.warn( "Link to unexisting local file #{filename} (from #{Dir.pwd})" ) if log.warn?
62
- end
63
-
64
- css = CSS.new()
65
- parameter[1..-2].each{|p|
66
- case p
67
- when 'size'
68
- txt << " (#{File.size(filename)/1024}KB)" if File.exist?(filename)
69
- when /(.*)=>(.*)/
70
- css[$1] = $2
71
- else
72
- log.warn( "Wiki-File with unknown setting #{p}" ) if log.warn?
73
- end
74
- }
75
- #Result:
76
- [
77
- oo.inline(m.pre_match, log),
78
- element(:a, { :href => filename, :alt => txt, :style => css }, oo.inline(txt, log) ),
79
- oo.inline(m.post_match,log)
80
- ]} ),
81
- Wikireg.new(:label, %r{\[\[label:(.*)\]\]},
82
- Proc.new{|m, oo, log|
83
- [ oo.inline(m.pre_match, log),
84
- element(:label, { :name => m[1]} ),
85
- oo.inline(m.post_match, log)
86
- ]
87
- } ),
88
- Wikireg.new(:ref, %r{<ref>(.*)</ref>},
89
- Proc.new{|m, oo, log|
90
- puts "<ref> is obsolete, use {{footnote}}. To get footnotes set {{footnotes|ref}}"
91
- [ oo.inline(m.pre_match, log),
92
- element(:footnote, { :groupid => 'ref' }, oo.inline(m[1],log) ),
93
- oo.inline(m.post_match, log)
94
- ]
95
- } ),
96
- Wikireg.new(:bf_it, /''''(.*?)''''/,
97
- Proc.new{|m, oo, log| [ oo.inline(m.pre_match, log),
98
- element(:textbf, {}, element(:emph, {}, oo.inline(m[1], log) )),
99
- oo.inline(m.post_match, log)
100
- ]} ),
101
- Wikireg.new(:bf, /'''(.*?)'''/,
102
- Proc.new{|m, oo, log| [ oo.inline(m.pre_match, log),
103
- element(:textbf, {}, oo.inline(m[1], log)),
104
- oo.inline(m.post_match, log)
105
- ]} ),
106
- Wikireg.new(:it, /''(.*?)''/,
107
- Proc.new{|m, oo, log| [ oo.inline(m.pre_match, log),
108
- element(:emph, {}, oo.inline(m[1], log)),
109
- oo.inline(m.post_match, log)
110
- ]} ),
111
- #Soll in Wikipedia-Artikeln nicht verwendet werden.
112
- Wikireg.new(:small, %r{<small>(.*)</small>},
113
- Proc.new{|m, oo, log|
114
- [ oo.inline(m.pre_match, log),
115
- element(:small, {}, oo.inline(m[1], log )),
116
- oo.inline(m.post_match, log)
117
- ]
118
- } ),
119
- Wikireg.new(:stroke, %r{<s>(.*)</s>},
120
- Proc.new{|m, oo, log|
121
- [ oo.inline(m.pre_match, log),
122
- element(:stroke, {}, oo.inline(m[1], log )),
123
- oo.inline(m.post_match, log)
124
- ]
125
- } ),
126
- #- Textbaustein {{...}}
127
- #Standard: [[ legt Textbaustein an, {{ nutzt diesen
128
- # http://de.wikipedia.org/wiki/Wikipedia:Textbausteine/Schwesterprojekte
129
- #- http://de.wikipedia.org/wiki/Wikipedia:Textbausteine
130
- Wikireg.new(:wikidef, /\[\[(.+?):(.*?)\]\]/,
131
- Proc.new{|m, oo, log|
132
- puts "wikidef #{m[1].inspect} obsolete, please use macro {{..|"
133
- [ oo.inline(m.pre_match, log),
134
- oo.wikidef(m[1], m[2] ),
135
- oo.inline(m.post_match, log)
136
- ]}
137
- ),
138
- Wikireg.new(:wiki_macro, /\{\{(.+?)(\|(.*?))?\}\}/,
139
- Proc.new{|m, oo, log|
140
- [ oo.inline(m.pre_match, log),
141
- oo.wiki_macro(m[1], m[3] ),
142
- oo.inline(m.post_match, log)
143
- ].delete_if{|e| ! e or e.respond_to?(:to_str) and /\A\s*\Z/m =~ e}
144
- #[].delete(nil) may return nil -> use delete_if
145
- }
146
- ),
147
- #Problem: detect end of url without a end-character
39
+ #[[Bild:Dateiname|Zusatzinfos|Beschreibung]]
40
+ #Zusatzinfos:
41
+ # -left
42
+ # -right
43
+ Wikireg.new(:bild, /\[\[Bild:(.*?)\]\]/,
44
+ Proc.new{|m, oo, log|
45
+ parameter = m[1].split('|')
46
+ [ oo.inline(m.pre_match, log),
47
+ oo.wiki_bild( parameter.first, parameter[1..-1], log),
48
+ oo.inline(m.post_match, log),
49
+ ]
50
+ } ),
51
+ Wikireg.new(:file, /\[\[File:(.*)\]\]/,
52
+ Proc.new{|m, oo, log|
53
+ parameter = m[1].split('|')
54
+ filename = parameter[0]
55
+ if parameter.size > 1
56
+ txt = "#{parameter.last}"
57
+ else
58
+ txt = File.basename(filename)
59
+ end
60
+ if Wikireg.give_message? and ! File.exist?(filename)
61
+ log.warn( "Link to unexisting local file #{filename} (from #{Dir.pwd})" ) if log.warn?
62
+ end
63
+
64
+ css = CSS.new()
65
+ parameter[1..-2].each{|p|
66
+ case p
67
+ when 'size'
68
+ txt << " (#{File.size(filename)/1024}KB)" if File.exist?(filename)
69
+ when /(.*)=>(.*)/
70
+ css[$1] = $2
71
+ else
72
+ log.warn( "Wiki-File with unknown setting #{p}" ) if log.warn?
73
+ end
74
+ }
75
+ #Result:
76
+ [
77
+ oo.inline(m.pre_match, log),
78
+ element(:a, { :href => filename, :alt => txt, :style => css }, oo.inline(txt, log) ),
79
+ oo.inline(m.post_match,log)
80
+ ]} ),
81
+ Wikireg.new(:label, %r{\[\[label:(.*)\]\]},
82
+ Proc.new{|m, oo, log|
83
+ [ oo.inline(m.pre_match, log),
84
+ element(:label, { :name => m[1]} ),
85
+ oo.inline(m.post_match, log)
86
+ ]
87
+ } ),
88
+ Wikireg.new(:ref, %r{<ref>(.*)</ref>},
89
+ Proc.new{|m, oo, log|
90
+ puts "<ref> is obsolete, use {{footnote}}. To get footnotes set {{footnotes|ref}}"
91
+ [ oo.inline(m.pre_match, log),
92
+ element(:footnote, { :groupid => 'ref' }, oo.inline(m[1],log) ),
93
+ oo.inline(m.post_match, log)
94
+ ]
95
+ } ),
96
+ Wikireg.new(:bf_it, /''''(.*?)''''/,
97
+ Proc.new{|m, oo, log| [ oo.inline(m.pre_match, log),
98
+ element(:textbf, {}, element(:emph, {}, oo.inline(m[1], log) )),
99
+ oo.inline(m.post_match, log)
100
+ ]} ),
101
+ Wikireg.new(:bf, /'''(.*?)'''/,
102
+ Proc.new{|m, oo, log| [ oo.inline(m.pre_match, log),
103
+ element(:textbf, {}, oo.inline(m[1], log)),
104
+ oo.inline(m.post_match, log)
105
+ ]} ),
106
+ Wikireg.new(:it, /''(.*?)''/,
107
+ Proc.new{|m, oo, log| [ oo.inline(m.pre_match, log),
108
+ element(:emph, {}, oo.inline(m[1], log)),
109
+ oo.inline(m.post_match, log)
110
+ ]} ),
111
+ #Soll in Wikipedia-Artikeln nicht verwendet werden.
112
+ Wikireg.new(:small, %r{<small>(.*)</small>},
113
+ Proc.new{|m, oo, log|
114
+ [ oo.inline(m.pre_match, log),
115
+ element(:small, {}, oo.inline(m[1], log )),
116
+ oo.inline(m.post_match, log)
117
+ ]
118
+ } ),
119
+ Wikireg.new(:stroke, %r{<s>(.*)</s>},
120
+ Proc.new{|m, oo, log|
121
+ [ oo.inline(m.pre_match, log),
122
+ element(:stroke, {}, oo.inline(m[1], log )),
123
+ oo.inline(m.post_match, log)
124
+ ]
125
+ } ),
126
+ #- Textbaustein {{...}}
127
+ #Standard: [[ legt Textbaustein an, {{ nutzt diesen
128
+ # http://de.wikipedia.org/wiki/Wikipedia:Textbausteine/Schwesterprojekte
129
+ #- http://de.wikipedia.org/wiki/Wikipedia:Textbausteine
130
+ Wikireg.new(:wikidef, /\[\[(.+?):(.*?)\]\]/,
131
+ Proc.new{|m, oo, log|
132
+ puts "wikidef #{m[1].inspect} obsolete, please use macro {{..|"
133
+ [ oo.inline(m.pre_match, log),
134
+ oo.wikidef(m[1], m[2] ),
135
+ oo.inline(m.post_match, log)
136
+ ]}
137
+ ),
138
+ Wikireg.new(:wiki_macro, /\{\{(.+?)(\|(.*?))?\}\}/,
139
+ Proc.new{|m, oo, log|
140
+ [ oo.inline(m.pre_match, log),
141
+ oo.wiki_macro(m[1], m[3] ),
142
+ oo.inline(m.post_match, log)
143
+ ].delete_if{|e| ! e or e.respond_to?(:to_str) and /\A\s*\Z/m =~ e}
144
+ #[].delete(nil) may return nil -> use delete_if
145
+ }
146
+ ),
147
+ #Problem: detect end of url without a end-character
148
148
  #[uri text]
149
- Wikireg.new(:url1, %r{\[\s*((?:https?://|\.|C:\\|C:\/|ftp:|mailto:|webcal://).*?)\s+(.*?)\s*\]},
150
- Proc.new{|m, oo, log|
151
- #Check local files, but without anchor
152
- if /\A\./ =~ m[1] #local file
153
- filename = oo.inputsource + m[1].split(/#/).first
154
- else
155
- filename = m[1].split(/#/).first
156
- end
149
+ Wikireg.new(:url1, %r{\[\s*((?:https?://|\.|C:\\|C:\/|ftp:|mailto:|webcal://).*?)\s+(.*?)\s*\]},
150
+ Proc.new{|m, oo, log|
151
+ #Check local files, but without anchor
152
+ if /\A\./ =~ m[1] #local file
153
+ filename = oo.inputsource + m[1].split(/#/).first
154
+ else
155
+ filename = m[1].split(/#/).first
156
+ end
157
157
  if Wikireg.give_message? and /\A(\.|\w:)/ =~ m[1] and ! File.exist?(filename)
158
158
  log.warn( "Link to unexisting local file #{filename} (from #{Dir.pwd})" ) if log.warn?
159
- end
160
- link_url = m[1]
161
- if /^\w:/ =~ link_url #local file with absolut path
162
- link_url = 'file://' + link_url
163
- end
164
- if m[2].size > 0
165
- linktext = m[2]
166
- else
167
- linktext = m[1].sub(/http:\/\//, '').sub(/\/$/, '')
168
- end
169
- [ oo.inline(m.pre_match, log),
170
- element(:a, {:href=> link_url }, oo.inline(linktext, log) ),
171
- oo.inline(m.post_match, log)
172
- ]
173
- }
174
- ),
159
+ end
160
+ link_url = m[1]
161
+ if /^\w:/ =~ link_url #local file with absolut path
162
+ link_url = 'file://' + link_url
163
+ end
164
+ if m[2].size > 0
165
+ linktext = m[2]
166
+ else
167
+ linktext = m[1].sub(/http:\/\//, '').sub(/\/$/, '')
168
+ end
169
+ [ oo.inline(m.pre_match, log),
170
+ element(:a, {:href=> link_url }, oo.inline(linktext, log) ),
171
+ oo.inline(m.post_match, log)
172
+ ]
173
+ }
174
+ ),
175
175
  #uri http...
176
- Wikireg.new(:url2, %r{(https?://.*?)(\s|\Z)},
177
- Proc.new{|m, oo, log|
178
- [ oo.inline(m.pre_match, log),
179
- #~ element(:a, {:href=> m[1]}, m[1] ), #hier kein oo.inline
180
- element(:url, {}, m[1] ), #hier kein oo.inline
181
- m[2], #Space/CR
182
- oo.inline(m.post_match, log)
183
- ]} ),
184
- Wikireg.new(:wikilink, /\[\[(.+?)(\|(.*?))?\]\]/,
185
- #~ Wikireg.new(:wikilink, /\[\[(.+?)\]\]/,
186
- Proc.new{|m, oo, log|
187
- linktext = m[1]
188
- #m[2] includes the |
189
- if m[3]
190
- linktext = m[3]
191
- end
192
- [ oo.inline(m.pre_match, log),
193
- element(:a, {:href=> m[1]},
194
- oo.inline(linktext, log)
195
- ),
196
- oo.inline(m.post_match, log)
197
- ]
198
- } ),
176
+ Wikireg.new(:url2, %r{(https?://.*?)(\s|\Z)},
177
+ Proc.new{|m, oo, log|
178
+ [ oo.inline(m.pre_match, log),
179
+ #~ element(:a, {:href=> m[1]}, m[1] ), #hier kein oo.inline
180
+ element(:url, {}, m[1] ), #hier kein oo.inline
181
+ m[2], #Space/CR
182
+ oo.inline(m.post_match, log)
183
+ ]} ),
184
+ Wikireg.new(:wikilink, /\[\[(.+?)(\|(.*?))?\]\]/,
185
+ #~ Wikireg.new(:wikilink, /\[\[(.+?)\]\]/,
186
+ Proc.new{|m, oo, log|
187
+ linktext = m[1]
188
+ #m[2] includes the |
189
+ if m[3]
190
+ linktext = m[3]
191
+ end
192
+ [ oo.inline(m.pre_match, log),
193
+ element(:a, {:href=> m[1]},
194
+ oo.inline(linktext, log)
195
+ ),
196
+ oo.inline(m.post_match, log)
197
+ ]
198
+ } ),
199
199
  ]
200
200
 
201
201
  #require 'LotusNotes.rb'
202
202
  WIKI_INLINE_REPLACEMENT_NOTES =
203
- Wikireg.new(:notes, /(Notes:.*?)(\s|\Z)/, Proc.new{|m, oo, log|
204
- [
205
- oo.inline( m.pre_match, log),
206
- LN_Link.new( m[1] ).to_element,
207
- m[2],
208
- oo.inline( m.post_match, log ),
209
- ]})
203
+ Wikireg.new(:notes, /(Notes:.*?)(\s|\Z)/, Proc.new{|m, oo, log|
204
+ [
205
+ oo.inline( m.pre_match, log),
206
+ LN_Link.new( m[1] ).to_element,
207
+ m[2],
208
+ oo.inline( m.post_match, log ),
209
+ ]})
210
210
 
211
211
  WIKI_INLINE_REPLACEMENTS_SYMBOLS = [
212
- #Problem: Native LaTeX with beamer and \only...
213
- Wikireg.new(:arrow, /->/,
214
- Proc.new{|m, oo, log|
215
- [ oo.inline(m.pre_match, log),
216
- element(:rightarrow),
217
- oo.inline(m.post_match, log),
218
- ]
219
- } ),
220
- Wikireg.new(:Arrow, /=>/,
221
- Proc.new{|m, oo, log|
222
- [ oo.inline(m.pre_match, log),
223
- element(:Rightarrow),
224
- oo.inline(m.post_match, log),
225
- ]
226
- } ),
227
- ]
212
+ #Problem: Native LaTeX with beamer and \only...
213
+ Wikireg.new(:arrow, /->/,
214
+ Proc.new{|m, oo, log|
215
+ [ oo.inline(m.pre_match, log),
216
+ element(:rightarrow),
217
+ oo.inline(m.post_match, log),
218
+ ]
219
+ } ),
220
+ Wikireg.new(:Arrow, /=>/,
221
+ Proc.new{|m, oo, log|
222
+ [ oo.inline(m.pre_match, log),
223
+ element(:Rightarrow),
224
+ oo.inline(m.post_match, log),
225
+ ]
226
+ } ),
227
+ ]
228
228
 
229
229
  WIKI_INLINE_REPLACEMENTS_UNDERSCORE = Wikireg.new(:underscore, /_/,
230
- Proc.new{|m, oo, log|
231
- [ oo.inline(m.pre_match, log),
232
- "\\_",
233
- oo.inline(m.post_match, log),
234
- ]
235
- } )
236
-
230
+ Proc.new{|m, oo, log|
231
+ [ oo.inline(m.pre_match, log),
232
+ "\\_",
233
+ oo.inline(m.post_match, log),
234
+ ]
235
+ } )
236
+
237
237
  #require 'LotusNotes.rb'
238
238
  if defined? LN_Link
239
- WIKI_INLINE_REPLACEMENTS << WIKI_INLINE_REPLACEMENT_NOTES
239
+ WIKI_INLINE_REPLACEMENTS << WIKI_INLINE_REPLACEMENT_NOTES
240
240
  end
241
241
 
242
242
  module Wiki_helper
243
- #Transfer the input to a list.
244
- #input can be
245
- #-String
246
- #-List
247
- #-File (if .rb, then the part after __END__ is taken)
248
- #The method returns a list with lines, but no \n
249
- def get_input( input, lineoffset, close_it = false )
250
- inputlist = []
251
- if input.is_a?(String)
252
- #~ inputlist = input.split("\n")
253
- #Convert to Array, but keep the \n
254
- inputlist = input.split("\n")
255
- elsif input.is_a?(Array)
256
- inputlist = input.flatten.map{|l| l.chomp()}
257
- elsif input.is_a?(File)
258
- #If file is a ruby scriot, then the wiki-code in after __END__
259
- if /\.rb\Z/ =~ input.path and $0 != input.path
260
- line = input.readline while line != "__END__\n"
261
- end
262
- lineoffset = input.lineno
263
- inputlist << input.readlines.map{|l| l.chomp}
264
- input.close if close_it
265
- end
266
- return inputlist, lineoffset
267
- end
243
+ #Transfer the input to a list.
244
+ #input can be
245
+ #-String
246
+ #-List
247
+ #-File (if .rb, then the part after __END__ is taken)
248
+ #The method returns a list with lines, but no \n
249
+ def get_input( input, lineoffset, close_it = false )
250
+ inputlist = []
251
+ if input.is_a?(String)
252
+ #~ inputlist = input.split("\n")
253
+ #Convert to Array, but keep the \n
254
+ inputlist = input.split("\n")
255
+ elsif input.is_a?(Array)
256
+ inputlist = input.flatten.map{|l| l.nil? ? '' : l.chomp()}
257
+ elsif input.is_a?(File)
258
+ #If file is a ruby scriot, then the wiki-code in after __END__
259
+ if /\.rb\Z/ =~ input.path and $0 != input.path
260
+ line = input.readline while line != "__END__\n"
261
+ end
262
+ lineoffset = input.lineno
263
+ inputlist << input.readlines.map{|l| l.chomp}
264
+ input.close if close_it
265
+ end
266
+ return inputlist, lineoffset
267
+ end
268
268
  end
269
269
  #
270
270
  #Struct for wiki elements.
@@ -281,263 +281,345 @@ class Wikielements < Struct.new('Wikielements', :first, :l1,:l2,:l3,:l4, :tab,
281
281
  end
282
282
  end
283
283
 
284
-
284
+ #
285
+ #Get text in wiki-format and build a docgenerator-version.
286
+ #
285
287
  class Wikitext
286
- #Read text and convert it to a Document.
287
- def initialize(
288
- options = {}
289
- )
290
- #convert from old interface
291
- options = {
292
- :wiki_inline_replacements => options
293
- } if options.is_a?(Array)
294
- @options = {
295
- :wiki_inline_replacements => WIKI_INLINE_REPLACEMENTS + WIKI_INLINE_REPLACEMENTS_SYMBOLS,
288
+ #
289
+ #Make short description for the Wiki-syntax
290
+ def self.help( version = :syntax)
291
+ hlp = []
292
+ hlp << "Wikitext.help #{version.inspect}"
293
+ hlp << "-------------------------------------"
294
+ case version
295
+ when :syntax
296
+ hlp << <<main
297
+ Sections:
298
+ ==title==
299
+ ===subtitle===
300
+ ====subsubtitle====
301
+ Lists:
302
+ * unordered
303
+ # ordered
304
+ description-like:
305
+ ;key
306
+ :entry
307
+ Pictures:
308
+ [[Bild:path|options]]
309
+ For options use Wikitext.help(:img)
310
+ Tabulars:
311
+ Use Wikitext.help(:tab) for details
312
+ Specials:
313
+ ---- hrule
314
+ main
315
+ when :img
316
+ hlp << <<main
317
+ Pictures in Wikitext:
318
+ [[Bild:path|options]]
319
+ The complete command must be in one line.
320
+ Options:
321
+ - href=
322
+ - alt=
323
+ - imgclass=: Used for CSS-class (img)
324
+ - figureclass=: Used for CSS-class (span/div)
325
+ - left, right: CSS: float
326
+ - aftertitle/beforetitle: Text before/after image
327
+ - thumb: Add a thumb in the text and link to picture
328
+ - \d*px: size/width
329
+ - width=xx% define width for img/includegraphics
330
+ - xx = : Used for CSS in img
331
+ main
332
+ when :tab
333
+ hlp << <<tabhelp
334
+ Tabulars in Wikitext:
335
+ {|taboptions
336
+ |[lineoptions|]
337
+ |-[newline-options]
338
+ |
339
+ |}
340
+ taboptions:
341
+ - columns=: number of columns (required)
342
+ - columndescription: For LaTeX
343
+ - border=: HTML
344
+ - .* = (.*): Used for CSS
345
+ newline-options
346
+ - toprule
347
+ - midrule
348
+ - hline
349
+ - .* = (.*): Used for CSS
350
+ lineoptions:
351
+ - colspan =
352
+ - pos
353
+ - .* = (.*): Used for CSS
354
+
355
+ Remark: If the text contains macros with | there is a bit confusion,
356
+ what is a parameter of the cell and whats part of the macro.
357
+
358
+ Solution: Define the end of cell parameters with ||
359
+ tabhelp
360
+ else
361
+ hlp << "Sorry, option #{version.inspect} unknown"
362
+ end
363
+ return hlp.join("\n")
364
+ end #help
365
+ #Read text and convert it to a Document.
366
+ def initialize(
367
+ options = {}
368
+ )
369
+ #convert from old interface
370
+ options = {
371
+ :wiki_inline_replacements => options
372
+ } if options.is_a?(Array)
373
+ @options = {
374
+ :wiki_inline_replacements => WIKI_INLINE_REPLACEMENTS + WIKI_INLINE_REPLACEMENTS_SYMBOLS,
296
375
  :log => Log4r::Logger.new('Wikitext', Log4r::INFO),
297
- :inputsource => './',
298
- :parsetest => false #Make an immediate test for parsing
299
- }.update(options)
300
- @source = []
301
- #This rules can be extended via the accessors.
302
- @wiki_inline_replacements = @options[:wiki_inline_replacements]
303
- @lineoffset = 0 #for better debugging
304
- @inputsource = @options[:inputsource]
305
- @log = @options[:log]
376
+ :inputsource => './',
377
+ :parsetest => false #Make an immediate test for parsing
378
+ }.update(options)
379
+ @source = []
380
+ #Hash with all footnote groups
381
+ @footnotegroups = {}
382
+ #This rules can be extended via the accessors.
383
+ @wiki_inline_replacements = @options[:wiki_inline_replacements]
384
+ @lineoffset = 0 #for better debugging
385
+ @inputsource = @options[:inputsource]
386
+ @log = @options[:log]
306
387
  @log.outputters = Log4r::StdoutOutputter.new('log_stdout') if @log.outputters.empty?
307
- self << @options[:content] if @options[:content]
308
- @parent = self
309
- end
310
- #Line offset.
311
- #Is used as initial value in <<
312
- attr_writer :lineoffset
313
- #Used for relative filecheck
314
- attr_accessor :inputsource
315
- #Array with the rules for the inline elements (like text formatting...)
316
- #Can be extended/replaces by this accessor
317
- #
318
- #Don't include arrays. elements must be 'Wikireg'.
319
- attr_reader :wiki_inline_replacements
388
+ self << @options[:content] if @options[:content]
389
+ @parent = self
390
+ end
391
+ #Line offset.
392
+ #Is used as initial value in <<
393
+ attr_writer :lineoffset
394
+ #Used for relative filecheck
395
+ attr_accessor :inputsource
396
+ #Array with the rules for the inline elements (like text formatting...)
397
+ #Can be extended/replaces by this accessor
398
+ #
399
+ #Don't include arrays. elements must be 'Wikireg'.
400
+ attr_reader :wiki_inline_replacements
320
401
  #Logger
321
- attr_reader :log
322
- #Element, where the wiki test belongs to.
323
- #Can be used in the procs insiede a wikirule.
324
- attr_accessor :parent
325
- #Wiki-Code, which is translated to to_element.
326
- #Source is an array
327
- attr_accessor :source
328
-
329
- include Wiki_helper
330
- #Add contents to Wiki-Text
331
- def <<( input )
332
- inputlist, lineoffset = get_input( input, @lineoffset )
333
- #The immediate parsing may help, when an error occurs.
334
- #The immediat parsing returns error messages with correct lineoffsets.
335
- #(On the other side, it may helt to see the @source itself)
336
- wiki2doc( inputlist.join("\n"), lineoffset ) if @options[:parsetest] == true
337
- @source.concat(inputlist)
338
- return self
339
- end
340
- #Prepare output for docgenerator.
402
+ attr_reader :log
403
+ #Element, where the wiki test belongs to.
404
+ #Can be used in the procs insiede a wikirule.
405
+ attr_accessor :parent
406
+ #Wiki-Code, which is translated to to_element.
407
+ #Source is an array
408
+ attr_accessor :source
409
+
410
+ include Wiki_helper
411
+ #Add contents to Wiki-Text
412
+ def <<( input )
413
+ inputlist, lineoffset = get_input( input, @lineoffset )
414
+ #The immediate parsing may help, when an error occurs.
415
+ #The immediat parsing returns error messages with correct lineoffsets.
416
+ #(On the other side, it may helt to see the @source itself)
417
+ wiki2doc( inputlist.join("\n"), lineoffset ) if @options[:parsetest] == true
418
+ @source.concat(inputlist)
419
+ return self
420
+ end
421
+ #Prepare output for docgenerator.
341
422
  #
342
423
  #Attention! to_doc uses another logger then the wiki.
343
424
  #If it should be the same, it must be added at definition of the wiki.
344
- def to_doc( target, options = {} )
425
+ def to_doc( target, options = {} )
345
426
  o = Docgenerator_logger.set_option_defaults(options)
346
427
  o[:log].debug("enter to_doc for Wikitext #{self.inspect}") if o[:log].debug?
347
- Footnotegroup.clear()
348
- doc = wiki2doc( @source.join("\n") ) #return lists of element
428
+ @footnotegroups = {} #Avoid the multiple additions to groups (this makes parallel processing inpossible!)
429
+ doc = wiki2doc( @source.join("\n") ) #return lists of element
349
430
  doc.to_doc(target, options )
350
- end
351
-
352
- #
353
- #Method is called for wiki-structures like
354
- # [[key:value]]
355
- #This can be used to adapt the wiki for special usages.
356
- #
357
- #This is a inline replacement.
358
- #The return code is added at the location, where it is defined
359
- def wikidef( key, value )
431
+ end #Wikitext.to_doc
432
+
433
+ #
434
+ #Method is called for wiki-structures like
435
+ # [[key:value]]
436
+ #This can be used to adapt the wiki for special usages.
437
+ #
438
+ #This is a inline replacement.
439
+ #The return code is added at the location, where it is defined
440
+ def wikidef( key, value )
360
441
  @log.warn("#{self.class}#wikidef #{key}: #{value} in line #{@lineno}" ) if log.warn?
361
- return value
362
- end
363
- #Include a picture
364
- # [[Bild:Dateiname|Zusatzinfos|Beschreibung]]
365
- #Zusatzinfos:
366
- # -left/right
367
- # -___px scale the pic. When used in combination with thumb, a pic "widht-picname) is searched.
368
- # -thumb (usefull in combination with href or width=50%)
369
- #figure_type:
370
- #The picture is framed by this value.
371
- #When you use :div, you can't make inline-Pics.
372
- #:span can be used also as float (HTML)
373
- #Correct LaTeX: figure (or not?
374
- def wiki_bild( picname, parameter, log, figure_type = :span)
375
- thumb = false #Use thumb instead
376
- href = false #make pic clickabe
377
- figure = element(figure_type, { :style => css_fig = CSS.new() }).cR
378
- css_img = CSS.new()
379
- option = { :src => picname, :style => css_img } #Options for img
380
- before_img = []
381
- after_img = []
382
-
383
- parameter.each{|p|
384
- case p
385
- when /href=(.*)/; href = $1
386
- when /alt=(.*)/; option[:alt] = $1
387
- when /imgclass=(.*)/; option[:class] = $1
388
- when /figureclass=(.*)/; figure[:class] << $1
389
- when /^class=(.*)/; option[:class] = $1 #old
390
- when 'left', 'right'
391
- css_fig[:float] = p
392
- when /aftertitle(=(.*))*/
393
- after_img << element(:br, { :clear => 'all' } ).cr
394
- after_img << $2
395
- when /beforetitle(=(.*))*/
396
- before_img << $2
397
- after_img << element(:br, { :clear => 'all' } ).cr
398
- when /thumb(=(.*))*/
399
- #Add a thumb in the text and link to picture
400
- thumb = true #look later for width-picname
401
- thumb = $2 if $2
402
- if File.exist?( @inputsource + picname ) and !href
403
- href = picname
404
- end
405
- when /\A\d*px\Z/ #size
406
- option[:width] = p
407
- when /(width)=(.*)/
408
- css_img[$1] = $2
409
- w = $2 #store it, $2 is replaced in next regex.
410
- case w
411
- when /100%/
412
- option[:width] = "\\textwidth"
413
- when /\A(\d+)%/
414
- option[:width] = "0.#{$1}\\textwidth"
415
- else
416
- option[:width] = w
417
- end
418
- when /(.*)=(.*)/
419
- css_img[$1] = $2
420
- else
421
- log.warn( "Wiki-Picture with unknown setting #{p}" ) if log.warn?
422
- end
423
- }
424
-
425
- bild = []
426
- bild = element(:a, {:href=>href }).cr if href
427
-
428
- figure << before_img if ! before_img.empty?
429
- figure << bild
430
- figure << after_img if ! after_img.empty?
442
+ return value
443
+ end
444
+ #Include a picture
445
+ # [[Bild:Dateiname|Zusatzinfos|Beschreibung]]
446
+ #Zusatzinfos:
447
+ # -left/right
448
+ # -___px scale the pic. When used in combination with thumb, a pic "widht-picname) is searched.
449
+ # -thumb (usefull in combination with href or width=50%)
450
+ #figure_type:
451
+ #The picture is framed by this value.
452
+ #When you use :div, you can't make inline-Pics.
453
+ #:span can be used also as float (HTML)
454
+ #Correct LaTeX: figure (or not?
455
+ def wiki_bild( picname, parameter, log, figure_type = :span)
456
+ thumb = false #Use thumb instead
457
+ href = false #make pic clickabe
458
+ figure = element(figure_type, { :style => css_fig = CSS.new() }).cR
459
+ css_img = CSS.new()
460
+ option = { :src => picname, :style => css_img } #Options for img
461
+ before_img = []
462
+ after_img = []
463
+
464
+ parameter.each{|p|
465
+ case p
466
+ when /href=(.*)/; href = $1
467
+ when /alt=(.*)/; option[:alt] = $1
468
+ when /imgclass=(.*)/; option[:class] = $1
469
+ when /figureclass=(.*)/; figure[:class] << $1
470
+ when /^class=(.*)/; option[:class] = $1 #old
471
+ when 'left', 'right'
472
+ css_fig[:float] = p
473
+ when /aftertitle(=(.*))*/
474
+ after_img << element(:br, { :clear => 'all' } ).cr
475
+ after_img << $2
476
+ when /beforetitle(=(.*))*/
477
+ before_img << $2
478
+ after_img << element(:br, { :clear => 'all' } ).cr
479
+ when /thumb(=(.*))*/
480
+ #Add a thumb in the text and link to picture
481
+ thumb = true #look later for width-picname
482
+ thumb = $2 if $2
483
+ if File.exist?( @inputsource + picname ) and !href
484
+ href = picname
485
+ end
486
+ when /\A\d*px\Z/ #size
487
+ option[:width] = p
488
+ when /(width)=(.*)/
489
+ css_img[$1] = $2
490
+ w = $2 #store it, $2 is replaced in next regex.
491
+ case w
492
+ when /100%/
493
+ option[:width] = "\\textwidth"
494
+ when /\A(\d+)%/
495
+ option[:width] = "0.#{$1}\\textwidth"
496
+ else
497
+ option[:width] = w
498
+ end
499
+ when /(.*)=(.*)/
500
+ css_img[$1] = $2
501
+ else
502
+ log.warn( "Wiki-Picture with unknown setting #{p}" ) if log.warn?
503
+ end
504
+ }
505
+
506
+ bild = []
507
+ bild = element(:a, {:href=>href }).cr if href
508
+
509
+ figure << before_img if ! before_img.empty?
510
+ figure << bild
511
+ figure << after_img if ! after_img.empty?
431
512
 
432
- if thumb == true
433
- if File.exist?( "#{option[:width]}-#{option[:src]}" )
434
- thumb = "#{option[:width]}-#{option[:src]}"
435
- else
436
- thumb = picname
437
- end
438
- end
439
- option[:src] = thumb if thumb
440
-
441
- if /^(http|file|.:\/|\/)/ =~ option[:src]
442
- src = option[:src]
443
- else
444
- src = @inputsource + option[:src]
445
- end
446
- if /^http/ !~ src and ! File.exist?( (src).sub(%r{file:\/\/}, '') )
447
- log.warn( "Wikireg:bild: Picture #{option[:src]} not found (check from #{Dir.pwd} #{inputsource})" ) if log.warn?
448
- end
449
- if thumb and ! File.exist?( @inputsource + thumb )
450
- log.warn( "Wikireg:bild: Thumb #{thumb} not found (check from #{Dir.pwd} #{inputsource})" ) if log.warn?
451
- end
452
- if href and /^http:/!~ href and ! File.exist?( @inputsource + href )
453
- log.warn("Wikireg:bild: reference #{href} not found (check from #{Dir.pwd} #{inputsource})" ) if log.warn?
454
- #~ puts Dir.pwd
455
- #~ puts @inputsource.inspect
456
- #~ puts href
457
- #~ puts option[:src]
458
- #~ puts '-'*10
459
- end
460
-
461
- bild << element(:img, option )
462
- figure
463
- end #wiki_bild
464
-
465
- #
466
- #Analyses {{-Textmacros.
467
- #If it is redefined, but want to keep the standard method,
468
- #then you can call it via super in the else-branch of your case-command.
469
- def wiki_macro( key, value, log = @log )
470
- if value
471
- val = value.split('|')
472
- else
473
- val = []
474
- end
475
- case key
476
- when 'maketitle', 'author', 'title', 'date'
477
- val = val[0]
478
- return [
479
- element( key.to_sym,{},val ).cr,
480
- ]
481
- when 'Commons'
482
- return [
483
- element(:a, { :href => "http://commons.wikimedia.org/wiki/#{val[0]}" }, "Commons: #{val[0]}" ).cr,
484
- ]
485
- #~ when 'Wikibooks'
486
- #~ #fixme language?
487
- #~ return [
488
- #~ element(:a, { :href => "http://en.wikibooks.org/wiki/#{val[0]}" }, "Commons: #{val[0]}" ).cr,
489
- #~ ]
490
- when 'newline'
491
- if val.include?('clear')
492
- return element(:br, {:clear=>'all'})
493
- else
494
- return element(:br)
495
- end
496
- when 'dmoz'
497
- def dmoz_analyse(val)
498
- if val[1]
499
- catname = val[1]
500
- else
501
- catname = val[0].split(/\//).last.gsub(/_/, ' ')
502
- end
503
- cat = val[0].sub(%r{http://(www|editors)*.dmoz.org/}, '')
504
- cat << '/' if cat[-1,1] != '/'
505
- return cat, catname
506
- end
507
- cat, catname = dmoz_analyse(val)
508
- return [
509
- 'Weitere Links zum Thema ',
510
- element(:a, { :href => "http://dmoz.org/#{cat}" }, catname ),
511
- ' im Open Directory Project'
512
- ]
513
- when 'dmozed'
514
- #fixme: Umlaute
515
- cat, catname = dmoz_analyse(val)
516
- return [
517
- element(:a, { :href => "http://dmoz.org/#{cat}" }, catname ),
518
- ' ',
519
- element(:a, { :href => "http://editors.dmoz.org/editors/editcat.cgi?cat=#{cat}" },
520
- [ '(Edit)'])
521
- ]
522
- #footnotes|groupid
523
- when 'footnotes'
524
- #~ value = self.object_id if ! value
525
- value = nil if ! value
526
- return Footnotegroup.get( value )
527
- #footnote[groupid]
528
- when /footnote(\[(.*)\])*/
529
- #fixme footnotegroup?
530
- #~ $2 ? groupid = $2 : groupid = self.object_id
531
- $2 ? groupid = $2 : groupid = nil
532
- return [
533
- element(:footnote, { :groupid =>groupid }, self.inline(value, log) ),
534
- ]
535
- when 'html'
536
- return element(:htmlonly, {}, value )
537
- when 'rubycode', 'rubyvar' ##Pfui, eval
538
- log.warn( "#{self.class}#wiki_macro: eval in line #{@lineno} ('#{value}')" ) if log.warn?
539
- #~ return eval(value)
540
- return eval(value, binding, 'Wiki', @lineno)
513
+ if thumb == true
514
+ if File.exist?( "#{option[:width]}-#{option[:src]}" )
515
+ thumb = "#{option[:width]}-#{option[:src]}"
516
+ else
517
+ thumb = picname
518
+ end
519
+ end
520
+ option[:src] = thumb if thumb
521
+
522
+ if /^(http|file|.:\/|\/)/ =~ option[:src]
523
+ src = option[:src]
524
+ else
525
+ src = @inputsource + option[:src]
526
+ end
527
+ if /^http/ !~ src and ! File.exist?( (src).sub(%r{file:\/\/}, '') )
528
+ log.warn( "Wikireg:bild: Picture #{option[:src]} not found (check from #{Dir.pwd} #{inputsource})" ) if log.warn?
529
+ end
530
+ if thumb and ! File.exist?( @inputsource + thumb )
531
+ log.warn( "Wikireg:bild: Thumb #{thumb} not found (check from #{Dir.pwd} #{inputsource})" ) if log.warn?
532
+ end
533
+ if href and /^http:/!~ href and ! File.exist?( @inputsource + href )
534
+ log.warn("Wikireg:bild: reference #{href} not found (check from #{Dir.pwd} #{inputsource})" ) if log.warn?
535
+ #~ puts Dir.pwd
536
+ #~ puts @inputsource.inspect
537
+ #~ puts href
538
+ #~ puts option[:src]
539
+ #~ puts '-'*10
540
+ end
541
+
542
+ bild << element(:img, option )
543
+ figure
544
+ end #wiki_bild
545
+
546
+ #
547
+ #Analyses {{-Textmacros.
548
+ #If it is redefined, but want to keep the standard method,
549
+ #then you can call it via super in the else-branch of your case-command.
550
+ def wiki_macro( key, value, log = @log )
551
+ if value
552
+ val = value.split('|')
553
+ else
554
+ val = []
555
+ end
556
+ case key
557
+ when 'maketitle', 'author', 'title', 'date'
558
+ val = val[0]
559
+ return [
560
+ element( key.to_sym,{},val ).cr,
561
+ ]
562
+ when 'Commons'
563
+ return [
564
+ element(:a, { :href => "http://commons.wikimedia.org/wiki/#{val[0]}" }, "Commons: #{val[0]}" ).cr,
565
+ ]
566
+ #~ when 'Wikibooks'
567
+ #~ #fixme language?
568
+ #~ return [
569
+ #~ element(:a, { :href => "http://en.wikibooks.org/wiki/#{val[0]}" }, "Commons: #{val[0]}" ).cr,
570
+ #~ ]
571
+ when 'newline'
572
+ if val.include?('clear')
573
+ return element(:br, {:clear=>'all'})
574
+ else
575
+ return element(:br)
576
+ end
577
+ when 'dmoz'
578
+ def dmoz_analyse(val)
579
+ if val[1]
580
+ catname = val[1]
581
+ else
582
+ catname = val[0].split(/\//).last.gsub(/_/, ' ')
583
+ end
584
+ cat = val[0].sub(%r{http://(www|editors)*.dmoz.org/}, '')
585
+ cat << '/' if cat[-1,1] != '/'
586
+ return cat, catname
587
+ end
588
+ cat, catname = dmoz_analyse(val)
589
+ return [
590
+ 'Weitere Links zum Thema ',
591
+ element(:a, { :href => "http://dmoz.org/#{cat}" }, catname ),
592
+ ' im Open Directory Project'
593
+ ]
594
+ when 'dmozed'
595
+ #fixme: Umlaute
596
+ cat, catname = dmoz_analyse(val)
597
+ return [
598
+ element(:a, { :href => "http://dmoz.org/#{cat}" }, catname ),
599
+ ' ',
600
+ element(:a, { :href => "http://editors.dmoz.org/editors/editcat.cgi?cat=#{cat}" },
601
+ [ '(Edit)'])
602
+ ]
603
+ #footnotes|groupid
604
+ when 'footnotes'
605
+ #~ value = self.object_id if ! value
606
+ value = Footnotegroup::DEFAULTGROUPID unless value
607
+ return @footnotegroups[value]
608
+ #footnote[groupid]
609
+ when /footnote(\[(.*)\])*/
610
+ groupid = $2 ? $2 : Footnotegroup::DEFAULTGROUPID
611
+ if ! @footnotegroups[groupid]
612
+ @footnotegroups[groupid] = Footnotegroup.new(groupid)
613
+ end
614
+ return [
615
+ element(:footnote, { :group => @footnotegroups[groupid] }, self.inline(value, log) ),
616
+ ]
617
+ when 'html'
618
+ return element(:htmlonly, {}, value )
619
+ when 'rubycode', 'rubyvar' ##Pfui, eval
620
+ log.warn( "#{self.class}#wiki_macro: eval in line #{@lineno} ('#{value}')" ) if log.warn?
621
+ #~ return eval(value)
622
+ return eval(value, binding, 'Wiki', @lineno)
541
623
  when 'verbatimfile'
542
624
  if File.exist?( val.first )
543
625
  return element(:verbatim,
@@ -555,477 +637,492 @@ class Wikitext
555
637
  log.error( "#{self.class}#wiki_macro: File #{value} missing for filecontent in line #{@lineno}" ) if log.error?
556
638
  end
557
639
  #A symbol. The corresponding element must be defined.
558
- when 'symbol'; return element(value.to_sym)
559
- when 'backslash'; return element(:backslash )
560
- when '^'; return element(:ensuremath, {}, element(:'^' ) )
561
- when '>'; return element(:gt)
562
- when '<'; return element(:lt)
563
- when 'percent', '%'; return element(:percent )
564
- when 'rbrace'; return element(:rbrace )
565
- when '_'; return element(:underscore )
566
- when ' '; return element(:relax )
567
- when 'lbrace'; return element(:lbrace )
568
- when 'tilde', 'sim'; return element(:sim )
569
- when 'math'; return element(:ensuremath,{}, value )
640
+ when 'symbol'; return element(value.to_sym)
641
+ when 'backslash'; return element(:backslash )
642
+ when '^'; return element(:ensuremath, {}, element(:'^' ) )
643
+ when '>'; return element(:gt)
644
+ when '<'; return element(:lt)
645
+ when '&'; return element(:'\&')
646
+ when 'percent', '%'; return element(:percent )
647
+ when 'rbrace'; return element(:rbrace )
648
+ when '_'; return element(:underscore )
649
+ when ' '; return element(:relax )
650
+ when '...'; return element(:ldots )
651
+ when 'lbrace'; return element(:lbrace )
652
+ when 'tilde', 'sim'; return element(:sim )
653
+ when 'math'; return element(:ensuremath,{}, value )
570
654
  #>>>requires privat/affiliate.rb
571
- when 'asin'
655
+ when 'asin'
572
656
  return Amazon.new.asin_in_iframe( value ) if defined? JPC
573
657
  log.error( "#{self.class}#wiki_macro: No privat/docgenerator_affiliate available (line #{@lineno})" ) if log.error?
574
658
  return ''
575
- when 'amazon' #~ {{amazon|produktlinie|keywords}}
659
+ when 'amazon' #~ {{amazon|produktlinie|keywords}}
576
660
  return Amazon.make_link(val) if defined? JPC
577
661
  log.error( "#{self.class}#wiki_macro: No privat/docgenerator_affiliate available (line #{@lineno})" ) if log.error?
578
662
  return ''
579
- when 'jpc' #~ {{amazon|produktlinie|keywords}}
663
+ when 'jpc' #~ {{amazon|produktlinie|keywords}}
580
664
  return JPC.make_link(val) if defined? JPC
581
665
  log.error( "#{self.class}#wiki_macro: No privat/docgenerator_affiliate available (line #{@lineno})" ) if log.error?
582
666
  return ''
583
667
  #<<<requires privat/affiliate.rb
584
- when 'fixme'
585
- log.info( "Fixme: #{value}" ) if log.info?
586
- return element(:comment, {}, [ 'Fixme: ', value ] )
587
- else
588
- log.error( "#{self.class}#wiki_macro Key '#{key}' unknown in line #{@lineno} ('#{value}')" ) if log.error?
589
- return value
590
- end
591
- end
668
+ when 'fixme'
669
+ log.info( "Fixme: #{value}" ) if log.info?
670
+ return element(:comment, {}, [ 'Fixme: ', value ] )
671
+ else
672
+ log.error( "#{self.class}#wiki_macro Key '#{key}' unknown in line #{@lineno} ('#{value}')" ) if log.error?
673
+ return value
674
+ end
675
+ end
592
676
 
593
677
 
594
- #Little structure for use in wiki2doc.
595
- Wiki_line = Struct.new('Wiki_line', :type, :content, :lineno, :indent, :add_info)
596
- #
597
- #Parse the text and creates the elements of it.
598
- #
599
- def wiki2doc( txt, lineoffset = 0, log = @log )
600
- (@wiki_inline_replacements ).each{|rule|
601
- if ! rule.is_a?(Wikireg)
602
- log.fatal( "Wikitext.wiki2doc: rule is no Wikireg #{rule.inspect}" ) if log.fatal?
603
- end
604
- }
678
+ #Little structure for use in wiki2doc.
679
+ Wiki_line = Struct.new('Wiki_line', :type, :content, :lineno, :indent, :add_info)
680
+ #
681
+ #Parse the text and creates the elements of it.
682
+ #
683
+ def wiki2doc( txt, lineoffset = 0, log = @log )
684
+ (@wiki_inline_replacements ).each{|rule|
685
+ if ! rule.is_a?(Wikireg)
686
+ log.fatal( "Wikitext.wiki2doc: rule is no Wikireg #{rule.inspect}" ) if log.fatal?
687
+ end
688
+ }
605
689
 
606
- lines = []
607
- @lineno = lineoffset
608
- collector = nil #collect content for other application
609
- collectorline = nil #collect content for other application
610
-
611
- txt.each{|line|
612
- if line.gsub!( /#~.*/, '') #delete comments
613
- #skip processing, if the line is now empty.
614
- #Without this, empty paragraphs can be created.
615
- next if line == "\n"
616
- end
617
- @lineno += 1
690
+ lines = []
691
+ @lineno = lineoffset
692
+ collector = nil #collect content for other application
693
+ collectorline = nil #collect content for other application
694
+
695
+ txt.each{|line|
696
+
697
+ if line.gsub!( /#~.*/, '') #delete comments
698
+ #skip processing, if the line is now empty.
699
+ #Without this, empty paragraphs can be created.
700
+ next if line == "\n"
701
+ end
702
+ @lineno += 1
618
703
 
619
- #if the content should be turned into new variant, do it here.
620
- if collector
621
- if /^<<</ =~ line #close the collector
622
- lines << Wiki_line.new(:collector, collector, collectorline )
623
- collector = nil
624
- else
625
- collector << line.chomp #collect content to collector
626
- end
627
- next
628
- end
629
- #Preparse. Detect line type and assign it
630
- case line.chomp
631
- #Example:
632
- #>>>structogramm{title;width;height}
633
- when /^>>>(.*)\{(.*)\}/
634
- args = []
635
- ctype = $1
636
- args = $2.split(/[;]/) if $2
637
- collector = WikiCollector.create(ctype, args )
638
- collectorline = @lineno
639
- if ! collector
704
+ #if the content should be turned into new variant, do it here.
705
+ if collector
706
+ if /^<<</ =~ line #close the collector
707
+ lines << Wiki_line.new(:collector, collector, collectorline )
708
+ collector = nil
709
+ else
710
+ collector << line.chomp #collect content to collector
711
+ end
712
+ next
713
+ end
714
+ #Preparse. Detect line type and assign it
715
+ case line.chomp
716
+ #Example:
717
+ #>>>structogramm{title;width;height}
718
+ when /^>>>(.*)\{(.*)\}/
719
+ args = []
720
+ ctype = $1
721
+ args = $2.split(/[;]/) if $2
722
+ collector = WikiCollector.create(ctype, args )
723
+ collectorline = @lineno
724
+ if ! collector
640
725
  log.error( "#{__FILE__}##{__LINE__}: Undefined Collector #{ctype.inspect} used. Take Array instead (line #{@lineno})" ) if log.error?
641
- collector = []
642
- end
643
- #===[key]Titel===
644
- when /\A(=+)(?:\[(.*?)\])?(.+?)(=+)\s*/ #:h1, :h2, :h3, :h4, :h5, :h6
645
- #~ puts $1, $2, $3
646
- if $1.size != $4.size
647
- log.warn("#{__FILE__}: Heading problem #{$1} doesn't match <#{$3}> #{line.inspect}" ) if log.warn?
648
- end
649
- #Level starts with ==
650
- # =title= is not supported.
651
- h_level = "h#{$1.size - 1}".to_sym
652
- lines << Wiki_line.new(h_level, self.inline($3, log), @lineno, nil, $2)
653
- when /^\s*$/ #empty line
654
- lines << Wiki_line.new(:p,nil, @lineno)
655
- when /^((?:\*|\#)+)(\s*)/ #:li
656
- lines << Wiki_line.new(:li, self.inline($~.post_match, log), @lineno, $2.size, $1)
657
- #Experiment f�r items in description
658
- #~ when /^(:)?((?:\*|\#)+)(\s*)/ #:li
659
- #~ puts '>' * 15
660
- #~ puts line.inspect
661
- #~ puts $1.inspect
662
- #~ puts $2.inspect
663
- #~ puts $3.inspect
664
- #~ puts '<' * 15
665
- #~ lines << Wiki_line.new(:li, self.inline($~.post_match, log), @lineno, $3.size, $2)
666
- when /^;(\s*)/ #:dt
667
- lines << Wiki_line.new(:dt, self.inline($~.post_match, log), @lineno, $1.size)
668
- when /^:(\s*)/ #:dd
669
- lastline = lines.last
670
- if ! lastline
671
- log.warn( "#{__FILE__}: Use ':' at start of wiki text. #{@lineno}" ) if log.warn?
672
- lastline = Wiki_line.new() #Avoid error with method type
673
- end
674
- #If there was already an indent before, loo back.
675
- if lastline.type == :indent
676
- #find first line before indent
677
- lines.reverse.each{|line|
678
- lastline = line
679
- break if lastline.type != :indent
680
- }
681
- end
682
- if [:dt,:dd].include?(lastline.type)
683
- lines << Wiki_line.new(:dd, self.inline($~.post_match, log), @lineno, $1.size)
684
- else #-> quote
685
- lines << Wiki_line.new(:quote, self.inline($~.post_match, log), @lineno, $1.size)
686
- end
687
- when /^----$/ #:hr #line
688
- lines << Wiki_line.new(:hr,nil,@lineno)
689
- when /^(\s+)/ #:indent #can be: continuation of a list or a verbatim
690
- lines << Wiki_line.new(:indent, $~.post_match, @lineno, $1.size)
691
- when /^\{\|/ #:tab
692
- lines << Wiki_line.new(:tabular,$~.post_match,@lineno)
693
- when /^\|\}/ #:tabend
694
- lines << Wiki_line.new(:tabular_end,$~.post_match,@lineno)
695
- when /^\|-/ #:tabrow
696
- lines << Wiki_line.new(:tabular_row,$~.post_match,@lineno)
697
- when /^\|(.*\|)*(.*?)\s*$/ #:tabcell
698
- par = $1
699
- txt = $2
700
- #if the text contains macros with | there is a bit confusion,
701
- #what is a parameter of the cell and whats part of the macro.
702
- #
703
- #Solution:
704
- #Define the end of cell parameters with ||
705
- if par and par =~ /\|\|/
706
- par = $~.pre_match #parameters only before ||
707
- txt = $~.post_match + txt #txt all after ||
708
- end
709
- lines << Wiki_line.new(:tabular_cell ,self.inline(txt, log),@lineno,nil,par)
710
- else
711
- #~ puts "??\tUnknown line (#{__FILE__} line #{__LINE__})"
712
- #~ puts "??\tUnknown line: #{line.inspect}"
713
- #lines << Wiki_line.new(:text, self.inline(line, log), @lineno)
714
- #Insert space at end of line, but before \n.
715
- #Without, a line break results in HTML-Text without space between flow text
716
- lines << Wiki_line.new(:text, self.inline("#{line.chomp} \n", log), @lineno)
717
- end
718
- } #txt.each |line|
719
-
720
- if collector
726
+ collector = []
727
+ end
728
+ #===[key]Titel===
729
+ when /\A(=+)(?:\[(.*?)\])?(.+?)(=+)\s*/ #:h1, :h2, :h3, :h4, :h5, :h6
730
+ #~ puts $1, $2, $3
731
+ if $1.size != $4.size
732
+ log.warn("#{__FILE__}: Heading problem #{$1} doesn't match <#{$3}> #{line.inspect}" ) if log.warn?
733
+ end
734
+ #Level starts with ==
735
+ # =title= is not supported.
736
+ h_level = "h#{$1.size - 1}".to_sym
737
+ lines << Wiki_line.new(h_level, self.inline($3, log), @lineno, nil, $2)
738
+ when /^\s*$/ #empty line
739
+ lines << Wiki_line.new(:p, nil, @lineno)
740
+ when /^((?:\*|\#)+)(\s*)/ #:li
741
+ lines << Wiki_line.new(:li, self.inline($~.post_match, log), @lineno, $2.size, $1)
742
+ #Experiment f�r items in description
743
+ #~ when /^(:)?((?:\*|\#)+)(\s*)/ #:li
744
+ #~ puts '>' * 15
745
+ #~ puts line.inspect
746
+ #~ puts $1.inspect
747
+ #~ puts $2.inspect
748
+ #~ puts $3.inspect
749
+ #~ puts '<' * 15
750
+ #~ lines << Wiki_line.new(:li, self.inline($~.post_match, log), @lineno, $3.size, $2)
751
+ when /^;(\s*)/ #:dt
752
+ lines << Wiki_line.new(:dt, self.inline($~.post_match, log), @lineno, $1.size)
753
+ when /^:(\s*)/ #:dd
754
+ lastline = lines.last
755
+ if ! lastline
756
+ log.warn( "#{__FILE__}: Use ':' at start of wiki text. #{@lineno}" ) if log.warn?
757
+ lastline = Wiki_line.new() #Avoid error with method type
758
+ end
759
+ #If there was already an indent before, loo back.
760
+ if lastline.type == :indent
761
+ #find first line before indent
762
+ lines.reverse.each{|line|
763
+ lastline = line
764
+ break if lastline.type != :indent
765
+ }
766
+ end
767
+ if [:dt,:dd].include?(lastline.type)
768
+ lines << Wiki_line.new(:dd, self.inline($~.post_match, log), @lineno, $1.size)
769
+ else #-> quote
770
+ lines << Wiki_line.new(:quote, self.inline($~.post_match, log), @lineno, $1.size)
771
+ end
772
+ when /^----$/ #:hr #line
773
+ lines << Wiki_line.new(:hr,nil,@lineno)
774
+ when /^(\s+)/ #:indent #can be: continuation of a list or a verbatim
775
+ lines << Wiki_line.new(:indent, $~.post_match, @lineno, $1.size)
776
+ when /^\{\|/ #:tab
777
+ lines << Wiki_line.new(:tabular,$~.post_match,@lineno)
778
+ when /^\|\}/ #:tabend
779
+ lines << Wiki_line.new(:tabular_end,$~.post_match,@lineno)
780
+ when /^\|-/ #:tabrow
781
+ lines << Wiki_line.new(:tabular_row,$~.post_match,@lineno)
782
+ when /^\|(.*\|)*(.*?)\s*$/ #:tabcell
783
+ par = $1
784
+ txt = $2
785
+ #if the text contains macros with | there is a bit confusion,
786
+ #what is a parameter of the cell and whats part of the macro.
787
+ #
788
+ #Solution:
789
+ #Define the end of cell parameters with ||
790
+ if par and par =~ /\|\|/
791
+ par = $~.pre_match #parameters only before ||
792
+ txt = $~.post_match + txt #txt all after ||
793
+ end
794
+ lines << Wiki_line.new(:tabular_cell ,self.inline(txt, log),@lineno,nil,par)
795
+ else
796
+ #~ puts "??\tUnknown line (#{__FILE__} line #{__LINE__})"
797
+ #~ puts "??\tUnknown line: #{line.inspect}"
798
+ #lines << Wiki_line.new(:text, self.inline(line, log), @lineno)
799
+ #Insert space at end of line, but before \n.
800
+ #Without, a line break results in HTML-Text without space between flow text
801
+ lines << Wiki_line.new(:text, self.inline("#{line.chomp} \n", log), @lineno)
802
+ end
803
+ } #txt.each |line|
804
+
805
+ if collector
721
806
  log.error( "#{__FILE__}##{__LINE__}: Content Collector not closed (start in line #{collectorline}" ) if log.error?
722
- end
723
-
724
- elements = [] #main container
725
- lists ={} #lists.
726
- lines.each{|line|
727
- case line.type
728
- when :h1, :h2, :h3, :h4, :h5, :h6
729
- elements << element( line.type,{},line.content).cr
730
- if line.add_info
731
- elements.last[:id] << line.add_info
732
- end
733
- #~ elements << element( line.type,{},self.inline(line.content, log)).cr
734
- when :p #new paragraph
735
- #fixme: how to detect new paragraph or continuation of item/pre/verbatim
736
- if ! elements.last #Start wiki
737
- elements << element( :p ).cr
738
- elsif elements.last.is_a?(:p) and ! elements.last.content?
739
- #There is already an empty new par, we can use it.
740
- elsif elements.last.is_a?(ListEnvironment)
741
- #The next indent decides, if we need a new paragraph or continue in the last item.
742
- elements.last.content.last << nil #Add neutral flag for new paragraph
743
- else
744
- elements << element( :p ).cr
745
- end
746
- when :hr
747
- elements << element( :hr ).cr
748
- when :text
749
- if ! elements.last or ! elements.last.is_a?(:p)
750
- elements << element( :p ).cr
751
- end
752
- elements.last << line.content
753
- when :li
754
- if ! elements.last.is_a?(ListEnvironment) #ListEnvironment can be also a :dl
755
- lists = {} #delete all lists to start fresh
756
- end
757
- #~ puts "-----#{line.add_info}\t#{line.content.inspect}\t#{lists.keys.inspect}"
758
- listtype = ''
759
- loclist = {} #temporary list of lists. will be stored in 'lists'
760
- 1.upto(line.add_info.size){|level|
761
- leveltyp = line.add_info[0..level-1] #typ of listhirarchie
762
- if lists[leveltyp] #list already defined
763
- loclist[leveltyp] = lists[leveltyp]
764
- loclist[leveltyp] << element(:li,{}, line.content).cR if leveltyp == line.add_info
765
- else #create new list
766
- case line.add_info[-1,1]
767
- when '*'
768
- list_type = :ul
769
- when '#'
770
- list_type = :ol
771
- else
772
- log.error( "#{self.class}#wiki2doc: Unknown list type #{v}" ) if log.error?
773
- end
774
- loclist[leveltyp] = element( list_type ).CR
775
- #include first item in list
776
- loclist[leveltyp] << li = element(:li,{}).cR #add first item line
777
- li << line.content if leveltyp == line.add_info #add content to item line
778
- #Include list
779
- if level == 1 #Add first list to element-list
780
- elements << loclist[leveltyp]
781
- elsif leveltyp == line.add_info #add new list to previous list
782
- loclist[line.add_info[0,level-1]].content.last << loclist[leveltyp]
783
- end
784
- end
785
- }
786
- #copy lists and delete all other lists (so we get level changes)
787
- lists = loclist
788
- when :dt
789
- #~ lists = {} #mixture dl and ul/ol not possible actual
790
- if ! elements.last.is_a?(:dl)
791
- elements << element(:dl).cR
792
- lists[':'] = elements.last
793
- end
794
- elements.last << element(:dt,{},line.content ).cr
795
- when :dd
796
- if ! elements.last.is_a?(:dl)
807
+ end
808
+
809
+ elements = [] #main container
810
+ lists ={} #lists.
811
+ lines.each{|line|
812
+ case line.type
813
+ when :h1, :h2, :h3, :h4, :h5, :h6
814
+ elements << element( line.type,{},line.content).cr
815
+ if line.add_info
816
+ elements.last[:id] << line.add_info
817
+ end
818
+ #~ elements << element( line.type,{},self.inline(line.content, log)).cr
819
+ when :p #new paragraph
820
+ #fixme: how to detect new paragraph or continuation of item/pre/verbatim
821
+ if ! elements.last #Start wiki
822
+ elements << element( :p ).cr
823
+ elsif elements.last.is_a?(:p) and elements.last.content.empty?
824
+ #There is already an empty new par, we can use it.
825
+ elsif elements.last.is_a?(ListEnvironment)
826
+ #The next indent decides, if we need a new paragraph or continue in the last item.
827
+ elements.last.content.last << nil #Add neutral flag for new paragraph
828
+ else
829
+ elements << element( :p ).cr
830
+ end
831
+ when :hr
832
+ elements << element( :hr ).cr
833
+ when :text
834
+ if ! elements.last or ! elements.last.is_a?(:p)
835
+ elements << element( :p ).cr
836
+ end
837
+ elements.last << line.content
838
+ when :li
839
+ if ! elements.last.is_a?(ListEnvironment) #ListEnvironment can be also a :dl
840
+ lists = {} #delete all lists to start fresh
841
+ end
842
+ #~ puts "-----#{line.add_info}\t#{line.content.inspect}\t#{lists.keys.inspect}"
843
+ listtype = ''
844
+ loclist = {} #temporary list of lists. will be stored in 'lists'
845
+ 1.upto(line.add_info.size){|level|
846
+ leveltyp = line.add_info[0..level-1] #typ of listhirarchie
847
+ if lists[leveltyp] #list already defined
848
+ loclist[leveltyp] = lists[leveltyp]
849
+ loclist[leveltyp] << element(:li,{}, line.content).cR if leveltyp == line.add_info
850
+ else #create new list
851
+ case line.add_info[-1,1]
852
+ when '*'
853
+ list_type = :ul
854
+ when '#'
855
+ list_type = :ol
856
+ else
857
+ log.error( "#{self.class}#wiki2doc: Unknown list type #{v}" ) if log.error?
858
+ end
859
+ loclist[leveltyp] = element( list_type ).CR
860
+ #include first item in list
861
+ loclist[leveltyp] << li = element(:li,{}).cR #add first item line
862
+ li << line.content if leveltyp == line.add_info #add content to item line
863
+ #Include list
864
+ if level == 1 #Add first list to element-list
865
+ elements << loclist[leveltyp]
866
+ elsif leveltyp == line.add_info #add new list to previous list
867
+ loclist[line.add_info[0,level-1]].content.last << loclist[leveltyp]
868
+ end
869
+ end
870
+ }
871
+ #copy lists and delete all other lists (so we get level changes)
872
+ lists = loclist
873
+ when :dt
874
+ #~ lists = {} #mixture dl and ul/ol not possible actual
875
+ if ! elements.last.is_a?(:dl)
876
+ elements << element(:dl).cR
877
+ lists[':'] = elements.last
878
+ end
879
+ elements.last << element(:dt,{},line.content ).cr
880
+ when :dd
881
+ if ! elements.last.is_a?(:dl)
797
882
  log.warn( "#{self.class}#wiki2doc(#{line.lineno}: :dl without :dt (#{line.content.strip})" ) if log.warn?
798
- elements << element(:dl).cr
799
- end
800
- elements.last << element(:dd,{},line.content).cr
801
- when :quote
802
- if ! elements.last.is_a?(:quote)
803
- elements << element(:quote).cR
804
- end
805
- if line.content =~ /^\s*$/ #Empty line
806
- elements.last << element(:newline).cR
807
- else
808
- elements.last << line.content
809
- elements.last << ' '
810
- end
811
- when :indent
812
- #~ puts "#{self.class}#wiki2doc(#{line.lineno}: indent: #{line.indent}\t#{line.add_info}\t#{line.content}"
813
- #Check if the indent is part of a list item
814
- if elements.last.is_a?(ListEnvironment)
815
- lastlist = lists[lists.keys.max] #Get last (deepest) list
816
- lastitem = lastlist.content.last
817
-
818
- case lastitem.content.last
819
- when nil #new paragraph
820
- lastitem << element(:p, {}, self.inline(line.content, log)).cr
821
- when Element #add content to last element
822
- lastitem.content.last << self.inline(line.content, log)
823
- else #add content to item line
824
- lastitem << ' '
825
- lastitem << self.inline(line.content, log)
826
- end
827
- elsif elements.last.is_a?(:dl)
828
- lastitem << self.inline(line.content, log)
829
- elsif ! elements.last.is_a?(:pre)
830
- elements << element(:pre).cR
831
- end
832
- if elements.last.is_a?(:pre)
833
- elements.last << (' ' * (line.indent - 1 )) + line.content + "\n"
834
- end
835
- when :tabular
836
- if /longtable/ =~ line.content
837
- elements << tab = element(:longtable, {:style=>CSS.new()}).CR
838
- else
839
- elements << tab = element(:tabular, {:style=>CSS.new()}).CR
840
- end
841
- if line.content #options
842
- options = line.content.split('|')
843
- options.each{|opt|
844
- case opt
845
- when /columndescription\s*=\s*(.*)/
846
- tab[:columndescription] << $1 #TeX-Format
847
- when /columns\s*=\s*(.*)/
848
- tab[:columns] << $1.to_i
849
- when /border\s*=\s*(.*)/
850
- tab[:border] << $1.to_i
851
- when /(.*)\s*=\s*(.*)/
852
- #~ puts "#{__FILE__}##{__LINE__}: #{opt}" if ! tab[:style].content.first
853
- tab[:style].content.first[$1] = $2
854
- else
883
+ elements << element(:dl).cr
884
+ end
885
+ elements.last << element(:dd,{},line.content).cr
886
+ when :quote
887
+ if ! elements.last.is_a?(:quote)
888
+ elements << element(:quote).cR
889
+ end
890
+ if line.content =~ /^\s*$/ #Empty line
891
+ elements.last << element(:newline).cR
892
+ else
893
+ elements.last << line.content
894
+ elements.last << ' '
895
+ end
896
+ when :indent
897
+ #~ puts "#{self.class}#wiki2doc(#{line.lineno}: indent: #{line.indent}\t#{line.add_info}\t#{line.content}"
898
+ #Check if the indent is part of a list item
899
+ if elements.last.is_a?(ListEnvironment)
900
+ lastlist = lists[lists.keys.max] #Get last (deepest) list
901
+ lastitem = lastlist.content.last
902
+
903
+ case lastitem.content.last
904
+ when nil #new paragraph
905
+ lastitem << element(:p, {}, self.inline(line.content, log)).cr
906
+ when Element #add content to last element
907
+ lastitem.content.last << self.inline(line.content, log)
908
+ else #add content to item line
909
+ lastitem << ' '
910
+ lastitem << self.inline(line.content, log)
911
+ end
912
+ elsif elements.last.is_a?(:dl)
913
+ lastitem << self.inline(line.content, log)
914
+ elsif ! elements.last.is_a?(:pre)
915
+ elements << element(:pre).cR
916
+ end
917
+ if elements.last.is_a?(:pre)
918
+ elements.last << (' ' * (line.indent - 1 )) + line.content + "\n"
919
+ end
920
+ when :tabular
921
+ if /longtable/ =~ line.content
922
+ elements << tab = element(:longtable, {:style=>CSS.new()}).CR
923
+ else
924
+ elements << tab = element(:tabular, {:style=>CSS.new()}).CR
925
+ end
926
+ if line.content #options
927
+ options = line.content.split('|')
928
+ options.each{|opt|
929
+ case opt
930
+ when /columndescription\s*=\s*(.*)/
931
+ tab[:columndescription] << $1.gsub(/!/, '|') #TeX-Format
932
+ when /columns\s*=\s*(.*)/
933
+ tab[:columns] << $1.to_i
934
+ when /border\s*=\s*(.*)/
935
+ tab[:border] << $1.to_i
936
+ when /(.*)\s*=\s*(.*)/
937
+ #~ puts "#{__FILE__}##{__LINE__}: #{opt}" if ! tab[:style].content.first
938
+ tab[:style].content.first[$1] = $2
939
+ else
855
940
  log.warn( "#{self.class}#wiki2doc(#{line.lineno}: options for table unknown: #{opt}" ) if log.warn?
856
- end
857
- }
858
- end
859
- #Add first row
860
- elements.last << element(:tr, {} ).cr
861
- when :tabular_end
862
- elements << nil
863
- when :tabular_row
864
- if ! elements.last.is_a?(:tabular)
865
- log.warn( "#{self.class}#wiki2doc(#{line.lineno}: Add row to non-tabular" ) if log.warn?
866
- end
867
- prev_row = elements.last.content.last
941
+ end
942
+ }
943
+ end
944
+ #Add first row
945
+ elements.last << element(:tr, {} ).cr
946
+ when :tabular_end
947
+ elements << nil
948
+ when :tabular_row
949
+ if ! elements.last.is_a?(:tabular)
950
+ log.warn( "#{self.class}#wiki2doc(#{line.lineno}: Add row to non-tabular" ) if log.warn?
951
+ end
952
+ prev_row = elements.last.content.last
868
953
  rowcss = CSS.new()
869
- elements.last << element(:tr, { :style => rowcss } ).cr
870
- if line.content #options
871
- options = line.content.split('|')
954
+ elements.last << element(:tr, { :style => rowcss } ).cr
955
+ if line.content #options
956
+ options = line.content.split('|')
872
957
  #~ puts options.inspect
873
- options.each{|opt|
874
- case opt
875
- when 'toprule'; prev_row.toprule
876
- when 'midrule'; prev_row.midrule
877
- when 'hline'; prev_row.hline
878
- when /(.+)=(.+)/ #CSS?
958
+ options.each{|opt|
959
+ case opt
960
+ when 'toprule'; prev_row.toprule
961
+ when 'midrule'; prev_row.midrule
962
+ when 'hline'; prev_row.hline
963
+ when /(.+)=(.+)/ #CSS?
879
964
  rowcss[$1] = $2
880
- when /\A\s*\Z/ #empty option
881
- else
965
+ when /\A\s*\Z/ #empty option
966
+ else
882
967
  log.warn( "#{self.class}#wiki2doc(#{line.lineno}): Unknown line option #{opt.inspect}" ) if log.warn?
883
- end
884
- }
885
- end
886
- when :tabular_cell
887
- cellcss = CSS.new()
888
- colspan = 1
889
- pos = 'c'
890
- if line.add_info #options
891
- #fixme: Tabelle mit verschiedenen Optionen??
892
- options = line.add_info.split('|')
893
- options.each{|opt|
894
- case opt
895
- when /colspan\s*=\s*(.*)/
896
- colspan = $1.to_i
897
- when /pos\s*=\s*(.*)/
898
- pos = $1
899
- when /(.*?)\s*=\s*(.*)/
900
- cellcss[$1] = $2
901
- else
902
- log.warn( "options for table cell unknown: #{opt} (line #{line.lineno})" ) if log.warn?
903
- end
904
- }
905
- end
906
- row = elements.last.content.last
907
- if colspan > 1
908
- row << element(:multicolumn, { :colspan => colspan, :style => cellcss, :pos => pos }, line.content).cr
909
- else
910
- row << element(:td, { :style => cellcss }, line.content).cr
911
- end
912
- when :collector
913
- #~ if line.content.respond_to? :to_doc
914
- #~ elements << line.content.to_element
915
- #~ else
916
- elements << line.content
917
- #~ end
918
- else
919
- log.error("#{self.class}#wiki2doc(#{line.lineno}): New line type #{line.type.inspect} (#{line.content.inspect})" ) if log.error?
920
- elements << element( line.type,{},self.inline(line.content, log)).cr
921
- end
922
- }
923
- return elements
924
- end #wiki2doc
925
- #Translate text for inline tags.
926
- def inline( intext, log, subs = @wiki_inline_replacements )
927
- return Wikitext.inline( intext, log, subs, self )
928
- end
929
- #Translate text for inline tags.
930
- #
931
- #This can also be used from "outside" to translate single lines.
932
- #To keep the same environment if called via an object, the object is given in oo.
933
- def self.inline( intext, log, subs = WIKI_INLINE_REPLACEMENTS,
934
- oo = self)
935
- subs.each{|rule|
936
- if rule.regex =~ intext
937
- if rule.proc.is_a?( Proc )
938
- return rule.proc.call($~, oo, log)
939
- else
940
- return rule.proc
941
- end
942
- end
943
- }
944
- return intext
945
- end
968
+ end
969
+ }
970
+ end
971
+ when :tabular_cell
972
+ cellcss = CSS.new()
973
+ colspan = 1
974
+ pos = 'c'
975
+ if line.add_info #options
976
+ #fixme: Tabelle mit verschiedenen Optionen??
977
+ options = line.add_info.split('|')
978
+ options.each{|opt|
979
+ case opt
980
+ when /colspan\s*=\s*(.*)/
981
+ colspan = $1.to_i
982
+ when /pos\s*=\s*(.*)/
983
+ pos = $1
984
+ when /(.*?)\s*=\s*(.*)/
985
+ cellcss[$1] = $2
986
+ else
987
+ log.warn( "options for table cell unknown: #{opt} (line #{line.lineno})" ) if log.warn?
988
+ end
989
+ }
990
+ end
991
+ row = elements.last.content.last
992
+ if colspan > 1
993
+ row << element(:multicolumn, { :colspan => colspan, :style => cellcss, :pos => pos }, line.content).cr
994
+ else
995
+ row << element(:td, { :style => cellcss }, line.content).cr
996
+ end
997
+ when :collector
998
+ #~ if line.content.respond_to? :to_doc
999
+ #~ elements << line.content.to_element
1000
+ #~ else
1001
+ elements << line.content
1002
+ #~ end
1003
+ else
1004
+ log.error("#{self.class}#wiki2doc(#{line.lineno}): New line type #{line.type.inspect} (#{line.content.inspect})" ) if log.error?
1005
+ elements << element( line.type,{},self.inline(line.content, log)).cr
1006
+ end
1007
+ }
1008
+
1009
+ #Delete empty paragraphs
1010
+ elements.map!{|element|
1011
+ if element.is_a?(:p) and element.content.empty?
1012
+ nil #Delete empty paragraphs
1013
+ else
1014
+ element
1015
+ end
1016
+ }
1017
+
1018
+ return elements
1019
+ end #wiki2doc
1020
+ #Translate text for inline tags.
1021
+ def inline( intext, log, subs = @wiki_inline_replacements )
1022
+ return Wikitext.inline( intext, log, subs, self )
1023
+ end
1024
+ #Translate text for inline tags.
1025
+ #
1026
+ #This can also be used from "outside" to translate single lines.
1027
+ #To keep the same environment if called via an object, the object is given in oo.
1028
+ def self.inline( intext, log, subs = WIKI_INLINE_REPLACEMENTS,
1029
+ oo = self)
1030
+ subs.each{|rule|
1031
+ if rule.regex =~ intext
1032
+ if rule.proc.is_a?( Proc )
1033
+ return rule.proc.call($~, oo, log)
1034
+ else
1035
+ return rule.proc
1036
+ end
1037
+ end
1038
+ }
1039
+ return intext
1040
+ end
1041
+ #Obsolete method -don't use.
946
1042
  def toccss()
947
1043
  @log.error("Usage of obsolete toccss, use CSS_collection[:toc]") if @log.error?
948
1044
  return CSS_collection[:toc].style.to_html
949
1045
  end
950
- #Make a table of contents
951
- #
952
- #Options:
953
- #- listtype: :ul or :ol
954
- #- addlinks: Set label for each header.
955
- def toc( i_options = {} )
956
- options = {
957
- :listtype => :ul,
958
- :level => 4,
959
- :startlevel => 1,
960
- :addlinks => true
961
- }.update(i_options)
962
- uls = {}
963
- uls[options[:startlevel]] = element(options[:listtype])
964
- @source.flatten.each{|line|
965
- if /\A(=+)(?:\[(.*?)\])?(.+?)(=+)\s*\z/ =~ line #:h1, :h2, :h3, :h4, :h5, :h6
966
- level = $1.size.to_i - 1
967
- anker = $2
968
- titletext = $3
969
- #Entfernen von Wiki-Links im Titel.
970
- titletext.sub!(/\[\..*\s+(.*)\]/, '\1')
971
-
972
- next if level > options[:level]
973
- if level < options[:startlevel]
974
- log.warn( "#{self.class}#toc: TOC starts at #{options[:startlevel]}, but level #{level} defined at #{line}" ) if log.warn?
975
- next
976
- end
977
- if anker
978
- titel = element(:a, {:href=>"##{anker}"}, titletext)
979
- elsif options[:addlinks]
980
- #Build label for toc
981
- toclabel = []
982
- 1.upto(level){|i|
983
- if uls[i]
984
- if i == level #same level - add one for actual element
985
- toclabel << uls[i].content.size + 1
986
- else #Previous level - use size
987
- toclabel << uls[i].content.size
988
- end
989
- else #First element on this level
990
- toclabel << 1
991
- end
992
- }
993
- #~ puts "toclabel <#{$3}>\t#{toclabel.inspect}\t#{toclabel.join('-')}"
994
- titel = element(:a, {:href=>"##{toclabel.join('-')}"}, titletext)
995
- line.sub!(/^(=+)/, "\\1[#{toclabel.join('-')}]")
996
- else
997
- titel = titletext
998
- end
999
- options[:startlevel].upto(6){|i|
1000
- #Create 'higher' sections (indicates a problem in the text)
1001
- if i < level
1002
- if ! uls[i]
1003
- log.warn( "#{self.class}#toc: Sectioning jumps over level #{i} at #{line}" ) if log.warn?
1004
- uls[i-1].content.last << uls[i] = element(options[:listtype] ).Cr if uls[i-1]
1005
- end
1006
- if ! uls[i].content.last
1007
- uls[i] << element(:li,{}, '' ).cr
1008
- end
1009
- elsif i == level
1010
- #Create new level if necessary
1011
- if ! uls[level]
1012
- uls[level-1].content.last << uls[level] = element(options[:listtype] ).Cr
1013
- end
1014
- #Add section title
1015
- uls[level] << element(:li,{}, titel ).cr
1016
- else
1017
- #delete lower levels of previous topic
1018
- uls[i] = nil
1019
- end
1020
- }
1021
- end
1022
- }
1023
- return element(:div, { :class => 'toc' }, uls[options[:startlevel]] ).CR
1024
- end
1025
- def footnotes()
1026
- footnotes = Footnotegroup.get( self.object_id)
1027
- return footnotes
1028
- end
1046
+ #Make a table of contents
1047
+ #
1048
+ #Options:
1049
+ #- listtype: :ul or :ol
1050
+ #- addlinks: Set label for each header.
1051
+ def toc( i_options = {} )
1052
+ options = {
1053
+ :listtype => :ul,
1054
+ :level => 4,
1055
+ :startlevel => 1,
1056
+ :addlinks => true,
1057
+ :tocclass => 'toc',
1058
+ }.update(i_options)
1059
+ uls = {}
1060
+ uls[options[:startlevel]] = element(options[:listtype])
1061
+ @source.flatten.each{|line|
1062
+ if /\A(=+)(?:\[(.*?)\])?(.+?)(=+)\s*\z/ =~ line #:h1, :h2, :h3, :h4, :h5, :h6
1063
+ level = $1.size.to_i - 1
1064
+ anker = $2
1065
+ titletext = $3
1066
+ #Entfernen von Wiki-Links im Titel.
1067
+ titletext.sub!(/\[\..*\s+(.*)\]/, '\1')
1068
+
1069
+ next if level > options[:level]
1070
+ if level < options[:startlevel]
1071
+ log.warn( "#{self.class}#toc: TOC starts not at #{options[:startlevel]}, but level #{level} defined at #{line}" ) if log.warn?
1072
+ next
1073
+ end
1074
+ if anker
1075
+ titel = element(:a, {:href=>"##{anker}"}, titletext)
1076
+ elsif options[:addlinks]
1077
+ #Build label for toc
1078
+ toclabel = []
1079
+ 1.upto(level){|i|
1080
+ if uls[i]
1081
+ if i == level #same level - add one for actual element
1082
+ toclabel << uls[i].content.size + 1
1083
+ else #Previous level - use size
1084
+ toclabel << uls[i].content.size
1085
+ end
1086
+ else #First element on this level
1087
+ toclabel << 1
1088
+ end
1089
+ }
1090
+ #~ puts "toclabel <#{$3}>\t#{toclabel.inspect}\t#{toclabel.join('-')}"
1091
+ titel = element(:a, {:href=>"##{toclabel.join('-')}"}, titletext)
1092
+ line.sub!(/^(=+)/, "\\1[#{toclabel.join('-')}]")
1093
+ else
1094
+ titel = titletext
1095
+ end
1096
+ options[:startlevel].upto(6){|i|
1097
+ #Create 'higher' sections (indicates a problem in the text)
1098
+ if i < level
1099
+ if ! uls[i]
1100
+ log.warn( "#{self.class}#toc: Sectioning jumps over level #{i} at #{line}" ) if log.warn?
1101
+ uls[i-1].content.last << uls[i] = element(options[:listtype] ).Cr if uls[i-1]
1102
+ end
1103
+ if ! uls[i].content.last
1104
+ uls[i] << element(:li,{}, '' ).cr
1105
+ end
1106
+ elsif i == level
1107
+ #Create new level if necessary
1108
+ if ! uls[level]
1109
+ uls[level-1].content.last << uls[level] = element(options[:listtype] ).Cr
1110
+ end
1111
+ #Add section title
1112
+ uls[level] << element(:li,{}, titel ).cr
1113
+ else
1114
+ #delete lower levels of previous topic
1115
+ uls[i] = nil
1116
+ end
1117
+ }
1118
+ end
1119
+ }
1120
+ return element(:div, { :class => options[:tocclass] }, uls[options[:startlevel]] ).CR
1121
+ end
1122
+ def footnotes()
1123
+ footnotes = Footnotegroup.get( self.object_id)
1124
+ return footnotes
1125
+ end
1029
1126
  end
1030
1127
 
1031
1128
  #Wiki-Collector is a hash with collectors.
@@ -1035,64 +1132,64 @@ end
1035
1132
  #
1036
1133
  #Usage example: see code2structogramm
1037
1134
  class WikiCollector
1038
- @@variants = {}
1039
- #Add a new collector type.
1040
- #
1041
- #Each collector must implement the following methods:
1042
- #-new without parameters.
1043
- #-<< get lines of wiki-source
1044
- #-to_doc return the result
1135
+ @@variants = {}
1136
+ #Add a new collector type.
1137
+ #
1138
+ #Each collector must implement the following methods:
1139
+ #-new without parameters.
1140
+ #-<< get lines of wiki-source
1141
+ #-to_doc return the result
1045
1142
  #See the two examples
1046
1143
  #- WikiCollectorHTML
1047
1144
  #- WikiCollectorFilecontent
1048
1145
  #
1049
- def self.add(key, classtype)
1050
- if @@variants[key]
1051
- puts "WikiCollector: Double assignment #{key.inspect}, #{classtype}"
1052
- end
1053
- if ! classtype.method_defined?(:'<<')
1054
- puts "WikiCollector: Collector <#{key.inspect}> doesn't support <<"
1055
- return false
1056
- end
1057
- if ! classtype.method_defined?(:to_doc)
1058
- puts "WikiCollector: Collector <#{key.inspect}> doesn't support to_doc"
1059
- return false
1060
- end
1061
- @@variants[key] = classtype
1062
- end
1063
- #Get an instance of the requested collector.
1064
- def self.create(key, arguments = [] )
1065
- #~ puts "WikiCollector: request #{key.inspect}"
1066
- if @@variants[key.to_sym]
1067
- begin
1068
- return @@variants[key.to_sym].new(*arguments)
1069
- rescue ArgumentError
1070
- puts "WikiCollector: Collector <#{key.inspect}> get wrong parameters"
1071
- return false
1072
- end
1073
- else
1074
- puts "WikiCollector: Collector <#{key}> not found (available: #{@@variants.keys.inspect})"
1075
- return nil
1076
- end
1077
- end
1146
+ def self.add(key, classtype)
1147
+ if @@variants[key]
1148
+ puts "WikiCollector: Double assignment #{key.inspect}, #{classtype}"
1149
+ end
1150
+ if ! classtype.method_defined?(:'<<')
1151
+ puts "WikiCollector: Collector <#{key.inspect}> doesn't support <<"
1152
+ return false
1153
+ end
1154
+ if ! classtype.method_defined?(:to_doc)
1155
+ puts "WikiCollector: Collector <#{key.inspect}> doesn't support to_doc"
1156
+ return false
1157
+ end
1158
+ @@variants[key] = classtype
1159
+ end
1160
+ #Get an instance of the requested collector.
1161
+ def self.create(key, arguments = [] )
1162
+ #~ puts "WikiCollector: request #{key.inspect}"
1163
+ if @@variants[key.to_sym]
1164
+ begin
1165
+ return @@variants[key.to_sym].new(*arguments)
1166
+ rescue ArgumentError
1167
+ puts "WikiCollector: Collector <#{key.inspect}> get wrong parameters"
1168
+ return false
1169
+ end
1170
+ else
1171
+ puts "WikiCollector: Collector <#{key}> not found (available: #{@@variants.keys.inspect})"
1172
+ return nil
1173
+ end
1174
+ end
1078
1175
  end #WikiCollector
1079
1176
  #
1080
1177
  #A little collector of "Plain-HTML".
1081
1178
  #
1082
1179
  class WikiCollectorHTML < Element
1083
- Element.add( [:wikicollectorhtml], WikiCollectorHTML)
1180
+ Element.add( [:wikicollectorhtml], WikiCollectorHTML)
1084
1181
  #Start without parameters.
1085
1182
  #Can be called in a Wiki with:
1086
1183
  # >>>html{}
1087
1184
  # here you can add plain HTML
1088
1185
  # <<<
1089
- def initialize()
1090
- @htmlcode = []
1091
- end
1186
+ def initialize()
1187
+ @htmlcode = []
1188
+ end
1092
1189
  #Add another line from Wiki
1093
- def <<(content)
1094
- @htmlcode << content
1095
- end
1190
+ def <<(content)
1191
+ @htmlcode << content
1192
+ end
1096
1193
  #
1097
1194
  #Return the content 'as is', but only for HTML
1098
1195
  def to_doc( target, options = {} )
@@ -1102,44 +1199,60 @@ class WikiCollectorHTML < Element
1102
1199
  else
1103
1200
  ''
1104
1201
  end
1105
- #~ return element(:onlyhtml,{},@htmlcode).restrict_to(:html).to_doc(target)
1106
- end
1107
- #~ def to_html()
1108
- #~ return @htmlcode
1109
- #~ end
1110
- #~ def to_latex(); ''; end
1111
- #~ def to_wiki(); ''; end
1112
- #~ def to_text(); ''; end
1202
+ #~ return element(:onlyhtml,{},@htmlcode).restrict_to(:html).to_doc(target)
1203
+ end
1204
+ #~ def to_html()
1205
+ #~ return @htmlcode
1206
+ #~ end
1207
+ #~ def to_latex(); ''; end
1208
+ #~ def to_wiki(); ''; end
1209
+ #~ def to_text(); ''; end
1113
1210
  end
1114
1211
  WikiCollector.add(:html, WikiCollectorHTML )
1115
1212
 
1116
1213
  if __FILE__ == $0
1214
+
1117
1215
  puts 'Use the unit test for complete test'
1118
1216
 
1217
+ puts Wikitext.help
1218
+ puts Wikitext.help(:img)
1219
+ puts Wikitext.help(:tab)
1220
+
1221
+ #~ wiki = Wikitext.new(:content => <<wiki
1222
+ #~ There are normal footnotes{{footnote|Like this one}}. But:
1223
+ #~ Here is a footnote in group 1{{footnote[group1]some remarks}}, and
1224
+ #~ a second footnote{{footnote[group1]more remarks}}.
1225
+ #~ In another group{{footnote[group2]Each group gets a name}}, we can define further remarks.
1226
+
1227
+ #~ ----
1228
+ #~ Normal Footnotes:
1229
+ #~ {{footnotes}}
1230
+ #~ ----
1231
+ #~ Footnote group 1:
1232
+ #~ {{footnotes|group1}}
1233
+ #~ ----
1234
+ #~ Footnote group 2:
1235
+ #~ {{footnotes|group2}}
1236
+ #~ wiki
1237
+ #~ )
1119
1238
  wiki = Wikitext.new(:content => <<wiki
1120
- There are normal footnotes{{footnote|Like this one}}. But:
1121
- Here is a footnote in group 1{{footnote[group1]some remarks}}, and
1122
- a second footnote{{footnote[group1]more remarks}}.
1123
- In another group{{footnote[group2]Each group gets a name}}, we can define further remarks.
1239
+ vorher
1240
+
1241
+ nachher
1242
+ nachher2
1124
1243
 
1125
- ----
1126
- Normal Footnotes:
1127
- {{footnotes}}
1128
- ----
1129
- Footnote group 1:
1130
- {{footnotes|group1}}
1131
- ----
1132
- Footnote group 2:
1133
- {{footnotes|group2}}
1244
+ ==test==
1245
+ drei
1134
1246
  wiki
1135
- )
1247
+ )
1136
1248
  puts '---------------------'
1137
1249
 
1250
+
1138
1251
  #~ puts wiki.toc.inspect
1139
1252
  #~ puts wiki.toc.to_html
1140
1253
  #~ puts wiki.toc.to_wiki
1141
1254
  #~ puts '--------HTML-------------'
1142
- #~ puts wiki.to_html
1255
+ puts wiki.to_html
1143
1256
  #~ puts '--------HTML-------------'
1144
1257
  #~ puts wiki.to_html
1145
1258
  #~ puts '--------LaTeX-------------'
@@ -1148,6 +1261,10 @@ puts '---------------------'
1148
1261
  #~ puts wiki.to_wiki
1149
1262
  #~ puts '--------Text-------------'
1150
1263
  #~ puts wiki.to_text
1264
+
1265
+ doc = Document.new()
1266
+ doc.body << wiki
1267
+ doc.save('test.html')
1151
1268
  end
1152
1269
 
1153
1270