maruku 0.5.0 → 0.5.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.
@@ -42,14 +42,6 @@ Same thing as `html_math_engine`, only for PNG output.
42
42
  module MaRuKu; module Out; module HTML
43
43
 
44
44
 
45
- def add_class_to(el, cl)
46
- el.attributes['class'] =
47
- if already = el.attributes['class']
48
- already + " " + cl
49
- else
50
- cl
51
- end
52
- end
53
45
 
54
46
  # Creates an xml Mathml document of self.math
55
47
  def render_mathml(kind, tex)
@@ -205,8 +205,9 @@ class CharSourceStrscan
205
205
  include SpanLevelParser
206
206
  include MaRuKu::Strings
207
207
 
208
- def initialize(s)
208
+ def initialize(s, parent=nil)
209
209
  @s = StringScanner.new(s)
210
+ @parent = parent
210
211
  end
211
212
 
212
213
  # Return current char as a FixNum (or nil).
@@ -273,9 +274,9 @@ end
273
274
 
274
275
 
275
276
  class CharSourceDebug
276
- def initialize(s)
277
- @a = CharSourceManual.new(s)
278
- @b = CharSourceStrscan.new(s)
277
+ def initialize(s, parent)
278
+ @a = CharSourceManual.new(s, parent)
279
+ @b = CharSourceStrscan.new(s, parent)
279
280
  end
280
281
 
281
282
  def method_missing(methodname, *args)
@@ -127,6 +127,7 @@ Disabled by default because of security concerns.
127
127
  result[:unresolved_references] << " #{v}"
128
128
  end
129
129
 
130
+ # $stderr.puts "Unresolved reference #{v.inspect} (avail: #{self.ald.keys.inspect})"
130
131
  result[v.to_sym] = true
131
132
  end
132
133
  else
@@ -278,10 +278,10 @@ module MaRuKu; module In; module Markdown; module SpanLevelParser
278
278
  end
279
279
 
280
280
  def extension_meta(src, con, break_on_chars)
281
- if m = src.read_regexp(/(\w)+\:/)
281
+ if m = src.read_regexp(/([^:]+):/)
282
282
  name = m[1]
283
- content = m[2]
284
283
  al = read_attribute_list(src, con, break_on_chars)
284
+ # puts "#{name}=#{al.inspect}"
285
285
  self.doc.ald[name] = al
286
286
  con.push md_ald(name, al)
287
287
  else
@@ -624,6 +624,11 @@ module MaRuKu; module In; module Markdown; module SpanLevelParser
624
624
  con.push_element md_im_image(alt_text, url, title)
