bhollis / maruku

A pure-Ruby Markdown-superset interpreter (Official Repo).
MIT License
500 stars 80 forks source link

"<" character does not appear to work in $$ equations #63

Closed metasoarous closed 11 years ago

metasoarous commented 11 years ago

When trying to run the following

md = "$$ x<y $$ \n is an equation."
Maruku.new(md).to_html

I get the following error

REXML::ParseException: #<REXML::ParseException: malformed XML: missing tag start
Line: 1
Position: 16
Last 80 unconsumed characters:
<y</code>>

[[[Insert bunch of stack trace]]]
...
malformed XML: missing tag start
Line: 1
Position: 16
Last 80 unconsumed characters:
<y</code>
Line: 95
Position: 16
Last 80 unconsumed characters:
<y</code>
from /home/cts/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/rexml/parsers/treeparser.rb:95:in `rescue in parse'

I'm not having this problem with the inline equations, just those in '$$'.

Any chance there is a workaround for this until is really fixed?

Thanks

metasoarous commented 11 years ago

Hrm.. I guess I should have been using \lt anyway... Still, seems like this could be handled more gracefully.

distler commented 11 years ago
require 'maruku'
require 'maruku/ext/math'
md = "$$ x<y $$ \n is an equation."
Maruku.new(md, :html_math_engine => 'itex2mml').to_html

yields

"<div class=\"maruku-equation\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\"
display=\"block\"  class=\"maruku-mathml\"><mi>x</mi><merror><mtext>Unknown
character</mtext></merror><mi>y</mi></math><span class=\"maruku-eq-tex\"><code
style=\"display: none\">x&lt;y</code></span></div>\n<p>is an equation.</p>"

(which is an error, but seems graceful enough to me).

require 'maruku'
require 'maruku/ext/math'
md = "$$ x<y $$ \n is an equation."
Maruku.new(md).to_html

yields

"<div class=\"maruku-equation\"><code class=\"maruku-mathml\"> x&lt;y </code><span
class=\"maruku-eq-tex\"><code style=\"display: none\">x&lt;y</code></span></div>\n<p>
is an equation.</p>"
metasoarous commented 11 years ago

Hmm... I specified html_math_engine using MaRuKu::Gloabls[:html_math_engine] = 'itex2mml', and definitely did not get that graceful a response. I'll have to take another look at my environment when I'm at home to see what might be the root of the discrepancy.

Thanks for your response.

distler commented 11 years ago

You probably didn't require 'maruku/ext/math'.

metasoarous commented 11 years ago

Nope, I did require 'maruku/ext/math. Running your code exactly gives this full stack trace:

/home/cts/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/rexml/parsers/treeparser.rb:95:in `rescue in parse': #<REXML::ParseException: malformed XML: missing tag start (REXML::ParseException)
Line: 1
Position: 18
Last 80 unconsumed characters:
<y </code>>
/home/cts/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/rexml/parsers/baseparser.rb:373:in `pull'
/home/cts/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/rexml/parsers/treeparser.rb:22:in `parse'
/home/cts/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/rexml/document.rb:230:in `build'
/home/cts/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/rexml/document.rb:43:in `initialize'
/home/cts/.rvm/gems/ruby-1.9.2-p320/gems/maruku-0.6.1/lib/maruku/ext/math/mathml_engines/none.rb:11:in `new'
/home/cts/.rvm/gems/ruby-1.9.2-p320/gems/maruku-0.6.1/lib/maruku/ext/math/mathml_engines/none.rb:11:in `convert_to_mathml_none'
/home/cts/.rvm/gems/ruby-1.9.2-p320/gems/maruku-0.6.1/lib/maruku/ext/math/to_html.rb:51:in `render_mathml'
/home/cts/.rvm/gems/ruby-1.9.2-p320/gems/maruku-0.6.1/lib/maruku/ext/math/to_html.rb:119:in `to_html_equation'
/home/cts/.rvm/gems/ruby-1.9.2-p320/gems/maruku-0.6.1/lib/maruku/output/to_html.rb:970:in `block in array_to_html'
/home/cts/.rvm/gems/ruby-1.9.2-p320/gems/maruku-0.6.1/lib/maruku/output/to_html.rb:961:in `each'
/home/cts/.rvm/gems/ruby-1.9.2-p320/gems/maruku-0.6.1/lib/maruku/output/to_html.rb:961:in `array_to_html'
/home/cts/.rvm/gems/ruby-1.9.2-p320/gems/maruku-0.6.1/lib/maruku/output/to_html.rb:956:in `children_to_html'
/home/cts/.rvm/gems/ruby-1.9.2-p320/gems/maruku-0.6.1/lib/maruku/output/to_html.rb:50:in `to_html'
mathtest.rb:4:in `<main>'
...
malformed XML: missing tag start
Line: 1
Position: 18
Last 80 unconsumed characters:
<y </code>
Line: 1
Position: 18
Last 80 unconsumed characters:
<y </code>
  from /home/cts/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/rexml/parsers/treeparser.rb:20:in `parse'
  from /home/cts/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/rexml/document.rb:230:in `build'
  from /home/cts/.rvm/rubies/ruby-1.9.2-p320/lib/ruby/1.9.1/rexml/document.rb:43:in `initialize'
  from /home/cts/.rvm/gems/ruby-1.9.2-p320/gems/maruku-0.6.1/lib/maruku/ext/math/mathml_engines/none.rb:11:in `new'
  from /home/cts/.rvm/gems/ruby-1.9.2-p320/gems/maruku-0.6.1/lib/maruku/ext/math/mathml_engines/none.rb:11:in `convert_to_mathml_none'
  from /home/cts/.rvm/gems/ruby-1.9.2-p320/gems/maruku-0.6.1/lib/maruku/ext/math/to_html.rb:51:in `render_mathml'
  from /home/cts/.rvm/gems/ruby-1.9.2-p320/gems/maruku-0.6.1/lib/maruku/ext/math/to_html.rb:119:in `to_html_equation'
  from /home/cts/.rvm/gems/ruby-1.9.2-p320/gems/maruku-0.6.1/lib/maruku/output/to_html.rb:970:in `block in array_to_html'
  from /home/cts/.rvm/gems/ruby-1.9.2-p320/gems/maruku-0.6.1/lib/maruku/output/to_html.rb:961:in `each'
  from /home/cts/.rvm/gems/ruby-1.9.2-p320/gems/maruku-0.6.1/lib/maruku/output/to_html.rb:961:in `array_to_html'
  from /home/cts/.rvm/gems/ruby-1.9.2-p320/gems/maruku-0.6.1/lib/maruku/output/to_html.rb:956:in `children_to_html'
  from /home/cts/.rvm/gems/ruby-1.9.2-p320/gems/maruku-0.6.1/lib/maruku/output/to_html.rb:50:in `to_html'
  from mathtest.rb:4:in `<main>'

I'm running maruku 0.6.1 on ruby 1.9.2p320 (2012-04-20 revision 35421) [x86_64-linux]

If you let me know what versions of things you are running, I can see if switching addresses the issue.

Thanks

distler commented 11 years ago

Sorry, I can't comment on 0.6.1,

If you still get an error, after switching to the master branch here (or to my "Nokogiri" branch), then we can talk.

metasoarous commented 11 years ago

Building the master branch does solve this problem. Thanks!