maruku 0.5.9 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (135) hide show
  1. data/bin/maruku +6 -1
  2. data/bin/marutest +25 -18
  3. data/lib/maruku.rb +3 -0
  4. data/lib/maruku/ext/div.rb +39 -6
  5. data/lib/maruku/ext/math/latex_fix.rb +1 -0
  6. data/lib/maruku/ext/math/mathml_engines/blahtex.rb +9 -8
  7. data/lib/maruku/ext/math/parsing.rb +15 -1
  8. data/lib/maruku/ext/math/to_html.rb +34 -17
  9. data/lib/maruku/ext/math/to_latex.rb +4 -0
  10. data/lib/maruku/helpers.rb +3 -3
  11. data/lib/maruku/input/charsource.rb +1 -1
  12. data/lib/maruku/input/parse_block.rb +1 -0
  13. data/lib/maruku/input/parse_doc.rb +12 -5
  14. data/lib/maruku/input/parse_span_better.rb +24 -10
  15. data/lib/maruku/output/s5/to_s5.rb +14 -1
  16. data/lib/maruku/output/to_html.rb +20 -1
  17. data/lib/maruku/output/to_latex.rb +27 -0
  18. data/lib/maruku/output/to_latex_entities.rb +2 -2
  19. data/lib/maruku/output/to_s.rb +5 -2
  20. data/lib/maruku/string_utils.rb +2 -2
  21. data/lib/maruku/structures.rb +2 -0
  22. data/lib/maruku/tests/new_parser.rb +5 -2
  23. data/lib/maruku/version.rb +1 -1
  24. data/tests/bugs/code_in_links.md +85 -0
  25. data/tests/bugs/complex_escaping.md +34 -0
  26. data/tests/unittest/abbreviations.md +2 -10
  27. data/tests/unittest/alt.md +2 -3
  28. data/tests/unittest/attributes/att2.md +2 -4
  29. data/tests/unittest/attributes/att3.md +2 -7
  30. data/tests/unittest/attributes/attributes.md +2 -15
  31. data/tests/unittest/attributes/circular.md +2 -7
  32. data/tests/unittest/attributes/default.md +2 -6
  33. data/tests/unittest/blank.md +2 -5
  34. data/tests/unittest/blanks_in_code.md +2 -21
  35. data/tests/unittest/bug_def.md +2 -3
  36. data/tests/unittest/bug_table.md +2 -11
  37. data/tests/unittest/code.md +2 -9
  38. data/tests/unittest/code2.md +2 -8
  39. data/tests/unittest/code3.md +2 -21
  40. data/tests/unittest/data_loss.md +2 -7
  41. data/tests/unittest/divs/div1.md +32 -57
  42. data/tests/unittest/divs/div2.md +6 -7
  43. data/tests/unittest/divs/div3_nest.md +8 -13
  44. data/tests/unittest/easy.md +2 -3
  45. data/tests/unittest/email.md +2 -3
  46. data/tests/unittest/encoding/iso-8859-1.md +2 -5
  47. data/tests/unittest/encoding/utf-8.md +2 -5
  48. data/tests/unittest/entities.md +2 -20
  49. data/tests/unittest/escaping.md +2 -12
  50. data/tests/unittest/extra_dl.md +2 -10
  51. data/tests/unittest/extra_header_id.md +2 -13
  52. data/tests/unittest/extra_table1.md +2 -8
  53. data/tests/unittest/footnotes.md +2 -19
  54. data/tests/{bugs/html.md → unittest/hang.md} +9 -9
  55. data/tests/unittest/headers.md +2 -7
  56. data/tests/unittest/hex_entities.md +2 -3
  57. data/tests/unittest/hrule.md +2 -11
  58. data/tests/unittest/html2.md +2 -6
  59. data/tests/unittest/html3.md +2 -6
  60. data/tests/unittest/html4.md +2 -7
  61. data/tests/unittest/html5.md +2 -5
  62. data/tests/unittest/ie.md +2 -23
  63. data/tests/unittest/images.md +2 -14
  64. data/tests/unittest/images2.md +2 -5
  65. data/tests/unittest/inline_html.md +6 -102
  66. data/tests/unittest/inline_html2.md +2 -5
  67. data/tests/unittest/links.md +17 -50
  68. data/tests/unittest/links2.md +2 -3
  69. data/tests/unittest/list1.md +2 -10
  70. data/tests/unittest/list12.md +2 -5
  71. data/tests/unittest/list2.md +2 -10
  72. data/tests/unittest/list3.md +2 -14
  73. data/tests/unittest/list4.md +2 -17
  74. data/tests/unittest/lists.md +2 -39
  75. data/tests/unittest/lists10.md +2 -7
  76. data/tests/unittest/lists11.md +2 -5
  77. data/tests/unittest/lists6.md +2 -3
  78. data/tests/unittest/lists9.md +2 -11
  79. data/tests/unittest/lists_after_paragraph.md +3 -51
  80. data/tests/unittest/lists_ol.md +2 -52
  81. data/tests/unittest/loss.md +2 -3
  82. data/tests/unittest/math/equations.md +54 -37
  83. data/tests/unittest/math/inline.md +4 -12
  84. data/tests/unittest/math/math2.md +4 -57
  85. data/tests/unittest/math/notmath.md +2 -5
  86. data/tests/unittest/math/table.md +5 -11
  87. data/tests/unittest/math/table2.md +2 -8
  88. data/tests/unittest/misc_sw.md +2 -80
  89. data/tests/unittest/notyet/escape.md +2 -5
  90. data/tests/unittest/notyet/header_after_par.md +2 -13
  91. data/tests/unittest/notyet/ticks.md +2 -3
  92. data/tests/unittest/notyet/triggering.md +2 -39
  93. data/tests/unittest/olist.md +2 -9
  94. data/tests/unittest/one.md +2 -3
  95. data/tests/unittest/paragraph.md +2 -3
  96. data/tests/unittest/paragraph_rules/dont_merge_ref.md +2 -5
  97. data/tests/unittest/paragraph_rules/tab_is_blank.md +2 -5
  98. data/tests/unittest/paragraphs.md +2 -10
  99. data/tests/unittest/pending/amps.md +2 -4
  100. data/tests/unittest/pending/empty_cells.md +2 -6
  101. data/tests/unittest/pending/link.md +2 -21
  102. data/tests/unittest/pending/ref.md +2 -3
  103. data/tests/unittest/recover/recover_links.md +7 -8
  104. data/tests/{bugs → unittest/red_tests}/abbrev.md +12 -103
  105. data/tests/unittest/{lists7.md → red_tests/lists7.md} +2 -13
  106. data/tests/unittest/{lists7b.md → red_tests/lists7b.md} +2 -10
  107. data/tests/unittest/{lists8.md → red_tests/lists8.md} +2 -9
  108. data/tests/unittest/red_tests/xml.md +70 -0
  109. data/tests/unittest/references/long_example.md +2 -7
  110. data/tests/unittest/references/spaces_and_numbers.md +2 -3
  111. data/tests/unittest/smartypants.md +2 -47
  112. data/tests/unittest/syntax_hl.md +2 -18
  113. data/tests/unittest/table_attributes.md +2 -8
  114. data/tests/unittest/test.md +2 -3
  115. data/tests/unittest/underscore_in_words.md +27 -0
  116. data/tests/unittest/wrapping.md +2 -11
  117. data/tests/unittest/xml2.md +2 -5
  118. data/tests/unittest/xml3.md +2 -8
  119. data/tests/unittest/xml_instruction.md +2 -10
  120. data/unit_test_span.sh +2 -1
  121. metadata +242 -241
  122. data/docs/changelog.html +0 -490
  123. data/docs/entity_test.html +0 -258
  124. data/docs/exd.html +0 -307
  125. data/docs/index.html +0 -332
  126. data/docs/markdown_syntax.html +0 -690
  127. data/docs/maruku.html +0 -332
  128. data/docs/proposal.html +0 -326
  129. data/docs/tmp.md +0 -2
  130. data/lib/sort_prof.rb +0 -22
  131. data/tests/bugs/links.md +0 -47
  132. data/tests/diagrams/diagrams.md +0 -302
  133. data/tests/s5/a.md +0 -13
  134. data/tests/s5/instiki+s5.md +0 -105
  135. data/tests/unittest/xml.md +0 -54
