maruku 0.4.2.1 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. data/bin/maruku +66 -20
  2. data/bin/marutest +12 -2
  3. data/docs/changelog.html +188 -23
  4. data/docs/changelog.md +128 -5
  5. data/docs/entity_test.html +245 -240
  6. data/docs/entity_test.md +2 -0
  7. data/docs/exd.html +181 -23
  8. data/docs/index.html +130 -349
  9. data/docs/markdown_syntax.html +55 -51
  10. data/docs/maruku.html +130 -349
  11. data/docs/maruku.md +154 -339
  12. data/docs/math.md +143 -0
  13. data/docs/proposal.html +16 -12
  14. data/lib/maruku.rb +6 -3
  15. data/lib/maruku/attributes.rb +7 -2
  16. data/lib/maruku/defaults.rb +27 -27
  17. data/lib/maruku/errors_management.rb +10 -9
  18. data/lib/maruku/ext/diagrams/diagrams.rb +8 -0
  19. data/lib/maruku/ext/diagrams/grid.rb +78 -0
  20. data/lib/maruku/ext/diagrams/inspect.rb +11 -0
  21. data/lib/maruku/ext/diagrams/layout.rb +105 -0
  22. data/lib/maruku/ext/diagrams/parser.rb +219 -0
  23. data/lib/maruku/ext/diagrams/structures.rb +168 -0
  24. data/lib/maruku/ext/diagrams/to_html.rb +37 -0
  25. data/lib/maruku/ext/diagrams/to_latex.rb +308 -0
  26. data/lib/maruku/ext/diagrams/unittest.rb +123 -0
  27. data/lib/maruku/ext/math.rb +11 -0
  28. data/lib/maruku/ext/math/elements.rb +26 -0
  29. data/lib/maruku/ext/math/mathml_engines/blahtex.rb +108 -0
  30. data/lib/maruku/ext/math/mathml_engines/itex2mml.rb +29 -0
  31. data/lib/maruku/ext/math/mathml_engines/none.rb +20 -0
  32. data/lib/maruku/ext/math/mathml_engines/ritex.rb +24 -0
  33. data/lib/maruku/ext/math/parsing.rb +82 -0
  34. data/lib/maruku/ext/math/to_html.rb +178 -0
  35. data/lib/maruku/ext/math/to_latex.rb +21 -0
  36. data/lib/maruku/helpers.rb +11 -0
  37. data/lib/maruku/input/charsource.rb +1 -1
  38. data/lib/maruku/input/extensions.rb +68 -0
  39. data/lib/maruku/input/html_helper.rb +91 -60
  40. data/lib/maruku/input/parse_block.rb +10 -9
  41. data/lib/maruku/input/parse_doc.rb +21 -13
  42. data/lib/maruku/input/parse_span_better.rb +19 -8
  43. data/lib/maruku/input/type_detection.rb +5 -3
  44. data/lib/maruku/output/to_html.rb +236 -67
  45. data/lib/maruku/output/to_latex.rb +69 -26
  46. data/lib/maruku/output/to_latex_entities.rb +14 -2
  47. data/lib/maruku/output/to_s.rb +8 -0
  48. data/lib/maruku/structures.rb +1 -1
  49. data/lib/maruku/tests/benchmark.rb +2 -2
  50. data/lib/maruku/tests/new_parser.rb +13 -5
  51. data/lib/maruku/version.rb +1 -1
  52. data/lib/sort_prof.rb +22 -0
  53. data/tests/diagrams/diagrams.md +54 -0
  54. data/tests/math/syntax.md +46 -0
  55. data/tests/math_usage/document.md +13 -0
  56. data/tests/unittest/attributes/attributes.md +50 -6
  57. data/tests/unittest/easy.md +1 -1
  58. data/tests/unittest/email.md +3 -3
  59. data/tests/unittest/entities.md +12 -7
  60. data/tests/unittest/escaping.md +4 -4
  61. data/tests/unittest/extra_table1.md +3 -1
  62. data/tests/unittest/footnotes.md +5 -5
  63. data/tests/unittest/headers.md +3 -3
  64. data/tests/unittest/images.md +7 -7
  65. data/tests/unittest/inline_html.md +51 -5
  66. data/tests/unittest/links.md +7 -7
  67. data/tests/unittest/list2.md +1 -1
  68. data/tests/unittest/lists.md +1 -1
  69. data/tests/unittest/lists_after_paragraph.md +1 -1
  70. data/tests/unittest/lists_ol.md +1 -1
  71. data/tests/unittest/math/equations.md +82 -0
  72. data/tests/unittest/math/inline.md +80 -0
  73. data/tests/unittest/math/table.md +51 -0
  74. data/tests/unittest/math/table2.md +67 -0
  75. data/tests/unittest/misc_sw.md +24 -24
  76. data/tests/unittest/notyet/ticks.md +1 -1
  77. data/tests/unittest/references/long_example.md +2 -2
  78. data/tests/unittest/smartypants.md +4 -4
  79. data/tests/unittest/xml.md +68 -0
  80. data/tests/unittest/xml2.md +36 -0
  81. data/tests/unittest/xml3.md +52 -0
  82. data/tests/unittest/xml_instruction.md +5 -5
  83. metadata +33 -4
  84. data/docs/a.html +0 -6
  85. data/docs/char.html +0 -1924
