Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r86667 - in trunk/tools/quickbook: src test
From: dnljms_at_[hidden]
Date: 2013-11-12 15:35:14


Author: danieljames
Date: 2013-11-12 15:35:14 EST (Tue, 12 Nov 2013)
New Revision: 86667
URL: http://svn.boost.org/trac/boost/changeset/86667

Log:
Support source code tagging for sections.

Text files modified:
   trunk/tools/quickbook/src/actions.cpp | 3 +
   trunk/tools/quickbook/src/document_state.cpp | 41 ++++++++++++++++++++++++++++-----------
   trunk/tools/quickbook/src/document_state.hpp | 5 +++
   trunk/tools/quickbook/src/document_state_impl.hpp | 6 +++-
   trunk/tools/quickbook/src/state.cpp | 13 ++++++++++++
   trunk/tools/quickbook/src/state.hpp | 1
   trunk/tools/quickbook/test/source_mode-1_7.gold | 4 +++
   trunk/tools/quickbook/test/source_mode-1_7.quickbook | 5 ++++
   8 files changed, 62 insertions(+), 16 deletions(-)

Modified: trunk/tools/quickbook/src/actions.cpp
==============================================================================
--- trunk/tools/quickbook/src/actions.cpp Tue Nov 12 15:34:46 2013 (r86666)
+++ trunk/tools/quickbook/src/actions.cpp 2013-11-12 15:35:14 EST (Tue, 12 Nov 2013) (r86667)
@@ -1652,7 +1652,8 @@
                 detail::make_identifier(content.get_quickbook()),
             !element_id.empty() ?
                 id_category::explicit_section_id :
- id_category::generated_section);
+ id_category::generated_section,
+ state.current_source_mode());
 
         state.out << "\n<section id=\"" << full_id << "\">\n";
         state.out << "<title>";

Modified: trunk/tools/quickbook/src/document_state.cpp
==============================================================================
--- trunk/tools/quickbook/src/document_state.cpp Tue Nov 12 15:34:46 2013 (r86666)
+++ trunk/tools/quickbook/src/document_state.cpp 2013-11-12 15:35:14 EST (Tue, 12 Nov 2013) (r86667)
@@ -74,16 +74,19 @@
         unsigned const level;
         std::string const id_1_1;
         id_placeholder const* const placeholder_1_6;
+ source_mode_info const source_mode;
 
         section_info(boost::shared_ptr<section_info> const& parent,
                 file_info const* current_file, boost::string_ref id,
- boost::string_ref id_1_1, id_placeholder const* placeholder_1_6) :
+ boost::string_ref id_1_1, id_placeholder const* placeholder_1_6,
+ source_mode_info const& source_mode) :
             parent(parent),
             compatibility_version(current_file->compatibility_version),
             file_depth(current_file->depth),
             level(parent ? parent->level + 1 : 1),
             id_1_1(detail::to_s(id_1_1)),
- placeholder_1_6(placeholder_1_6) {}
+ placeholder_1_6(placeholder_1_6),
+ source_mode(source_mode) {}
     };
 
     //
@@ -122,9 +125,9 @@
     }
 
     std::string document_state::begin_section(boost::string_ref id,
- id_category category)
+ id_category category, source_mode_info const& source_mode)
     {
- return state->begin_section(id, category)->to_string();
+ return state->begin_section(id, category, source_mode)->to_string();
     }
 
     void document_state::end_section()
@@ -137,6 +140,13 @@
         return state->current_file->document->current_section->level;
     }
 
+ source_mode_info document_state::section_source_mode() const
+ {
+ return state->current_file ?
+ state->current_file->document->current_section->source_mode :
+ source_mode_info();
+ }
+
     std::string document_state::old_style_id(boost::string_ref id, id_category category)
     {
         return state->old_style_id(id, category)->to_string();
@@ -283,19 +293,23 @@
 
             // Create a section for the new document.
 
+ source_mode_info default_source_mode;
+
             if (!initial_doc_id.empty()) {
- return create_new_section(id, id_category::explicit_section_id);
+ return create_new_section(id, id_category::explicit_section_id,
+ default_source_mode);
             }
             else if (!title.empty()) {
                 return create_new_section(
                     detail::make_identifier(title.get_quickbook()),
- id_category::generated_doc);
+ id_category::generated_doc,
+ default_source_mode);
             }
             else if (compatibility_version >= 106u) {
- return create_new_section("doc", id_category::numbered);
+ return create_new_section("doc", id_category::numbered, default_source_mode);
             }
             else {
- return create_new_section("", id_category::generated_doc);
+ return create_new_section("", id_category::generated_doc, default_source_mode);
             }
         }
         else {
@@ -388,15 +402,17 @@
 
     id_placeholder const* document_state_impl::begin_section(
             boost::string_ref id,
- id_category category)
+ id_category category,
+ source_mode_info const& source_mode)
     {
         current_file->document->section_id_1_1 = detail::to_s(id);
- return create_new_section(id, category);
+ return create_new_section(id, category, source_mode);
     }
 
     id_placeholder const* document_state_impl::create_new_section(
             boost::string_ref id,
- id_category category)
+ id_category category,
+ source_mode_info const& source_mode)
     {
         boost::shared_ptr<section_info> parent =
             current_file->document->current_section;
@@ -442,7 +458,8 @@
 
         current_file->document->current_section =
             boost::make_shared<section_info>(parent,
- current_file.get(), id, id_1_1, placeholder_1_6);
+ current_file.get(), id, id_1_1, placeholder_1_6,
+ source_mode);
 
         return p;
     }

