$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r75840 - in trunk/tools/quickbook: src test/doc-info test/include
From: dnljms_at_[hidden]
Date: 2011-12-07 04:19:08
Author: danieljames
Date: 2011-12-07 04:19:07 EST (Wed, 07 Dec 2011)
New Revision: 75840
URL: http://svn.boost.org/trac/boost/changeset/75840
Log:
Quickbook: In 1.6 don't put 'inline' code blocks in paragraphs.
Might rename them 'explicit' code blocks.
Text files modified: 
   trunk/tools/quickbook/src/actions.cpp                    |    81 ++++++++++++++++++++++----------------- 
   trunk/tools/quickbook/src/actions.hpp                    |    28 ++-----------                           
   trunk/tools/quickbook/src/actions_class.cpp              |     6 +-                                      
   trunk/tools/quickbook/src/actions_class.hpp              |     2                                         
   trunk/tools/quickbook/test/doc-info/source-mode-1.6.gold |     8 ---                                     
   trunk/tools/quickbook/test/include/code-include.gold     |     2                                         
   6 files changed, 54 insertions(+), 73 deletions(-)
Modified: trunk/tools/quickbook/src/actions.cpp
==============================================================================
--- trunk/tools/quickbook/src/actions.cpp	(original)
+++ trunk/tools/quickbook/src/actions.cpp	2011-12-07 04:19:07 EST (Wed, 07 Dec 2011)
@@ -586,53 +586,62 @@
 
     void code_action::operator()(parse_iterator first, parse_iterator last) const
     {
-        write_anchors(actions, out);
+        bool inline_code = type == inline_ ||
+            (type == inline_block && qbk_version_n < 106u);
+        bool block = type != inline_;
 
-        // preprocess the code section to remove the initial indentation
-        mapped_file_builder mapped;
-        mapped.start(actions.current_file);
-        mapped.unindent_and_add(first.base(), last.base());
+        if (inline_code) {
+            write_anchors(actions, actions.phrase);
+        }
+        else {
+            actions.paragraph();
+            write_anchors(actions, actions.out);
+        }
 
-        file_ptr f = mapped.release();
+        std::string str;
 
-        if (f->source.empty())
-            return; // Nothing left to do here. The program is empty.
+        if (block) {
+            // preprocess the code section to remove the initial indentation
+            mapped_file_builder mapped;
+            mapped.start(actions.current_file);
+            mapped.unindent_and_add(first.base(), last.base());
 
-        parse_iterator first_(f->source.begin());
-        parse_iterator last_(f->source.end());
+            file_ptr f = mapped.release();
 
-        file_ptr saved_file = f;
-        boost::swap(actions.current_file, saved_file);
+            if (f->source.empty())
+                return; // Nothing left to do here. The program is empty.
 
-        // print the code with syntax coloring
-        std::string str = syntax_highlight(first_, last_, actions, actions.source_mode);
+            parse_iterator first_(f->source.begin());
+            parse_iterator last_(f->source.end());
 
-        boost::swap(actions.current_file, saved_file);
+            file_ptr saved_file = f;
+            boost::swap(actions.current_file, saved_file);
 
-        //
-        // We must not place a \n after the <programlisting> tag
-        // otherwise PDF output starts code blocks with a blank line:
-        //
-        out << "<programlisting>";
-        out << str;
-        out << "</programlisting>\n";
-    }
+            // print the code with syntax coloring
+            str = syntax_highlight(first_, last_, actions, actions.source_mode);
 
-    void inline_code_action::operator()(parse_iterator first, parse_iterator last) const
-    {
-        write_anchors(actions, out);
-
-        std::string save;
-        out.swap(save);
-
-        // print the code with syntax coloring
-        std::string str = syntax_highlight(first, last, actions, actions.source_mode);
+            boost::swap(actions.current_file, saved_file);
+        }
+        else {
+            parse_iterator first_(first);
+            str = syntax_highlight(first_, last, actions, actions.source_mode);
+        }
 
-        out.swap(save);
+        if (block) {
+            collector& output = inline_code ? actions.phrase : actions.out;
 
-        out << "<code>";
-        out << str;
-        out << "</code>";
+            // We must not place a \n after the <programlisting> tag
+            // otherwise PDF output starts code blocks with a blank line:
+            //
+            output << "<programlisting>";
+            output << str;
+            output << "</programlisting>\n";
+        }
+        else {
+            actions.phrase << "<code>";
+            actions.phrase << str;
+            actions.phrase << "</code>";
+        }
     }
 
     void plain_char_action::operator()(char ch) const
