maruku 0.5.3 → 0.5.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.
Files changed (51) hide show
  1. data/bin/maruku +14 -6
  2. data/bin/marutest +19 -10
  3. data/docs/changelog.html +49 -8
  4. data/docs/changelog.md +26 -1
  5. data/docs/entity_test.html +1 -1
  6. data/docs/exd.html +43 -24
  7. data/docs/index.html +4 -6
  8. data/docs/markdown_syntax.html +81 -170
  9. data/docs/maruku.html +4 -6
  10. data/docs/maruku.md +1 -1
  11. data/docs/proposal.html +21 -41
  12. data/lib/maruku.rb +5 -0
  13. data/lib/maruku/attributes.rb +3 -2
  14. data/lib/maruku/defaults.rb +3 -1
  15. data/lib/maruku/ext/math.rb +30 -0
  16. data/lib/maruku/ext/math/elements.rb +3 -2
  17. data/lib/maruku/ext/math/parsing.rb +81 -58
  18. data/lib/maruku/ext/math/to_html.rb +5 -5
  19. data/lib/maruku/helpers.rb +2 -0
  20. data/lib/maruku/input/charsource.rb +1 -1
  21. data/lib/maruku/input/extensions.rb +6 -5
  22. data/lib/maruku/input/parse_block.rb +7 -8
  23. data/lib/maruku/input/parse_doc.rb +1 -1
  24. data/lib/maruku/input/parse_span_better.rb +4 -4
  25. data/lib/maruku/input_textile2/t2_parser.rb +163 -0
  26. data/lib/maruku/maruku.rb +1 -1
  27. data/lib/maruku/output/s5/fancy.rb +756 -0
  28. data/lib/maruku/output/s5/to_s5.rb +104 -0
  29. data/lib/maruku/output/to_html.rb +103 -49
  30. data/lib/maruku/string_utils.rb +1 -1
  31. data/lib/maruku/textile2.rb +1 -0
  32. data/lib/maruku/version.rb +3 -1
  33. data/maruku_gem.rb +33 -0
  34. data/tests/s5/s5profiling.md +48 -0
  35. data/tests/unittest/blanks_in_code.md +6 -12
  36. data/tests/unittest/code3.md +3 -5
  37. data/tests/unittest/data_loss.md +53 -0
  38. data/tests/unittest/email.md +2 -2
  39. data/tests/unittest/entities.md +3 -5
  40. data/tests/unittest/footnotes.md +5 -5
  41. data/tests/unittest/ie.md +1 -1
  42. data/tests/unittest/images.md +2 -2
  43. data/tests/unittest/inline_html.md +6 -10
  44. data/tests/unittest/links.md +1 -1
  45. data/tests/unittest/list2.md +5 -5
  46. data/tests/unittest/lists.md +13 -13
  47. data/tests/unittest/lists_ol.md +13 -13
  48. data/tests/unittest/math/math2.md +84 -0
  49. data/tests/unittest/math/notmath.md +48 -0
  50. data/tests/unittest/syntax_hl.md +3 -5
  51. metadata +11 -2