data/bin/maruku CHANGED
@@ -3,6 +3,7 @@
3
3
  require 'maruku'
4
4
  require 'optparse'
5
5
 
6
+
6
7
  def cli_puts(s)
7
8
  $stderr.puts(s) if MaRuKu::Globals[:verbose]
8
9
  end
@@ -57,6 +58,10 @@ opt = OptionParser.new do |opts|
57
58
  puts "Maruku #{MaRuKu::Version}"; exit
58
59
  end
59
60
 
61
+ opts.on_tail("--ext EXTENSIONS", "Use maruku extensions (comma separated)" ) do |s|
62
+ s.split(",").each do |e| require "maruku/ext/#{e}"; end
63
+ end
64
+
60
65
  opts.on_tail("-h", "--help", "Show this message") do
61
66
  puts opts
62
67
  exit
@@ -131,7 +136,7 @@ inputs.each do |f, input|
131
136
  suffix='.pretty_md'
132
137
  out = doc.to_markdown
133
138
  when :s5
134
- suffix='_s5slides.xhtml'
139
+ suffix='_s5slides.html'
135
140
  out = doc.to_s5({:content_only => false})
136
141
  end
137
142
 
data/bin/marutest CHANGED
@@ -189,27 +189,34 @@ def run_test(filename, its_ok, verbose=true)
189
189
  end