@@ -0,0 +1,143 @@
1
+ LaTeX preamble: math_preamble.tex
2
+ LaTeX use listings: true
3
+ CSS: math.css style.css
4
+
5
+ Math support in Maruku
6
+ ======================
7
+
8
+
9
+ Introduction...
10
+
11
+ * toc
12
+ {:toc}
13
+
14
+ Syntax
15
+ ---------------------------------------
16
+
17
+ ### Inline math
18
+
19
+ Inline math are comprised inside couples of `$`.
20
+
21
+ Everything inside `$` will be passed as-is to LaTeX: no Markdown
22
+ interpretation will take place.
23
+
24
+ Example: $x^{n}+y^{n} \neq z^{n}$ for $n \geq 3$
25
+
26
+ > Example: $x^{n}+y^{n} \neq z^{n}$ for $n \geq 3$
27
+
28
+ ### Equations
29
+
30
+ Equations are specified using either the `$$ ... $$` or `\[ ... \]`
31
+ LaTeX notation. Equations can span multiple lines.
32
+
33
+ \[
34
+ \sum_{n=1}^\infty \frac{1}{n}
35
+ \text{ is divergent, but }
36
+ \lim_{n \to \infty} \sum_{i=1}^n \frac{1}{i} - \ln n \text{exists.}
37
+ \]
38
+
39
+ > \[
40
+ > \sum_{n=1}^\infty \frac{1}{n}
41
+ > \text{ is divergent, but }
42
+ > \lim_{n \to \infty} \sum_{i=1}^n \frac{1}{i} - \ln n \quad \text{exists.}
43
+ > \]
44
+
45
+ Some random AMSTeX symbols:
46
+
47
+ $$ \beth \Subset \bigtriangleup \bumpeq \ggg \pitchfork $$
48
+
49
+ $$ \beth \Subset \bigtriangleup \bumpeq \ggg \pitchfork $$
50
+
51
+
52
+ ## Cross references ## {#cross}
53
+
54
+ Create a label for an equation in two ways:
55
+
56
+ * LaTeX style
57
+
58
+ Consider \eqref{a}:
59
+
60
+ $$ \alpha = \beta \label{a} $$
61
+
62
+ * More readable style:
63
+
64
+ Consider (eq:a):
65
+
66
+ $$ \alpha = \beta $$ (a)
67
+
68
+ You can mix the two.
69
+
70
+ Labels will work as expected also in the PDF output, whatever
71
+ style you use: Maruku will insert the necessary `\label` commands.
72
+
73
+ The following are 4 equations, labeled A,B,C,D:
74
+
75
+ $$ \alpha $$ (A)
76
+
77
+ \[
78
+ \beta
79
+ \] (B)
80
+
81
+ $$ \gamma \label{C} $$
82
+
83
+ \[
84
+ \delta \label{D}
85
+ \]
86
+
87
+ You can now refer to (eq:A), (eq:B), \eqref{C}, \eqref{D}.
88
+
89
+
90
+ Enabling the extension
91
+ ---------------------------------------
92
+
93
+ ### On the command line
94
+
95
+ Use the `-m` option to choose the kind of output. Possible choices are:
96
+
97
+ * `-m itex2mml`
98
+
99
+ [Instructions for itex2mml][itex2mml].
100
+
101
+ * `-m ritex`
102
+ * `-m blahtex`
103
+
104
+ * `-mi blahtex`
105
+
106
+
107
+ [itex2mml]: http://golem.ph.utexas.edu/~distler/code/itexToMML/
108
+
109
+ ### With embedded Maruku
110
+
111
+ First, you have to enable the math extension.
112
+
113
+ require 'maruku' # loads maruku
114
+ require 'maruku/ext/math' # loads the math extension
115
+
116
+
117
+ ### MathML output
118
+
119
+ ...
120
+
121
+ ### PNG output ###
122
+
123
+ Other parameters of interests are:
124
+
125
+ * `Globals[:math_png_dir]`
126
+ * `Globals[:math_png_dir_url]`
127
+
128
+
129
+ Advanced topics
130
+ ---------------
131
+
132
+ ### Styling equations ####
133
+
134
+ ...
135
+
136
+ ### Aligning PNGs ####
137
+
138
+ ...
139
+
140
+
141
+
142
+
143
+
@@ -1,10 +1,14 @@
1
- <?xml version='1.0' encoding='utf-8'?>
2
- <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN'
3
- 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
4
- <html lang='en' xml:lang='en' xmlns='http://www.w3.org/1999/xhtml'><head><meta content='text/html; charset=utf-8' http-equiv='Content-type' /><title>Proposal for adding a meta-data syntax to Markdown</title><link href='style.css' rel='stylesheet' type='text/css' /></head><body>
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <!DOCTYPE html PUBLIC
3
+ "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN"
4
+ "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">
5
+ <html xmlns:svg='http://www.w3.org/2000/svg' xml:lang='en' xmlns='http://www.w3.org/1999/xhtml'>
6
+ <head><meta content='application/xhtml+xml;charset=utf-8' http-equiv='Content-type' /><title>Proposal for adding a meta-data syntax to Markdown</title><link href='style.css' rel='stylesheet' type='text/css' />
7
+ </head>
8
+ <body>
5
9
  <h1 id='proposal_for_adding_a_metadata_syntax_to_markdown'>Proposal for adding a meta-data syntax to Markdown</h1>