@@ -0,0 +1,104 @@
1
+ # This module groups all functions related to HTML export.
2
+ module MaRuKu
3
+
4
+ class MDDocument
5
+
6
+ # Render as an HTML fragment (no head, just the content of BODY). (returns a string)
7
+ def to_s5(context={})
8
+ indent = context[:indent] || -1
9
+ ie_hack = context[:ie_hack] ||true
10
+
11
+ doc = Document.new(nil,{:respect_whitespace =>:all})
12
+ html = Element.new('html', doc)
13
+ html.add_namespace('http://www.w3.org/1999/xhtml')
14
+ html.add_namespace('svg', "http://www.w3.org/2000/svg" )
15
+
16
+ head = Element.new('head', html)
17
+ me = Element.new 'meta', head
18
+ me.attributes['http-equiv'] = 'Content-type'
19
+ me.attributes['content'] = 'text/html;charset=utf-8'
20
+
21
+
22
+ # Create title element
23
+ doc_title = self.attributes[:title] || self.attributes[:subject] || ""
24
+ title = Element.new 'title', head
25
+ title << Text.new(doc_title)
26
+
27
+
28
+ body = Element.new('body', html)
29
+
30
+ slide_header = self.attributes[:slide_header]
31
+ slide_footer = self.attributes[:slide_footer]
32
+ slide_topleft = self.attributes[:slide_topleft]
33
+ slide_topright = self.attributes[:slide_topright]
34
+ slide_bottomleft = self.attributes[:slide_bottomleft]
35
+ slide_bottomright = self.attributes[:slide_bottomright]
36
+
37
+ dummy_layout_slide =
38
+ "<div class='layout'>
39
+ <div id='controls'><!-- DO NOT EDIT --></div>
40
+ <div id='currentSlide'><!-- DO NOT EDIT --></div>
41
+ <div id='header'> #{slide_header}</div>
42
+ <div id='footer'> #{slide_footer}</div>
43
+ <div class='topleft'> #{slide_topleft}</div>
44
+ <div class='topright'> #{slide_topright}</div>
45
+ <div class='bottomleft'> #{slide_bottomleft}</div>
46
+ <div class='bottomright'> #{slide_bottomright}</div>
47
+ </div>"
48
+ body.add_element Document.new(dummy_layout_slide, {:respect_whitespace =>:all}).root
49
+
50
+ presentation = Element.new 'div', body
51
+ presentation.attributes['class'] = 'presentation'
52
+
53
+ first_slide="
54
+ <div class='slide'>
55
+ <h1> #{self.attributes[:title]}</h1>
56
+ <h2> #{self.attributes[:subtitle]}</h2>
57
+ <h3> #{self.attributes[:author]}</h3>
58
+ <h4> #{self.attributes[:company]}</h4>
59
+ </div>
60
+ "
61
+ presentation.add_element Document.new(first_slide).root
62
+
63
+ slide_num = 0
64
+ self.toc.section_children.each do |slide|
65
+ slide_num += 1
66
+ @doc.attributes[:doc_prefix] = "s#{slide_num}"
67
+
68
+ puts "Slide #{slide_num}: " + slide.header_element.to_s
69
+ div = Element.new('div', presentation)
70
+ div.attributes['class'] = 'slide'
71
+
72
+ h1 = Element.new 'h1', div
73
+ slide.header_element.children_to_html.each do |e| h1 << e; end
74
+
75
+
76
+ array_to_html(slide.immediate_children).each do |e| div << e end
77
+
78
+ # render footnotes
79
+ if @doc.footnotes_order.size > 0
80
+ div << render_footnotes
81
+ @doc.footnotes_order = []
82
+ end
83
+ end
84
+
85
+
86
+ doc2 = Document.new("<div>"+S5_external+"</div>",{:respect_whitespace =>:all})
87
+ doc2.root.children.each{ |child| head << child }
88
+
89
+
90
+ add_css_to(head)
91
+
92
+ xml = ""
93
+
94
+ # REXML Bug? if indent!=-1 whitespace is not respected for 'pre' elements
95
+ # containing code.
96
+ html.write(xml,indent,transitive=true,ie_hack);
97
+
98
+ Xhtml10strict + xml
99
+ end
100
+
101
+ end
102
+
103
+
104
+ end
@@ -74,28 +74,30 @@ module MaRuKu; module Out; module HTML
74
74
  # REXML Bug? if indent!=-1 whitespace is not respected for 'pre' elements
75
75
  # containing code.
76
76
  doc.write(xml,indent,transitive=true,ie_hack);
77
+
78
+ Xhtml11_mathml2_svg11 + xml
79
+ end
80
+
77
81
 
