From 7ca05863ad264e8759a2d46c1cda824f33646ce8 Mon Sep 17 00:00:00 2001
From: Daniel James <daniel@calamity.org.uk>
Date: Tue, 1 Nov 2011 18:58:47 +0000
Subject: [PATCH] Quickbook: Fully qualify footnote and callout ids.

[SVN r75219]
---
 src/actions.cpp            |  13 ++--
 test/callouts.gold         | 130 +++++++++++++++++++++++++++++++++++++
 test/callouts.quickbook    |  25 +++++++
 test/quickbook-manual.gold |  12 ++--
 4 files changed, 169 insertions(+), 11 deletions(-)

diff --git a/src/actions.cpp b/src/actions.cpp
index 7770251..6209866 100644
--- a/src/actions.cpp
+++ b/src/actions.cpp
@@ -273,7 +273,9 @@ namespace quickbook
         value_consumer values = phrase;
         actions.phrase
             << "<footnote id=\""
-            << actions.ids.add(actions.doc_id + ".f", id_generator::numbered)
+            << actions.ids.add(fully_qualified_id(actions.doc_id,
+                    actions.qualified_section_id, "f"),
+                    id_generator::numbered)
             << "\"><para>"
             << values.consume().get_boostbook()
             << "</para></footnote>";
@@ -1273,17 +1275,18 @@ namespace quickbook
         std::vector<std::string> callout_ids;
         std::vector<template_body> args;
         unsigned int size = symbol->params.size();
+        std::string callout_base_id =
+            fully_qualified_id(actions.doc_id,
+                actions.qualified_section_id, "c");
 
         for(unsigned int i = 0; i < size; ++i)
         {
             std::string callout_id1 =
                 actions.ids.add(
-                    actions.doc_id + ".c",
-                    id_generator::numbered);
+                    callout_base_id, id_generator::numbered);
             std::string callout_id2 =
                 actions.ids.add(
-                    actions.doc_id + ".c",
-                    id_generator::numbered);
+                    callout_base_id, id_generator::numbered);
 
             std::string code;
             code += "<co id=\"" + callout_id1 + "\" ";
diff --git a/test/callouts.gold b/test/callouts.gold
index f816ed0..a6ca2b1 100644
--- a/test/callouts.gold
+++ b/test/callouts.gold
@@ -130,4 +130,134 @@
       </para>
     </callout>
   </calloutlist>
