omf_web 1.2.3 → 1.2.4
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.
- data/lib/irods4r/file.rb +2 -0
- data/lib/irods4r/icommands.rb +5 -0
- data/lib/irods4r.rb +1 -1
- data/lib/omf-web/content/git_repository.rb +3 -1
- data/lib/omf-web/content/irods_repository.rb +1 -1
- data/lib/omf-web/content/repository.rb +1 -0
- data/lib/omf-web/data_source_proxy.rb +14 -0
- data/lib/omf-web/theme/abstract_page.rb +4 -1
- data/lib/omf-web/thin/logging.rb +8 -1
- data/lib/omf-web/version.rb +1 -1
- data/lib/omf-web/widget/data_widget.rb +6 -1
- data/lib/omf-web/widget/text/maruku/helpers.rb +211 -211
- data/lib/omf-web/widget/text/maruku/input/parse_block.rb +498 -499
- data/lib/omf-web/widget/text/maruku/output/to_html.rb +810 -808
- data/lib/omf-web/widget/text/maruku.rb +54 -18
- data/lib/omf-web/widget/text/text_widget.rb +13 -13
- data/share/htdocs/graph/js/abstract_widget.js +1 -1
- data/share/htdocs/js/data_source3.js +36 -8
- data/share/htdocs/js/data_source_repo.js +14 -6
- metadata +2 -2
@@ -21,87 +21,87 @@
|
|
21
21
|
require 'rexml/document'
|
22
22
|
|
23
23
|
begin
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
require 'rexml/formatters/pretty'
|
25
|
+
require 'rexml/formatters/default'
|
26
|
+
$rexml_new_version = true
|
27
27
|
rescue LoadError
|
28
|
-
|
28
|
+
$rexml_new_version = false
|
29
29
|
end
|
30
30
|
|
31
31
|
class String
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
32
|
+
# A string is rendered into HTML by creating
|
33
|
+
# a REXML::Text node. REXML takes care of all the encoding.
|
34
|
+
def to_html
|
35
|
+
REXML::Text.new(self)
|
36
|
+
end
|
37
37
|
end
|
38
38
|
|
39
39
|
|
40
40
|
# This module groups all functions related to HTML export.
|
41
41
|
module MaRuKu; module Out; module HTML
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
42
|
+
include REXML
|
43
|
+
|
44
|
+
# Render as an HTML fragment (no head, just the content of BODY). (returns a string)
|
45
|
+
def to_html(context={})
|
46
|
+
Thread.current['maruku_context'] = context
|
47
|
+
indent = context[:indent] || -1
|
48
|
+
ie_hack = context[:ie_hack] || true
|
49
|
+
|
50
|
+
div = Element.new 'dummy'
|
51
|
+
children_to_html.each do |e|
|
52
|
+
div << e
|
53
|
+
end
|
54
|
+
|
55
|
+
# render footnotes
|
56
|
+
if @doc.footnotes_order.size > 0
|
57
|
+
div << render_footnotes
|
58
|
+
end
|
59
|
+
|
60
|
+
doc = Document.new(nil,{:respect_whitespace =>:all})
|
61
|
+
doc << div
|
62
|
+
|
63
|
+
# REXML Bug? if indent!=-1 whitespace is not respected for 'pre' elements
|
64
|
+
# containing code.
|
65
|
+
xml =""
|
66
|
+
|
67
|
+
if $rexml_new_version
|
68
|
+
formatter = if indent > -1
|
69
|
+
REXML::Formatters::Pretty.new( indent, ie_hack )
|
70
|
+
else
|
71
|
+
REXML::Formatters::Default.new( ie_hack )
|
72
|
+
end
|
73
|
+
formatter.write( div, xml)
|
74
|
+
else
|
75
|
+
div.write(xml,indent,transitive=true,ie_hack)
|
76
|
+
end
|
77
|
+
|
78
|
+
xml.gsub!(/\A<dummy>\s*/,'')
|
79
|
+
xml.gsub!(/\s*<\/dummy>\Z/,'')
|
80
|
+
xml.gsub!(/\A<dummy\s*\/>/,'')
|
81
|
+
xml
|
82
|
+
end
|
83
|
+
|
84
|
+
# Render to a complete HTML document (returns a string)
|
85
|
+
def to_html_document(context={})
|
86
|
+
indent = context[:indent] || -1
|
87
|
+
ie_hack = context[:ie_hack] ||true
|
88
|
+
doc = to_html_document_tree
|
89
|
+
xml = ""
|
90
|
+
|
91
|
+
# REXML Bug? if indent!=-1 whitespace is not respected for 'pre' elements
|
92
|
+
# containing code.
|
93
|
+
doc.write(xml,indent,transitive=true,ie_hack);
|
94
|
+
|
95
|
+
Xhtml11_mathml2_svg11 + xml
|
96
|
+
end
|
97
|
+
|
98
|
+
unless defined? Xhtml10strict
|
99
|
+
Xhtml10strict =
|
100
100
|
"<?xml version='1.0' encoding='utf-8'?>
|
101
101
|
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN'
|
102
102
|
'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>\n"
|
103
103
|
|
104
|
-
|
104
|
+
Xhtml11strict_mathml2 = '<?xml version="1.0" encoding="utf-8"?>
|
105
105
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN"
|
106
106
|
"http://www.w3.org/TR/MathML2/dtd/xhtml-math11-f.dtd" [
|
107
107
|
<!ENTITY mathml "http://www.w3.org/1998/Math/MathML">
|
@@ -117,7 +117,7 @@ module MaRuKu; module Out; module HTML
|
|
117
117
|
end
|
118
118
|
|
119
119
|
|
120
|
-
|
120
|
+
def xml_newline() Text.new("\n") end
|
121
121
|
|
122
122
|
|
123
123
|
=begin maruku_doc
|
@@ -129,16 +129,16 @@ If a title is not specified, the first header will be used.
|
|
129
129
|
|
130
130
|
These should be equivalent:
|
131
131
|
|
132
|
-
|
132
|
+
Title: my document
|
133
133
|
|
134
|
-
|
134
|
+
Content
|
135
135
|
|
136
136
|
and
|
137
137
|
|
138
|
-
|
139
|
-
|
138
|
+
my document
|
139
|
+
===========
|
140
140
|
|
141
|
-
|
141
|
+
Content
|
142
142
|
|
143
143
|
In both cases, the title is set to "my document".
|
144
144
|
=end
|
@@ -159,22 +159,22 @@ Synonim for `title`.
|
|
159
159
|
=end
|
160
160
|
|
161
161
|
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
162
|
+
# Render to an HTML fragment (returns a REXML document tree)
|
163
|
+
def to_html_tree
|
164
|
+
div = Element.new 'div'
|
165
|
+
div.attributes['class'] = 'maruku_wrapper_div'
|
166
|
+
children_to_html.each do |e|
|
167
|
+
div << e
|
168
|
+
end
|
169
169
|
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
170
|
+
# render footnotes
|
171
|
+
if @doc.footnotes_order.size > 0
|
172
|
+
div << render_footnotes
|
173
|
+
end
|
174
174
|
|
175
|
-
|
176
|
-
|
177
|
-
|
175
|
+
doc = Document.new(nil,{:respect_whitespace =>:all})
|
176
|
+
doc << div
|
177
|
+
end
|
178
178
|
|
179
179
|
=begin maruku_doc
|
180
180
|
Attribute: css
|
@@ -186,178 +186,179 @@ Summary: Activates CSS stylesheets for HTML.
|
|
186
186
|
|
187
187
|
Example:
|
188
188
|
|
189
|
-
|
189
|
+
CSS: style.css math.css
|
190
190
|
|
191
191
|
=end
|
192
192
|
|
193
193
|
unless defined? METAS
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
194
|
+
METAS = %w{description keywords author revised}
|
195
|
+
end
|
196
|
+
|
197
|
+
# Render to a complete HTML document (returns a REXML document tree)
|
198
|
+
def to_html_document_tree
|
199
|
+
doc = Document.new(nil,{:respect_whitespace =>:all})
|
200
|
+
# doc << XMLDecl.new
|
201
|
+
|
202
|
+
root = Element.new('html', doc)
|
203
|
+
root.add_namespace('http://www.w3.org/1999/xhtml')
|
204
|
+
root.add_namespace('svg', "http://www.w3.org/2000/svg" )
|
205
|
+
lang = self.attributes[:lang] || 'en'
|
206
|
+
root.attributes['xml:lang'] = lang
|
207
|
+
|
208
|
+
root << xml_newline
|
209
|
+
head = Element.new 'head', root
|
210
|
+
|
211
|
+
#<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8">
|
212
|
+
me = Element.new 'meta', head
|
213
|
+
me.attributes['http-equiv'] = 'Content-type'
|
214
214
|
# me.attributes['content'] = 'text/html;charset=utf-8'
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
215
|
+
me.attributes['content'] = 'application/xhtml+xml;charset=utf-8'
|
216
|
+
|
217
|
+
METAS.each do |m|
|
218
|
+
if value = self.attributes[m.to_sym]
|
219
|
+
meta = Element.new 'meta', head
|
220
|
+
meta.attributes['name'] = m
|
221
|
+
meta.attributes['content'] = value.to_s
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
225
|
+
|
226
|
+
self.attributes.each do |k,v|
|
227
|
+
if k.to_s =~ /\Ameta-(.*)\Z/
|
228
|
+
meta = Element.new 'meta', head
|
229
|
+
meta.attributes['name'] = $1
|
230
|
+
meta.attributes['content'] = v.to_s
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
|
235
|
+
|
236
|
+
# Create title element
|
237
|
+
doc_title = self.attributes[:title] || self.attributes[:subject] || ""
|
238
|
+
title = Element.new 'title', head
|
239
|
+
title << Text.new(doc_title)
|
240
|
+
|
241
|
+
add_css_to(head)
|
242
|
+
|
243
|
+
|
244
|
+
root << xml_newline
|
245
|
+
|
246
|
+
body = Element.new 'body'
|
247
|
+
|
248
|
+
children_to_html.each do |e|
|
249
|
+
body << e
|
250
|
+
end
|
251
|
+
|
252
|
+
# render footnotes
|
253
|
+
if @doc.footnotes_order.size > 0
|
254
|
+
body << render_footnotes
|
255
|
+
end
|
256
|
+
|
257
|
+
# When we are rendering a whole document, we add a signature
|
258
|
+
# at the bottom.
|
259
|
+
if get_setting(:maruku_signature)
|
260
|
+
body << maruku_html_signature
|
261
|
+
end
|
262
|
+
|
263
|
+
root << body
|
264
|
+
|
265
|
+
doc
|
266
|
+
end
|
267
|
+
|
268
|
+
def add_css_to(head)
|
269
|
+
if css_list = self.attributes[:css]
|
270
|
+
css_list.split.each do |css|
|
271
|
+
# <link type="text/css" rel="stylesheet" href="..." />
|
272
|
+
link = Element.new 'link'
|
273
|
+
link.attributes['type'] = 'text/css'
|
274
|
+
link.attributes['rel'] = 'stylesheet'
|
275
|
+
link.attributes['href'] = css
|
276
|
+
head << link
|
277
|
+
head << xml_newline
|
278
|
+
end
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
282
|
+
# returns "st","nd","rd" or "th" as appropriate
|
283
|
+
def day_suffix(day)
|
284
|
+
s = {
|
285
|
+
1 => 'st',
|
286
|
+
2 => 'nd',
|
287
|
+
3 => 'rd',
|
288
|
+
21 => 'st',
|
289
|
+
22 => 'nd',
|
290
|
+
23 => 'rd',
|
291
|
+
31 => 'st'
|
292
|
+
}
|
293
|
+
return s[day] || 'th';
|
294
|
+
end
|
295
|
+
|
296
|
+
# formats a nice date
|
297
|
+
def nice_date
|
298
|
+
t = Time.now
|
299
|
+
t.strftime(" at %H:%M on ")+
|
300
|
+
t.strftime("%A, %B %d")+
|
301
|
+
day_suffix(t.day)+
|
302
|
+
t.strftime(", %Y")
|
303
|
+
end
|
304
|
+
|
305
|
+
def maruku_html_signature
|
306
|
+
div = Element.new 'div'
|
307
|
+
div.attributes['class'] = 'maruku_signature'
|
308
|
+
Element.new 'hr', div
|
309
|
+
span = Element.new 'span', div
|
310
|
+
span.attributes['style'] = 'font-size: small; font-style: italic'
|
311
|
+
span << Text.new('Created by ')
|
312
|
+
a = Element.new('a', span)
|
313
|
+
a.attributes['href'] = 'http://maruku.rubyforge.org'
|
314
|
+
a.attributes['title'] = 'Maruku: a Markdown-superset interpreter for Ruby'
|
315
|
+
a << Text.new('Maruku')
|
316
|
+
span << Text.new(nice_date+".")
|
317
|
+
div
|
318
|
+
end
|
319
|
+
|
320
|
+
def render_footnotes()
|
321
|
+
div = Element.new 'div'
|
322
|
+
div.attributes['class'] = 'footnotes'
|
323
|
+
div << Element.new('hr')
|
324
|
+
ol = Element.new 'ol'
|
325
|
+
@doc.footnotes_order.each_with_index do |fid, i| num = i+1
|
326
|
+
f = self.footnotes[fid]
|
327
|
+
if f
|
328
|
+
li = f.wrap_as_element('li')
|
329
|
+
li.attributes['id'] = "#{get_setting(:doc_prefix)}fn:#{num}"
|
330
|
+
|
331
|
+
a = Element.new 'a'
|
332
|
+
a.attributes['href'] = "\##{get_setting(:doc_prefix)}fnref:#{num}"
|
333
|
+
a.attributes['rev'] = 'footnote'
|
334
|
+
a<< Text.new('↩', true, nil, true)
|
335
|
+
li.insert_after(li.children.last, a)
|
336
|
+
ol << li
|
337
|
+
else
|
338
|
+
maruku_error "Could not find footnote id '#{fid}' among ["+
|
339
|
+
self.footnotes.keys.map{|s|"'"+s+"'"}.join(', ')+"]."
|
340
|
+
end
|
341
|
+
end
|
342
|
+
div << ol
|
343
|
+
div
|
344
|
+
end
|
345
|
+
|
346
|
+
|
347
|
+
def to_html_hrule; create_html_element 'hr' end
|
348
|
+
def to_html_linebreak; Element.new 'br' end
|
349
|
+
|
350
|
+
# renders children as html and wraps into an element of given name
|
351
|
+
#
|
352
|
+
# Sets 'id' if meta is set
|
353
|
+
def wrap_as_element(name, attributes_to_copy=[])
|
354
|
+
m = create_html_element(name, attributes_to_copy)
|
355
|
+
#puts "MMM>>> #{m} - #{attributes_to_copy}"
|
356
|
+
children_to_html.each do |e| m << e; end
|
356
357
|
|
357
358
|
# m << Comment.new( "{"+self.al.to_md+"}") if not self.al.empty?
|
358
359
|
# m << Comment.new( @attributes.inspect) if not @attributes.empty?
|
359
|
-
|
360
|
-
|
360
|
+
m
|
361
|
+
end
|
361
362
|
|
362
363
|
=begin maruku_doc
|
363
364
|
Attribute: id
|
@@ -391,85 +392,87 @@ It is copied as a standard HTML attribute.
|
|
391
392
|
|
392
393
|
|
393
394
|
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
395
|
+
unless defined? HTML4Attributes
|
396
|
+
HTML4Attributes = {}
|
397
|
+
end
|
398
|
+
|
399
|
+
coreattrs = [:id, :class, :style, :title]
|
400
|
+
i18n = [:lang, 'xml:lang'.to_sym]
|
401
|
+
events = [
|
402
|
+
:onclick, :ondblclick, :onmousedown, :onmouseup, :onmouseover,
|
403
|
+
:onmousemove, :onmouseout,
|
404
|
+
:onkeypress, :onkeydown, :onkeyup]
|
405
|
+
attrs = coreattrs + i18n + events
|
406
|
+
cellhalign = [:align, :char, :charoff]
|
407
|
+
cellvalign = [:valign]
|
408
|
+
[
|
409
|
+
['body', attrs + [:onload, :onunload]],
|
410
|
+
['address', attrs],
|
411
|
+
['div', attrs],
|
412
|
+
['a', attrs+[:charset, :type, :name, :rel, :rev, :accesskey, :shape, :coords, :tabindex,
|
413
|
+
:onfocus,:onblur]],
|
414
|
+
['img', attrs + [:longdesc, :name, :height, :width, :alt] ],
|
415
|
+
['p', attrs],
|
416
|
+
[['h1','h2','h3','h4','h5','h6'], attrs],
|
417
|
+
[['pre'], attrs],
|
418
|
+
[['q', 'blockquote'], attrs+[:cite]],
|
419
|
+
[['ins','del'], attrs+[:cite,:datetime]],
|
420
|
+
[['ol','ul','li'], attrs],
|
421
|
+
['table',attrs+[:summary, :width, :frame, :rules, :border, :cellspacing, :cellpadding]],
|
422
|
+
['caption',attrs],
|
423
|
+
[['colgroup','col'],attrs+[:span, :width]+cellhalign+cellvalign],
|
424
|
+
[['thead','tbody','tfoot'], attrs+cellhalign+cellvalign],
|
425
|
+
[['td','td','th'], attrs+[:abbr, :axis, :headers, :scope, :rowspan, :colspan, :cellvalign, :cellhalign]],
|
426
|
+
|
427
|
+
# altri
|
428
|
+
[['em','code','strong','hr','span','dl','dd','dt'], attrs]
|
429
|
+
].each do |el, a| [*el].each do |e| HTML4Attributes[e] = a end end
|
430
|
+
|
431
|
+
|
432
|
+
def create_html_element(name, attributes_to_copy=[])
|
433
|
+
m = Element.new name
|
434
|
+
#puts "ATTR>>> #{@attributes}"
|
435
|
+
if atts = HTML4Attributes[name] then
|
436
|
+
atts.each do |att|
|
437
|
+
if v = @attributes[att] then
|
438
|
+
m.attributes[att.to_s] = v.to_s
|
439
|
+
end
|
440
|
+
end
|
441
|
+
else
|
442
|
+
# puts "not atts for #{name.inspect}"
|
443
|
+
end
|
444
|
+
m
|
445
|
+
end
|
446
|
+
|
447
|
+
|
448
|
+
def to_html_ul
|
449
|
+
if @attributes[:toc]
|
450
|
+
# render toc
|
451
|
+
html_toc = @doc.toc.to_html
|
452
|
+
return html_toc
|
453
|
+
else
|
454
|
+
add_ws wrap_as_element('ul')
|
455
|
+
end
|
456
|
+
end
|
457
|
+
|
458
|
+
|
459
|
+
def to_html_paragraph
|
460
|
+
#add_ws wrap_as_element('p')
|
461
|
+
dt = Element.new 'p'
|
460
462
|
dt.attributes['class'] = 'drop-target'
|
461
|
-
dt.attributes['line_no'] = Thread.current['line_no']
|
463
|
+
dt.attributes['line_no'] = Thread.current['maruku.line_no']
|
462
464
|
dt.attributes['delegate'] = 'plan' # should most likely go into the js column handler
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
465
|
+
dt.text = ' ';
|
466
|
+
p = wrap_as_element('p')
|
467
|
+
p.attributes['class'] = 'content'
|
468
|
+
[Text.new("\n"), p, dt, Text.new("\n")]
|
469
|
+
end
|
470
|
+
def to_html_ol; add_ws wrap_as_element('ol') end
|
471
|
+
def to_html_li; add_ws wrap_as_element('li') end
|
472
|
+
def to_html_li_span; add_ws wrap_as_element('li') end
|
473
|
+
def to_html_quote; add_ws wrap_as_element('blockquote') end
|
474
|
+
def to_html_strong; wrap_as_element('strong') end
|
475
|
+
def to_html_emphasis; wrap_as_element('em') end
|
473
476
|
|
474
477
|
=begin maruku_doc
|
475
478
|
Attribute: use_numbered_headers
|
@@ -482,59 +485,60 @@ In LaTeX export, the numbering of headers is managed
|
|
482
485
|
by Maruku, to have the same results in both HTML and LaTeX.
|
483
486
|
=end
|
484
487
|
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
488
|
+
# nil if not applicable, else string
|
489
|
+
def section_number
|
490
|
+
return nil if not get_setting(:use_numbered_headers)
|
491
|
+
|
492
|
+
n = @attributes[:section_number]
|
493
|
+
if n && (not n.empty?)
|
494
|
+
n.join('.')+". "
|
495
|
+
else
|
496
|
+
nil
|
497
|
+
end
|
498
|
+
end
|
499
|
+
|
500
|
+
# nil if not applicable, else SPAN element
|
501
|
+
def render_section_number
|
502
|
+
# if we are bound to a section, add section number
|
503
|
+
if num = section_number
|
504
|
+
span = Element.new 'span'
|
505
|
+
span.attributes['class'] = 'maruku_section_number'
|
506
|
+
span << Text.new(section_number)
|
507
|
+
span
|
508
|
+
else
|
509
|
+
nil
|
510
|
+
end
|
511
|
+
end
|
512
|
+
|
513
|
+
def to_html_header_orig
|
514
|
+
element_name = "h#{self.level}"
|
515
|
+
h = wrap_as_element element_name
|
516
|
+
|
517
|
+
if span = render_section_number
|
518
|
+
h.insert_before(h.children.first, span)
|
519
|
+
end
|
520
|
+
add_ws h
|
521
|
+
end
|
522
|
+
|
523
|
+
def to_html_header
|
524
|
+
element_name = "h#{self.level}"
|
525
|
+
h = wrap_as_element element_name
|
526
|
+
|
527
|
+
if span = render_section_number
|
528
|
+
h.insert_before(h.children.first, span)
|
529
|
+
end
|
530
|
+
#puts "h>>> #{h}"
|
531
|
+
add_ws h
|
532
|
+
end
|
533
|
+
|
534
|
+
|
535
|
+
def source2html(source)
|
532
536
|
# source = source.gsub(/&/,'&')
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
537
|
+
source = Text.normalize(source)
|
538
|
+
source = source.gsub(/\'/,''') # IE bug
|
539
|
+
source = source.gsub(/'/,''') # IE bug
|
540
|
+
Text.new(source, true, nil, true )
|
541
|
+
end
|
538
542
|
|
539
543
|
=begin maruku_doc
|
540
544
|
Attribute: html_use_syntax
|
@@ -549,86 +553,86 @@ languages. Remember to set the `lang` attribute of the code block.
|
|
549
553
|
|
550
554
|
Examples:
|
551
555
|
|
552
|
-
|
553
|
-
|
556
|
+
require 'maruku'
|
557
|
+
{:lang=ruby html_use_syntax=true}
|
554
558
|
|
555
559
|
and
|
556
560
|
|
557
|
-
|
558
|
-
|
561
|
+
<div style="text-align:center">Div</div>
|
562
|
+
{:lang=html html_use_syntax=true}
|
559
563
|
|
560
564
|
produces:
|
561
565
|
|
562
|
-
|
566
|
+
require 'maruku'
|
563
567
|
{:lang=ruby html_use_syntax=true}
|
564
568
|
|
565
569
|
and
|
566
570
|
|
567
|
-
|
571
|
+
<div style="text-align:center">Div</div>
|
568
572
|
{:lang=html html_use_syntax=true}
|
569
573
|
|
570
574
|
=end
|
571
575
|
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
576
|
+
$syntax_loaded = false
|
577
|
+
def to_html_code;
|
578
|
+
source = self.raw_code
|
579
|
+
|
580
|
+
lang = self.attributes[:lang] || @doc.attributes[:code_lang]
|
581
|
+
|
582
|
+
lang = 'xml' if lang=='html'
|
583
|
+
|
584
|
+
use_syntax = get_setting :html_use_syntax
|
585
|
+
|
586
|
+
element =
|
587
|
+
if use_syntax && lang
|
588
|
+
begin
|
589
|
+
if not $syntax_loaded
|
590
|
+
require 'rubygems'
|
591
|
+
require 'syntax'
|
592
|
+
require 'syntax/convertors/html'
|
593
|
+
$syntax_loaded = true
|
594
|
+
end
|
595
|
+
convertor = Syntax::Convertors::HTML.for_syntax lang
|
596
|
+
|
597
|
+
# eliminate trailing newlines otherwise Syntax crashes
|
598
|
+
source = source.gsub(/\n*\Z/,'')
|
599
|
+
|
600
|
+
html = convertor.convert( source )
|
601
|
+
html = html.gsub(/\'/,''') # IE bug
|
602
|
+
html = html.gsub(/'/,''') # IE bug
|
603
|
+
# html = html.gsub(/&/,'&')
|
604
|
+
|
605
|
+
code = Document.new(html, {:respect_whitespace =>:all}).root
|
606
|
+
code.name = 'code'
|
607
|
+
code.attributes['class'] = lang
|
608
|
+
code.attributes['lang'] = lang
|
609
|
+
|
610
|
+
pre = Element.new 'pre'
|
611
|
+
pre << code
|
612
|
+
pre
|
613
|
+
rescue LoadError => e
|
614
|
+
maruku_error "Could not load package 'syntax'.\n"+
|
615
|
+
"Please install it, for example using 'gem install syntax'."
|
616
|
+
to_html_code_using_pre(source)
|
617
|
+
rescue Object => e
|
618
|
+
maruku_error"Error while using the syntax library for code:\n#{source.inspect}"+
|
619
|
+
"Lang is #{lang} object is: \n"+
|
620
|
+
self.inspect +
|
621
|
+
"\nException: #{e.class}: #{e.message}\n\t#{e.backtrace.join("\n\t")}"
|
622
|
+
|
623
|
+
tell_user("Using normal PRE because the syntax library did not work.")
|
624
|
+
to_html_code_using_pre(source)
|
625
|
+
end
|
626
|
+
else
|
627
|
+
to_html_code_using_pre(source)
|
628
|
+
end
|
629
|
+
|
630
|
+
color = get_setting(:code_background_color)
|
631
|
+
if color != Globals[:code_background_color]
|
632
|
+
element.attributes['style'] = "background-color: #{color};"
|
633
|
+
end
|
634
|
+
add_ws element
|
635
|
+
end
|
632
636
|
|
633
637
|
=begin maruku_doc
|
634
638
|
Attribute: code_background_color
|
@@ -650,182 +654,182 @@ of the form `#ff00ff`.
|
|
650
654
|
=end
|
651
655
|
|
652
656
|
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
+
def to_html_code_using_pre(source)
|
658
|
+
pre = create_html_element 'pre'
|
659
|
+
code = Element.new 'code', pre
|
660
|
+
s = source
|
657
661
|
|
658
662
|
# s = s.gsub(/&/,'&')
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
663
|
+
s = Text.normalize(s)
|
664
|
+
s = s.gsub(/\'/,''') # IE bug
|
665
|
+
s = s.gsub(/'/,''') # IE bug
|
666
|
+
|
667
|
+
if get_setting(:code_show_spaces)
|
668
|
+
# 187 = raquo
|
669
|
+
# 160 = nbsp
|
670
|
+
# 172 = not
|
671
|
+
s.gsub!(/\t/,'»'+' '*3)
|
672
|
+
s.gsub!(/ /,'¬')
|
673
|
+
end
|
674
|
+
|
675
|
+
text = Text.new(s, respect_ws=true, parent=nil, raw=true )
|
676
|
+
|
677
|
+
if lang = self.attributes[:lang]
|
678
|
+
code.attributes['lang'] = lang
|
679
|
+
code.attributes['class'] = lang
|
680
|
+
end
|
681
|
+
code << text
|
682
|
+
pre
|
683
|
+
end
|
684
|
+
|
685
|
+
def to_html_inline_code;
|
686
|
+
pre = create_html_element 'code'
|
687
|
+
source = self.raw_code
|
688
|
+
pre << source2html(source)
|
689
|
+
|
690
|
+
color = get_setting(:code_background_color)
|
691
|
+
if color != Globals[:code_background_color]
|
692
|
+
pre.attributes['style'] = "background-color: #{color};"+(pre.attributes['style']||"")
|
693
|
+
end
|
694
|
+
|
695
|
+
pre
|
696
|
+
end
|
697
|
+
|
698
|
+
def add_class_to(el, cl)
|
699
|
+
el.attributes['class'] =
|
700
|
+
if already = el.attributes['class']
|
701
|
+
already + " " + cl
|
702
|
+
else
|
703
|
+
cl
|
704
|
+
end
|
705
|
+
end
|
706
|
+
|
707
|
+
def add_class_to_link(a)
|
708
|
+
return # not ready yet
|
709
|
+
|
710
|
+
# url = a.attributes['href']
|
711
|
+
# return if not url
|
712
|
+
#
|
713
|
+
# if url =~ /^#/
|
714
|
+
# add_class_to(a, 'maruku-link-samedoc')
|
715
|
+
# elsif url =~ /^http:/
|
716
|
+
# add_class_to(a, 'maruku-link-external')
|
717
|
+
# else
|
718
|
+
# add_class_to(a, 'maruku-link-local')
|
719
|
+
# end
|
720
|
+
#
|
717
721
|
# puts a.attributes['class']
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
722
|
+
end
|
723
|
+
|
724
|
+
|
725
|
+
def to_html_immediate_link
|
726
|
+
a = create_html_element 'a'
|
727
|
+
url = self.url
|
728
|
+
text = url.gsub(/^mailto:/,'') # don't show mailto
|
729
|
+
a << Text.new(text)
|
730
|
+
a.attributes['href'] = url
|
731
|
+
add_class_to_link(a)
|
732
|
+
a
|
733
|
+
end
|
734
|
+
|
735
|
+
def to_html_link
|
736
|
+
a = wrap_as_element 'a'
|
737
|
+
id = self.ref_id
|
738
|
+
|
739
|
+
if ref = @doc.refs[id]
|
740
|
+
url = ref[:url]
|
741
|
+
title = ref[:title]
|
742
|
+
a.attributes['href'] = url if url
|
743
|
+
a.attributes['title'] = title if title
|
744
|
+
else
|
745
|
+
maruku_error "Could not find ref_id = #{id.inspect} for #{self.inspect}\n"+
|
746
|
+
"Available refs are #{@doc.refs.keys.inspect}"
|
747
|
+
tell_user "Not creating a link for ref_id = #{id.inspect}."
|
748
|
+
return wrap_as_element('span')
|
749
|
+
end
|
746
750
|
|
747
751
|
# add_class_to_link(a)
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
752
|
+
return a
|
753
|
+
end
|
754
|
+
|
755
|
+
def to_html_im_link
|
756
|
+
if url = self.url
|
757
|
+
title = self.title
|
758
|
+
a = wrap_as_element 'a'
|
759
|
+
a.attributes['href'] = url
|
756
760
|
a.attributes['xhref'] = url # BUG ALERT: Strange behaviour of jquery's replaceWith related to href
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
764
|
-
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
761
|
+
a.attributes['title'] = title if title
|
762
|
+
return a
|
763
|
+
else
|
764
|
+
maruku_error"Could not find url in #{self.inspect}"
|
765
|
+
tell_user "Not creating a link for ref_id = #{id.inspect}."
|
766
|
+
return wrap_as_element('span')
|
767
|
+
end
|
768
|
+
end
|
769
|
+
|
770
|
+
def add_ws(e)
|
771
|
+
[Text.new("\n"), e, Text.new("\n")]
|
772
|
+
end
|
769
773
|
##### Email address
|
770
774
|
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
779
|
-
|
780
|
-
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
-
|
785
|
-
|
786
|
-
|
787
|
-
|
788
|
-
|
789
|
-
|
790
|
-
|
775
|
+
def obfuscate(s)
|
776
|
+
res = ''
|
777
|
+
s.each_byte do |char|
|
778
|
+
res += "&#%03d;" % char
|
779
|
+
end
|
780
|
+
res
|
781
|
+
end
|
782
|
+
|
783
|
+
def to_html_email_address
|
784
|
+
email = self.email
|
785
|
+
a = create_html_element 'a'
|
786
|
+
#a.attributes['href'] = Text.new("mailto:"+obfuscate(email),false,nil,true)
|
787
|
+
#a.attributes.add Attribute.new('href',Text.new(
|
788
|
+
#"mailto:"+obfuscate(email),false,nil,true))
|
789
|
+
# Sorry, for the moment it doesn't work
|
790
|
+
a.attributes['href'] = "mailto:#{email}"
|
791
|
+
|
792
|
+
a << Text.new(obfuscate(email),false,nil,true)
|
793
|
+
a
|
794
|
+
end
|
791
795
|
|
792
796
|
##### Images
|
793
797
|
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
|
798
|
+
def to_html_image
|
799
|
+
a = create_html_element 'img'
|
800
|
+
id = self.ref_id
|
801
|
+
if ref = @doc.refs[id]
|
802
|
+
url = ref[:url]
|
803
|
+
title = ref[:title]
|
804
|
+
a.attributes['src'] = url.to_s
|
805
|
+
a.attributes['alt'] = children_to_s
|
806
|
+
else
|
807
|
+
maruku_error"Could not find id = #{id.inspect} for\n #{self.inspect}"
|
808
|
+
tell_user "Could not create image with ref_id = #{id.inspect};"+
|
809
|
+
" Using SPAN element as replacement."
|
810
|
+
return wrap_as_element('span')
|
811
|
+
end
|
808
812
|
raise "IMAGE: #{url}"
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
|
813
|
+
return a
|
814
|
+
end
|
815
|
+
|
816
|
+
def to_html_im_image
|
817
|
+
if not url = self.url
|
818
|
+
maruku_error "Image with no url: #{self.inspect}"
|
819
|
+
tell_user "Could not create image with ref_id = #{id.inspect};"+
|
820
|
+
" Using SPAN element as replacement."
|
821
|
+
return wrap_as_element('span')
|
822
|
+
end
|
823
|
+
if url_resolver = (Thread.current['maruku_context'] || {})[:img_url_resolver]
|
824
|
+
url = url_resolver.call(url)
|
825
|
+
end
|
826
|
+
|
827
|
+
title = self.title
|
828
|
+
a = create_html_element 'img'
|
829
|
+
a.attributes['src'] = url.to_s
|
830
|
+
a.attributes['alt'] = children_to_s
|
831
|
+
return a
|
832
|
+
end
|
829
833
|
|
830
834
|
=begin maruku_doc
|
831
835
|
Attribute: filter_html
|
@@ -835,208 +839,206 @@ If true, raw HTML is discarded from the output.
|
|
835
839
|
|
836
840
|
=end
|
837
841
|
|
838
|
-
|
839
|
-
|
840
|
-
|
841
|
-
|
842
|
-
|
843
|
-
|
844
|
-
|
845
|
-
|
846
|
-
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
|
864
|
-
|
865
|
-
|
866
|
-
|
867
|
-
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
|
878
|
-
|
879
|
-
|
880
|
-
|
881
|
-
|
882
|
-
|
883
|
-
|
884
|
-
|
885
|
-
end
|
886
|
-
|
887
|
-
if not @doc.footnotes[id]
|
888
|
-
return []
|
842
|
+
def to_html_raw_html
|
843
|
+
return [] if get_setting(:filter_html)
|
844
|
+
|
845
|
+
raw_html = self.raw_html
|
846
|
+
if rexml_doc = @parsed_html
|
847
|
+
root = rexml_doc.root
|
848
|
+
if root.nil?
|
849
|
+
s = "Bug in REXML: root() of Document is nil: \n#{rexml_doc.inspect}\n"+
|
850
|
+
"Raw HTML:\n#{raw_html.inspect}"
|
851
|
+
maruku_error s
|
852
|
+
tell_user 'The REXML version you have has a bug, omitting HTML'
|
853
|
+
div = Element.new 'div'
|
854
|
+
#div << Text.new(s)
|
855
|
+
return div
|
856
|
+
end
|
857
|
+
|
858
|
+
# copies the @children array (FIXME is it deep?)
|
859
|
+
elements = root.to_a
|
860
|
+
return elements
|
861
|
+
else # invalid
|
862
|
+
# Creates red box with offending HTML
|
863
|
+
tell_user "Wrapping bad html in a PRE with class 'markdown-html-error'\n"+
|
864
|
+
add_tabs(raw_html,1,'|')
|
865
|
+
pre = Element.new('pre')
|
866
|
+
pre.attributes['style'] = 'border: solid 3px red; background-color: pink'
|
867
|
+
pre.attributes['class'] = 'markdown-html-error'
|
868
|
+
pre << Text.new("REXML could not parse this XML/HTML: \n#{raw_html}", true)
|
869
|
+
return pre
|
870
|
+
end
|
871
|
+
end
|
872
|
+
|
873
|
+
def to_html_abbr
|
874
|
+
abbr = Element.new 'abbr'
|
875
|
+
abbr << Text.new(children[0])
|
876
|
+
abbr.attributes['title'] = self.title if self.title
|
877
|
+
abbr
|
878
|
+
end
|
879
|
+
|
880
|
+
def to_html_footnote_reference
|
881
|
+
id = self.footnote_id
|
882
|
+
|
883
|
+
# save the order of used footnotes
|
884
|
+
order = @doc.footnotes_order
|
885
|
+
|
886
|
+
if order.include? id
|
887
|
+
# footnote has already been used
|
888
|
+
return []
|
889
889
|
end
|
890
890
|
|
891
|
-
|
892
|
-
|
891
|
+
if not @doc.footnotes[id]
|
892
|
+
return []
|
893
|
+
end
|
893
894
|
|
894
|
-
|
895
|
-
|
895
|
+
# take next number
|
896
|
+
order << id
|
896
897
|
|
897
|
-
|
898
|
-
|
899
|
-
a = Element.new 'a'
|
900
|
-
a << Text.new(num.to_s)
|
901
|
-
a.attributes['href'] = "\##{get_setting(:doc_prefix)}fn:#{num}"
|
902
|
-
a.attributes['rel'] = 'footnote'
|
903
|
-
sup << a
|
898
|
+
#num = order.size;
|
899
|
+
num = order.index(id) + 1
|
904
900
|
|
905
|
-
|
906
|
-
|
901
|
+
sup = Element.new 'sup'
|
902
|
+
sup.attributes['id'] = "#{get_setting(:doc_prefix)}fnref:#{num}"
|
903
|
+
a = Element.new 'a'
|
904
|
+
a << Text.new(num.to_s)
|
905
|
+
a.attributes['href'] = "\##{get_setting(:doc_prefix)}fn:#{num}"
|
906
|
+
a.attributes['rel'] = 'footnote'
|
907
|
+
sup << a
|
908
|
+
|
909
|
+
sup
|
910
|
+
end
|
907
911
|
|
908
912
|
## Definition lists ###
|
909
|
-
|
910
|
-
|
911
|
-
|
912
|
-
|
913
|
-
|
914
|
-
|
915
|
-
|
916
|
-
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
922
|
-
|
923
|
-
|
924
|
-
|
925
|
-
|
926
|
-
|
927
|
-
|
928
|
-
|
929
|
-
|
930
|
-
|
931
|
-
|
932
|
-
|
933
|
-
|
934
|
-
|
935
|
-
|
936
|
-
|
937
|
-
|
938
|
-
|
939
|
-
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
|
944
|
-
|
945
|
-
|
946
|
-
|
947
|
-
|
948
|
-
|
949
|
-
|
950
|
-
|
951
|
-
|
952
|
-
|
953
|
-
|
954
|
-
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
961
|
-
|
962
|
-
|
963
|
-
|
964
|
-
|
965
|
-
|
966
|
-
|
967
|
-
|
968
|
-
|
969
|
-
|
970
|
-
|
971
|
-
|
972
|
-
|
913
|
+
def to_html_definition_list() add_ws wrap_as_element('dl') end
|
914
|
+
def to_html_definition() children_to_html end
|
915
|
+
def to_html_definition_term() add_ws wrap_as_element('dt') end
|
916
|
+
def to_html_definition_data() add_ws wrap_as_element('dd') end
|
917
|
+
|
918
|
+
# FIXME: Ugly code
|
919
|
+
def to_html_table
|
920
|
+
align = self.align
|
921
|
+
num_columns = align.size
|
922
|
+
|
923
|
+
head = @children.slice(0, num_columns)
|
924
|
+
rows = []
|
925
|
+
i = num_columns
|
926
|
+
while i<@children.size
|
927
|
+
rows << @children.slice(i, num_columns)
|
928
|
+
i += num_columns
|
929
|
+
end
|
930
|
+
|
931
|
+
table = create_html_element 'table'
|
932
|
+
thead = Element.new 'thead'
|
933
|
+
tr = Element.new 'tr'
|
934
|
+
array_to_html(head).each do |x| tr<<x end
|
935
|
+
thead << tr
|
936
|
+
table << thead
|
937
|
+
|
938
|
+
tbody = Element.new 'tbody'
|
939
|
+
rows.each do |row|
|
940
|
+
tr = Element.new 'tr'
|
941
|
+
array_to_html(row).each_with_index do |x,i|
|
942
|
+
x.attributes['style'] ="text-align: #{align[i].to_s};"
|
943
|
+
tr<<x
|
944
|
+
end
|
945
|
+
|
946
|
+
tbody << tr << Text.new("\n")
|
947
|
+
end
|
948
|
+
table << tbody
|
949
|
+
table
|
950
|
+
end
|
951
|
+
|
952
|
+
def to_html_head_cell; wrap_as_element('th') end
|
953
|
+
def to_html_cell
|
954
|
+
if @attributes[:scope]
|
955
|
+
wrap_as_element('th', [:scope])
|
956
|
+
else
|
957
|
+
wrap_as_element('td')
|
958
|
+
end
|
959
|
+
end
|
960
|
+
|
961
|
+
def to_html_entity
|
962
|
+
MaRuKu::Out::Latex.need_entity_table
|
963
|
+
|
964
|
+
entity_name = self.entity_name
|
965
|
+
|
966
|
+
if (e = MaRuKu::Out::Latex::ENTITY_TABLE[entity_name]) && e.html_num
|
967
|
+
entity_name = e.html_num
|
968
|
+
end
|
969
|
+
|
970
|
+
# Fix for Internet Explorer
|
971
|
+
if entity_name == 'apos'
|
972
|
+
entity_name = 39
|
973
|
+
end
|
974
|
+
|
975
|
+
|
976
|
+
if entity_name.kind_of? Fixnum
|
973
977
|
# Entity.new(entity_name)
|
974
|
-
|
975
|
-
|
976
|
-
|
977
|
-
|
978
|
-
|
979
|
-
|
980
|
-
|
981
|
-
|
982
|
-
|
983
|
-
|
984
|
-
|
985
|
-
|
986
|
-
|
987
|
-
|
988
|
-
|
989
|
-
|
990
|
-
|
991
|
-
|
992
|
-
|
993
|
-
|
994
|
-
|
995
|
-
|
996
|
-
|
997
|
-
|
998
|
-
|
999
|
-
|
1000
|
-
|
1001
|
-
|
1002
|
-
|
1003
|
-
|
1004
|
-
|
1005
|
-
|
1006
|
-
|
1007
|
-
|
1008
|
-
|
1009
|
-
|
1010
|
-
|
1011
|
-
|
1012
|
-
|
1013
|
-
|
1014
|
-
|
1015
|
-
|
1016
|
-
|
1017
|
-
|
1018
|
-
|
1019
|
-
|
1020
|
-
|
1021
|
-
|
1022
|
-
|
1023
|
-
|
1024
|
-
|
1025
|
-
|
1026
|
-
|
1027
|
-
|
1028
|
-
|
1029
|
-
|
1030
|
-
|
1031
|
-
|
1032
|
-
|
1033
|
-
|
1034
|
-
|
1035
|
-
|
1036
|
-
e << h
|
1037
|
-
end
|
978
|
+
Text.new('&#%d;' % [entity_name], false, nil, true)
|
979
|
+
else
|
980
|
+
Text.new('&%s;' % [entity_name], false, nil, true)
|
981
|
+
end
|
982
|
+
end
|
983
|
+
|
984
|
+
def to_html_xml_instr
|
985
|
+
target = self.target || ''
|
986
|
+
code = self.code || ''
|
987
|
+
REXML::Instruction.new(target, code)
|
988
|
+
end
|
989
|
+
|
990
|
+
# Convert each child to html
|
991
|
+
def children_to_html
|
992
|
+
array_to_html(@children)
|
993
|
+
end
|
994
|
+
|
995
|
+
def array_to_html(array)
|
996
|
+
#array.each {|a| puts a.inspect }
|
997
|
+
res = []
|
998
|
+
res << (e = [])
|
999
|
+
first_header = true
|
1000
|
+
array.each do |c|
|
1001
|
+
method = c.kind_of?(MDElement) ? "to_html_#{c.node_type}" : "to_html"
|
1002
|
+
if not c.respond_to?(method)
|
1003
|
+
#raise "Object does not answer to #{method}: #{c.class} #{c.inspect}"
|
1004
|
+
next
|
1005
|
+
end
|
1006
|
+
|
1007
|
+
Thread.current['maruku.line_no'] = c.line_no if c.respond_to? :line_no
|
1008
|
+
h = c.send(method)
|
1009
|
+
if h.nil?
|
1010
|
+
raise "Nil html created by method #{method}:\n#{h.inspect}\n"+
|
1011
|
+
" for object #{c.inspect[0,300]}"
|
1012
|
+
end
|
1013
|
+
|
1014
|
+
if method == 'to_html_header'
|
1015
|
+
if res.length > 1
|
1016
|
+
res.pop
|
1017
|
+
s = res[-1][-1]
|
1018
|
+
e.each do |el| s << el end
|
1019
|
+
e = res[-1]
|
1020
|
+
end
|
1021
|
+
e << (s = Element.new('section'))
|
1022
|
+
#puts c.inspect
|
1023
|
+
s.attributes['line_no'] = c.line_no
|
1024
|
+
s.attributes['level'] = c.level
|
1025
|
+
|
1026
|
+
toc = Thread.current['maruku.toc'] ||= []
|
1027
|
+
li = c.level - 1
|
1028
|
+
toc[li] = toc[li] ? (toc[li] + 1) : 1
|
1029
|
+
s.attributes['toc'] = toc.map {|l| l ? l : 1 }.join('.')
|
1030
|
+
|
1031
|
+
res << (e = [])
|
1032
|
+
|
1033
|
+
end
|
1034
|
+
|
1035
|
+
if h.kind_of?Array
|
1036
|
+
e.concat(h) #h.each do |hh| e << hh end
|
1037
|
+
else
|
1038
|
+
e << h
|
1039
|
+
end
|
1038
1040
|
# puts "LOOP ENDN res: #{res.inspect} -- e: #{e.inspect}"
|
1039
|
-
|
1041
|
+
end
|
1040
1042
|
# puts "after: #{res.inspect} e: #{e.inspect}"
|
1041
1043
|
if res.length > 1
|
1042
1044
|
res.pop
|
@@ -1045,11 +1047,11 @@ If true, raw HTML is discarded from the output.
|
|
1045
1047
|
e = res[-1]
|
1046
1048
|
end
|
1047
1049
|
#puts e.inspect
|
1048
|
-
|
1049
|
-
|
1050
|
+
e
|
1051
|
+
end
|
1050
1052
|
|
1051
|
-
|
1052
|
-
|
1053
|
+
def to_html_ref_definition; [] end
|
1054
|
+
def to_latex_ref_definition; [] end
|
1053
1055
|
|
1054
1056
|
end # HTML
|
1055
1057
|
end # out
|