maruku 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. data/bin/{maruku0.3 → marudown} +6 -14
  2. data/bin/maruku +1 -1
  3. data/bin/marutest +37 -9
  4. data/docs/TOFIX.html +22 -0
  5. data/docs/TOFIX.md +3 -0
  6. data/docs/changelog-0.2.13.html +30 -0
  7. data/docs/changelog-0.2.13.md +6 -0
  8. data/docs/changelog-0.3.html +19 -5
  9. data/docs/faq.html +51 -40
  10. data/docs/faq.md +3 -3
  11. data/docs/hidden_o_n_squared.md +10 -0
  12. data/docs/index.html +84 -396
  13. data/docs/markdown_syntax.html +139 -330
  14. data/docs/markdown_syntax.md +80 -93
  15. data/docs/maruku.html +84 -396
  16. data/docs/maruku.md +88 -158
  17. data/docs/proposal.html +13 -106
  18. data/docs/proposal.md +3 -3
  19. data/docs/todo.html +38 -28
  20. data/lib/maruku.rb +77 -11
  21. data/lib/maruku/attributes.rb +186 -0
  22. data/lib/maruku/defaults.rb +40 -0
  23. data/lib/maruku/errors_management.rb +55 -39
  24. data/lib/maruku/helpers.rb +156 -72
  25. data/lib/maruku/input/charsource.rb +319 -0
  26. data/lib/maruku/{html_helper.rb → input/html_helper.rb} +30 -9
  27. data/lib/maruku/input/linesource.rb +111 -0
  28. data/lib/maruku/input/parse_block.rb +562 -0
  29. data/lib/maruku/{parse_doc.rb → input/parse_doc.rb} +60 -28
  30. data/lib/maruku/{parse_span_better.rb → input/parse_span_better.rb} +226 -256
  31. data/lib/maruku/input/type_detection.rb +137 -0
  32. data/lib/maruku/maruku.rb +33 -0
  33. data/lib/maruku/{to_html.rb → output/to_html.rb} +151 -132
  34. data/lib/maruku/{to_latex.rb → output/to_latex.rb} +31 -35
  35. data/lib/maruku/{to_latex_entities.rb → output/to_latex_entities.rb} +25 -3
  36. data/lib/maruku/output/to_latex_strings.rb +64 -0
  37. data/lib/maruku/output/to_markdown.rb +164 -0
  38. data/lib/maruku/{to_s.rb → output/to_s.rb} +6 -0
  39. data/lib/maruku/string_utils.rb +12 -181
  40. data/lib/maruku/structures.rb +91 -67
  41. data/lib/maruku/structures_inspect.rb +78 -0
  42. data/lib/maruku/structures_iterators.rb +24 -2
  43. data/lib/maruku/tests/benchmark.rb +41 -9
  44. data/lib/maruku/tests/new_parser.rb +317 -286
  45. data/lib/maruku/tests/tests.rb +20 -0
  46. data/lib/maruku/toc.rb +64 -64
  47. data/lib/maruku/usage/example1.rb +33 -0
  48. data/lib/maruku/version.rb +8 -2
  49. data/tests/unittest/abbreviations.md +27 -16
  50. data/tests/unittest/attributes/attributes.md +89 -0
  51. data/tests/unittest/attributes/circular.md +51 -0
  52. data/tests/unittest/attributes/default.md +47 -0
  53. data/tests/unittest/blank.md +10 -6
  54. data/tests/unittest/blanks_in_code.md +26 -26
  55. data/tests/unittest/code.md +9 -9
  56. data/tests/unittest/code2.md +12 -13
  57. data/tests/unittest/code3.md +34 -34
  58. data/tests/unittest/easy.md +9 -7
  59. data/tests/unittest/email.md +9 -7
  60. data/tests/unittest/encoding/iso-8859-1.md +41 -4
  61. data/tests/unittest/encoding/utf-8.md +6 -5
  62. data/tests/unittest/entities.md +52 -80
  63. data/tests/unittest/escaping.md +47 -35
  64. data/tests/unittest/extra_dl.md +19 -29
  65. data/tests/unittest/extra_header_id.md +31 -24
  66. data/tests/unittest/extra_table1.md +14 -32
  67. data/tests/unittest/footnotes.md +58 -42
  68. data/tests/unittest/headers.md +11 -11
  69. data/tests/unittest/hrule.md +14 -24
  70. data/tests/unittest/images.md +41 -26
  71. data/tests/unittest/inline_html.md +104 -56
  72. data/tests/unittest/inline_html2.md +38 -0
  73. data/tests/unittest/links.md +74 -33
  74. data/tests/unittest/list1.md +18 -15
  75. data/tests/unittest/list2.md +31 -13
  76. data/tests/unittest/list3.md +29 -28
  77. data/tests/unittest/list4.md +103 -12
  78. data/tests/unittest/lists.md +86 -53
  79. data/tests/unittest/lists6.md +53 -0
  80. data/tests/unittest/lists7.md +31 -0
  81. data/tests/unittest/lists_after_paragraph.md +105 -71
  82. data/tests/unittest/lists_ol.md +149 -73
  83. data/tests/unittest/misc_sw.md +366 -326
  84. data/tests/unittest/notyet/escape.md +10 -10
  85. data/tests/unittest/notyet/header_after_par.md +20 -14
  86. data/tests/unittest/notyet/ticks.md +8 -35
  87. data/tests/unittest/notyet/triggering.md +72 -45
  88. data/tests/unittest/olist.md +78 -0
  89. data/tests/unittest/one.md +5 -3
  90. data/tests/unittest/paragraph.md +5 -3
  91. data/tests/unittest/paragraph_rules/dont_merge_ref.md +15 -9
  92. data/tests/unittest/paragraph_rules/tab_is_blank.md +9 -5
  93. data/tests/unittest/paragraphs.md +21 -26
  94. data/tests/unittest/recover/recover_links.md +6 -5
  95. data/tests/unittest/references/long_example.md +39 -30
  96. data/tests/unittest/references/spaces_and_numbers.md +2 -2
  97. data/tests/unittest/syntax_hl.md +33 -31
  98. data/tests/unittest/test.md +4 -6
  99. data/tests/unittest/wrapping.md +43 -26
  100. metadata +160 -139
  101. data/docs/markdown_extra2.html +0 -87
  102. data/docs/markdown_extra2.md +0 -83
  103. data/docs/markdown_syntax_2.html +0 -152
  104. data/lib/maruku/parse_block.rb +0 -564
  105. data/lib/maruku/parse_span.rb +0 -451
  106. data/lib/maruku/to_latex_strings.rb +0 -59
  107. data/lib/maruku/to_markdown.rb +0 -110
  108. data/lib/test.rb +0 -29