78
- xhtml10strict = "
82
+ Xhtml10strict = "
79
83
  <?xml version='1.0' encoding='utf-8'?>
80
84
  <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN'
81
85
  'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>\n"
82
86
 
83
- xhtml11strict_mathml2 = '<?xml version="1.0" encoding="utf-8"?>
87
+ Xhtml11strict_mathml2 = '<?xml version="1.0" encoding="utf-8"?>
84
88
  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN"
85
89
  "http://www.w3.org/TR/MathML2/dtd/xhtml-math11-f.dtd" [
86
90
  <!ENTITY mathml "http://www.w3.org/1998/Math/MathML">
87
91
  ]>
88
92
  '
89
93
 
90
- xhtml11_mathml2_svg11 =
94
+ Xhtml11_mathml2_svg11 =
91
95
  '<?xml version="1.0" encoding="utf-8"?>
92
96
  <!DOCTYPE html PUBLIC
93
97
  "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN"
94
98
  "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">
95
99
  '
96
-
97
- xhtml11_mathml2_svg11 + xml
98
- end
100
+
99
101
 
100
102
  def xml_newline() Text.new("\n") end
101
103
 
@@ -123,6 +125,14 @@ and
123
125
  In both cases, the title is set to "my document".
124
126
  =end
125
127
 
128
+ =begin maruku_doc
129
+ Attribute: doc_prefix
130
+ Scope: document
131
+
132
+ String to disambiguate footnote links.
133
+ =end
134
+
135
+
126
136
  =begin maruku_doc
127
137
  Attribute: subject
128
138
  Scope: document
@@ -170,20 +180,9 @@ Example:
170
180
  doc_title = self.attributes[:title] || self.attributes[:subject] || ""
171
181
  title = Element.new 'title', head
172
182
  title << Text.new(doc_title)
173
-
183
+
184
+ add_css_to(head)
174
185
 
175
-
176
- if css_list = self.attributes[:css]
177
- css_list.split.each do |css|
178
- # <link type="text/css" rel="stylesheet" href="..." />
179
- link = Element.new 'link'
180
- link.attributes['type'] = 'text/css'
181
- link.attributes['rel'] = 'stylesheet'
182
- link.attributes['href'] = css
183
- head << link
184
- head << xml_newline
185
- end
186
- end
187
186
 
188
187
  root << xml_newline
189
188
 
@@ -208,6 +207,20 @@ Example:
208
207
 
209
208
  doc
210
209
  end
210
+
211
+ def add_css_to(head)
212
+ if css_list = self.attributes[:css]
213
+ css_list.split.each do |css|
214
+ # <link type="text/css" rel="stylesheet" href="..." />
215
+ link = Element.new 'link'
216
+ link.attributes['type'] = 'text/css'
217
+ link.attributes['rel'] = 'stylesheet'
218
+ link.attributes['href'] = css
219
+ head << link
220
+ head << xml_newline
221
+ end
222
+ end
223
+ end
211
224
 
212
225
  # returns "st","nd","rd" or "th" as appropriate
213
226
  def day_suffix(day)
@@ -247,7 +260,7 @@ Example:
247
260
  div
248
261
  end
249
262
 
250
- def render_footnotes
263
+ def render_footnotes()
251
264
  div = Element.new 'div'
252
265
  div.attributes['class'] = 'footnotes'
253
266
  div << Element.new('hr')
@@ -256,10 +269,10 @@ Example:
256
269
  f = self.footnotes[fid]
257
270
  if f
258
271
  li = f.wrap_as_element('li')
259
- li.attributes['id'] = "fn:#{num}"
272
+ li.attributes['id'] = "#{get_setting(:doc_prefix)}fn:#{num}"
260
273
 
261
274
  a = Element.new 'a'
262
- a.attributes['href'] = "#fnref:#{num}"
275
+ a.attributes['href'] = "\##{get_setting(:doc_prefix)}fnref:#{num}"
263
276
  a.attributes['rev'] = 'footnote'