190
190
 
191
191
 
192
- md_pl = markdown_pl(markdown)
192
+ if false
193
+ md_pl = markdown_pl(markdown)
193
194
 
194
- f.write "\n*** Output of Markdown.pl ***\n"
195
- f.write md_pl
195
+ f.write "\n*** Output of Markdown.pl ***\n"
196
+ f.write md_pl
196
197
 
197
- f.write "\n*** Output of Markdown.pl (parsed) ***\n"
198
- begin
199
- doc = REXML::Document.new("<div>#{md_pl}</div>",{
200
- :compress_whitespace=>['div','p'],
201
- :ignore_whitespace_nodes=>['div','p'],
202
- :respect_whitespace=>['pre','code']
203
- })
204
- div = doc.root
205
- xml =""
206
- div.write_children(xml,indent=1,transitive=true,ie_hack=false)
207
- f.write xml
208
- rescue Exception=>e
209
- f.puts "Error: #{e.inspect}"
210
- end
211
- f.close
198
+ f.write "\n*** Output of Markdown.pl (parsed) ***\n"
199
+ begin
200
+ doc = REXML::Document.new("<div>#{md_pl}</div>",{
201
+ :compress_whitespace=>['div','p'],
202
+ :ignore_whitespace_nodes=>['div','p'],
203
+ :respect_whitespace=>['pre','code']
204
+ })
205
+ div = doc.root
206
+ xml =""
207
+ div.write_children(xml,indent=1,transitive=true,ie_hack=false)
208
+ f.write xml
209
+ rescue Exception=>e
210
+ f.puts "Error: #{e.inspect}"
211
+ end
212
+ f.close
213
+ else
214
+ f.write "\n*** Output of Markdown.pl ***\n"
215
+ f.write "(not used anymore)"
212
216
 
217
+ f.write "\n*** Output of Markdown.pl (parsed) ***\n"
218
+ f.write "(not used anymore)"
219
+ end
213
220
 
214
221
  return failed, relaxed, crashed
215
222
  end
data/lib/maruku.rb CHANGED
@@ -111,6 +111,9 @@ require 'maruku/errors_management'
111
111
  # Code for creating a table of contents
112
112
  require 'maruku/toc'
113
113
 
114
+ # Support for div Markdown extension
115
+ require 'maruku/ext/div'
116
+
114
117
  # Version and URL
115
118
  require 'maruku/version'
116
119
 
@@ -1,7 +1,20 @@
1
1
 
2
2
 