@@ -1,3 +1,23 @@
1
+ #--
2
+ # Copyright (C) 2006 Andrea Censi <andrea (at) rubyforge.org>
3
+ #
4
+ # This file is part of Maruku.
5
+ #
6
+ # Maruku is free software; you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation; either version 2 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # Maruku is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with Maruku; if not, write to the Free Software
18
+ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
+ #++
20
+
1
21
 
2
22
  require 'maruku'
3
23
 
data/lib/maruku/toc.rb CHANGED
@@ -1,3 +1,4 @@
1
+ #--
1
2
  # Copyright (C) 2006 Andrea Censi <andrea (at) rubyforge.org>
2
3
  #
3
4
  # This file is part of Maruku.
@@ -15,21 +16,19 @@
15
16
  # You should have received a copy of the GNU General Public License
16
17
  # along with Maruku; if not, write to the Free Software
17
18
  # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
+ #++
18
20
 
19
- require 'rexml/document'
20
21
 
21
-
22
- class Maruku
22
+ module MaRuKu
23
+
24
+ class MDDocument
23
25
  # an instance of Section (see below)
24
26
  attr_accessor :toc
25
27
  end
26
28
 
27
-
28
-
29
- class MDElement
30
29
  # This represents a section in the TOC.
31
30
  class Section
