From 8b008f8418dd2b8cb713dc3669c9d43a15a0d99c Mon Sep 17 00:00:00 2001 From: Jacques Distler Date: Sat, 18 Jun 2011 15:54:32 -0500 Subject: [PATCH] Fix Maruku Footnote Backlink Problem reported by Shamaoke. --- test/unit/page_renderer_test.rb | 15 +++++++++++++++ .../plugins/maruku/lib/maruku/output/to_html.rb | 16 +++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/test/unit/page_renderer_test.rb b/test/unit/page_renderer_test.rb index c17fd4cb..60d10024 100644 --- a/test/unit/page_renderer_test.rb +++ b/test/unit/page_renderer_test.rb @@ -216,6 +216,21 @@ END_THM end + def test_footnotes + assert_markup_parsed_as("

Ruby on Rails is a web-framework1. It uses the MVC2 architecture pattern. It has its good points3.

\n

  1. \n" + + "

    a reusable set of libraries \342\206\251

    \n
  2. \n

    Model View Controller \342\206\251

    \n<" + + "/li>
  3. \n

    Here are its good points

    \n\n
      \n
    1. Ease of use
    2. \n\n
    3. " + + "Rapid development
    4. \n
    \n\342\206\251
", + "Ruby on Rails is a web-framework[^framework]. It uses the MVC[^MVC] architecture pattern." + + " It has its good points[^points].\n\n[^framework]: a reusable set of libraries\n\n[^MVC]:" + + " Model View Controller\n\n[^points]: Here are its good points\n1. Ease of use\n2. Rapid d" + + "evelopment") + end + def test_ial_in_lists assert_markup_parsed_as( diff --git a/vendor/plugins/maruku/lib/maruku/output/to_html.rb b/vendor/plugins/maruku/lib/maruku/output/to_html.rb index ebbdbad1..7c4375c1 100644 --- a/vendor/plugins/maruku/lib/maruku/output/to_html.rb +++ b/vendor/plugins/maruku/lib/maruku/output/to_html.rb @@ -326,7 +326,21 @@ Example: a.attributes['href'] = "\##{get_setting(:doc_prefix)}fnref:#{num}" a.attributes['rev'] = 'footnote' a<< Text.new('↩', true, nil, true) - li.insert_after(li.children.last, a) + + last = nil + li.children.reverse_each do |child| + if child.node_type != :text + last = child + break + end + end + + if last and last.name == "p" + last.add_text(' '); + last.add(a); + else + li.insert_after(li.children.last, a) + end ol << li else maruku_error "Could not find footnote id '#{fid}' among ["+