3
- OpenDiv = /^[ ]{0,3}\+\-\-+\s*([^\s-]*)\s*\-*\s*$/
4
- CloseDiv = /^[ ]{0,3}\=\-\-+\s*([^\s-]*)\s*\-*\s*$/
3
+ #+-----------------------------------{.warning}------
4
+ #| this is the last warning!
5
+ #|
6
+ #| please, go away!
7
+ #|
8
+ #| +------------------------------------- {.menace} --
9
+ #| | or else terrible things will happen
10
+ #| +--------------------------------------------------
11
+ #+---------------------------------------------------
12
+
13
+ OpenDiv = /^[ ]{0,3}\+\-\-+\s*(\{([^{}]*|".*"|'.*')*\})?\s*\-*\s*$/
14
+ CloseDiv = /^[ ]{0,3}\=\-\-+\s*(\{([^{}]*|".*"|'.*')*\})?\s*\-*\s*$/
15
+ # note these are not enough for parsing the above example:
16
+ #OpenDiv = /^[ ]{0,3}\+\-\-+\s*(.*)$/
17
+ #CloseDiv = /^[ ]{0,3}\=\-\-+\s*(.*)$/
5
18
  StartPipe = /^[ ]{0,3}\|(.*)$/ # $1 is rest of line
6
19
  DecorativeClosing = OpenDiv
7
20
 
@@ -67,7 +80,7 @@ MaRuKu::In::Markdown::register_block_extension(
67
80
  al_string = ial_at_beginning || ial_at_end
68
81
  al = nil
69
82
 
70
- if al_string =~ /^\{(.*)\}$/
83
+ if al_string =~ /^\{(.*)\}\s*$/
71
84
  inside = $1
72
85
  cs = MaRuKu::In::Markdown::SpanLevelParser::CharSource
73
86
  al = al_string &&
@@ -84,8 +97,28 @@ MaRuKu::In::Markdown::register_block_extension(
84
97
 
85
98
  module MaRuKu; class MDElement
86
99
 
87
- def md_div(children, a=nil)
88
- self.md_el(:div, children, meta={}, a)
100
+ def md_div(children, al=nil)
101
+ type = label = num = nil
102
+ doc.refid2ref ||= {}
103
+ if al
104
+ al.each do |k, v|
105
+ case k
106
+ when :class
107
+ type = $1 if v =~ /^num_(\w*)/
108
+ when :id
109
+ label = v
110
+ end
111
+ end
112
+ end
113
+ if type
114
+ doc.refid2ref[type] ||= {}
115
+ num = doc.refid2ref[type].length + 1 || 1
116
+ end
117
+ e = self.md_el(:div, children, meta={:label => label, :type => type, :num => num}, al)
118
+ if type && label
119
+ doc.refid2ref[type].update({label => e})
120
+ end
121
+ e
89
122
  end
90
123
 
91
124
  end end
@@ -97,4 +130,4 @@ module MaRuKu; module Out; module HTML
97
130
  add_ws wrap_as_element('div')
98
131
  end
99
132
 
100
- end end end
133
+ end end end
@@ -3,6 +3,7 @@ class String
3
3
  def fix_latex
4
4
  if #{html_math_engine} == 'itex2mml'
5
5
  s = self.gsub("\\mathop{", "\\operatorname{")
6
+ s.gsub!(/\\begin\{svg\}.*?\\end\{svg\}/m, " ")
6
7
  s.gsub("\\space{", "\\itexspace{")
7
8
  else
8
9
  self
@@ -10,23 +10,24 @@ module MaRuKu; module Out; module HTML
10
10
 
11
11
  def convert_to_png_blahtex(kind, tex)
12
12
  begin
13
- FileUtils::mkdir_p MaRuKu::Globals[:html_png_dir]
13
+ FileUtils::mkdir_p get_setting(:html_png_dir)
14
14
 
15
15
  # first, we check whether this image has already been processed
16
16
  md5sum = Digest::MD5.hexdigest(tex+" params: ")
17
- result_file = File.join(MaRuKu::Globals[:html_png_dir], md5sum+".txt")
17
+ result_file = File.join(get_setting(:html_png_dir), md5sum+".txt")
18
18
 
19
19
  if not File.exists?(result_file)
20
20
  tmp_in = Tempfile.new('maruku_blahtex')
21
- f = tmp_in.open
21
+ f = tmp_in.open
22
22
  f.write tex
23
23
  f.close
24
24
 
25
25
  resolution = get_setting(:html_png_resolution)
26
26
 
27
- options = "--png --use-preview-package --shell-dvipng '/usr/bin/dvipng -D #{resolution}' "
28
- options += ("--temp-directory '%s' " % MaRuKu::Globals[:html_png_dir])
29
- options += ("--png-directory '%s'" % MaRuKu::Globals[:html_png_dir])
27
+ options = "--png --use-preview-package --shell-dvipng 'dvipng -D #{resolution}' "
28
+ options += "--displaymath " if kind == :equation
29
+ options += ("--temp-directory '%s' " % get_setting(:html_png_dir))
30
+ options += ("--png-directory '%s'" % get_setting(:html_png_dir))
30
31
 
31
32
  cmd = "blahtex #{options} < #{tmp_in.path} > #{result_file}"
32
33
  #$stderr.puts "$ #{cmd}"
@@ -52,7 +53,7 @@ module MaRuKu; module Out; module HTML
52
53
  height = height.text.to_f # XXX check != 0
53
54
  md5 = md5.text
54
55
 
55
- dir_url = MaRuKu::Globals[:html_png_url]
56
+ dir_url = get_setting(:html_png_url)
56
57
  return PNG.new("#{dir_url}#{md5}.png", depth, height)
57
58
  rescue Exception => e
58
59
  maruku_error "Error: #{e}"
@@ -62,7 +63,7 @@ module MaRuKu; module Out; module HTML
62
63
 
63
64
 
64
65
  def convert_to_mathml_blahtex(kind, tex)
65
- @@BlahtexCache = PStore.new(MaRuKu::Globals[:latex_cache_file])
66
+ @@BlahtexCache = PStore.new(get_setting(:latex_cache_file))
66
67
 
67
68
  begin
68
69
  @@BlahtexCache.transaction do
@@ -2,7 +2,7 @@ module MaRuKu
2
2
 
3
3
  class MDDocument
4
4
  # Hash equation id (String) to equation element (MDElement)
5
- attr_accessor :eqid2eq
5
+ safe_attr_accessor :eqid2eq, Hash
6
6
 
7
7
  def is_math_enabled?
8
8
  get_setting :math_enabled
@@ -103,3 +103,17 @@ end
103
103
  true
104
104
  }
105
105
  )