32
- # a Fixnum, is == header_element.meta[:level]
31
+ # a Fixnum, is == header_element.level
33
32
  attr_accessor :section_level
34
33
 
35
34
  # An array of fixnum, like [1,2,5] for Section 1.2.5
@@ -40,25 +39,23 @@ class MDElement
40
39
 
41
40
  # Array of immediate children of this element
42
41
  attr_accessor :immediate_children
42
+
43
43
  # Array of Section inside this section
44
44
  attr_accessor :section_children
45
45
 
46
-
47
46
  def initialize
48
47
  @immediate_children = []
49
48
  @section_children = []
50
49
  end
51
50
  end
52
- end
53
51
 
54
-
55
- class MDElement
56
52
  class Section
57
53
  def inspect(indent=1)
58
54
  s = ""
59
55
  if @header_element
60
56
  s += "\_"*indent + "(#{@section_level})>\t #{@section_number.join('.')} : "
61
- s += @header_element.children_to_s + " (id: '#{@header_element.meta[:id]}')\n"
57
+ s += @header_element.children_to_s +
58
+ " (id: '#{@header_element.attributes[:id]}')\n"
62
59
  else
63
60
  s += "Master\n"
64
61
  end
@@ -75,6 +72,9 @@ class MDElement
75
72
  section_children.each_with_index do |c,i|
76
73
  c.numerate(a.clone.push(i+1))
77
74
  end
75
+ if h = self.header_element
76
+ h.attributes[:section_number] = self.section_number
77
+ end
78
78
  end
79
79
 
80
80
  include REXML
@@ -98,7 +98,7 @@ class MDElement
98
98
  end
99
99
  a = c.header_element.wrap_as_element('a')
100
100
  a.delete_attribute 'id'
101
- a.attributes['href'] = "##{c.header_element.meta[:id]}"
101
+ a.attributes['href'] = "##{c.header_element.attributes[:id]}"
102
102
  li << a
103
103
  li << c.create_toc if c.section_children.size>0
104
104
  ul << li
@@ -119,7 +119,7 @@ class MDElement
119
119
  number = c.header_element.section_number
120
120
  s += number if number
121
121
  text = c.header_element.children_to_latex
122
- id = c.header_element.meta[:id]
122
+ id = c.header_element.attributes[:id]
123
123
  s += "\\hyperlink{#{id}}{#{text}}"
124
124
  s += "\\dotfill \\pageref*{#{id}} \\linebreak\n"
125
125
  s += c.to_latex_rec if c.section_children.size>0
@@ -129,71 +129,71 @@ class MDElement
129
129
  end
130
130
 
131
131
  end
132
- end
133
-
134
132
 
135
- class MDElement
133
+ class MDDocument
136
134
 
137
-
138
- def create_toc
139
- stack = []
135
+ def create_toc
136
+ each_element(:header) do |h|
137
+ h.attributes[:id] ||= h.generate_id
138
+ end
140
139
 
141
- # the ancestor section
142
- s = Section.new
143
- s.section_level = 0
140
+ stack = []
141
+
142
+ # the ancestor section
143
+ s = Section.new
144
+ s.section_level = 0
144
145
 
145
- stack.push s
146
+ stack.push s
146
147
 
147
- i = 0;
148
- while i < @children.size
149
-
150
- while i < @children.size
151
- if @children[i].node_type == :header
152
- level = @children[i].meta[:level]
153
- break if level <= stack.last.section_level+1
154
- end
148
+ i = 0;
149
+ while i < @children.size
150
+ while i < @children.size
151
+ if @children[i].node_type == :header
152
+ level = @children[i].level
153
+ break if level <= stack.last.section_level+1
154
+ end
155
155
 
156
- stack.last.immediate_children.push @children[i]
157
- i += 1
158
- end
156
+ stack.last.immediate_children.push @children[i]
157
+ i += 1
158
+ end
159
159
 