Modified: trunk/tools/quickbook/src/actions.hpp
==============================================================================
--- trunk/tools/quickbook/src/actions.hpp	(original)
+++ trunk/tools/quickbook/src/actions.hpp	2011-12-07 04:19:07 EST (Wed, 07 Dec 2011)
@@ -244,39 +244,21 @@
 
     struct code_action
     {
+        enum code_type { block, inline_block, inline_ };
+    
         // Does the actual syntax highlighing of code
 
         code_action(
-            collector& out
-          , collector& phrase
+            code_type type
           , quickbook::actions& actions)
-        : out(out)
-        , phrase(phrase)
+        : type(type)
         , actions(actions)
         {
         }
 
         void operator()(parse_iterator first, parse_iterator last) const;
 
-        collector& out;
-        collector& phrase;
-        quickbook::actions& actions;
-    };
-
-    struct inline_code_action
-    {
-        // Does the actual syntax highlighing of code inlined in text
-
-        inline_code_action(
-            collector& out
-          , quickbook::actions& actions)
-        : out(out)
-        , actions(actions)
-        {}
-
-        void operator()(parse_iterator first, parse_iterator last) const;
-
-        collector& out;
+        code_type type;
         quickbook::actions& actions;
     };
 
Modified: trunk/tools/quickbook/src/actions_class.cpp
==============================================================================
--- trunk/tools/quickbook/src/actions_class.cpp	(original)
+++ trunk/tools/quickbook/src/actions_class.cpp	2011-12-07 04:19:07 EST (Wed, 07 Dec 2011)
@@ -51,9 +51,9 @@
 
         , element(*this)
         , error(*this)
-        , code(out, phrase, *this)
-        , code_block(phrase, phrase, *this)
-        , inline_code(phrase, *this)
+        , code(code_action::block, *this)
+        , code_block(code_action::inline_block, *this)
+        , inline_code(code_action::inline_, *this)
         , paragraph(*this)
         , list_item(*this)
         , phrase_end(*this)
Modified: trunk/tools/quickbook/src/actions_class.hpp
==============================================================================
--- trunk/tools/quickbook/src/actions_class.hpp	(original)
+++ trunk/tools/quickbook/src/actions_class.hpp	2011-12-07 04:19:07 EST (Wed, 07 Dec 2011)
@@ -86,7 +86,7 @@
 
         code_action             code;
         code_action             code_block;
-        inline_code_action      inline_code;
+        code_action             inline_code;
         paragraph_action        paragraph;
         list_item_action        list_item;
         phrase_end_action       phrase_end;
Modified: trunk/tools/quickbook/test/doc-info/source-mode-1.6.gold
==============================================================================
--- trunk/tools/quickbook/test/doc-info/source-mode-1.6.gold	(original)
+++ trunk/tools/quickbook/test/doc-info/source-mode-1.6.gold	2011-12-07 04:19:07 EST (Wed, 07 Dec 2011)
@@ -14,9 +14,7 @@
       <code>This shouldn't be highlighted</code>
     </articlepurpose>
   </articleinfo>
-  <para>
 <programlisting>This shouldn't be highlighted.</programlisting>
-  </para>
   <article id="c___source_mode_include" last-revision="DEBUG MODE Date: 2000/12/20 12:00:00 $"
   xmlns:xi="http://www.w3.org/2001/XInclude">
     <title>C++ source mode include</title>
@@ -24,9 +22,7 @@
 <programlisting><phrase role="keyword">int</phrase> <phrase role="identifier">main</phrase><phrase role="special">()</phrase> <phrase role="special">{}</phrase></programlisting>
     </para>
   </article>
-  <para>
 <programlisting>This shouldn't be highlighted.</programlisting>
-  </para>
   <article id="python_source_mode_include" last-revision="DEBUG MODE Date: 2000/12/20 12:00:00 $"
   xmlns:xi="http://www.w3.org/2001/XInclude">
     <title>Python source mode include</title>
@@ -34,9 +30,7 @@
 <programlisting><phrase role="keyword">def</phrase> <phrase role="identifier">foo</phrase><phrase role="special">():</phrase></programlisting>
     </para>
   </article>
-  <para>
 <programlisting>This shouldn't be highlighted.</programlisting>
-  </para>
   <article id="teletype_source_mode_include" last-revision="DEBUG MODE Date: 2000/12/20 12:00:00 $"
   xmlns:xi="http://www.w3.org/2001/XInclude">
     <title>Teletype source mode include</title>
@@ -44,7 +38,5 @@
 <programlisting>This shouldn't be highlighted</programlisting>
     </para>
   </article>
-  <para>
 <programlisting>This shouldn't be highlighted.</programlisting>
-  </para>
 </article>
Modified: trunk/tools/quickbook/test/include/code-include.gold
==============================================================================
--- trunk/tools/quickbook/test/include/code-include.gold	(original)
+++ trunk/tools/quickbook/test/include/code-include.gold	2011-12-07 04:19:07 EST (Wed, 07 Dec 2011)
@@ -26,14 +26,12 @@
   <para>
     And any quickbook block markup.
   </para>
-  <para>
 <programlisting><phrase role="keyword">char</phrase><phrase role="special">*</phrase> <phrase role="identifier">foo</phrase><phrase role="special">()</phrase>
 <phrase role="special">{</phrase>
     <phrase role="comment">// return 'em, foo man!</phrase>
     <phrase role="keyword">return</phrase> <phrase role="string">"foo"</phrase><phrase role="special">;</phrase>
 <phrase role="special">}</phrase>
 </programlisting>
-  </para>
   <para>
     This should appear when <literal>stub.py</literal> is included.
   </para>