6
10
 
7
- <p>This document describes a syntax for attaching meta-data to block-level elements (headers, paragraphs, code blocks,&hellip;), and to span-level elements (links, images,&hellip;).</p>
11
+ <p>This document describes a syntax for attaching meta-data to block-level elements (headers, paragraphs, code blocks,&#8230;), and to span-level elements (links, images,&#8230;).</p>
8
12
 
9
13
  <p><strong><em>Note: this is an evolving proposal</em></strong></p>
10
14
 
@@ -25,7 +29,7 @@
25
29
  <p>instead of:</p>
26
30
  <pre><code>{ref_id}: key=val .class #id
27
31
  </code></pre>
28
- <p>Converters that don&rsquo;t use this syntax may just ignore everything which is in curly braces and starts with &rdquo;:&rdquo;.</p>
32
+ <p>Converters that don&#8217;t use this syntax may just ignore everything which is in curly braces and starts with &#8221;:&#8221;.</p>
29
33
  </li>
30
34
 
31
35
  <li>
@@ -109,7 +113,7 @@ second line of paragraph
109
113
  </li>
110
114
 
111
115
  <li>
112
- <p><code>.myclass</code> means &ldquo;add <code>myclass</code> to the current <code>class</code> attribute&rdquo;.</p>
116
+ <p><code>.myclass</code> means &#8220;add <code>myclass</code> to the current <code>class</code> attribute&#8221;.</p>
113
117
 
114
118
  <p>So these are equivalent:</p>
115
119
  <pre><code>{: .class1 .class2}
@@ -143,13 +147,13 @@ Line 2 of the paragraph.
143
147
  </code></pre>
144
148
  <p>Attribute lists may be indented up to 3 spaces:</p>
145
149
  <pre><code>Paragraph1
146
- &not;{:ok}
150
+ &#172;{:ok}
147
151
 
148
152
  Paragraph2
149
- &not;&not;{:ok}
153
+ &#172;&#172;{:ok}
150
154
 
151
155
  Paragraph2
152
- &not;&not;&not;{:ok}</code></pre>
156
+ &#172;&#172;&#172;{:ok}</code></pre>
153
157
  <h3 id='for_headers'><span class='maruku_section_number'>3.2. </span>For headers</h3>
154
158
 
155
159
  <p>For headers, you can put attribute lists on the same line:</p>
@@ -266,7 +270,7 @@ Blah blah blah.
266
270
 
267
271
  <p>Also, you <strong>must</strong> escape a closing curly brace <code>}</code> inside quoted values. This rule is for making life easier for interpreter that just want to skip the meta-data.</p>
