my_wiki_generator 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. data/my_wiki/grep.txt +238 -0
  2. data/my_wiki/my_wiki_generator.rb +248 -0
  3. data/my_wiki/templates/POST_GENERATION_REMINDER +1 -0
  4. data/my_wiki/templates/app/controllers/application.rb +75 -0
  5. data/my_wiki/templates/app/controllers/content_history_controller.rb +49 -0
  6. data/my_wiki/templates/app/controllers/login_controller.rb +93 -0
  7. data/my_wiki/templates/app/controllers/my_wiki_admin_controller.rb +26 -0
  8. data/my_wiki/templates/app/controllers/my_wiki_controller.rb +250 -0
  9. data/my_wiki/templates/app/controllers/page_admin_controller.rb +51 -0
  10. data/my_wiki/templates/app/controllers/user_admin_controller.rb +34 -0
  11. data/my_wiki/templates/app/helpers/application_helper.rb +3 -0
  12. data/my_wiki/templates/app/helpers/content_history_helper.rb +2 -0
  13. data/my_wiki/templates/app/helpers/login_helper.rb +2 -0
  14. data/my_wiki/templates/app/helpers/my_wiki_admin_helper.rb +2 -0
  15. data/my_wiki/templates/app/helpers/my_wiki_helper.rb +94 -0
  16. data/my_wiki/templates/app/helpers/page_admin_helper.rb +2 -0
  17. data/my_wiki/templates/app/helpers/user_admin_helper.rb +2 -0
  18. data/my_wiki/templates/app/models/attachment.rb +55 -0
  19. data/my_wiki/templates/app/models/content.rb +32 -0
  20. data/my_wiki/templates/app/models/content_history.rb +49 -0
  21. data/my_wiki/templates/app/models/content_sweeper.rb +7 -0
  22. data/my_wiki/templates/app/models/my_wiki_mailer.rb +29 -0
  23. data/my_wiki/templates/app/models/role.rb +18 -0
  24. data/my_wiki/templates/app/models/setting.rb +7 -0
  25. data/my_wiki/templates/app/models/user.rb +60 -0
  26. data/my_wiki/templates/app/views/content_history/_form.rhtml +19 -0
  27. data/my_wiki/templates/app/views/content_history/edit.rhtml +9 -0
  28. data/my_wiki/templates/app/views/content_history/list.rhtml +27 -0
  29. data/my_wiki/templates/app/views/content_history/new.rhtml +8 -0
  30. data/my_wiki/templates/app/views/content_history/show.rhtml +21 -0
  31. data/my_wiki/templates/app/views/layouts/my_wiki.rhtml +105 -0
  32. data/my_wiki/templates/app/views/login/edit.rhtml +25 -0
  33. data/my_wiki/templates/app/views/login/login.rhtml +23 -0
  34. data/my_wiki/templates/app/views/login/logout.rhtml +10 -0
  35. data/my_wiki/templates/app/views/login/signup.rhtml +23 -0
  36. data/my_wiki/templates/app/views/login/welcome.rhtml +13 -0
  37. data/my_wiki/templates/app/views/my_wiki/_form.rhtml +11 -0
  38. data/my_wiki/templates/app/views/my_wiki/css.rhtml +224 -0
  39. data/my_wiki/templates/app/views/my_wiki/diff.rhtml +4 -0
  40. data/my_wiki/templates/app/views/my_wiki/edit.rhtml +34 -0
  41. data/my_wiki/templates/app/views/my_wiki/fileinfo.rhtml +22 -0
  42. data/my_wiki/templates/app/views/my_wiki/list.rhtml +1 -0
  43. data/my_wiki/templates/app/views/my_wiki/mails.rhtml +1 -0
  44. data/my_wiki/templates/app/views/my_wiki/new.rhtml +6 -0
  45. data/my_wiki/templates/app/views/my_wiki/recent.rhtml +3 -0
  46. data/my_wiki/templates/app/views/my_wiki/search.rhtml +5 -0
  47. data/my_wiki/templates/app/views/my_wiki/search_result.rhtml +10 -0
  48. data/my_wiki/templates/app/views/my_wiki/show.rhtml +31 -0
  49. data/my_wiki/templates/app/views/my_wiki_admin/index.rhtml +5 -0
  50. data/my_wiki/templates/app/views/my_wiki_admin/setting.rhtml +64 -0
  51. data/my_wiki/templates/app/views/my_wiki_mailer/inform.rhtml +3 -0
  52. data/my_wiki/templates/app/views/page_admin/_form.rhtml +22 -0
  53. data/my_wiki/templates/app/views/page_admin/edit.rhtml +9 -0
  54. data/my_wiki/templates/app/views/page_admin/list.rhtml +55 -0
  55. data/my_wiki/templates/app/views/page_admin/new.rhtml +8 -0
  56. data/my_wiki/templates/app/views/page_admin/show.rhtml +8 -0
  57. data/my_wiki/templates/app/views/user_admin/_form.rhtml +10 -0
  58. data/my_wiki/templates/app/views/user_admin/change_password.rhtml +9 -0
  59. data/my_wiki/templates/app/views/user_admin/list.rhtml +25 -0
  60. data/my_wiki/templates/app/views/user_admin/signup.rhtml +20 -0
  61. data/my_wiki/templates/components/admin/menu/menu.rhtml +5 -0
  62. data/my_wiki/templates/components/admin/menu_controller.rb +3 -0
  63. data/my_wiki/templates/components/list/list/list.rhtml +11 -0
  64. data/my_wiki/templates/components/list/list_controller.rb +11 -0
  65. data/my_wiki/templates/components/sidebar/sidebar/show.rhtml +7 -0
  66. data/my_wiki/templates/components/sidebar/sidebar_controller.rb +9 -0
  67. data/my_wiki/templates/config/routes.rb +35 -0
  68. data/my_wiki/templates/db/migrate/001_my_wiki_migration.rb +75 -0
  69. data/my_wiki/templates/lib/diff/lcs.rb +1105 -0
  70. data/my_wiki/templates/lib/diff/lcs/array.rb +21 -0
  71. data/my_wiki/templates/lib/diff/lcs/block.rb +51 -0
  72. data/my_wiki/templates/lib/diff/lcs/callbacks.rb +322 -0
  73. data/my_wiki/templates/lib/diff/lcs/change.rb +169 -0
  74. data/my_wiki/templates/lib/diff/lcs/hunk.rb +257 -0
  75. data/my_wiki/templates/lib/diff/lcs/ldiff.rb +226 -0
  76. data/my_wiki/templates/lib/diff/lcs/string.rb +19 -0
  77. data/my_wiki/templates/lib/login_system.rb +87 -0
  78. data/my_wiki/templates/lib/markup/simple_markup.rb +489 -0
  79. data/my_wiki/templates/lib/markup/simple_markup/fragments.rb +329 -0
  80. data/my_wiki/templates/lib/markup/simple_markup/inline.rb +338 -0
  81. data/my_wiki/templates/lib/markup/simple_markup/lines.rb +151 -0
  82. data/my_wiki/templates/lib/markup/simple_markup/preprocess.rb +68 -0
  83. data/my_wiki/templates/lib/markup/simple_markup/to_flow.rb +188 -0
  84. data/my_wiki/templates/lib/markup/simple_markup/to_html.rb +302 -0
  85. data/my_wiki/templates/lib/markup/simple_markup/to_latex.rb +333 -0
  86. data/my_wiki/templates/lib/my_wiki_plugin.rb +60 -0
  87. data/my_wiki/templates/lib/my_wiki_plugins/christel.rb +5 -0
  88. data/my_wiki/templates/lib/my_wiki_plugins/join.rb +3 -0
  89. data/my_wiki/templates/lib/my_wiki_plugins/link_to_attach.rb +17 -0
  90. data/my_wiki/templates/lib/my_wiki_plugins/recent.rb +8 -0
  91. data/my_wiki/templates/public/javascripts/my_wiki.js +8 -0
  92. data/my_wiki/templates/public/stylesheets/my_wiki/back.jpg +0 -0
  93. data/my_wiki/templates/public/stylesheets/my_wiki/back1.jpg +0 -0
  94. data/my_wiki/templates/public/stylesheets/my_wiki/back2.jpg +0 -0
  95. data/my_wiki/templates/public/stylesheets/my_wiki/foot.jpg +0 -0
  96. data/my_wiki/templates/public/stylesheets/my_wiki/h1.gif +0 -0
  97. data/my_wiki/templates/public/stylesheets/my_wiki/h1.jpg +0 -0
  98. data/my_wiki/templates/public/stylesheets/my_wiki/menu.jpg +0 -0
  99. data/my_wiki/templates/public/stylesheets/my_wiki/menu2.jpg +0 -0
  100. data/my_wiki/templates/public/stylesheets/my_wiki/menu_c.jpg +0 -0
  101. data/my_wiki/templates/public/stylesheets/my_wiki/my_wiki.css +336 -0
  102. data/my_wiki/templates/public/stylesheets/my_wiki/title.jpg +0 -0
  103. metadata +181 -0
