131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
|
# File 'lib/bookmaker/base.rb', line 131
def self.generate_html
contents = ""
Dir.entries(text_dir).sort.each do |dirname|
next if %w(. .. .svn .git).include?(dirname) || File.file?(text_dir + "/#{dirname}")
chapter = ""
markup_files = Dir["#{text_dir}/#{dirname}/**/*.markdown"] + Dir["#{text_dir}/#{dirname}/**/*.textile"]
next if markup_files.empty?
markup_files.sort.each do |markup_file|
markup_contents = File.new(markup_file).read
begin
if markup_file =~ /\.textile$/
markup = BlackCloth.new(markup_contents)
else
markup = Discount.new(markup_contents)
end
rescue Exception => e
puts "Skipping #{markup_file} (#{e.message})"
next
end
parsed_contents = markup.to_html
if Object.const_defined?('Uv')
if markup.respond_to?(:syntax_blocks)
parsed_contents.gsub!(/@syntax:([0-9]+)/m) do |m|
syntax, code = markup.syntax_blocks[$1.to_i]
Bookmaker::Markup.syntax(code, syntax)
end
else
parsed_contents.gsub! /<pre><code>(.*?)<\/code><\/pre>/m do |block|
code = $1.gsub(/</, '<').gsub(/>/, '>').gsub(/&/, '&')
code_lines = StringIO.new(code).readlines
syntax_settings = code_lines.first
syntax = 'plain_text'
if syntax_settings =~ /syntax\(.*?\)\./
code = code_lines.slice(1, code_lines.size).join
m, syntax = *syntax_settings.match(/syntax\(([^ #]+).*?\)./)
m, source_file = *syntax_settings.match(/syntax\(.*?\)\. +(.*?)$/)
m, from_line, to_line = *syntax_settings.match(/syntax\(.*? ([0-9]+),([0-9]+)\)/)
m, block_name = *syntax_settings.match(/syntax\(.*?#([0-9a-z_]+)\)/)
code = Bookmaker::Markup.content_for({
:code => code,
:from_line => from_line,
:to_line => to_line,
:block_name => block_name,
:source_file => source_file
})
Bookmaker::Markup.syntax(code, syntax)
end
end
end
end
chapter << (parsed_contents + "\n\n")
end
contents << '<div class="chapter">%s</div>' % chapter
end
File.open(html_path, 'w+') do |f|
f << Bookmaker::Base.parse_layout(contents)
end
end
|