268
272
 
269
- <p>If you don&rsquo;t implement this syntax, you can get rid of the IAL by using this regular expression (this is written in Ruby):</p>
273
+ <p>If you don&#8217;t implement this syntax, you can get rid of the IAL by using this regular expression (this is written in Ruby):</p>
270
274
  <pre><code>r = /\{:(\\\}|[^\}])*\}/
271
275
 
272
276
  s.gsub(r, &#39;&#39;) # ignore metadata</code></pre>
@@ -283,4 +287,4 @@ for me
283
287
  <pre><code>this is
284
288
 
285
289
 
286
- for me </code></pre><div class='maruku_signature'><hr /><span style='font-size: small; font-style: italic'>Created by <a href='http://maruku.rubyforge.org' title='Maruku: a Markdown interpreter for Ruby'>Maruku</a> at 13:45 on Thursday, January 11st, 2007.</span></div></body></html>
290
+ for me </code></pre><div class='maruku_signature'><hr /><span style='font-size: small; font-style: italic'>Created by <a href='http://maruku.rubyforge.org' title='Maruku: a Markdown-superset interpreter for Ruby'>Maruku</a> at 14:11 on Tuesday, January 23rd, 2007.</span></div></body></html>
@@ -18,6 +18,8 @@
18
18
  # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
19
  #++
20
20
 
21
+ require 'rexml/document'
22
+
21
23
  # :include:MaRuKu.txt
22
24
  module MaRuKu
23
25
 
@@ -44,11 +46,9 @@ module MaRuKu
44
46
  module Helpers; end
45
47
 
46
48
  module Errors; end
47
-
48
- module Defaults; end
49
49
 
50
50
  class MDElement
51
- include Defaults
51
+ include REXML
52
52
  include MaRuKu
53
53
  include Out::Markdown
54
54
  include Out::HTML
@@ -60,6 +60,7 @@ module MaRuKu
60
60
 
61
61
 
62
62
  class MDDocument < MDElement
63
+ include In::Markdown
63
64
  include In::Markdown::SpanLevelParser
64
65
  include In::Markdown::BlockLevelParser
65
66
  end
@@ -99,6 +100,8 @@ require 'maruku/input/charsource'
99
100
  require 'maruku/input/parse_span_better'
100
101
  require 'maruku/input/rubypants'
101
102
 
103
+ require 'maruku/input/extensions'
104
+
102
105
  require 'maruku/attributes'
103
106
 
104
107
  require 'maruku/structures_iterators'
@@ -45,8 +45,11 @@ module MaRuKu;
45
45
  push [key, val]
46
46
  end
47
47
  def push_ref(ref_id);
48
+
48
49
  raise "Bad :ref #{ref_id.inspect}" if not ref_id
49
- push [:ref, ref_id]
50
+ push [:ref, ref_id+""]
51
+
52
+ # p "Now ", self ########################################
50
53
  end
51
54
  def push_class(val);
52
55
  raise "Bad :id #{val.inspect}" if not val
@@ -81,6 +84,7 @@ module MaRuKu; module In; module Markdown; module SpanLevelParser
81
84
  [ "a =b", :throw, "No whitespace before `=`." ],
82
85
  [ "a= b", :throw, "No whitespace after `=`." ],
83
86
 
87
+ [ "a b", [[:ref, 'a'],[:ref, 'b']], "More than one ref" ],
84
88
  [ "a b c", [[:ref, 'a'],[:ref, 'b'],[:ref, 'c']], "More than one ref" ],
85
89
  [ "hello notfound", [[:ref, 'hello'],[:ref, 'notfound']]],
86
90
 
@@ -129,6 +133,7 @@ module MaRuKu; module In; module Markdown; module SpanLevelParser
129
133
 
130
134
  # returns nil or an AttributeList
131
135
  def read_attribute_list(src, con, break_on_chars)
136
+
132
137
  separators = break_on_chars + [?=,?\ ,?\t]
133
138
  escaped = Maruku::EscapedCharInQuotes
134
139
 
@@ -210,7 +215,7 @@ module MaRuKu; module In; module Markdown; module SpanLevelParser
210
215
  end
211
216
 
212
217
  if not Globals[:debug_keep_ials]
213
- elements.delete_if {|x| is_ial(x)}
218
+ elements.delete_if {|x| is_ial(x) unless x == elements.first}
214
219
  end
215
220
  end
216
221
 
@@ -23,40 +23,40 @@ module MaRuKu
23
23
 
24
24
  Globals = {
25
25
  :unsafe_features => false,
26
+ :on_error => :warning,
26
27
 
27
- :debug_keep_ials => false,
28
28
 
29
- :maruku_signature => true
30
- }
29
+ :use_numbered_headers => false,
31
30
 
32
- module Defaults
33
- DEFAULT_CODE_COLOR = '#fef'
31
+ :maruku_signature => true,
32
+ :code_background_color => '#fef',
33
+ :code_show_spaces => false,
34
+ :html_math_engine => 'none', #ritex, itex2mml
34
35
 
35
- # unused
36
- DefaultAttributes = <<EOF
37
-
38
- {header}: .mrk-header
39
- {paragraph}: .mrk-par
40
- {strong}: .mrk-strong
41
- {emphasis}: .mrk-em
42
- {code}: .mrk-code
43
- {code_block}: .mrk-code_block
44
-
45
- {example}: pre_filter=""
46
-
47
- EOF
48
-
49
- end
50
-
36
+ :html_png_engine => 'none',
37
+ :html_png_dir => 'pngs',
38
+ :html_png_url => 'pngs/',
39
+ :html_png_resolution => 200,
40
+
41
+ :html_use_syntax => false,
42
+
43
+ :latex_use_listings => false,
44
+ :latex_cjk => false,
45
+
46
+ :debug_keep_ials => false,
47
+
48
+ }
51
49
 