264
277
  a<< Text.new('&#8617;', true, nil, true)
265
278
  li.insert_after(li.children.last, a)
@@ -316,11 +329,55 @@ Output: HTML
316
329
  It is copied as a standard HTML attribute.
317
330
  =end
318
331
 
319
- StandardAttributes = [:id, :style, :class]
332
+
333
+
334
+
335
+
336
+ HTML4Attributes = {}
337
+
338
+ coreattrs = [:id, :class, :style, :title]
339
+ i18n = [:lang, 'xml:lang'.to_sym]
340
+ events = [
341
+ :onclick, :ondblclick, :onmousedown, :onmouseup, :onmouseover,
342
+ :onmousemove, :onmouseout,
343
+ :onkeypress, :onkeydown, :onkeyup]
344
+ attrs = coreattrs + i18n + events
345
+ cellhalign = [:align, :char, :charoff]
346
+ cellvalign = [:valign]
347
+ [
348
+ ['body', attrs + [:onload, :onunload]],
349
+ ['address', attrs],
350
+ ['div', attrs],
351
+ ['a', attrs+[:charset, :type, :name, :rel, :rev, :accesskey, :shape, :coords, :tabindex,
352
+ :onfocus,:onblur]],
353
+ ['img', attrs + [:longdesc, :name, :height, :width, :alt] ],
354
+ ['p', attrs],
355
+ [['h1','h2','h3','h4','h5','h6'], attrs],
356
+ [['pre'], attrs],
357
+ [['q', 'blockquote'], attrs+[:cite]],
358
+ [['ins','del'], attrs+[:cite,:datetime]],
359
+ [['ol','ul','li'], attrs],
360
+ ['table',attrs+[:summary, :width, :frame, :rules, :border, :cellspacing, :cellpadding]],
361
+ ['caption',attrs],
362
+ [['colgroup','col'],attrs+[:span, :width]+cellhalign+cellvalign],
363
+ [['thead','tbody','tfoot'], attrs+cellhalign+cellvalign],
364
+ [['td','td','th'], attrs+[:abbr, :axis, :headers, :scope, :rowspan, :colspan, :cellvalign, :cellhalign]],
365
+
366
+ # altri
367
+ [['em','code','strong','hr','span','dl','dd','dt'], attrs]
368
+ ].each do |el, a| [*el].each do |e| HTML4Attributes[e] = a end end
369
+
370
+
320
371
  def create_html_element(name, attributes_to_copy=[])
321
372
  m = Element.new name
322
- (StandardAttributes+attributes_to_copy).each do |a|
323
- if v = @attributes[a] then m.attributes[a.to_s] = v.to_s end
373
+ if atts = HTML4Attributes[name] then
374
+ atts.each do |att|
375
+ if v = @attributes[att] then
376
+ m.attributes[att.to_s] = v.to_s
377
+ end
378
+ end
379
+ else
380
+ # puts "not atts for #{name.inspect}"
324
381
  end
325
382
  m
326
383
  end
@@ -432,6 +489,7 @@ and
432
489
 
433
490
  =end
434
491
 
492
+ $syntax_loaded = false
435
493
  def to_html_code;
436
494
  source = self.raw_code
437
495
 
@@ -547,7 +605,7 @@ of the form `#ff00ff`.
547
605
 
548
606
  color = get_setting(:code_background_color)
549
607
  if color != Globals[:code_background_color]
550
- pre.attributes['style'] = "background-color: #{color};"
608
+ pre.attributes['style'] = "background-color: #{color};"+(pre.attributes['style']||"")
551
609
  end
552
610
 
553
611
  pre
@@ -565,17 +623,17 @@ of the form `#ff00ff`.
565
623
  def add_class_to_link(a)
566
624
  return # not ready yet
567
625
 