@@ -0,0 +1,19 @@
1
+ #! /usr/env/bin ruby
2
+ #--
3
+ # Copyright 2004 Austin Ziegler <diff-lcs@halostatue.ca>
4
+ # adapted from:
5
+ # Algorithm::Diff (Perl) by Ned Konz <perl@bike-nomad.com>
6
+ # Smalltalk by Mario I. Wolczko <mario@wolczko.com>
7
+ # implements McIlroy-Hunt diff algorithm
8
+ #
9
+ # This program is free software. It may be redistributed and/or modified under
10
+ # the terms of the GPL version 2 (or later), the Perl Artistic licence, or the
11
+ # Ruby licence.
12
+ #
13
+ # $Id: string.rb,v 1.3 2004/08/08 20:33:09 austin Exp $
14
+ #++
15
+ # Includes Diff::LCS into String.
16
+
17
+ class String
18
+ include Diff::LCS
19
+ end
@@ -0,0 +1,87 @@
1
+ require_dependency "user"
2
+
3
+ module LoginSystem
4
+
5
+ protected
6
+
7
+ # overwrite this if you want to restrict access to only a few actions
8
+ # or if you want to check if the user has the correct rights
9
+ # example:
10
+ #
11
+ # # only allow nonbobs
12
+ # def authorize?(user)
13
+ # user.login != "bob"
14
+ # end
15
+ def authorize?(user)
16
+ true
17
+ end
18
+
19
+ # overwrite this method if you only want to protect certain actions of the controller
20
+ # example:
21
+ #
22
+ # # don't protect the login and the about method
23
+ # def protect?(action)
24
+ # if ['action', 'about'].include?(action)
25
+ # return false
26
+ # else
27
+ # return true
28
+ # end
29
+ # end
30
+ def protect?(action)
31
+ true
32
+ end
33
+
34
+ # login_required filter. add
35
+ #
36
+ # before_filter :login_required
37
+ #
38
+ # if the controller should be under any rights management.
39
+ # for finer access control you can overwrite
40
+ #
41
+ # def authorize?(user)
42
+ #
43
+ def login_required
44
+
45
+ if not protect?(action_name)
46
+ return true
47
+ end
48
+
49
+ if @session[:user] and authorize?(@session[:user])
50
+ return true
51
+ end
52
+
53
+ # store current location so that we can
54
+ # come back after the user logged in
55
+ store_location
56
+
57
+ # call overwriteable reaction to unauthorized access
58
+ access_denied
59
+ return false
60
+ end
61
+
62
+ # overwrite if you want to have special behavior in case the user is not authorized
63
+ # to access the current operation.
64
+ # the default action is to redirect to the login screen
65
+ # example use :
66
+ # a popup window might just close itself for instance
67
+ def access_denied
68
+ redirect_to :controller=>"/login", :action =>"login"
69
+ end
70
+
71
+ # store current uri in the session.
72
+ # we can return to this location by calling return_location
73
+ def store_location
74
+ @session[:return_to] = @request.request_uri
75
+ end
76
+
77
+ # move to the last store_location call or to the passed default one
78
+ def redirect_back_or_default(default)
79
+ if @session[:return_to].nil?
80
+ redirect_to default
81
+ else
82
+ redirect_to_url @session[:return_to]
83
+ @session[:return_to] = nil
84
+ end
85
+ end
86
+
87
+ end
@@ -0,0 +1,489 @@
1
+ # = Introduction
2
+ #
3
+ # SimpleMarkup parses plain text documents and attempts to decompose
4
+ # them into their constituent parts. Some of these parts are high-level:
5
+ # paragraphs, chunks of verbatim text, list entries and the like. Other
6
+ # parts happen at the character level: a piece of bold text, a word in
7
+ # code font. This markup is similar in spirit to that used on WikiWiki
8
+ # webs, where folks create web pages using a simple set of formatting
9
+ # rules.
10
+ #
11
+ # SimpleMarkup itself does no output formatting: this is left to a
12
+ # different set of classes.
13
+ #
14
+ # SimpleMarkup is extendable at runtime: you can add new markup
15
+ # elements to be recognised in the documents that SimpleMarkup parses.
16
+ #
17
+ # SimpleMarkup is intended to be the basis for a family of tools which
18
+ # share the common requirement that simple, plain-text should be
19
+ # rendered in a variety of different output formats and media. It is
20
+ # envisaged that SimpleMarkup could be the basis for formating RDoc
21
+ # style comment blocks, Wiki entries, and online FAQs.
22
+ #
23
+ # = Basic Formatting
24
+ #
25
+ # * SimpleMarkup looks for a document's natural left margin. This is
26
+ # used as the initial margin for the document.
27
+ #
28
+ # * Consecutive lines starting at this margin are considered to be a
29
+ # paragraph.
30
+ #
31
+ # * If a paragraph starts with a "*", "-", or with "<digit>.", then it is
32
+ # taken to be the start of a list. The margin in increased to be the
33
+ # first non-space following the list start flag. Subsequent lines
34
+ # should be indented to this new margin until the list ends. For
35
+ # example:
36
+ #
37
+ # * this is a list with three paragraphs in
38
+ # the first item. This is the first paragraph.
39
+ #
40
+ # And this is the second paragraph.
41
+ #
42
+ # 1. This is an indented, numbered list.
43
+ # 2. This is the second item in that list
44
+ #
45
+ # This is the third conventional paragraph in the
46
+ # first list item.
47
+ #
48
+ # * This is the second item in the original list
49
+ #
50
+ # * You can also construct labeled lists, sometimes called description
51
+ # or definition lists. Do this by putting the label in square brackets
52
+ # and indenting the list body:
53
+ #
54
+ # [cat] a small furry mammal
55
+ # that seems to sleep a lot
56
+ #
57
+ # [ant] a little insect that is known
58
+ # to enjoy picnics
59
+ #
60
+ # A minor variation on labeled lists uses two colons to separate the
61
+ # label from the list body:
62
+ #
63
+ # cat:: a small furry mammal
64
+ # that seems to sleep a lot
65
+ #
66
+ # ant:: a little insect that is known
67
+ # to enjoy picnics
68
+ #
69
+ # This latter style guarantees that the list bodies' left margins are
70
+ # aligned: think of them as a two column table.
71
+ #
72
+ # * Any line that starts to the right of the current margin is treated
73
+ # as verbatim text. This is useful for code listings. The example of a
74
+ # list above is also verbatim text.
75
+ #
76
+ # * A line starting with an equals sign (=) is treated as a
77
+ # heading. Level one headings have one equals sign, level two headings
78
+ # have two,and so on.
79
+ #
80
+ # * A line starting with three or more hyphens (at the current indent)
81
+ # generates a horizontal rule. THe more hyphens, the thicker the rule
82
+ # (within reason, and if supported by the output device)
83
+ #
84
+ # * You can use markup within text (except verbatim) to change the
85
+ # appearance of parts of that text. Out of the box, SimpleMarkup
86
+ # supports word-based and general markup.
87
+ #
88
+ # Word-based markup uses flag characters around individual words:
89
+ #
90
+ # [\*word*] displays word in a *bold* font
91
+ # [\_word_] displays word in an _emphasized_ font
92
+ # [\+word+] displays word in a +code+ font
93
+ #
94
+ # General markup affects text between a start delimiter and and end
95
+ # delimiter. Not surprisingly, these delimiters look like HTML markup.
96
+ #
97
+ # [\<b>text...</b>] displays word in a *bold* font
98
+ # [\<em>text...</em>] displays word in an _emphasized_ font
99
+ # [\<i>text...</i>] displays word in an _emphasized_ font
100
+ # [\<tt>text...</tt>] displays word in a +code+ font
101
+ #
102
+ # Unlike conventional Wiki markup, general markup can cross line
103
+ # boundaries. You can turn off the interpretation of markup by
104
+ # preceding the first character with a backslash, so \\\<b>bold
105
+ # text</b> and \\\*bold* produce \<b>bold text</b> and \*bold
106
+ # respectively.
107
+ #
108
+ # = Using SimpleMarkup
109
+ #
110
+ # For information on using SimpleMarkup programatically,
111
+ # see SM::SimpleMarkup.
112
+ #
113
+ # Author:: Dave Thomas, dave@pragmaticprogrammer.com
114
+ # Version:: 0.0
115
+ # License:: Ruby license
116
+
117
+
118
+
119
+ require 'markup/simple_markup/fragments'
120
+ require 'markup/simple_markup/lines.rb'
121
+
122
+ module SM #:nodoc:
123
+
124
+ # == Synopsis
125
+ #
126
+ # This code converts <tt>input_string</tt>, which is in the format
127
+ # described in markup/simple_markup.rb, to HTML. The conversion
128
+ # takes place in the +convert+ method, so you can use the same
129
+ # SimpleMarkup object to convert multiple input strings.
130
+ #
131
+ # require 'rdoc/markup/simple_markup'
132
+ # require 'rdoc/markup/simple_markup/to_html'
133
+ #
134
+ # p = SM::SimpleMarkup.new
135
+ # h = SM::ToHtml.new
136
+ #
137
+ # puts p.convert(input_string, h)
138
+ #
139
+ # You can extend the SimpleMarkup parser to recognise new markup
140
+ # sequences, and to add special processing for text that matches a
141
+ # regular epxression. Here we make WikiWords significant to the parser,
142
+ # and also make the sequences {word} and \<no>text...</no> signify
143
+ # strike-through text. When then subclass the HTML output class to deal
144
+ # with these:
145
+ #
146
+ # require 'rdoc/markup/simple_markup'
147
+ # require 'rdoc/markup/simple_markup/to_html'
148
+ #
149
+ # class WikiHtml < SM::ToHtml
150
+ # def handle_special_WIKIWORD(special)
151
+ # "<font color=red>" + special.text + "</font>"
152
+ # end
153
+ # end
154
+ #
155
+ # p = SM::SimpleMarkup.new
156
+ # p.add_word_pair("{", "}", :STRIKE)
157
+ # p.add_html("no", :STRIKE)
158
+ #
159
+ # p.add_special(/\b([A-Z][a-z]+[A-Z]\w+)/, :WIKIWORD)
160
+ #
161
+ # h = WikiHtml.new
162
+ # h.add_tag(:STRIKE, "<strike>", "</strike>")
163
+ #
164
+ # puts "<body>" + p.convert(ARGF.read, h) + "</body>"
165
+ #
166
+ # == Output Formatters
167
+ #
168
+ # _missing_
169
+ #
170
+ #
171
+
172
+ class SimpleMarkup
173
+
174
+ SPACE = ?\s
175
+
176
+ # List entries look like:
177
+ # * text
178
+ # 1. text
179
+ # [label] text
180
+ # label:: text
181
+ # || text (added by ando)
182
+ #
183
+ # Flag it as a list entry, and
184
+ # work out the indent for subsequent lines
185
+
186
+ SIMPLE_LIST_RE = /^(
187
+ ( \* (?# bullet)
188
+ |- (?# bullet)
189
+ |\d+\. (?# numbered )
190
+ |[A-Za-z]\. (?# alphabetically numbered )
191
+ )
192
+ \s+
193
+ )\S/x
194
+
195
+ LABEL_LIST_RE = /^(
196
+ ( \[.*?\] (?# labeled )
197
+ |\S.*:: (?# note )
198
+ )(?:\s+|$)
199
+ )/x
200
+
201
+ TABLE_ROW_RE = /^(
202
+ \|\|
203
+ ).*/x
204
+
205
+
206
+ ##
207
+ # take a block of text and use various heuristics to determine
208
+ # it's structure (paragraphs, lists, and so on). Invoke an
209
+ # event handler as we identify significant chunks.
210
+ #
211
+
212
+ def initialize
213
+ @am = AttributeManager.new
214
+ @output = nil
215
+ end
216
+
217
+ ##
218
+ # Add to the sequences used to add formatting to an individual word
219
+ # (such as *bold*). Matching entries will generate attibutes
220
+ # that the output formatters can recognize by their +name+
221
+
222
+ def add_word_pair(start, stop, name)
223
+ @am.add_word_pair(start, stop, name)
224
+ end
225
+
226
+ ##
227
+ # Add to the sequences recognized as general markup
228
+ #
229
+
230
+ def add_html(tag, name)
231
+ @am.add_html(tag, name)
232
+ end
233
+
234
+ ##
235
+ # Add to other inline sequences. For example, we could add
236
+ # WikiWords using something like:
237
+ #
238
+ # parser.add_special(/\b([A-Z][a-z]+[A-Z]\w+)/, :WIKIWORD)
239
+ #
240
+ # Each wiki word will be presented to the output formatter
241
+ # via the accept_special method
242
+ #
243
+
244
+ def add_special(pattern, name)
245
+ @am.add_special(pattern, name)
246
+ end
247
+
248
+
249
+ # We take a string, split it into lines, work out the type of
250
+ # each line, and from there deduce groups of lines (for example
251
+ # all lines in a paragraph). We then invoke the output formatter
252
+ # using a Visitor to display the result
253
+
254
+ def convert(str, op)
255
+ @lines = Lines.new(str.split(/\r?\n/).collect { |aLine|
256
+ Line.new(aLine) })
257
+ return "" if @lines.empty?
258
+ @lines.normalize
259
+ assign_types_to_lines
260
+ group = group_lines
261
+ # call the output formatter to handle the result
262
+ # group.to_a.each {|i| p i}
263
+ group.accept(@am, op)
264
+ end
265
+
266
+
267
+ #######
268
+ private
269
+ #######
270
+
271
+
272
+ ##
273
+ # Look through the text at line indentation. We flag each line as being
274
+ # Blank, a paragraph, a list element, or verbatim text
275
+ #
276
+
277
+ def assign_types_to_lines(margin = 0, level = 0)
278
+
279
+ while line = @lines.next
280
+ if line.isBlank?
281
+ line.stamp(Line::BLANK, level)
282
+ next
283
+ end
284
+
285
+ # if a line contains non-blanks before the margin, then it must belong
286
+ # to an outer level
287
+
288
+ text = line.text
289
+
290
+ for i in 0...margin
291
+ if text[i] != SPACE
292
+ @lines.unget
293
+ return
294
+ end
295
+ end
296
+
297
+ active_line = text[margin..-1]
298
+
299
+ # Rules (horizontal lines) look like
300
+ #
301
+ # --- (three or more hyphens)
302
+ #
303
+ # The more hyphens, the thicker the rule
304
+ #
305
+
306
+ if /^(---+)\s*$/ =~ active_line
307
+ line.stamp(Line::RULE, level, $1.length-2)
308
+ next
309
+ end
310
+
311
+ # Then look for list entries. First the ones that have to have
312
+ # text following them (* xxx, - xxx, and dd. xxx)
313
+
314
+ if SIMPLE_LIST_RE =~ active_line
315
+
316
+ offset = margin + $1.length
317
+ prefix = $2
318
+ prefix_length = prefix.length
319
+
320
+ flag = case prefix
321
+ when "*","-" then ListBase::BULLET
322
+ when /^\d/ then ListBase::NUMBER
323
+ when /^[A-Z]/ then ListBase::UPPERALPHA
324
+ when /^[a-z]/ then ListBase::LOWERALPHA
325
+ else raise "Invalid List Type: #{self.inspect}"
326
+ end
327
+
328
+ line.stamp(Line::LIST, level+1, prefix, flag)
329
+ text[margin, prefix_length] = " " * prefix_length
330
+ assign_types_to_lines(offset, level + 1)
331
+ next
332
+ end
333
+
334
+
335
+ if LABEL_LIST_RE =~ active_line
336
+ offset = margin + $1.length
337
+ prefix = $2
338
+ prefix_length = prefix.length
339
+
340
+ next if handled_labeled_list(line, level, margin, offset, prefix)
341
+ end
342
+
343
+ # added by ando
344
+ if TABLE_ROW_RE =~ active_line
345
+ offset = margin + $1.length
346
+ line.stamp(Line::LIST, level+1, prefix, ListBase::TABLE)
347
+ assign_types_to_lines(offset, level + 1)
348
+ next
349
+ end
350
+
351
+ # Headings look like
352
+ # = Main heading
353
+ # == Second level
354
+ # === Third
355
+ #
356
+ # Headings reset the level to 0
357
+
358
+ if active_line[0] == ?= and active_line =~ /^(=+)\s*(.*)/
359
+ prefix_length = $1.length
360
+ prefix_length = 6 if prefix_length > 6
361
+ line.stamp(Line::HEADING, 0, prefix_length)
362
+ line.strip_leading(margin + prefix_length)
363
+ next
364
+ end
365
+
366
+ # If the character's a space, then we have verbatim text,
367
+ # otherwise
368
+
369
+ if active_line[0] == SPACE
370
+ line.strip_leading(margin) if margin > 0
371
+ line.stamp(Line::VERBATIM, level)
372
+ else
373
+ line.stamp(Line::PARAGRAPH, level)
374
+ end
375
+ end
376
+ end
377
+
378
+ # Handle labeled list entries, We have a special case
379
+ # to deal with. Because the labels can be long, they force
380
+ # the remaining block of text over the to right:
381
+ #
382
+ # this is a long label that I wrote:: and here is the
383
+ # block of text with
384
+ # a silly margin
385
+ #
386
+ # So we allow the special case. If the label is followed
387
+ # by nothing, and if the following line is indented, then
388
+ # we take the indent of that line as the new margin
389
+ #
390
+ # this is a long label that I wrote::
391
+ # here is a more reasonably indented block which
392
+ # will ab attached to the label.
393
+ #
394
+
395
+ def handled_labeled_list(line, level, margin, offset, prefix)
396
+ prefix_length = prefix.length
397
+ text = line.text
398
+ flag = nil
399
+ case prefix
400
+ when /^\[/
401
+ flag = ListBase::LABELED
402
+ prefix = prefix[1, prefix.length-2]
403
+ when /:$/
404
+ flag = ListBase::NOTE
405
+ prefix.chop!
406
+ else raise "Invalid List Type: #{self.inspect}"
407
+ end
408
+
409
+ # body is on the next line
410
+
411
+ if text.length <= offset
412
+ original_line = line
413
+ line = @lines.next
414
+ return(false) unless line
415
+ text = line.text
416
+
417
+ for i in 0..margin
418
+ if text[i] != SPACE
419
+ @lines.unget
420
+ return false
421
+ end
422
+ end
423
+ i = margin
424
+ i += 1 while text[i] == SPACE
425
+ if i >= text.length
426
+ @lines.unget
427
+ return false
428
+ else
429
+ offset = i
430
+ prefix_length = 0
431
+ @lines.delete(original_line)
432
+ end
433
+ end
434
+
435
+ line.stamp(Line::LIST, level+1, prefix, flag)
436
+ text[margin, prefix_length] = " " * prefix_length
437
+ assign_types_to_lines(offset, level + 1)
438
+ return true
439
+ end
440
+
441
+ # Return a block consisting of fragments which are
442
+ # paragraphs, list entries or verbatim text. We merge consecutive
443
+ # lines of the same type and level together. We are also slightly
444
+ # tricky with lists: the lines following a list introduction
445
+ # look like paragraph lines at the next level, and we remap them
446
+ # into list entries instead
447
+
448
+ def group_lines
449
+ @lines.rewind
450
+
451
+ inList = false
452
+ wantedType = wantedLevel = nil
453
+
454
+ block = LineCollection.new
455
+ group = nil
456
+
457
+ while line = @lines.next
458
+ if line.level == wantedLevel and line.type == wantedType
459
+ group.add_text(line.text)
460
+ else
461
+ group = block.fragment_for(line)
462
+ block.add(group)
463
+ if line.type == Line::LIST
464
+ wantedType = Line::PARAGRAPH
465
+ else
466
+ wantedType = line.type
467
+ end
468
+ wantedLevel = line.type == Line::HEADING ? line.param : line.level
469
+ end
470
+ end
471
+
472
+ block.normalize
473
+ block
474
+ end
475
+
476
+ ## for debugging, we allow access to our line contents as text
477
+ def content
478
+ @lines.as_text
479
+ end
480
+ public :content
481
+
482
+ ## for debugging, return the list of line types
483
+ def get_line_types
484
+ @lines.line_types
485
+ end
486
+ public :get_line_types
487
+ end
488
+
489
+ end