52
50
  class MDElement
53
- def get_boolean_setting(sym)
54
- if self.doc.attributes.has_key?(sym) then
55
- return !!self.doc.attributes[sym]
56
- elsif Globals.has_key?(sym)
57
- return !!Globals[sym]
51
+ def get_setting(sym)
52
+ if self.attributes.has_key?(sym) then
53
+ return self.attributes[sym]
54
+ elsif self.doc && self.doc.attributes.has_key?(sym) then
55
+ return self.doc.attributes[sym]
56
+ elsif MaRuKu::Globals.has_key?(sym)
57
+ return MaRuKu::Globals[sym]
58
58
  else
59
- puts "Bug: no default for #{sym.inspect}"
59
+ $stderr.puts "Bug: no default for #{sym.inspect}"
60
60
  nil
61
61
  end
62
62
  end
@@ -37,10 +37,9 @@ module MaRuKu
37
37
  end
38
38
 
39
39
  module Errors
40
- Default_on_error = :warning
41
40
 
42
41
  def maruku_error(s,src=nil,con=nil)
43
- policy = @doc ? (@doc.attributes[:on_error] || Default_on_error) : :raise
42
+ policy = get_setting(:on_error)
44
43
 
45
44
  case policy
46
45
  when :ignore
@@ -48,6 +47,8 @@ module Errors
48
47
  raise_error create_frame(describe_error(s,src,con))