568
- url = a.attributes['href']
569
- return if not url
570
-
571
- if url =~ /^#/
572
- add_class_to(a, 'maruku-link-samedoc')
573
- elsif url =~ /^http:/
574
- add_class_to(a, 'maruku-link-external')
575
- else
576
- add_class_to(a, 'maruku-link-local')
577
- end
578
-
626
+ # url = a.attributes['href']
627
+ # return if not url
628
+ #
629
+ # if url =~ /^#/
630
+ # add_class_to(a, 'maruku-link-samedoc')
631
+ # elsif url =~ /^http:/
632
+ # add_class_to(a, 'maruku-link-external')
633
+ # else
634
+ # add_class_to(a, 'maruku-link-local')
635
+ # end
636
+ #
579
637
  # puts a.attributes['class']
580
638
  end
581
639
 
@@ -659,10 +717,7 @@ of the form `#ff00ff`.
659
717
  url = ref[:url]
660
718
  title = ref[:title]
661
719
  a.attributes['src'] = url.to_s
662
- a.attributes['alt'] = title.to_s
663
- [:title, :class, :style].each do |s|
664
- a.attributes[s.to_s] = ref[s] if ref[s]
665
- end
720
+ a.attributes['alt'] = title.to_s if not a.attributes['alt']
666
721
  else
667
722
  maruku_error"Could not find id = #{id.inspect} for\n #{self.inspect}"
668
723
  tell_user "Could not create image with ref_id = #{id.inspect};"+
@@ -674,15 +729,15 @@ of the form `#ff00ff`.
674
729
 
675
730
  def to_html_im_image
676
731
  if not url = self.url
677
- maruku_error"Image with no url: #{self.inspect}"
732
+ maruku_error "Image with no url: #{self.inspect}"
678
733
  tell_user "Could not create image with ref_id = #{id.inspect};"+
679
- +" Using SPAN element as replacement."
734
+ " Using SPAN element as replacement."
680
735
  return wrap_as_element('span')
681
736
  end
682
737
  title = self.title
683
738
  a = create_html_element 'img'
684
- a.attributes['src'] = url
685
- a.attributes['alt'] = title.to_s
739
+ a.attributes['src'] = url.to_s
740
+ a.attributes['alt'] = title.to_s if not a.attributes['alt']
686
741
  return a
687
742
  end
688
743
 
@@ -733,10 +788,10 @@ of the form `#ff00ff`.
733
788
  num = order.size;
734
789
 
735
790
  sup = Element.new 'sup'
736
- sup.attributes['id'] = "fnref:#{num}"
791
+ sup.attributes['id'] = "#{get_setting(:doc_prefix)}fnref:#{num}"
737
792
  a = Element.new 'a'
738
793
  a << Text.new(num.to_s)
739
- a.attributes['href'] = "\#fn:#{num}"
794
+ a.attributes['href'] = "\##{get_setting(:doc_prefix)}fn:#{num}"
740
795
  a.attributes['rel'] = 'footnote'
741
796
  sup << a
742
797
 
@@ -762,8 +817,7 @@ of the form `#ff00ff`.
762
817
  i += num_columns
763
818
  end
764
819
 
765
- table = create_html_element 'table',
766
- [:summary, :width, :frame, :rules, :border, :cellspacing, :cellpadding]
820
+ table = create_html_element 'table'
767
821
  thead = Element.new 'thead'
768
822
  tr = Element.new 'tr'
769
823
  array_to_html(head).each do |x| tr<<x end
@@ -166,7 +166,7 @@ module MaRuKu; module Strings
166
166
  end
167
167
  i+=1
168
168
  end
169
- s[i, s.size-1]
169
+ s[i, s.size]
170
170
  end
171
171
 
172
172
  def dbg_describe_ary(a, prefix='')
@@ -0,0 +1 @@
1
+ require 'maruku/input_textile2/t2_parser'
@@ -19,7 +19,7 @@
19
19
  #++