106
+
107
+ # This adds support for \ref
108
+ RegRef = /\\ref\{(\w*)\}/
109
+ MaRuKu::In::Markdown::register_span_extension(
110
+ :chars => [?\\, ?(],
111
+ :regexp => RegRef,
112
+ :handler => lambda { |doc, src, con|
113
+ return false if not doc.is_math_enabled?
114
+ refid = src.read_regexp(RegRef).captures.compact.first
115
+ r = doc.md_el(:divref, [], meta={:refid=>refid})
116
+ con.push r
117
+ true
118
+ }
119
+ )
@@ -90,7 +90,7 @@ module MaRuKu; module Out; module HTML
90
90
  img = Element.new 'img'
91
91
  img.attributes['src'] = src
92
92
  img.attributes['style'] = style
93
- img.attributes['alt'] = "equation"
93
+ img.attributes['alt'] = "$#{self.math.strip}$"
94
94
  img
95
95
  end
96
96
 
@@ -103,7 +103,7 @@ module MaRuKu; module Out; module HTML
103
103
 
104
104
  if mathml
105
105
  add_class_to(mathml, 'maruku-mathml')
106
- span << mathml
106
+ return mathml
107
107
  end
108
108
 
109
109
  if png
@@ -121,15 +121,6 @@ module MaRuKu; module Out; module HTML
121
121
 
122
122
  div = create_html_element 'div'
123
123
  add_class_to(div, 'maruku-equation')
124
- if self.label # then numerate
125
- span = Element.new 'span'
126
- span.attributes['class'] = 'maruku-eq-number'
127
- num = self.num
128
- span << Text.new("(#{num})")
129
- div << span
130
- div.attributes['id'] = "eq:#{self.label}"
131
- end
132
-
133
124
  if mathml
134
125
  add_class_to(mathml, 'maruku-mathml')
135
126
  div << mathml
@@ -141,12 +132,21 @@ module MaRuKu; module Out; module HTML
141
132
  div << img
142
133
  end
143
134
 
144
- source_div = Element.new 'div'
145
- add_class_to(source_div, 'maruku-eq-tex')
146
- code = convert_to_mathml_none(:equation, self.math)
147
- code.attributes['style'] = 'display: none'
148
- source_div << code
149
- div << source_div
135
+ source_span = Element.new 'span'
136
+ add_class_to(source_span, 'maruku-eq-tex')
137
+ code = convert_to_mathml_none(:equation, self.math.strip)
138
+ code.attributes['style'] = 'display: none'
139
+ source_span << code
140
+ div << source_span
141
+
142
+ if self.label # then numerate
143
+ span = Element.new 'span'
144
+ span.attributes['class'] = 'maruku-eq-number'
145
+ num = self.num
146
+ span << Text.new("(#{num})")
147
+ div << span
148
+ div.attributes['id'] = "eq:#{self.label}"
149
+ end
150
150
  div
151
151
  end
152
152
 
@@ -164,6 +164,23 @@ module MaRuKu; module Out; module HTML
164
164
  end
165
165
  end
166
166
 
167
+ def to_html_divref
168
+ ref= nil
169
+ self.doc.refid2ref.each_value { |h|
170
+ ref = h[self.refid] if h.has_key?(self.refid)
171
+ }
172
+ if ref
173
+ num = ref.num
174
+ a = Element.new 'a'
175
+ a.attributes['class'] = 'maruku-ref'
176
+ a.attributes['href'] = "#" + self.refid
177
+ a << Text.new(num.to_s)
178
+ a
179
+ else
180
+ maruku_error "Cannot find div #{self.refid.inspect}"
181
+ Text.new "\\ref{#{self.refid}}"
182
+ end
183
+ end
167
184
 
168
185
  end end end
169
186
 
@@ -19,4 +19,8 @@ module MaRuKu; module Out; module Latex
19
19
  "\\eqref{#{self.eqid}}"
20
20
  end
21
21
 
22
+ def to_latex_divref
23
+ "\\ref{#{self.refid}}"
24
+ end
25
+
22
26
  end end end
@@ -91,10 +91,10 @@ module Helpers
91
91
  raw_html = "<marukuwrap>#{raw_html}</marukuwrap>"
92
92
  e.instance_variable_set :@parsed_html,
93
93
  REXML::Document.new(raw_html)
94
- rescue #Exception => ex
94
+ rescue REXML::ParseException => ex
95
95
  e.instance_variable_set :@parsed_html, nil
96
- # tell_user "Malformed block of HTML:\n"+
97
- # add_tabs(raw_html,1,'|')
96
+ maruku_recover "REXML cannot parse this block of HTML/XML:\n"+
97
+ add_tabs(raw_html,1,'|') + "\n"+ex.inspect
98
98
  # " #{raw_html.inspect}\n\n"+ex.inspect
99
99
  end
100
100
  e
@@ -122,7 +122,7 @@ class CharSourceManual
122
122
 
123
123
  def consume_whitespace
124
124
  while c = cur_char
125
- if (c == 32 || c == ?\t)
125
+ if (c == ?\s || c == ?\t)
126
126
  # puts "ignoring #{c}"
127
127
  ignore_char
128
128
  else
@@ -251,6 +251,7 @@ module MaRuKu; module In; module Markdown; module BlockLevelParser
251
251
  "I see that #{h.rest.inspect} is left after the raw HTML.", src
252
252
  end
253
253
  raw_html = h.stuff_you_read
254
+
254
255
  return md_html(raw_html)
255
256
  end
256
257
 
@@ -198,14 +198,17 @@ Disabled by default because of security concerns.
198
198
  XPath.match(doc, "//*[attribute::markdown]" ).each do |e|
199
199
  # puts "Found #{e}"
200
200
  # should we parse block-level or span-level?
201
- parse_blocks = (e.attributes['markdown'] == 'block') ||
202
- block_tags.include?(e.name)
203
- # remove 'markdown' attribute
204
- e.delete_attribute 'markdown'
201
+
202
+ how = e.attributes['markdown']
203
+ parse_blocks = (how == 'block') || block_tags.include?(e.name)
204
+
205
205
  # Select all text elements of e
206
206
  XPath.match(e, "//text()" ).each { |original_text|
207
207
  s = original_text.value.strip
208
208
  if s.size > 0
209
+
210
+ # puts "Parsing #{s.inspect} as blocks: #{parse_blocks} (#{e.name}, #{e.attributes['markdown']}) "
211
+
209
212
  el = md_el(:dummy,
210
213
  parse_blocks ? parse_text_as_markdown(s) :
211
214
  parse_lines_as_span([s]) )
@@ -217,7 +220,11 @@ Disabled by default because of security concerns.
217
220
 
218
221
  end
219
222
  }
220
-
223
+
224
+
225
+ # remove 'markdown' attribute
226
+ e.delete_attribute 'markdown'
227
+
221
228
  end
222
229
 
223
230
  end
@@ -185,15 +185,27 @@ module MaRuKu; module In; module Markdown; module SpanLevelParser
185
185
  maruku_recover "Threating as literal", src, con
186
186
  con.push_char src.shift_char
187
187
  else
188
- follows = src.cur_chars(4)
189
- if follows =~ /^\_\_\_[^\s\_]/
190
- con.push_element read_emstrong(src,'___')
191
- elsif follows =~ /^\_\_[^\s\_]/
192
- con.push_element read_strong(src,'__')
193
- elsif follows =~ /^\_[^\s\_]/
194
- con.push_element read_em(src,'_')
195
- else # _ is just a normal char
196
- con.push_char src.shift_char
188
+ # we don't want "mod_ruby" to start an emphasis
189
+ # so we start one only if
190
+ # 1) there's nothing else in the span (first char)
191
+ # or 2) the last char was a space
192
+ # or 3) the current string is empty
193
+ #if con.elements.empty? ||
194
+ if (con.cur_string =~ /\s\Z/) || (con.cur_string.size == 0)
195
+ # also, we check the next characters
196
+ follows = src.cur_chars(4)
197
+ if follows =~ /^\_\_\_[^\s\_]/
198
+ con.push_element read_emstrong(src,'___')
199
+ elsif follows =~ /^\_\_[^\s\_]/
200
+ con.push_element read_strong(src,'__')
201
+ elsif follows =~ /^\_[^\s\_]/
202
+ con.push_element read_em(src,'_')
203
+ else # _ is just a normal char
204
+ con.push_char src.shift_char
205
+ end
206
+ else
207
+ # _ is just a normal char
208
+ con.push_char src.shift_char
197
209
  end
198
210
  end
199
211
  when ?{ # extension
@@ -430,7 +442,8 @@ module MaRuKu; module In; module Markdown; module SpanLevelParser
430
442
  SPACE = ?\ # = 32
431
443
 
432
444
  # R_REF_ID = Regexp.compile(/([^\]\s]*)(\s*\])/)
433
- R_REF_ID = Regexp.compile(/([^\]\s]*)(\s*\])/)
445
+ # R_REF_ID = Regexp.compile(/([^\]\s]*)(\s*\])/)
446
+ R_REF_ID = Regexp.compile(/([^\]]*)\]/)
434
447
 
435
448
  # Reads a bracketed id "[refid]". Consumes also both brackets.
436
449
  def read_ref_id(src, con)
@@ -696,6 +709,7 @@ module MaRuKu; module In; module Markdown; module SpanLevelParser
696
709
  end
697
710
  end
698
711
  end
712
+
699
713
  def push_string_if_present
700
714
  if @cur_string.size > 0
701
715
  @elements << @cur_string