49
48
  when :warning
50
49
  tell_user create_frame(describe_error(s,src,con))
50
+ else
51
+ raise "BugBug: policy = #{policy.inspect}"
51
52
  end
52
53
  end
53
54
 
@@ -69,13 +70,13 @@ module Errors
69
70
  def create_frame(s)
70
71
  n = 75
71
72
  "\n" +
72
- " "+"_"*n << "\n"<<
73
- "| Maruku tells you:\n" <<
74
- "+"+"-"*n +"\n"+
75
- add_tabs(s,1,'| ') << "\n" <<
76
- "+" << "-"*n << "\n" <<
77
- add_tabs(caller[0, 5].join("\n"),1,'!') << "\n" <<
78
- "\\" << "_"*n << "\n"
73
+ " "+"_"*n + "\n"+
74
+ "| Maruku tells you:\n" +
75
+ "+" + ("-"*n) +"\n"+
76
+ add_tabs(s,1,'| ') + "\n" +
77
+ "+" + ("-"*n) + "\n" +
78
+ add_tabs(caller[0, 5].join("\n"),1,'!') + "\n" +
79
+ "\\" + ("_"*n) + "\n"
79
80
  end
80
81
 
81
82
  def describe_error(s,src,con)
@@ -0,0 +1,8 @@
1
+ require 'structures'
2
+ require 'parser'
3
+ require 'inspect'
4
+ require 'grid'
5
+ require 'to_html'
6
+ require 'to_latex'
7
+ require 'layout'
8
+
@@ -0,0 +1,78 @@
1
+ module Diagrams
2
+
3
+ class Grid
4
+ attr_accessor :width, :height
5
+
6
+ def initialize(width, height, init)
7
+ @width, @height = width, height
8
+ @data = Array.new
9
+ height.times do @data.push [init]*@width end
10
+ @init = init
11
+ end
12
+
13
+ def get(x, y)
14
+ @data[y][x]
15
+ end
16
+
17
+ def set(x, y, v)
18
+ @data[y][x] = v || @init
19
+ end
20
+
21
+ def inspect
22
+ @data.map{|x|
23
+ x.map{|y|
24
+ case y
25
+ when true; '#'
26
+ when false, nil; ' '
27
+ when Fixnum; y.chr
28
+ end
29
+ }.join
30
+ }.join("\n")
31
+ end
32
+
33
+ def inspect2(valid)
34
+ s = ""
35
+
36
+ s += "+" + "-"*@width + "+\n"
37
+ for y in 0..(@height-1)
38
+ s += "|"
39
+ for x in 0..(@width-1)
40
+ s += valid.get(x,y) ? get(x,y).chr : " "
41
+ end
42
+ s += "|"
43
+ s += "\n"
44
+ end
45
+ s += "+" + "-"*@width + "+\n"
46
+ s
47
+ end
48
+
49
+ def each
50
+ for y in 0..(height-1)
51
+ for x in 0..(width-1)
52
+ e = get(x,y)
53
+ yield x,y,e
54
+ end
55
+ end
56
+ end
57
+
58
+ def set_area(x,y,w,h,e)
59
+ for i in (x..x+w-1)
60
+ for j in (y..y+h-1)
61
+ set(i,j,e)
62
+ end
63
+ end
64
+ end
65
+
66
+ def read_area(x,y,w,h)
67
+ s = ""
68
+ for j in (y..y+h-1)
69
+ for i in (x..x+w-1)
70
+ s << get(i,j)
71
+ end
72
+ s << "\n"
73
+ end
74
+ s
75
+ end
76
+ end
77
+
78
+ end