From 39348c65c24c9255d81d6c89a947d00c794b13ee Mon Sep 17 00:00:00 2001 From: Jacques Distler Date: Sat, 25 Oct 2008 00:52:59 -0500 Subject: [PATCH] Make Andrea Happy Use a counter, instead of rand() to aid in generating unique IDs in Maruku. Add Unit test for the Theorem Environment. --- test/unit/page_renderer_test.rb | 77 ++++++++++++++++++- .../maruku/lib/maruku/ext/math/parsing.rb | 2 +- .../plugins/maruku/lib/maruku/output/to_s.rb | 5 +- .../plugins/maruku/lib/maruku/structures.rb | 5 ++ 4 files changed, 85 insertions(+), 4 deletions(-) diff --git a/test/unit/page_renderer_test.rb b/test/unit/page_renderer_test.rb index b8c3dbe8..ddecbbca 100644 --- a/test/unit/page_renderer_test.rb +++ b/test/unit/page_renderer_test.rb @@ -65,11 +65,86 @@ class PageRendererTest < Test::Unit::TestCase %{sin(x)

}, "equation $\\sin(x)$") - re = Regexp.new('

My Headline

\n\n

that Smart Engine GUI\?

') + re = Regexp.new('\\A

My Headline

\n\n

that Smart Engine GUI\?

\\Z') assert_match_markup_parsed_as(re, "My Headline\n===========\n\nthat SmartEngineGUI") assert_match_markup_parsed_as(re, "#My Headline#\n\nthat SmartEngineGUI") + + str1 = %{
\n
Definition
\n\n

Let H} + + %{ be a subgroup of a group G. A left coset of H in G} + + %{ is a subset of G that is of the form xH, where x} + + %{\342\210\210G and xH=\\\{<} + + %{/mo>xh:h\342\210\210H\\\}.

\n\n

Similarly a right coset of H in G is a subset of G that is of the form Hx, where Hx=\\\{hx:h\342\210\210} + + %{H\\\}.

\n
\n\n} + + %{
\n
Lemma
\n\n

} + + %{Let } + + %{H be a subgroup of a group G, and let x and y be elements of G. Suppose that xH\342\210\251y} + + %{H is non-empty. Then xH=yH.

\n\n\n
\n
Proof
\n\n

Let z be some e} + + %{lement of xH\342\210\251yH.

\n
\n\n} + + %{
\n
Lemma
\n\n

} + + %{Let } + + %{H be a finite subgroup of a group G.

\n
\n\n} + + %{
\n
Theorem
\n\n

\\(Lagrange\342\200\231s Theorem\\). Let G be a finite group, and let H be a subgroup of G.

\n
} + + str2 = <SVG } + diff --git a/vendor/plugins/maruku/lib/maruku/ext/math/parsing.rb b/vendor/plugins/maruku/lib/maruku/ext/math/parsing.rb index 9d7289e3..b8ba6052 100644 --- a/vendor/plugins/maruku/lib/maruku/ext/math/parsing.rb +++ b/vendor/plugins/maruku/lib/maruku/ext/math/parsing.rb @@ -2,7 +2,7 @@ module MaRuKu class MDDocument # Hash equation id (String) to equation element (MDElement) - attr_accessor :eqid2eq, :refid2ref + attr_accessor :eqid2eq def is_math_enabled? get_setting :math_enabled diff --git a/vendor/plugins/maruku/lib/maruku/output/to_s.rb b/vendor/plugins/maruku/lib/maruku/output/to_s.rb index dc326cce..51956097 100644 --- a/vendor/plugins/maruku/lib/maruku/output/to_s.rb +++ b/vendor/plugins/maruku/lib/maruku/output/to_s.rb @@ -45,8 +45,9 @@ class MDElement $uid += 1 title = "id#{$uid}" end - - title << "_" + rand(10000).to_s + + @doc.id_counter += 1 + title << "_" + @doc.id_counter.to_s end end diff --git a/vendor/plugins/maruku/lib/maruku/structures.rb b/vendor/plugins/maruku/lib/maruku/structures.rb index 937e4a5b..0bb69e58 100644 --- a/vendor/plugins/maruku/lib/maruku/structures.rb +++ b/vendor/plugins/maruku/lib/maruku/structures.rb @@ -144,6 +144,10 @@ class MDDocument safe_attr_accessor :footnotes_order, Array safe_attr_accessor :latex_required_packages, Array + + safe_attr_accessor :refid2ref, Hash + # A counter for generating unique IDs + safe_attr_accessor :id_counter, Integer def initialize(s=nil) super(:document) @@ -155,6 +159,7 @@ class MDDocument self.abbreviations = {} self.ald = {} self.latex_required_packages = [] + self.id_counter = 0 parse_doc(s) if s end