160
- break if i>=@children.size
160
+ break if i>=@children.size
161
161
 
162
- header = @children[i]
163
- level = header.meta[:level]
162
+ header = @children[i]
163
+ level = header.level
164
164
 
165
- if level > stack.last.section_level
166
- # this level is inside
165
+ if level > stack.last.section_level
166
+ # this level is inside
167
167
 
168
- s2 = Section.new
169
- s2.section_level = level
170
- s2.header_element = header
171
- header.instance_variable_set :@section, s2
168
+ s2 = Section.new
169
+ s2.section_level = level
170
+ s2.header_element = header
171
+ header.instance_variable_set :@section, s2
172
172
 
173
- stack.last.section_children.push s2
174
- stack.push s2
173
+ stack.last.section_children.push s2
174
+ stack.push s2
175
175
 
176
- i+=1
177
- elsif level == stack.last.section_level
178
- # this level is a sibling
179
- stack.pop
180
- else
181
- # this level is a parent
182
- stack.pop
183
- end
176
+ i+=1
177
+ elsif level == stack.last.section_level
178
+ # this level is a sibling
179
+ stack.pop
180
+ else
181
+ # this level is a parent
182
+ stack.pop
183
+ end
184
184
 
185
- end
185
+ end
186
186
 
187
- # If there is only one big header, then assume
188
- # it is the master
189
- if s.section_children.size == 1
190
- s = s.section_children.first
191
- end
187
+ # If there is only one big header, then assume
188
+ # it is the master
189
+ if s.section_children.size == 1
190
+ s = s.section_children.first
191
+ end
192
192
 
193
- # Assign section numbers
194
- s.numerate
193
+ # Assign section numbers
194
+ s.numerate
195
195
 
196
- s
196
+ s
197
+ end
197
198
  end
198
-
199
199
  end
@@ -0,0 +1,33 @@
1
+ require 'maruku'
2
+
3
+ text = <<EOF
4
+ Chapter 1
5
+ =========
6
+
7
+ It was a stormy and rainy night.
8
+
9
+ EOF
10
+
11
+ invalid = <<EOF
12
+
13
+ This is a [bad link.
14
+
15
+ EOF
16
+
17
+ Maruku.new(text).to_html
18
+
19
+ s = ""
20
+
21
+ begin
22
+ Maruku.new(invalid, {:on_error => :raise, :error_stream => s})
23
+ puts "Error! It should have thrown an exception."
24
+ rescue
25
+ # puts "ok, got error"
26
+ end
27
+
28
+ begin
29
+ Maruku.new(invalid, {:on_error => :warning, :error_stream => s})
30
+ rescue
31
+ puts "Error! It should not have thrown an exception."
32
+ end
33
+
@@ -1,3 +1,4 @@
1
+ #--
1
2
  # Copyright (C) 2006 Andrea Censi <andrea (at) rubyforge.org>
2
3
  #
3
4
  # This file is part of Maruku.
@@ -15,9 +16,10 @@
15
16
  # You should have received a copy of the GNU General Public License
16
17
  # along with Maruku; if not, write to the Free Software
17
18
  # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
+ #++
18
20
 
19
- class Maruku
20
- Version = '0.3.0'
21
+ module MaRuKu
22
+ Version = '0.4.0'
21
23
 
22
24
  MarukuURL = 'http://maruku.rubyforge.org/'
23
25
 
@@ -29,4 +31,8 @@ class Maruku
29
31
  true
30
32
  end
31
33
 
34
+ def new_meta_data?
35
+ true
36
+ end
37
+
32
38
  end
@@ -17,17 +17,20 @@ Operation Tigra Genesis is going well.
17
17
  md_el(:document,[
18
18
  md_par([
19
19
  "The ",
20
- md_el(:abbreviation,["HTML"] , {:title=>"Hyper Text Markup Language"}),
21
- " specification is maintained by the ",
22
- md_el(:abbreviation,["W3C"] , {:title=>"World Wide Web Consortium"}),
23
- "."
20
+ md_el(:abbr,["HTML"],{:title=>"Hyper Text Markup Language"},[]),
21
+ " specification is maintained by the ",
22
+ md_el(:abbr,["W3C"],{:title=>"World Wide Web Consortium"},[]),
23
+ "."
24
24
  ]),
25
- md_par([
25
+ md_el(:abbr_def,[],{:text=>"Hyper Text Markup Language",:abbr=>"HTML"},[]),
26
+ md_el(:abbr_def,[],{:text=>"World Wide Web Consortium",:abbr=>"W3C"},[]),
27
+ md_par([
26
28
  "Operation ",
27
- md_el(:abbreviation,["Tigra Genesis"] ),
28
- " is going well."
29
- ])
30
- ] )
29
+ md_el(:abbr,["Tigra Genesis"],{:title=>nil},[]),
30
+ " is going well."
31
+ ]),
32
+ md_el(:abbr_def,[],{:text=>nil,:abbr=>"Tigra Genesis"},[])
33
+ ],{},[])
31
34
  *** Output of to_html ***
32
35
 
33
36
  <p>The <abbr title='Hyper Text Markup Language'>HTML</abbr> specification is maintained by the <abbr title='World Wide Web Consortium'>W3C</abbr>.</p>
@@ -40,8 +43,16 @@ The HTML specification is maintained by the W3C.
40
43
  Operation Tigra Genesis is going well.
41
44
 
42
45
 
43
- *** Output of to_s ***
44
- The HTML specification is maintained by the W3C.Operation Tigra Genesis is going well.
46
+ *** Output of to_md ***
47
+ The HTMLspecification is maintained by
48
+ the W3C.
49
+
50
+ *[HTML]: Hyper Text Markup Language
51
+ *[W3C]: World Wide Web Consortium
52
+ Operation Tigra Genesisis going well.
53
+
54
+ *[Tigra Genesis]:
55
+
45
56
  *** Output of to_s ***
46
57
  The HTML specification is maintained by the W3C.Operation Tigra Genesis is going well.
47
58
  *** EOF ***
@@ -64,8 +75,8 @@ The HTML specification is maintained by the W3C.Operation Tigra Genesis is going
64
75
 
65
76
  *** Output of Markdown.pl (parsed) ***
66
77
  <p>The HTML specification is maintained by the W3C.</p
67
- ><p>*[HTML]: Hyper Text Markup Language
68
- *[W3C]: World Wide Web Consortium</p
69
- ><p>Operation Tigra Genesis is going well.</p
70
- ><p>*[Tigra Genesis]:</p
71
- >
78
+ ><p>*[HTML]: Hyper Text Markup Language
79
+ *[W3C]: World Wide Web Consortium</p
80
+ ><p>Operation Tigra Genesis is going well.</p
81
+ ><p>*[Tigra Genesis]:</p
82
+ >
@@ -0,0 +1,89 @@
1
+ This is a simple test for attributes
2
+ *** Parameters: ***
3
+ {}
4
+ *** Markdown input: ***
5
+
6
+ Header with attributes {#header1}
7
+ ----------------------
8
+
9
+ ### Header with attributes ### {#header2}
10
+
11
+ ### Header no attributes ###
12
+
13
+ {warn2}Paragraph with a.
14
+ {#par1}
15
+
16
+ Paragraph with *emphasis*{hello notfound}
17
+ {#par2}
18
+
19
+ {hello}: .chello
20
+ *** Output of inspect ***
21
+ md_el(:document,[
22
+ md_el(:header,["Header with attributes"],{:level=>2},[[:id, "header1"]]),
23
+ md_el(:header,["Header with attributes"],{:level=>3},[[:id, "header2"]]),
24
+ md_el(:header,["Header no attributes"],{:level=>3},[[:id, "par1"]]),
25
+ md_par([
26
+ "Paragraph with ",
27
+ md_em(["emphasis"], [[:ref, "hello"], [:ref, "notfound"]]),
28
+ md_ial([[:ref, "hello"], [:ref, "notfound"]])
29
+ ], [[:id, "par2"]]),
30
+ md_el(:ald,[],{:ald_id=>"hello",:ald=>[[:class, "chello"]]},[])
31
+ ],{},[])
32
+ *** Output of to_html ***
33
+
34
+ <h2 id='header1'>Header with attributes</h2>
35
+
36
+ <h3 id='header2'>Header with attributes</h3>
37
+
38
+ <h3 id='par1'>Header no attributes</h3>
39
+
40
+ <p id='par2'>Paragraph with <em class='chello'>emphasis</em></p>
41
+
42
+ *** Output of to_latex ***
43
+ \hypertarget{header1}{}\subsection*{{Header with attributes}}\label{header1}
44
+
45
+ \hypertarget{header2}{}\subsubsection*{{Header with attributes}}\label{header2}
46
+
47
+ \hypertarget{par1}{}\subsubsection*{{Header no attributes}}\label{par1}
48
+
49
+ Paragraph with {\em emphasis}
50
+
51
+
52
+ *** Output of to_md ***
53
+ Header with attributesHeader with attributesHeader no attributesParagraph with emphasis
54
+ *** Output of to_s ***
55
+ Header with attributesHeader with attributesHeader no attributesParagraph with emphasis
56
+ *** EOF ***
57
+
58
+
59
+
60
+ OK!
61
+
62
+
63
+
64
+ *** Output of Markdown.pl ***
65
+ <h2>Header with attributes {#header1} </h2>
66
+
67
+ <h3>Header with attributes ### {#header2}</h3>
68
+
69
+ <h3>Header no attributes</h3>
70
+
71
+ <p>{warn2}Paragraph with a.
72
+ {#par1}</p>
73
+
74
+ <p>Paragraph with <em>emphasis</em>{hello notfound}
75
+ {#par2}</p>
76
+
77
+ <p>{hello}: .chello</p>
78
+
79
+ *** Output of Markdown.pl (parsed) ***
80
+ <h2>Header with attributes {#header1} </h2
81
+ ><h3>Header with attributes ### {#header2}</h3
82
+ ><h3>Header no attributes</h3
83
+ ><p>{warn2}Paragraph with a.
84
+ {#par1}</p
85
+ ><p>Paragraph with <em>emphasis</em
86
+ >{hello notfound}
87
+ {#par2}</p
88
+ ><p>{hello}: .chello</p
89
+ >
@@ -0,0 +1,51 @@
1
+
2
+ *** Parameters: ***
3
+ {}
4
+ *** Markdown input: ***
5
+
6
+ Paragraph
7
+ {a}
8
+
9
+
10
+ {a}: b
11
+ {b}: a
12
+
13
+ *** Output of inspect ***
14
+ md_el(:document,[
15
+ md_par(["Paragraph"], [[:ref, "a"]]),
16
+ md_el(:ald,[],{:ald_id=>"a",:ald=>[[:ref, "b"]]},[]),
17
+ md_el(:ald,[],{:ald_id=>"b",:ald=>[[:ref, "a"]]},[])
18
+ ],{},[])
19
+ *** Output of to_html ***
20
+
21
+ <p>Paragraph</p>
22
+
23
+ *** Output of to_latex ***
24
+ Paragraph
25
+
26
+
27
+ *** Output of to_md ***
28
+ Paragraph
29
+ *** Output of to_s ***
30
+ Paragraph
31
+ *** EOF ***
32
+
33
+
34
+
35
+ OK!
36
+
37
+
38
+
39
+ *** Output of Markdown.pl ***
40
+ <p>Paragraph
41
+ {a}</p>
42
+
43
+ <p>{a}: b
44
+ {b}: a</p>
45
+
46
+ *** Output of Markdown.pl (parsed) ***
47
+ <p>Paragraph
48
+ {a}</p
49
+ ><p>{a}: b
50
+ {b}: a</p
51
+ >