625
625
  when ?[ # link ref
626
626
  ref_id = read_ref_id(src,con)
627
+ if ref_id.size == 0
628
+ ref_id = alt_text.to_s.downcase.gsub(' ','_')
629
+ else
630
+ ref_id = ref_id.downcase
631
+ end
627
632
  con.push_element md_image(alt_text, ref_id)
628
633
  else # no stuff
629
634
  con.push_elements children
@@ -394,7 +394,9 @@ by Maruku, to have the same results in both HTML and LaTeX.
394
394
  def source2html(source)
395
395
  source = source.gsub(/&/,'&amp;')
396
396
  source = Text.normalize(source)
397
- Text.new(source, true, nil, false )
397
+ source = source.gsub(/\&apos;/,'&#39;') # IE bug
398
+ source = source.gsub(/'/,'&#39;') # IE bug
399
+ Text.new(source, true, nil, true )
398
400
  end
399
401
 
400
402
  =begin maruku_doc
@@ -437,7 +439,6 @@ and
437
439
 
438
440
  lang = 'xml' if lang=='html'
439
441
 
440
-
441
442
  use_syntax = get_setting :html_use_syntax
442
443
 
443
444
  element =
@@ -455,9 +456,17 @@ and
455
456
  source = source.gsub(/\n*\Z/,'')
456
457
 
457
458
  html = convertor.convert( source )
458
-
459
- pre = Document.new(html, {:respect_whitespace =>:all}).root
460
- pre.attributes['class'] = lang
459
+ html = html.gsub(/\&apos;/,'&#39;') # IE bug
460
+ html = html.gsub(/'/,'&#39;') # IE bug
461
+ # html = html.gsub(/&/,'&amp;')
462
+
463
+ code = Document.new(html, {:respect_whitespace =>:all}).root
464
+ code.name = 'code'
465
+ code.attributes['class'] = lang
466
+ code.attributes['lang'] = lang
467
+
468
+ pre = Element.new 'pre'
469
+ pre << code
461
470
  pre
462
471
  rescue LoadError => e
463
472
  maruku_error "Could not load package 'syntax'.\n"+
@@ -480,7 +489,7 @@ and
480
489
  if color != Globals[:code_background_color]
481
490
  element.attributes['style'] = "background-color: #{color};"
482
491
  end
483
- element
492
+ add_ws element
484
493
  end
485
494
 
486
495
  =begin maruku_doc
@@ -523,6 +532,10 @@ of the form `#ff00ff`.
523
532
 
524
533
  text = Text.new(s, respect_ws=true, parent=nil, raw=true )
525
534
 
535
+ if lang = self.attributes[:lang]
536
+ code.attributes['lang'] = lang
537
+ code.attributes['class'] = lang
538
+ end
526
539
  code << text
527
540
  pre
528
541
  end
@@ -540,12 +553,40 @@ of the form `#ff00ff`.
540
553
  pre
541
554
  end
542
555
 
556
+ def add_class_to(el, cl)
557
+ el.attributes['class'] =
558
+ if already = el.attributes['class']
559
+ already + " " + cl
560
+ else
561
+ cl
562
+ end
563
+ end
564
+
565
+ def add_class_to_link(a)
566
+ return # not ready yet
567
+
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
+
579
+ # puts a.attributes['class']
580
+ end
581
+
582
+
543
583
  def to_html_immediate_link
544
584
  a = create_html_element 'a'
545
585
  url = self.url
546
586
  text = url.gsub(/^mailto:/,'') # don't show mailto
547
587
  a << Text.new(text)
548
588
  a.attributes['href'] = url
589
+ add_class_to_link(a)
549
590
  a
550
591
  end
551
592
 
@@ -564,6 +605,8 @@ of the form `#ff00ff`.
564
605
  tell_user "Not creating a link for ref_id = #{id.inspect}."
565
606
  return wrap_as_element('span')
566
607
  end
608
+
609
+ # add_class_to_link(a)
567
610
  return a
568
611
  end
569
612
 
@@ -623,7 +666,7 @@ of the form `#ff00ff`.
623
666
  else
624
667
  maruku_error"Could not find id = #{id.inspect} for\n #{self.inspect}"
625
668
  tell_user "Could not create image with ref_id = #{id.inspect};"+
626
- +" Using SPAN element as replacement."
669
+ " Using SPAN element as replacement."
627
670
  return wrap_as_element('span')
628
671
  end
629
672
  return a
@@ -506,11 +506,15 @@ Otherwise, a standard `verbatim` environment is used.
506
506
  id = self.ref_id
507
507
  ref = @doc.refs[id]
508
508
  if not ref
509
- $stderr.puts "Could not find id = '#{id}'"
509
+ maruku_error "Could not find ref #{id.inspect} for image.\n"+
510
+ "Available are: #{@docs.refs.keys.inspect}"
511
+ # $stderr.puts "Could not find id = '#{id}'"
510
512
  ""
511
513
  else
512
514
  url = ref[:url]
513
- "{\\bf Images not supported yet (#{latex_escape(url)})}"
515
+ $stderr.puts "Images not supported yet (#{url})"
516
+ # "{\\bf Images not supported yet (#{latex_escape(url)})}"
517
+ ""
514
518
  end
515
519
 
516
520
  end
@@ -67,8 +67,8 @@ module MaRuKu; module Out; module Latex
67
67
 
68
68
  # create hash @@entity_to_latex
69
69
  def Latex.init_entity_table
70
- $stderr.write "Creating entity table.."
71
- $stderr.flush
70
+ # $stderr.write "Creating entity table.."
71
+ # $stderr.flush
72
72
  doc = Document.new XML_TABLE
73
73
  doc.elements.each("//char") do |c|
74
74
  num = c.attributes['num'].to_i
@@ -92,7 +92,7 @@ module MaRuKu; module Out; module Latex
92
92
  ENTITY_TABLE[num] = e
93
93
  ENTITY_TABLE[name] = e
94
94
  end
95
- $stderr.puts "..done."
95
+ # $stderr.puts "..done."
96
96
  end
97
97
 
98
98
  ENTITY_TABLE = {}
@@ -19,7 +19,7 @@
19
19
  #++
20
20
 
21
21
  module MaRuKu
22
- Version = '0.5.0'
22
+ Version = '0.5.1'
23
23
 
24
24
  MarukuURL = 'http://maruku.rubyforge.org/'
25
25
 
@@ -22,9 +22,12 @@ md_el(:document,[
22
22
  md_el(:header,["Header with attributes"],{:level=>2},[[:id, "header1"]]),
23
23
  md_el(:header,["Header with attributes"],{:level=>3},[[:id, "header2"]]),
24
24
  md_el(:header,["Header no attributes"],{:level=>3},[]),
25
- md_par(["Paragraph with a."], [[:id, "par1"], [:ref, "warn2"]]),
26
- md_par(["Paragraph with ", md_em(["emphasis"])], [[:id, "par2"]]),
27
- md_el(:ald,[],{:ald=>[[:class, "chello"]],:ald_id=>"o"},[])
25
+ md_par(["Paragraph with a."], [[:id, "par1"]]),
26
+ md_par([
27
+ "Paragraph with ",
28
+ md_em(["emphasis"], [[:ref, "hello"], [:ref, "notfound"]])
29
+ ], [[:id, "par2"]]),
30
+ md_el(:ald,[],{:ald=>[[:class, "chello"]],:ald_id=>"hello"},[])
28
31
  ],{},[])
29
32
  *** Output of to_html ***
30
33
 
@@ -36,7 +39,7 @@ md_el(:document,[
36
39
 
37
40
  <p id='par1'>Paragraph with a.</p>
38
41
 
39
- <p id='par2'>Paragraph with <em>emphasis</em></p>
42
+ <p id='par2'>Paragraph with <em class='chello'>emphasis</em></p>
40
43
 
41
44
  *** Output of to_latex ***
42
45
  \hypertarget{header1}{}\subsection*{{Header with attributes}}\label{header1}
@@ -62,54 +65,10 @@ Header with attributesHeader with attributesHeader no attributesParagraph with a
62
65
 
63
66
 
64
67
 
65
-
66
- Failed tests: [:inspect]
67
-
68
- *** Output of inspect ***
69
- -----| WARNING | -----
70
- md_el(:document,[
71
- md_el(:header,["Header with attributes"],{:level=>2},[[:id, "header1"]]),
72
- md_el(:header,["Header with attributes"],{:level=>3},[[:id, "header2"]]),
73
- md_el(:header,["Header no attributes"],{:level=>3},[]),
74
- md_par(["Paragraph with a."], [[:id, "par1"]]),
75
- md_par([
76
- "Paragraph with ",
77
- md_em(["emphasis"], [[:ref, "hello notfound"], [:ref, "notfound"]])
78
- ], [[:id, "par2"]]),
79
- md_el(:ald,[],{:ald=>[[:class, "chello"]],:ald_id=>"o"},[])
80
- ],{},[])
81
- *** Output of to_html ***
82
-
83
- <h2 id='header1'>Header with attributes</h2>
84
-
85
- <h3 id='header2'>Header with attributes</h3>
86
-
87
- <h3 id='header_no_attributes'>Header no attributes</h3>
88
-
89
- <p id='par1'>Paragraph with a.</p>
90
-
91
- <p id='par2'>Paragraph with <em>emphasis</em></p>
92
-
93
- *** Output of to_latex ***
94
- \hypertarget{header1}{}\subsection*{{Header with attributes}}\label{header1}
95
-
96
- \hypertarget{header2}{}\subsubsection*{{Header with attributes}}\label{header2}
97
-
98
- \hypertarget{header_no_attributes}{}\subsubsection*{{Header no attributes}}\label{header_no_attributes}
99
-
100
- Paragraph with a.
101
-
102
- Paragraph with \emph{emphasis}
68
+ OK!
103
69
 
104
70
 
105
- *** Output of to_md ***
106
- Header with attributesHeader with attributesHeader no attributesParagraph with a.
107
71
 
108
- Paragraph with emphasis
109
-
110
-
111
- *** Output of to_s ***
112
- Header with attributesHeader with attributesHeader no attributesParagraph with a.Paragraph with emphasis
113
72
  *** Output of Markdown.pl ***
114
73
  <h2>Header with attributes {#header1} </h2>
115
74
 
@@ -36,19 +36,25 @@ md_el(:document,[
36
36
  *** Output of to_html ***
37
37
 
38
38
  <p>This block is composed of three lines:</p>
39
+
39
40
  <pre><code>one
40
41
 
41
42
  three
42
43
  </code></pre>
44
+
43
45
  <p>This block is composed of 5</p>
46
+
44
47
  <pre><code>one
45
48
 
46
49
 
47
50
  four
48
51
 
49
52
  </code></pre>
53
+
50
54
  <p>This block is composed of 2</p>
55
+
51
56
  <pre><code>two</code></pre>
57
+
52
58
  *** Output of to_latex ***
53
59
  This block is composed of three lines:
54
60
 
@@ -17,10 +17,12 @@ md_el(:document,[
17
17
  *** Output of to_html ***
18
18
 
19
19
  <p>Here is an example of AppleScript:</p>
20
+
20
21
  <pre><code>tell application &quot;Foo&quot;
21
22
  beep
22
23
  end tell
23
24
  tab</code></pre>
25
+
24
26
  *** Output of to_latex ***
25
27
  Here is an example of AppleScript:
26
28
 
@@ -13,7 +13,9 @@ md_el(:document,[
13
13
 
14
14
  <blockquote>
15
15
  <p>Code</p>
16
- <pre><code>Ciao</code></pre></blockquote>
16
+
17
+ <pre><code>Ciao</code></pre>
18
+ </blockquote>
17
19
 
18
20
  *** Output of to_latex ***
19
21
  \begin{quote}%
@@ -33,14 +33,22 @@ md_el(:document,[
33
33
  *** Output of to_html ***
34
34
 
35
35
  <p>This is code (4 spaces):</p>
36
+
36
37
  <pre><code>Code</code></pre>
38
+
37
39
  <p>This is not code</p>
40
+
38
41
  <pre><code>Code
39
42
  </code></pre>
43
+
40
44
  <p>This is code (1 tab):</p>
45
+
41
46
  <pre><code>Code</code></pre>
47
+
42
48
  <p>This is not code</p>
49
+
43
50
  <pre><code>Code</code></pre>
51
+
44
52
  *** Output of to_latex ***
45
53
  This is code (4 spaces):
46
54
 
@@ -33,9 +33,9 @@ This is an email address:
33
33
 
34
34
 
35
35
  *** Output of Markdown.pl ***
36
- <p>This is an email address: <a href="&#x6D;&#x61;&#x69;&#108;t&#x6F;:&#97;&#x6E;&#100;&#114;&#x65;&#97;&#64;&#105;&#x6E;&#x76;&#x61;&#x6C;&#x69;&#x64;.&#x69;&#116;">&#97;&#x6E;&#100;&#114;&#x65;&#97;&#64;&#105;&#x6E;&#x76;&#x61;&#x6C;&#x69;&#x64;.&#x69;&#116;</a></p>
36
+ <p>This is an email address: <a href="&#x6D;&#x61;&#105;&#108;&#116;&#111;:&#x61;&#x6E;&#100;&#x72;&#x65;&#97;&#64;i&#x6E;v&#97;&#108;&#105;&#100;&#x2E;&#105;&#116;">&#x61;&#x6E;&#100;&#x72;&#x65;&#97;&#64;i&#x6E;v&#97;&#108;&#105;&#100;&#x2E;&#105;&#116;</a></p>
37
37
 
38
38
  *** Output of Markdown.pl (parsed) ***
39
- <p>This is an email address: <a href='&amp;#x6D;&amp;#x61;&amp;#x69;&amp;#108;t&amp;#x6F;:&amp;#97;&amp;#x6E;&amp;#100;&amp;#114;&amp;#x65;&amp;#97;&amp;#64;&amp;#105;&amp;#x6E;&amp;#x76;&amp;#x61;&amp;#x6C;&amp;#x69;&amp;#x64;.&amp;#x69;&amp;#116;'>&#97;&#x6E;&#100;&#114;&#x65;&#97;&#64;&#105;&#x6E;&#x76;&#x61;&#x6C;&#x69;&#x64;.&#x69;&#116;</a
39
+ <p>This is an email address: <a href='&amp;#x6D;&amp;#x61;&amp;#105;&amp;#108;&amp;#116;&amp;#111;:&amp;#x61;&amp;#x6E;&amp;#100;&amp;#x72;&amp;#x65;&amp;#97;&amp;#64;i&amp;#x6E;v&amp;#97;&amp;#108;&amp;#105;&amp;#100;&amp;#x2E;&amp;#105;&amp;#116;'>&#x61;&#x6E;&#100;&#x72;&#x65;&#97;&#64;i&#x6E;v&#97;&#108;&#105;&#100;&#x2E;&#105;&#116;</a
40
40
  ></p
41
41
  >
@@ -58,8 +58,10 @@ md_el(:document,[
58
58
  <p>Entity-substitution does not happen in code blocks or inline code.</p>
59
59
 
60
60
  <p>The following should not be translated:</p>
61
+
61
62
  <pre><code>&amp;copy;
62
63
  </code></pre>
64
+
63
65
  <p>It should read just like this: <code>&amp;copy;</code>.</p>
64
66
 
65
67
  *** Output of to_latex ***
@@ -0,0 +1,112 @@
1
+ We must make sure that `&apos;` is always written as `&#39;`.
2
+
3
+ *** Parameters: ***
4
+ {} # params
5
+ *** Markdown input: ***
6
+ `<p>here's an apostrophe & a quote "</p>`
7
+
8
+ <p>here's an apostrophe & a quote "</p>
9
+ {:}
10
+
11
+ <p>here's an apostrophe & a quote "</p>
12
+ {:lang=xml}
13
+
14
+ <p>here's an apostrophe & a quote "</p>
15
+ {:html_use_syntax=true lang=not_supported}
16
+
17
+ <p>here's an apostrophe & a quote "</p>
18
+ {:html_use_syntax=true lang=xml}
19
+
20
+
21
+ *** Output of inspect ***
22
+ md_el(:document,[
23
+ md_par([md_code("<p>here's an apostrophe & a quote \"</p>")]),
24
+ md_el(:code,[],{:raw_code=>"<p>here's an apostrophe & a quote \"</p>"},[]),
25
+ md_el(:code,[],{:raw_code=>"<p>here's an apostrophe & a quote \"</p>"},[["lang", "xml"]]),
26
+ md_el(:code,[],{:raw_code=>"<p>here's an apostrophe & a quote \"</p>"},[["html_use_syntax", "true"], ["lang", "not_supported"]]),
27
+ md_el(:code,[],{:raw_code=>"<p>here's an apostrophe & a quote \"</p>"},[["html_use_syntax", "true"], ["lang", "xml"]])
28
+ ],{},[])
29
+ *** Output of to_html ***
30
+
31
+ <p><code>&lt;p&gt;here&#39;s an apostrophe &amp; a quote &quot;&lt;/p&gt;</code></p>
32
+
33
+ <pre><code>&lt;p&gt;here&#39;s an apostrophe &amp; a quote &quot;&lt;/p&gt;</code></pre>
34
+
35
+ <pre><code class='xml' lang='xml'>&lt;p&gt;here&#39;s an apostrophe &amp; a quote &quot;&lt;/p&gt;</code></pre>
36
+
37
+ <pre><code class='not_supported' lang='not_supported'>&lt;p&gt;here&#39;s an apostrophe &amp; a quote &quot;&lt;/p&gt;</code></pre>
38
+
39
+ <pre><code class='xml' lang='xml'><span class='punct'>&lt;</span><span class='tag'>p</span><span class='punct'>&gt;</span>here&#39;s an apostrophe &amp; a quote &quot;<span class='punct'>&lt;/</span><span class='tag'>p</span><span class='punct'>&gt;</span></code></pre>
40
+
41
+ *** Output of to_latex ***
42
+ \colorbox[rgb]{1.00,0.93,1.00}{\tt \char60p\char62here\char39s~an~apostrophe~\char38~a~quote~\char34\char60\char47p\char62}
43
+
44
+ \begin{verbatim}<p>here's an apostrophe & a quote "</p>\end{verbatim}
45
+ \begin{verbatim}<p>here's an apostrophe & a quote "</p>\end{verbatim}
46
+ \begin{verbatim}<p>here's an apostrophe & a quote "</p>\end{verbatim}
47
+ \begin{verbatim}<p>here's an apostrophe & a quote "</p>\end{verbatim}
48
+
49
+ *** Output of to_md ***
50
+
51
+
52
+
53
+ *** Output of to_s ***
54
+
55
+ *** EOF ***
56
+
57
+
58
+
59
+ OK!
60
+
61
+
62
+
63
+ *** Output of Markdown.pl ***
64
+ <p><code>&lt;p&gt;here's an apostrophe &amp; a quote "&lt;/p&gt;</code></p>
65
+
66
+ <pre><code>&lt;p&gt;here's an apostrophe &amp; a quote "&lt;/p&gt;
67
+ </code></pre>
68
+
69
+ <p>{:}</p>
70
+
71
+ <pre><code>&lt;p&gt;here's an apostrophe &amp; a quote "&lt;/p&gt;
72
+ </code></pre>
73
+
74
+ <p>{:lang=xml}</p>
75
+
76
+ <pre><code>&lt;p&gt;here's an apostrophe &amp; a quote "&lt;/p&gt;
77
+ </code></pre>
78
+
79
+ <p>{:html<em>use</em>syntax=true lang=not_supported}</p>
80
+
81
+ <pre><code>&lt;p&gt;here's an apostrophe &amp; a quote "&lt;/p&gt;
82
+ </code></pre>
83
+
84
+ <p>{:html<em>use</em>syntax=true lang=xml}</p>
85
+
86
+ *** Output of Markdown.pl (parsed) ***
87
+ <p
88
+ ><code>&lt;p&gt;here's an apostrophe &amp; a quote "&lt;/p&gt;</code
89
+ ></p
90
+ ><pre
91
+ ><code>&lt;p&gt;here's an apostrophe &amp; a quote "&lt;/p&gt;
92
+ </code
93
+ ></pre
94
+ ><p>{:}</p
95
+ ><pre
96
+ ><code>&lt;p&gt;here's an apostrophe &amp; a quote "&lt;/p&gt;
97
+ </code
98
+ ></pre
99
+ ><p>{:lang=xml}</p
100
+ ><pre
101
+ ><code>&lt;p&gt;here's an apostrophe &amp; a quote "&lt;/p&gt;
102
+ </code
103
+ ></pre
104
+ ><p>{:html<em>use</em
105
+ >syntax=true lang=not_supported}</p
106
+ ><pre
107
+ ><code>&lt;p&gt;here's an apostrophe &amp; a quote "&lt;/p&gt;
108
+ </code
109
+ ></pre
110
+ ><p>{:html<em>use</em
111
+ >syntax=true lang=xml}</p
112
+ >