Skip to content
This repository has been archived by the owner on Jan 5, 2025. It is now read-only.

Commit

Permalink
Merge pull request #142 from distler/master
Browse files Browse the repository at this point in the history
Fix Uninitialized eq2eqid Hash
  • Loading branch information
bhollis authored Oct 11, 2017
2 parents 0b0b430 + 167d845 commit ec44b27
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 1 deletion.
1 change: 0 additions & 1 deletion lib/maruku/ext/math/elements.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ def md_equation(math, label, numerate)
math = math.gsub(reglabel, '') if label = math[reglabel, 1]
num = nil
if (label || numerate) && @doc # take number
@doc.eqid2eq ||= {}
num = @doc.eqid2eq.size + 1
label = "eq#{num}" unless label # TODO do id for document
end
Expand Down
4 changes: 4 additions & 0 deletions lib/maruku/ext/math/parsing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ class MDDocument
# @return [String => MDElement]
attr_accessor :eqid2eq

def eqid2eq
@eqid2eq ||= {}
end

def is_math_enabled?
get_setting :math_enabled
end
Expand Down
21 changes: 21 additions & 0 deletions spec/block_docs/math/Instiki_Issue_52.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Fixes Uninitialized eq2eqid hash
*** Parameters: ***
require 'maruku/ext/math';{:html_math_engine => 'itex2mml'}
*** Markdown input: ***
This is an unresolved equation reference (eq:xyz).

*** Output of inspect ***
md_el(:document, md_par([
"This is an unresolved equation reference ",
md_el(:eqref, [], {:eqid=>"xyz"}),
"."
]))
*** Output of to_html ***
<p>This is an unresolved equation reference (eq:xyz).</p>

*** Output of to_latex ***
This is an unresolved equation reference \eqref{xyz}.
*** Output of to_md ***

*** Output of to_s ***

40 changes: 40 additions & 0 deletions spec/block_docs/math/Instiki_Issue_52_bis.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
Fixes Uninitialized eq2eqid hash
*** Parameters: ***
require 'maruku/ext/math';{:html_math_engine => 'itex2mml'}
*** Markdown input: ***
Here is an equation
\[\label{xxx}
\sin(\theta)
\]
Here we refer back to it (eq:xxx). Or \eqref{xxx}.
*** Output of inspect ***
md_el(:document, [
md_par("Here is an equation"),
md_el(:equation, [], {:math=>"\n\\sin(\\theta)\n\n", :label=>"xxx", :num=>1}),
md_par([
"Here we refer back to it ",
md_el(:eqref, [], {:eqid=>"xxx"}),
". Or ",
md_el(:eqref, [], {:eqid=>"xxx"}),
"."
])
])
*** Output of to_html ***
<p>Here is an equation</p>
<div class='maruku-equation' id='eq:xxx'><span class='maruku-eq-number'>(1)</span><math class='maruku-mathml' display='block' xmlns='http://www.w3.org/1998/Math/MathML'><semantics><mrow><mi>sin</mi><mo stretchy='false'>(</mo><mi>θ</mi><mo stretchy='false'>)</mo></mrow><annotation encoding='application/x-tex'>
\sin(\theta)

</annotation></semantics></math></div>
<p>Here we refer back to it <a class='maruku-eqref' href='#eq:xxx'>(1)</a>. Or <a class='maruku-eqref' href='#eq:xxx'>(1)</a>.</p>

*** Output of to_latex ***
Here is an equation

\begin{equation}
\sin(\theta)
\label{xxx}\end{equation}
Here we refer back to it \eqref{xxx}. Or \eqref{xxx}.
*** Output of to_md ***

*** Output of to_s ***

0 comments on commit ec44b27

Please sign in to comment.