+  <section id="callout_tests.test_section">
+    <title><link linkend="callout_tests.test_section">Try callouts in a section</link></title>
+    <para>
+      Example 1:
+    </para>
+    <para>
+      Now we can define a function that simulates an ordinary six-sided die.
+    </para>
+    <para>
+      
+<programlisting><phrase role="keyword">int</phrase> <phrase role="identifier">roll_die</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
+  <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">uniform_int</phrase><phrase role="special">&lt;&gt;</phrase> <phrase role="identifier">dist</phrase><phrase role="special">(</phrase><phrase role="number">1</phrase><phrase role="special">,</phrase> <phrase role="number">6</phrase><phrase role="special">);</phrase> <co id="callout_tests.test_section.c0" linkends="callout_tests.test_section.c1" />
+<phrase role="special">}</phrase>
+
+</programlisting>
+    </para>
+    <calloutlist>
+      <callout arearefs="callout_tests.test_section.c0" id="callout_tests.test_section.c1">
+        <para>
+          create a uniform_int distribution
+        </para>
+      </callout>
+    </calloutlist>
+    <para>
+      Example 2:
+    </para>
+    <para>
+      
+<programlisting><phrase role="keyword">int</phrase> <phrase role="identifier">roll_die</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
+  <co id="callout_tests.test_section.c2" linkends="callout_tests.test_section.c3" /><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">variate_generator</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">mt19937</phrase><phrase role="special">&amp;,</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">uniform_int</phrase><phrase role="special">&lt;&gt;</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">die</phrase><phrase role="special">(</phrase><phrase role="identifier">gen</phrase><phrase role="special">,</phrase> <phrase role="identifier">dist</phrase><phrase role="special">);</phrase>
+<phrase role="special">}</phrase>
+
+</programlisting>
+    </para>
+    <calloutlist>
+      <callout arearefs="callout_tests.test_section.c2" id="callout_tests.test_section.c3">
+        <important>
+          <para>
+            test
+          </para>
+        </important>
+      </callout>
+    </calloutlist>
+    <para>
+      Example 3:
+    </para>
+    <para>
+      
+<programlisting><phrase role="keyword">int</phrase> <phrase role="identifier">roll_die</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
+  <co id="callout_tests.test_section.c4" linkends="callout_tests.test_section.c5" /><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">variate_generator</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">mt19937</phrase><phrase role="special">&amp;,</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">uniform_int</phrase><phrase role="special">&lt;&gt;</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">die</phrase><phrase role="special">(</phrase><phrase role="identifier">gen</phrase><phrase role="special">,</phrase> <phrase role="identifier">dist</phrase><phrase role="special">);</phrase>
+<phrase role="special">}</phrase>
+
+</programlisting>
+    </para>
+    <calloutlist>
+      <callout arearefs="callout_tests.test_section.c4" id="callout_tests.test_section.c5">
+        <important>
+          <para>
+            test
+          </para>
+        </important>
+      </callout>
+    </calloutlist>
+    <para>
+      Example 3 (again!):
+    </para>
+    <para>
+      
+<programlisting><phrase role="keyword">int</phrase> <phrase role="identifier">roll_die</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
+  <co id="callout_tests.test_section.c6" linkends="callout_tests.test_section.c7" /><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">variate_generator</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">mt19937</phrase><phrase role="special">&amp;,</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">uniform_int</phrase><phrase role="special">&lt;&gt;</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">die</phrase><phrase role="special">(</phrase><phrase role="identifier">gen</phrase><phrase role="special">,</phrase> <phrase role="identifier">dist</phrase><phrase role="special">);</phrase>
+<phrase role="special">}</phrase>
+
+</programlisting>
+    </para>
+    <calloutlist>
+      <callout arearefs="callout_tests.test_section.c6" id="callout_tests.test_section.c7">
+        <important>
+          <para>
+            test
+          </para>
+        </important>
+      </callout>
+    </calloutlist>
+    <para>
+      Example 4:
+    </para>
+    <para>
+      
+<programlisting><phrase role="keyword">int</phrase> <phrase role="identifier">roll_die</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
+  <co id="callout_tests.test_section.c8" linkends="callout_tests.test_section.c9" /><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">variate_generator</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">mt19937</phrase><phrase role="special">&amp;,</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">uniform_int</phrase><phrase role="special">&lt;&gt;</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">die</phrase><phrase role="special">(</phrase><phrase role="identifier">gen</phrase><phrase role="special">,</phrase> <phrase role="identifier">dist</phrase><phrase role="special">);</phrase>
+<co id="callout_tests.test_section.c10" linkends="callout_tests.test_section.c11" /><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">uniform_int</phrase><phrase role="special">&lt;&gt;</phrase> <phrase role="identifier">dist</phrase><phrase role="special">(</phrase><phrase role="number">1</phrase><phrase role="special">,</phrase> <phrase role="number">6</phrase><phrase role="special">);</phrase> <co id="callout_tests.test_section.c12" linkends="callout_tests.test_section.c13" />
+<phrase role="special">}</phrase>
+
+</programlisting>
+    </para>
+    <calloutlist>
+      <callout arearefs="callout_tests.test_section.c8" id="callout_tests.test_section.c9">
+        <para>
+          callout 1
+        </para>
+      </callout>
+      <callout arearefs="callout_tests.test_section.c10" id="callout_tests.test_section.c11">
+        <para>
+          callout 2
+        </para>
+      </callout>
+      <callout arearefs="callout_tests.test_section.c12" id="callout_tests.test_section.c13">
+        <para>
+          create a uniform_int distribution
+        </para>
+      </callout>
+    </calloutlist>
+    <para>
+      
+<programlisting><co id="callout_tests.test_section.c14" linkends="callout_tests.test_section.c15" /><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">uniform_int</phrase><phrase role="special">&lt;&gt;</phrase> <phrase role="identifier">dist</phrase><phrase role="special">(</phrase><phrase role="number">1</phrase><phrase role="special">,</phrase> <phrase role="number">6</phrase><phrase role="special">);</phrase> <co id="callout_tests.test_section.c16" linkends="callout_tests.test_section.c17" />
+</programlisting>
+    </para>
+    <calloutlist>
+      <callout arearefs="callout_tests.test_section.c14" id="callout_tests.test_section.c15">
+        <para>
+          callout 2
+        </para>
+      </callout>
+      <callout arearefs="callout_tests.test_section.c16" id="callout_tests.test_section.c17">
+        <para>
+          create a uniform_int distribution
+        </para>
+      </callout>
+    </calloutlist>
+  </section>
 </article>