20
20
 
21
21
  module MaRuKu
22
- Version = '0.5.3'
22
+ Version = '0.5.4'
23
23
 
24
24
  MarukuURL = 'http://maruku.rubyforge.org/'
25
25
 
@@ -27,6 +27,8 @@ module MaRuKu
27
27
  #
28
28
  # Note: it is not guaranteed that if it's false
29
29
  # then no special features will be used.
30
+ #
31
+ # So please, ignore it for now.
30
32
  def markdown_extra?
31
33
  true
32
34
  end
data/maruku_gem.rb ADDED
@@ -0,0 +1,33 @@
1
+
2
+ require 'lib/maruku/version'
3
+
4
+ $spec = Gem::Specification.new do |s|
5
+ s.name = 'maruku'
6
+ s.version = MaRuKu::Version
7
+ s.summary = "Maruku is a Markdown-superset interpreter written in Ruby."
8
+ s.description = %{Maruku is a Markdown interpreter in Ruby.
9
+ It features native export to HTML and PDF (via Latex). The
10
+ output is really beautiful!
11
+ }
12
+ s.files = Dir['lib/**/*.rb'] + Dir['lib/*.rb'] +
13
+ Dir['docs/*.md'] + Dir['docs/*.html'] +
14
+ Dir['tests/**/*.md'] +
15
+ Dir['bin/*'] + ['Rakefile', 'maruku_gem.rb']
16
+
17
+ s.bindir = 'bin'
18
+ s.executables = ['maruku','marutex']
19
+
20
+ s.require_path = 'lib'
21
+ s.autorequire = 'maruku'
22
+
23
+ s.add_dependency('syntax', '>= 1.0.0')
24
+
25
+ s.author = "Andrea Censi"
26
+ s.email = "andrea@rubyforge.org"
27
+ s.homepage = "http://maruku.rubyforge.org"
28
+ end
29
+
30
+ # s.has_rdoc = true
31
+ # s.extra_rdoc_files = Dir['[A-Z]*']
32
+ # s.rdoc_options << '--title' << 'Builder -- Easy XML Building'
33
+
@@ -0,0 +1,48 @@
1
+ subtitle: news
2
+ author: Andrea Censi
3
+ company: Università La Sapienza
4
+ css: math.css
5
+
6
+ RDK news
7
+ ========
8
+
9
+ Profiling
10
+ ---------------------------------------------------------
11
+
12
+ 1. `ragent2` writes profiling information on a pipe.
13
+ 2. `rdk-profiler` reads the pipe and creates graphs in HTML+Javascript.
14
+ 3. The user reads the data on a browser.
15
+
16
+ Things logged
17
+ -----------------------------------------------------------
18
+
19
+ 17288397 1730000 0 16384 END pantiltClient
20
+ 17288439 1730000 0 16384 START pantiltClient
21
+ 17288564 1730000 0 16384 LOCK pantiltClient:tilt
22
+ 17288622 1730000 0 16384 UNLOCK pantiltClient:tilt
23
+
24
+ * `START/END`: how much does it take to ...?
25
+
26
+ Footnotes 1/2
27
+ ---------------------------------------------------
28
+
29
+ You can use footnotes [^1]
30
+
31
+ [^1]: And they work.
32
+
33
+ Footnotes 2/2
34
+ ---------------------------------------------------
35
+
36
+ Each footnote on its page [^2]
37
+
38
+ [^2]: alone.
39
+
40
+ And now: math!
41
+ ---------------------------------------------------
42
+
43
+ Consider, for example the group $\int_{a}^{b} x^{a} db$ of
44
+
45
+ \[ \alpha_{\beta}^{\gamma} \]
46
+
47
+ Unfortunately S5 and MathML are mutually exclusive.
48
+ See <http://meyerweb.com/eric/thoughts/category/tech/s5/> for explanations.