Modified: trunk/tools/quickbook/src/document_state.hpp
==============================================================================
--- trunk/tools/quickbook/src/document_state.hpp Tue Nov 12 15:34:46 2013 (r86666)
+++ trunk/tools/quickbook/src/document_state.hpp 2013-11-12 15:35:14 EST (Tue, 12 Nov 2013) (r86667)
@@ -13,6 +13,7 @@
 #include <boost/utility/string_ref.hpp>
 #include <string>
 #include "values.hpp"
+#include "syntax_highlight.hpp"
 
 namespace quickbook
 {
@@ -65,9 +66,11 @@
 
         void end_file();
 
- std::string begin_section(boost::string_ref, id_category);
+ std::string begin_section(boost::string_ref, id_category,
+ source_mode_info const&);
         void end_section();
         int section_level() const;
+ source_mode_info section_source_mode() const;
 
         std::string old_style_id(boost::string_ref, id_category);
         std::string add_id(boost::string_ref, id_category);

Modified: trunk/tools/quickbook/src/document_state_impl.hpp
==============================================================================
--- trunk/tools/quickbook/src/document_state_impl.hpp Tue Nov 12 15:34:46 2013 (r86666)
+++ trunk/tools/quickbook/src/document_state_impl.hpp 2013-11-12 15:35:14 EST (Tue, 12 Nov 2013) (r86667)
@@ -96,7 +96,8 @@
             id_category category);
         id_placeholder const* begin_section(
                 boost::string_ref id,
- id_category category);
+ id_category category,
+ source_mode_info const&);
         void end_section();
 
     private:
@@ -106,7 +107,8 @@
                 boost::shared_ptr<section_info> const& section);
         id_placeholder const* create_new_section(
                 boost::string_ref id,
- id_category category);
+ id_category category,
+ source_mode_info const&);
     };
 
     std::string replace_ids(document_state_impl const& state, boost::string_ref xml,

Modified: trunk/tools/quickbook/src/state.cpp
==============================================================================
--- trunk/tools/quickbook/src/state.cpp Tue Nov 12 15:34:46 2013 (r86666)
+++ trunk/tools/quickbook/src/state.cpp 2013-11-12 15:35:14 EST (Tue, 12 Nov 2013) (r86667)
@@ -10,6 +10,7 @@
 =============================================================================*/
 #include "state.hpp"
 #include "state_save.hpp"
+#include "document_state.hpp"
 #include "quickbook.hpp"
 #include "grammar.hpp"
 #include "native_text.hpp"
@@ -103,9 +104,21 @@
         in_list_save.pop();
     }
 
+ source_mode_info state::tagged_source_mode() const {
+ source_mode_info result;
+
+ BOOST_FOREACH(source_mode_info const& s, tagged_source_mode_stack) {
+ result.update(s);
+ }
+
+ return result;
+ }
+
     source_mode_info state::current_source_mode() const {
         source_mode_info result = source_mode;
 
+ result.update(document.section_source_mode());
+
         BOOST_FOREACH(source_mode_info const& s, tagged_source_mode_stack) {
             result.update(s);
         }

Modified: trunk/tools/quickbook/src/state.hpp
==============================================================================
--- trunk/tools/quickbook/src/state.hpp Tue Nov 12 15:34:46 2013 (r86666)
+++ trunk/tools/quickbook/src/state.hpp 2013-11-12 15:35:14 EST (Tue, 12 Nov 2013) (r86667)
@@ -107,6 +107,7 @@
         std::string end_callouts();
 
         source_mode_info current_source_mode() const;
+ source_mode_info tagged_source_mode() const;
         void change_source_mode(source_mode_type);
         void push_tagged_source_mode(source_mode_type);
         void pop_tagged_source_mode();

Modified: trunk/tools/quickbook/test/source_mode-1_7.gold
==============================================================================
--- trunk/tools/quickbook/test/source_mode-1_7.gold Tue Nov 12 15:34:46 2013 (r86666)
+++ trunk/tools/quickbook/test/source_mode-1_7.gold 2013-11-12 15:35:14 EST (Tue, 12 Nov 2013) (r86667)
@@ -56,4 +56,8 @@
     role="special">()</phrase> <phrase role="special">{}</phrase></code>. Not highlighted:
     <code>int main() {}</code>.
   </para>
+ <section id="source_mode_test.cpp">
+ <title><link linkend="source_mode_test.cpp">C++ section</link></title>
+<programlisting><phrase role="keyword">int</phrase> <phrase role="identifier">main</phrase><phrase role="special">()</phrase> <phrase role="special">{}</phrase></programlisting>
+ </section>
 </article>

Modified: trunk/tools/quickbook/test/source_mode-1_7.quickbook
==============================================================================
--- trunk/tools/quickbook/test/source_mode-1_7.quickbook Tue Nov 12 15:34:46 2013 (r86666)
+++ trunk/tools/quickbook/test/source_mode-1_7.quickbook 2013-11-12 15:35:14 EST (Tue, 12 Nov 2013) (r86667)
@@ -17,3 +17,8 @@
 [!teletype]`int main() {}` shouldn't be, but `int main() {}` should.
 
 [!c++] `int main() {}`. Not highlighted: `int main() {}`.
+
+[!c++]
+[section:cpp C++ section]
+``int main() {}``
+[endsect]


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk