maruku 0.5.6 → 0.5.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. data/bin/maruku +16 -9
  2. data/bin/marutest +2 -0
  3. data/docs/maruku.md +0 -51
  4. data/lib/maruku/input/linesource.rb +1 -0
  5. data/lib/maruku/input/parse_block.rb +28 -19
  6. data/lib/maruku/input/parse_doc.rb +1 -0
  7. data/lib/maruku/output/to_html.rb +24 -8
  8. data/lib/maruku/output/to_latex.rb +1 -1
  9. data/lib/maruku/version.rb +1 -1
  10. data/tests/unittest/abbreviations.md +2 -12
  11. data/tests/unittest/alt.md +1 -10
  12. data/tests/unittest/attributes/att2.md +1 -3
  13. data/tests/unittest/attributes/att3.md +1 -11
  14. data/tests/unittest/attributes/attributes.md +1 -16
  15. data/tests/unittest/attributes/circular.md +1 -9
  16. data/tests/unittest/attributes/default.md +1 -10
  17. data/tests/unittest/blank.md +1 -9
  18. data/tests/unittest/blanks_in_code.md +1 -26
  19. data/tests/unittest/bug_def.md +1 -8
  20. data/tests/unittest/bug_table.md +1 -11
  21. data/tests/unittest/code.md +1 -14
  22. data/tests/unittest/code2.md +1 -16
  23. data/tests/unittest/code3.md +1 -26
  24. data/tests/unittest/data_loss.md +1 -12
  25. data/tests/unittest/easy.md +1 -11
  26. data/tests/unittest/email.md +3 -11
  27. data/tests/unittest/encoding/iso-8859-1.md +1 -9
  28. data/tests/unittest/encoding/utf-8.md +1 -7
  29. data/tests/unittest/entities.md +78 -35
  30. data/tests/unittest/escaping.md +5 -25
  31. data/tests/unittest/extra_dl.md +1 -10
  32. data/tests/unittest/extra_header_id.md +1 -18
  33. data/tests/unittest/extra_table1.md +1 -8
  34. data/tests/unittest/footnotes.md +1 -21
  35. data/tests/unittest/headers.md +1 -11
  36. data/tests/unittest/hex_entities.md +1 -8
  37. data/tests/unittest/hrule.md +1 -8
  38. data/tests/unittest/html2.md +1 -12
  39. data/tests/unittest/html3.md +1 -15
  40. data/tests/unittest/html4.md +1 -6
  41. data/tests/unittest/html5.md +1 -8
  42. data/tests/unittest/ie.md +32 -33
  43. data/tests/unittest/images.md +2 -19
  44. data/tests/unittest/images2.md +1 -10
  45. data/tests/unittest/inline_html.md +22 -145
  46. data/tests/unittest/inline_html2.md +1 -3
  47. data/tests/unittest/links.md +22 -8
  48. data/tests/unittest/links2.md +1 -8
  49. data/tests/unittest/list1.md +1 -19
  50. data/tests/unittest/list12.md +43 -0
  51. data/tests/unittest/list2.md +1 -21
  52. data/tests/unittest/list3.md +1 -29
  53. data/tests/unittest/list4.md +1 -19
  54. data/tests/unittest/lists.md +1 -59
  55. data/tests/unittest/lists10.md +2 -13
  56. data/tests/unittest/lists11.md +2 -28
  57. data/tests/unittest/lists6.md +1 -0
  58. data/tests/unittest/lists7.md +56 -8
  59. data/tests/unittest/lists7b.md +136 -0
  60. data/tests/unittest/lists8.md +1 -22
  61. data/tests/unittest/lists9.md +1 -21
  62. data/tests/unittest/lists_after_paragraph.md +3 -48
  63. data/tests/unittest/lists_ol.md +1 -81
  64. data/tests/unittest/loss.md +1 -4
  65. data/tests/unittest/math/equations.md +1 -14
  66. data/tests/unittest/math/inline.md +1 -15
  67. data/tests/unittest/math/math2.md +38 -12
  68. data/tests/unittest/math/notmath.md +1 -9
  69. data/tests/unittest/math/table.md +1 -9
  70. data/tests/unittest/math/table2.md +33 -10
  71. data/tests/unittest/misc_sw.md +1 -195
  72. data/tests/unittest/notyet/escape.md +3 -13
  73. data/tests/unittest/notyet/header_after_par.md +1 -11
  74. data/tests/unittest/notyet/ticks.md +2 -11
  75. data/tests/unittest/notyet/triggering.md +1 -32
  76. data/tests/unittest/olist.md +1 -15
  77. data/tests/unittest/one.md +1 -8
  78. data/tests/unittest/paragraph.md +1 -8
  79. data/tests/unittest/paragraph_rules/dont_merge_ref.md +1 -10
  80. data/tests/unittest/paragraph_rules/tab_is_blank.md +1 -9
  81. data/tests/unittest/paragraphs.md +1 -14
  82. data/tests/unittest/recover/recover_links.md +1 -6
  83. data/tests/unittest/references/long_example.md +1 -17
  84. data/tests/unittest/references/spaces_and_numbers.md +1 -0
  85. data/tests/unittest/smartypants.md +21 -6
  86. data/tests/unittest/syntax_hl.md +1 -24
  87. data/tests/unittest/table_attributes.md +1 -8
  88. data/tests/unittest/test.md +1 -5
  89. data/tests/unittest/wrapping.md +1 -18
  90. data/tests/unittest/xml.md +1 -15
  91. data/tests/unittest/xml2.md +1 -3
  92. data/tests/unittest/xml3.md +1 -9
  93. data/tests/unittest/xml_instruction.md +1 -10
  94. metadata +211 -215
data/bin/maruku CHANGED
@@ -136,22 +136,29 @@ inputs.each do |f, input|
136
136
  dir = File.dirname(f)
137
137
  job = File.join(dir, File.basename(f, File.extname(f)))
138
138
  output_file = job + suffix
139
+ else
140
+ job = File.basename(output_file, File.extname(output_file))
139
141
  end
140
142
 
141
143
  if output_file == "-"
142
144
  $stderr.puts "Writing to standard output"
143
145
  $stdout.puts out
144
146
  else
145
- $stderr.puts "Writing to #{output_file}"
146
- File.open(output_file,'w') do |f| f.puts out end
147
- end
148
147
 
149
- if export == :pdf
150
- cmd = "pdflatex '#{job}' -interaction=nonstopmode "+
151
- "'-output-directory=#{dir}' "
152
- # run twice for cross references
153
- system cmd
154
- system cmd
148
+ if not (export == :pdf)
149
+ $stderr.puts "Writing to #{output_file}"
150
+ File.open(output_file,'w') do |f| f.puts out end
151
+ else
152
+ $stderr.puts "Writing to #{job}.tex"
153
+ File.open("#{job}.tex",'w') do |f| f.puts out end
154
+ cmd = "pdflatex '#{job}.tex' -interaction=nonstopmode "+
155
+ "'-output-directory=#{dir}' "
156
+ $stderr.puts "maruku: executing $ #{cmd}"
157
+ # run twice for cross references
158
+ system cmd
159
+ system cmd
160
+ end
161
+
155
162
  end
156
163
  else # write to stdout
157
164
  $stderr.puts "Writing to standard output"
@@ -147,6 +147,8 @@ def run_test(filename, its_ok, verbose=true)
147
147
 
148
148
 
149
149
  TOTEST.each do |x|
150
+ expected[x].strip!
151
+ actual[x].strip!
150
152
  if not equals(expected[x], actual[x])
151
153
  if its_ok.include? x
152
154
  expected[x] = actual[x]
@@ -123,29 +123,6 @@ Have fun!
123
123
 
124
124
  See the [changelog](http://maruku.rubyforge.org/changelog.html#stable).
125
125
 
126
- Download {#download}
127
- --------
128
-
129
- The development site is <http://rubyforge.org/projects/maruku/>.
130
-
131
- Install with:
132
-
133
- $ gem install maruku
134
- {:shell}
135
-
136
- Released files can also be seen at <http://rubyforge.org/frs/?group_id=2795>.
137
-
138
- Anonymous access to the repository is possible with:
139
-
140
- $ svn checkout svn://rubyforge.org/var/svn/maruku/trunk
141
- {:shell}
142
-
143
- If you want commit access to the repository, just create an account on Rubyforge and [drop me a mail][contact].
144
-
145
- ### Bugs report ###
146
-
147
- Use the [tracker][tracker] or [drop me an email][contact].
148
-
149
126
 
150
127
  Usage
151
128
  --------
@@ -187,34 +164,6 @@ transform to PDF:
187
164
  {:shell}
188
165
 
189
166
 
190
- Maruku and Bluecloth {#maruku-and-bluecloth}
191
- --------------------
192
-
193
- The other Ruby implementation of Markdown is [Bluecloth].
194
-
195
- Maruku is much different in philosophy from Bluecloth: the biggest
196
- difference is that *parsing* is separated from *rendering*.
197
- In Maruku, an in-memory representation of the Markdown
198
- document is created. Instead, Bluecloth mantains the document in
199
- memory as a String at all times, and does a series of `gsub`
200
- to transform to HTML.
201
-
202
- Maruku is usually faster than Bluecloth. Bluecloth is faster
203
- for very small documents. Bluecloth sometimes chokes on very big
204
- documents (it is reported that the blame should be on Ruby's regexp
205
- implementation).
206
-
207
- This is the canonical benchmark (the Markdown specification),
208
- executed with Ruby 1.8.5 on a Powerbook 1.5GhZ:
209
-
210
- BlueCloth (to_html): parsing 0.01 sec + rendering 1.87 sec = 1.88 sec (1.00x)
211
- Maruku (to_html): parsing 0.66 sec + rendering 0.43 sec = 1.09 sec (1.73x)
212
- Maruku (to_latex): parsing 0.67 sec + rendering 0.23 sec = 0.90 sec (2.10x)
213
-
214
- Please note that Maruku has a lot more features and therefore is
215
- looking for much more patterns in the file.
216
-
217
-
218
167
 
219
168
  Maruku summary of features {#features}
220
169
  --------------------------
@@ -28,6 +28,7 @@ module MaRuKu; module In; module Markdown; module BlockLevelParser
28
28
 
29
29
  class LineSource
30
30
  include MaRuKu::Strings
31
+ attr_reader :parent
31
32
 
32
33
  def initialize(lines, parent=nil, parent_offset=nil)
33
34
  raise "NIL lines? " if not lines
@@ -65,22 +65,8 @@ module MaRuKu; module In; module Markdown; module BlockLevelParser
65
65
  when :ald
66
66
  output.push read_ald(src)
67
67
  when :text
68
- if src.cur_line =~ MightBeTableHeader and
69
- (src.next_line && src.next_line =~ TableSeparator)
70
- output.push read_table(src)
71
- elsif [:header1,:header2].include? src.next_line.md_type
72
- output.push read_header12(src)
73
- elsif eventually_comes_a_def_list(src)
74
- definition = read_definition(src)
75
- if output.last.kind_of?(MDElement) &&
76
- output.last.node_type == :definition_list then
77
- output.last.children << definition
78
- else
79
- output.push md_el(:definition_list, [definition])
80
- end
81
- else # Start of a paragraph
82
- output.push read_paragraph(src)
83
- end
68
+ # paragraph, or table, or definition list
69
+ read_text_material(src, output)
84
70
  when :header2, :hrule
85
71
  # hrule
86
72
  src.shift_line
@@ -102,7 +88,12 @@ module MaRuKu; module In; module Markdown; module BlockLevelParser
102
88
  when :raw_html; e = read_raw_html(src); output << e if e
103
89
 
104
90
  when :footnote_text; output.push read_footnote_text(src)
105
- when :ref_definition; read_ref_definition(src, output)
91
+ when :ref_definition;
92
+ if src.parent && (src.cur_index == 0)
93
+ read_text_material(src, output)
94
+ else
95
+ read_ref_definition(src, output)
96
+ end
106
97
  when :abbreviation; output.push read_abbreviation(src)
107
98
  when :xml_instr; read_xml_instruction(src, output)
108
99
  when :metadata;
@@ -149,6 +140,24 @@ module MaRuKu; module In; module Markdown; module BlockLevelParser
149
140
  output
150
141
  end
151
142
 
143
+ def read_text_material(src, output)
144
+ if src.cur_line =~ MightBeTableHeader and
145
+ (src.next_line && src.next_line =~ TableSeparator)
146
+ output.push read_table(src)
147
+ elsif [:header1,:header2].include? src.next_line.md_type
148
+ output.push read_header12(src)
149
+ elsif eventually_comes_a_def_list(src)
150
+ definition = read_definition(src)
151
+ if output.last.kind_of?(MDElement) &&
152
+ output.last.node_type == :definition_list then
153
+ output.last.children << definition
154
+ else
155
+ output.push md_el(:definition_list, [definition])
156
+ end
157
+ else # Start of a paragraph
158
+ output.push read_paragraph(src)
159
+ end
160
+ end
152
161
 
153
162
 
154
163
  def read_ald(src)
@@ -274,9 +283,9 @@ module MaRuKu; module In; module Markdown; module BlockLevelParser
274
283
  item_type = src.cur_line.md_type
275
284
  first = src.shift_line
276
285
 
277
- # Ugly things going on inside `read_indented_content`
278
286
  indentation = spaces_before_first_char(first)
279
287
  break_list = [:ulist, :olist, :ial]
288
+ # Ugly things going on inside `read_indented_content`
280
289
  lines, want_my_paragraph =
281
290
  read_indented_content(src,indentation, break_list, item_type)
282
291
 
@@ -285,7 +294,7 @@ module MaRuKu; module In; module Markdown; module BlockLevelParser
285
294
  stripped = first[indentation, first.size-1]
286
295
  lines.unshift stripped
287
296
 
288
- #dbg_describe_ary(lines, 'LIST ITEM ')
297
+ # dbg_describe_ary(lines, 'LIST ITEM ')
289
298
 
290
299
  src2 = LineSource.new(lines, src, parent_offset)
291
300
  children = parse_blocks(src2)
@@ -173,6 +173,7 @@ Disabled by default because of security concerns.
173
173
  self.abbreviations.each do |abbrev, title|
174
174
  reg = Regexp.new(Regexp.escape(abbrev))
175
175
  self.replace_each_string do |s|
176
+ # bug if many abbreviations are present (agorf)
176
177
  if m = reg.match(s)
177
178
  e = md_abbr(abbrev.dup, title ? title.dup : nil)
178
179
  [m.pre_match, e, m.post_match]
@@ -18,9 +18,16 @@
18
18
  # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
19
  #++
20
20
 
21
-
22
21
  require 'rexml/document'
23
22
 
23
+ begin
24
+ require 'rexml/formatters/pretty'
25
+ require 'rexml/formatters/default'
26
+ $rexml_new_version = true
27
+ rescue LoadError
28
+ $rexml_new_version = false
29
+ end
30
+
24
31
  class String
25
32
  # A string is rendered into HTML by creating
26
33
  # a REXML::Text node. REXML takes care of all the encoding.
@@ -30,11 +37,6 @@ class String
30
37
  end
31
38
 
32
39
 
33
- class REXML::Element
34
- # We only want to output the children in Maruku::to_html
35
- public :write_children
36
- end
37
-
38
40
  # This module groups all functions related to HTML export.
39
41
  module MaRuKu; module Out; module HTML
40
42
  include REXML
@@ -42,7 +44,7 @@ module MaRuKu; module Out; module HTML
42
44
  # Render as an HTML fragment (no head, just the content of BODY). (returns a string)
43
45
  def to_html(context={})
44
46
  indent = context[:indent] || -1
45
- ie_hack = context[:ie_hack] ||true
47
+ ie_hack = context[:ie_hack] || true
46
48
 
47
49
  div = Element.new 'dummy'
48
50
  children_to_html.each do |e|
@@ -60,7 +62,21 @@ module MaRuKu; module Out; module HTML
60
62
  # REXML Bug? if indent!=-1 whitespace is not respected for 'pre' elements
61
63
  # containing code.
62
64
  xml =""
63
- div.write_children(xml,indent,transitive=true,ie_hack)
65
+
66
+ if $rexml_new_version
67
+ formatter = if indent > -1
68
+ REXML::Formatters::Pretty.new( indent, ie_hack )
69
+ else
70
+ REXML::Formatters::Default.new( ie_hack )
71
+ end
72
+ formatter.write( div, xml)
73
+ else
74
+ div.write(xml,indent,transitive=true,ie_hack)
75
+ end
76
+
77
+ xml.gsub!(/\A<dummy>\s*/,'')
78
+ xml.gsub!(/\s*<\/dummy>\Z/,'')
79
+ xml.gsub!(/\A<dummy\s*\/>/,'')
64
80
  xml
65
81
  end
66
82
 
@@ -365,7 +365,7 @@ Otherwise, a standard `verbatim` environment is used.
365
365
  color = get_setting(:code_background_color)
366
366
  colorspec = latex_color(color, 'colorbox')
367
367
 
368
- "#{colorspec}{\\tt #{s}}"
368
+ "{#{colorspec}{\\tt #{s}}}"
369
369
  end
370
370
 
371
371
  def to_latex_immediate_link
@@ -19,7 +19,7 @@
19
19
  #++
20
20
 
21
21
  module MaRuKu
22
- Version = '0.5.6'
22
+ Version = '0.5.7'
23
23
 
24
24
  MarukuURL = 'http://maruku.rubyforge.org/'
25
25
 
@@ -32,17 +32,13 @@ md_el(:document,[
32
32
  md_el(:abbr_def,[],{:abbr=>"Tigra Genesis",:text=>nil},[])
33
33
  ],{},[])
34
34
  *** Output of to_html ***
35
-
36
35
  <p>The <abbr title='Hyper Text Markup Language'>HTML</abbr> specification is maintained by the <abbr title='World Wide Web Consortium'>W3C</abbr>.</p>
37
36
 
38
37
  <p>Operation <abbr>Tigra Genesis</abbr> is going well.</p>
39
-
40
38
  *** Output of to_latex ***
41
39
  The HTML specification is maintained by the W3C.
42
40
 
43
41
  Operation Tigra Genesis is going well.
44
-
45
-
46
42
  *** Output of to_md ***
47
43
  The HTMLspecification is maintained by
48
44
  the W3C.
@@ -51,8 +47,7 @@ the W3C.
51
47
  *[W3C]: World Wide Web Consortium
52
48
  Operation Tigra Genesisis going well.
53
49
 
54
- *[Tigra Genesis]:
55
-
50
+ *[Tigra Genesis]:
56
51
  *** Output of to_s ***
57
52
  The HTML specification is maintained by the W3C.Operation Tigra Genesis is going well.
58
53
  *** EOF ***
@@ -74,9 +69,4 @@ The HTML specification is maintained by the W3C.Operation Tigra Genesis is going
74
69
  <p>*[Tigra Genesis]:</p>
75
70
 
76
71
  *** Output of Markdown.pl (parsed) ***
77
- <p>The HTML specification is maintained by the W3C.</p
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
- >
72
+ Error: #<NoMethodError: private method `write_children' called for <div> ... </>:REXML::Element>
@@ -8,17 +8,11 @@ Write a comment here
8
8
  *** Output of inspect ***
9
9
  md_el(:document,[md_par([md_im_image(["bar"], "/foo.jpg", nil)])],{},[])
10
10
  *** Output of to_html ***
11
-
12
11
  <p><img src='/foo.jpg' alt='bar' /></p>
13
-
14
12
  *** Output of to_latex ***
15
13
 
16
-
17
-
18
14
  *** Output of to_md ***
19
15
  bar
20
-
21
-
22
16
  *** Output of to_s ***
23
17
  bar
24
18
  *** EOF ***
@@ -33,7 +27,4 @@ bar
33
27
  <p><img src="/foo.jpg" alt="bar" title="" /></p>
34
28
 
35
29
  *** Output of Markdown.pl (parsed) ***
36
- <p
37
- ><img title='' src='/foo.jpg' alt='bar'/
38
- ></p
39
- >
30
+ Error: #<NoMethodError: private method `write_children' called for <div> ... </>:REXML::Element>
@@ -31,6 +31,4 @@ md_el(:document,[
31
31
  {:b: a}</p>
32
32
 
33
33
  *** Output of Markdown.pl (parsed) ***
34
- <p>{a}: a
35
- {:b: a}</p
36
- >
34
+ Error: #<NoMethodError: private method `write_children' called for <div> ... </>:REXML::Element>
@@ -13,23 +13,17 @@ md_el(:document,[
13
13
  md_par(["Paragraph2"], [[:id, "par2"]])
14
14
  ],{},[])
15
15
  *** Output of to_html ***
16
-
17
16
  <p id='par1'>Paragraph1</p>
18
17
 
19
18
  <p id='par2'>Paragraph2</p>
20
-
21
19
  *** Output of to_latex ***
22
20
  Paragraph1
23
21
 
24
22
  Paragraph2
25
-
26
-
27
23
  *** Output of to_md ***
28
24
  Paragraph1
29
25
 
30
26
  Paragraph2
31
-
32
-
33
27
  *** Output of to_s ***
34
28
  Paragraph1Paragraph2
35
29
  *** EOF ***
@@ -48,8 +42,4 @@ Paragraph1Paragraph2
48
42
  Paragraph2</p>
49
43
 
50
44
  *** Output of Markdown.pl (parsed) ***
51
- <p>Paragraph1
52
- {:#par1}</p
53
- ><p>{:#par2}
54
- Paragraph2</p
55
- >
45
+ Error: #<NoMethodError: private method `write_children' called for <div> ... </>:REXML::Element>
@@ -30,7 +30,6 @@ md_el(:document,[
30
30
  md_el(:ald,[],{:ald=>[[:class, "chello"]],:ald_id=>"hello"},[])
31
31
  ],{},[])
32
32
  *** Output of to_html ***
33
-
34
33
  <h2 id='header1'>Header with attributes</h2>
35
34
 
36
35
  <h3 id='header2'>Header with attributes</h3>
@@ -40,7 +39,6 @@ md_el(:document,[
40
39
  <p id='par1'>Paragraph with a.</p>
41
40
 
42
41
  <p id='par2'>Paragraph with <em class='chello'>emphasis</em></p>
43
-
44
42
  *** Output of to_latex ***
45
43
  \hypertarget{header1}{}\subsection*{{Header with attributes}}\label{header1}
46
44
 
@@ -51,14 +49,10 @@ md_el(:document,[
51
49
  Paragraph with a.
52
50
 
53
51
  Paragraph with \emph{emphasis}
54
-
55
-
56
52
  *** Output of to_md ***
57
53
  Header with attributesHeader with attributesHeader no attributesParagraph with a.
58
54
 
59
55
  Paragraph with emphasis
60
-
61
-
62
56
  *** Output of to_s ***
63
57
  Header with attributesHeader with attributesHeader no attributesParagraph with a.Paragraph with emphasis
64
58
  *** EOF ***
@@ -85,13 +79,4 @@ Header with attributesHeader with attributesHeader no attributesParagraph with a
85
79
  <p>{:hello: .chello}</p>
86
80
 
87
81
  *** Output of Markdown.pl (parsed) ***
88
- <h2>Header with attributes {#header1} </h2
89
- ><h3>Header with attributes ### {#header2}</h3
90
- ><h3>Header no attributes</h3
91
- ><p>{:warn2}Paragraph with a.
92
- {#par1}</p
93
- ><p>Paragraph with <em>emphasis</em
94
- >{:hello notfound}
95
- {#par2}</p
96
- ><p>{:hello: .chello}</p
97
- >
82
+ Error: #<NoMethodError: private method `write_children' called for <div> ... </>:REXML::Element>