diff --git a/test/callouts.quickbook b/test/callouts.quickbook
index 0d1a47a..b17e904 100644
--- a/test/callouts.quickbook
+++ b/test/callouts.quickbook
@@ -24,3 +24,28 @@ Example 4:
 
 [example4]
 [example4a]
+
+[section:test_section Try callouts in a section]
+
+Example 1:
+
+[example1]
+
+Example 2:
+
+[example2]
+
+Example 3:
+
+[example3]
+
+Example 3 (again!):
+
+[example3]
+
+Example 4:
+
+[example4]
+[example4a]
+
+[endsect]
\ No newline at end of file
diff --git a/test/quickbook-manual.gold b/test/quickbook-manual.gold
index 38a638e..50c3a40 100644
--- a/test/quickbook-manual.gold
+++ b/test/quickbook-manual.gold
@@ -404,7 +404,7 @@ the true business precept.]
         </para>
         <para>
           Unlike QuickBook's standard formatting scheme, the rules for simpler alternatives
-          are much stricter<footnote id="quickbook.f0">
+          are much stricter<footnote id="quickbook.syntax.phrase.simple_formatting.f0">
           <para>
             Thanks to David Barrett, author of <ulink url="http://quinthar.com/qwikiwiki/index.php?page=Home">Qwiki</ulink>,
             for sharing these samples and teaching me these obscure formatting rules.
@@ -1030,7 +1030,7 @@ escape (no processing/formatting)
 <programlisting><!--quickbook-escape-prefix-->[footnote A sample footnote]
 <!--quickbook-escape-postfix--></programlisting>
         <para>
-          will generate this<footnote id="quickbook.f1">
+          will generate this<footnote id="quickbook.syntax.phrase.footnotes.f0">
           <para>
             A sample footnote
           </para>
@@ -2789,20 +2789,20 @@ for the journey to old age.]]]
         </para>
         <para>
           
-<programlisting><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="identifier">foo_bar</phrase><phrase role="special">()</phrase> <co id="quickbook.c0" linkends="quickbook.c1" />
+<programlisting><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="identifier">foo_bar</phrase><phrase role="special">()</phrase> <co id="quickbook.syntax.block.import.c0" linkends="quickbook.syntax.block.import.c1" />
 <phrase role="special">{</phrase>
-    <phrase role="keyword">return</phrase> <phrase role="string">&quot;foo-bar&quot;</phrase><phrase role="special">;</phrase> <co id="quickbook.c2" linkends="quickbook.c3" />
+    <phrase role="keyword">return</phrase> <phrase role="string">&quot;foo-bar&quot;</phrase><phrase role="special">;</phrase> <co id="quickbook.syntax.block.import.c2" linkends="quickbook.syntax.block.import.c3" />
 <phrase role="special">}</phrase>
 </programlisting>
         </para>
         <calloutlist>
-          <callout arearefs="quickbook.c0" id="quickbook.c1">
+          <callout arearefs="quickbook.syntax.block.import.c0" id="quickbook.syntax.block.import.c1">
             <para>
               The <emphasis>Mythical</emphasis> FooBar. See <ulink url="http://en.wikipedia.org/wiki/Foobar">Foobar
               for details</ulink>
             </para>
           </callout>
-          <callout arearefs="quickbook.c2" id="quickbook.c3">
+          <callout arearefs="quickbook.syntax.block.import.c2" id="quickbook.syntax.block.import.c3">
             <para>
               return 'em, foo-bar man!
             </para>