Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r65005 - in trunk/tools/quickbook: . detail doc test
From: dnljms_at_[hidden]
Date: 2010-08-25 16:28:16


Author: danieljames
Date: 2010-08-25 16:28:15 EDT (Wed, 25 Aug 2010)
New Revision: 65005
URL: http://svn.boost.org/trac/boost/changeset/65005

Log:
Don't escape docinfo fields for quickbook <= 1.2
Text files modified:
   trunk/tools/quickbook/detail/actions.cpp | 112 ++++++++++++++++++---------------------
   trunk/tools/quickbook/detail/actions.hpp | 39 +++++++++++++
   trunk/tools/quickbook/detail/actions_class.cpp | 5 -
   trunk/tools/quickbook/detail/actions_class.hpp | 56 ++++++++++----------
   trunk/tools/quickbook/doc/quickbook.qbk | 2
   trunk/tools/quickbook/doc_info.hpp | 11 +--
   trunk/tools/quickbook/test/xml-escape_1_2.gold | 6 +-
   trunk/tools/quickbook/test/xml-escape_1_2.quickbook | 6 +-
   8 files changed, 132 insertions(+), 105 deletions(-)

Modified: trunk/tools/quickbook/detail/actions.cpp
==============================================================================
--- trunk/tools/quickbook/detail/actions.cpp (original)
+++ trunk/tools/quickbook/detail/actions.cpp 2010-08-25 16:28:15 EDT (Wed, 25 Aug 2010)
@@ -1502,7 +1502,8 @@
     void include_action::operator()(iterator first, iterator last) const
     {
         fs::path filein = include_search(actions.filename.parent_path(), std::string(first,last));
- std::string doc_type, doc_id, doc_dirname, doc_last_revision;
+ std::string doc_type, doc_id;
+ docinfo_string doc_dirname, doc_last_revision;
 
         // swap the filenames
         std::swap(actions.filename, filein);
@@ -1566,19 +1567,24 @@
         //~ actions.templates = templates; $$$ fixme $$$
     }
 
- void xml_author::operator()(std::pair<std::string, std::string> const& author) const
+ std::string const& docinfo_string::get(unsigned version) const
+ {
+ return (qbk_version_n < version) ? raw : encoded;
+ }
+
+ void xml_author::operator()(actions::author const& name) const
     {
         out << " <author>\n"
             << " <firstname>"
- << author.first
+ << name.first.get(103)
             << "</firstname>\n"
             << " <surname>"
- << author.second
+ << name.second.get(103)
             << "</surname>\n"
             << " </author>\n";
     }
 
- void xml_copyright::operator()(std::pair<std::vector<std::string>, std::string> const& copyright) const
+ void xml_copyright::operator()(actions::copyright_item const& copyright) const
     {
         out << "\n" << " <copyright>\n";
 
@@ -1588,7 +1594,7 @@
           , xml_year(out));
 
         out << " <holder>"
- << copyright.second
+ << copyright.second.get(103)
             << "</holder>\n"
             << " </copyright>\n"
             << "\n"
@@ -1608,12 +1614,23 @@
         // The doc_info in the file has been parsed. Here's what we'll do
         // *before* anything else.
 
+ if (!actions.doc_id_tmp.empty())
+ actions.doc_id = actions.doc_id_tmp.get(103);
+
         if (actions.doc_id.empty())
             actions.doc_id = detail::make_identifier(
- actions.doc_title_raw.begin(),actions.doc_title_raw.end());
+ actions.doc_title.raw.begin(),actions.doc_title.raw.end());
+
+ if (actions.doc_dirname.empty() && actions.doc_type == "library") {
+ if (!actions.doc_id_tmp.empty()) {
+ actions.doc_dirname = actions.doc_id_tmp;
+ }
+ else {
+ actions.doc_dirname.raw = actions.doc_dirname.encoded = actions.doc_id;
+ }
+ }
 
- if (actions.doc_dirname.empty() && actions.doc_type == "library")
- actions.doc_dirname = actions.doc_id;
+ actions.doc_id_tmp.clear();
 
         if (actions.doc_last_revision.empty())
         {
@@ -1627,7 +1644,7 @@
                     "$" /* prevent CVS substitution */ "Date: %Y/%m/%d %H:%M:%S $"),
                 current_gm_time
             );
- actions.doc_last_revision = strdate;
+ actions.doc_last_revision.raw = actions.doc_last_revision.encoded = strdate;
         }
 
         // if we're ignoring the document info, we're done.
@@ -1681,18 +1698,18 @@
         
         if(actions.doc_type == "library")
         {
- out << " name=\"" << actions.doc_title << "\"\n";
+ out << " name=\"" << actions.doc_title.get(103) << "\"\n";
         }
 
         if(!actions.doc_dirname.empty())
         {
             out << " dirname=\""
- << actions.doc_dirname
+ << actions.doc_dirname.get(103)
                 << "\"\n";
         }
 
         out << " last-revision=\""
- << actions.doc_last_revision
+ << actions.doc_last_revision.get(103)
             << "\" \n"
             << " xmlns:xi=\"http://www.w3.org/2001/XInclude\">\n";
             
@@ -1724,9 +1741,9 @@
         if (!actions.doc_title.empty())
         {
             out << " <title>"
- << actions.doc_title;
+ << actions.doc_title.get(103);
             if (!actions.doc_version.empty()) {
- out << ' ' << actions.doc_version;
+ out << ' ' << actions.doc_version.get(103);
             }
             out<< "</title>\n\n\n";
         }
@@ -1756,33 +1773,15 @@
               , xml_copyright(out));
         }
 
- if (qbk_version_n < 103)
+ if (!actions.doc_license.empty())
         {
- if (!actions.doc_license_1_1.empty())
- {
- out << " <legalnotice>\n"
- << " <para>\n"
- << " ";
- detail::print_string(actions.doc_license_1_1, out.get());
- out << "\n"
- << " </para>\n"
- << " </legalnotice>\n"
- << "\n"
- ;
- }
- }
- else
- {
- if (!actions.doc_license.empty())
- {
- out << " <legalnotice>\n"
- << " <para>\n"
- << " " << actions.doc_license << "\n"
- << " </para>\n"
- << " </legalnotice>\n"
- << "\n"
- ;
- }
+ out << " <legalnotice>\n"
+ << " <para>\n"
+ << " " << actions.doc_license.get(103) << "\n"
+ << " </para>\n"
+ << " </legalnotice>\n"
+ << "\n"
+ ;
         }
 
         if (!actions.doc_purpose.empty())
@@ -1792,23 +1791,11 @@
                 invalid_attributes.push_back("purpose");
             }
 
- if (qbk_version_n < 103)
- {
- out << " <" << actions.doc_type << "purpose>\n"
- << " ";
- detail::print_string(actions.doc_purpose_1_1, out.get());
- out << " </" << actions.doc_type << "purpose>\n"
- << "\n"
- ;
- }
- else
- {
- out << " <" << actions.doc_type << "purpose>\n"
- << " " << actions.doc_purpose
- << " </" << actions.doc_type << "purpose>\n"
- << "\n"
+ out << " <" << actions.doc_type << "purpose>\n"
+ << " " << actions.doc_purpose.get(103)
+ << " </" << actions.doc_type << "purpose>\n"
+ << "\n"
                 ;
- }
         }
 
         if (!actions.doc_categories.empty())
@@ -1818,13 +1805,13 @@
                 invalid_attributes.push_back("category");
             }
 
- for(actions::string_list::const_iterator
+ for(actions::docinfo_list::const_iterator
                 it = actions.doc_categories.begin(),
                 end = actions.doc_categories.end();
                 it != end; ++it)
             {
                 out << " <" << actions.doc_type << "category name=\"category:"
- << *it
+ << it->get(103)
                     << "\"></" << actions.doc_type << "category>\n"
                     << "\n"
                 ;
@@ -1853,6 +1840,13 @@
         phrase.swap(out);
     }
 
+ void phrase_to_docinfo_action::operator()(iterator first, iterator last) const
+ {
+ out.encoded.clear();
+ phrase.swap(out.encoded);
+ out.raw = std::string(first, last);
+ }
+
     void copy_stream_action::operator()(iterator first, iterator last) const
     {
         std::string str;

Modified: trunk/tools/quickbook/detail/actions.hpp
==============================================================================
--- trunk/tools/quickbook/detail/actions.hpp (original)
+++ trunk/tools/quickbook/detail/actions.hpp 2010-08-25 16:28:15 EDT (Wed, 25 Aug 2010)
@@ -838,6 +838,29 @@
         quickbook::actions& actions;
     };
 
+ struct docinfo_string {
+ std::string raw;
+ std::string encoded;
+
+ docinfo_string() : raw(), encoded() {}
+
+ void swap(docinfo_string& x) {
+ raw.swap(x.raw);
+ encoded.swap(x.encoded);
+ }
+
+ void clear() {
+ raw.clear();
+ encoded.clear();
+ }
+
+ bool empty() const {
+ return raw.empty();
+ }
+
+ std::string const& get(unsigned version) const;
+ };
+
     struct xml_author
     {
         // Handles xml author
@@ -845,7 +868,7 @@
         xml_author(collector& out)
         : out(out) {}
 
- void operator()(std::pair<std::string, std::string> const& author) const;
+ void operator()(std::pair<docinfo_string, docinfo_string> const& author) const;
 
         collector& out;
     };
@@ -869,7 +892,7 @@
         xml_copyright(collector& out)
             : out(out) {}
 
- void operator()(std::pair<std::vector<std::string>, std::string> const &copyright) const;
+ void operator()(std::pair<std::vector<std::string>, docinfo_string> const &copyright) const;
 
         collector& out;
     };
@@ -888,6 +911,18 @@
         collector& phrase;
     };
 
+ struct phrase_to_docinfo_action
+ {
+ phrase_to_docinfo_action(docinfo_string& out, collector& phrase)
+ : out(out)
+ , phrase(phrase) {}
+
+ void operator()(iterator first, iterator last) const;
+
+ docinfo_string& out;
+ collector& phrase;
+ };
+
     struct copy_stream_action
     {
         copy_stream_action(collector& out, collector& phrase)

Modified: trunk/tools/quickbook/detail/actions_class.cpp
==============================================================================
--- trunk/tools/quickbook/detail/actions_class.cpp (original)
+++ trunk/tools/quickbook/detail/actions_class.cpp 2010-08-25 16:28:15 EDT (Wed, 25 Aug 2010)
@@ -21,7 +21,6 @@
     // header info
         : doc_type()
         , doc_title()
- , doc_title_raw()
         , doc_version()
         , doc_id()
         , doc_dirname()
@@ -32,8 +31,6 @@
         , doc_license()
         , doc_last_revision()
         , include_doc_id()
- , doc_license_1_1()
- , doc_purpose_1_1()
 
     // main output stream
         , out(out_)
@@ -77,7 +74,7 @@
         , extract_doc_license(doc_license, phrase)
         , extract_doc_purpose(doc_purpose, phrase)
         , extract_doc_version(doc_version, phrase)
- , extract_doc_id(doc_id, phrase)
+ , extract_doc_id(doc_id_tmp, phrase)
         , extract_doc_dirname(doc_dirname, phrase)
         , extract_copyright_second(copyright.second, phrase)
         , extract_name_second(name.second, phrase)

Modified: trunk/tools/quickbook/detail/actions_class.hpp
==============================================================================
--- trunk/tools/quickbook/detail/actions_class.hpp (original)
+++ trunk/tools/quickbook/detail/actions_class.hpp 2010-08-25 16:28:15 EDT (Wed, 25 Aug 2010)
@@ -27,33 +27,33 @@
     ///////////////////////////////////////////////////////////////////////////
 
         typedef std::vector<std::string> string_list;
- typedef std::vector<std::pair<std::string, std::string> > author_list;
- typedef std::vector<std::pair<string_list, std::string> > copyright_list;
+
+ typedef std::vector<docinfo_string> docinfo_list;
+ typedef std::pair<docinfo_string, docinfo_string> author;
+ typedef std::vector<author> author_list;
+ typedef std::pair<string_list, docinfo_string> copyright_item;
+ typedef std::vector<copyright_item> copyright_list;
         typedef std::pair<char, int> mark_type;
         static int const max_template_depth = 100;
 
     // header info
         std::string doc_type;
- std::string doc_title;
- std::string doc_title_raw;
- std::string doc_version;
+ docinfo_string doc_title;
+ docinfo_string doc_version;
         std::string doc_id;
- std::string doc_dirname;
+ docinfo_string doc_dirname;
         copyright_list doc_copyrights;
- std::string doc_purpose;
- string_list doc_categories;
+ docinfo_string doc_purpose;
+ docinfo_list doc_categories;
         author_list doc_authors;
- std::string doc_license;
- std::string doc_last_revision;
+ docinfo_string doc_license;
+ docinfo_string doc_last_revision;
         std::string include_doc_id;
- std::string doc_license_1_1;
- std::string doc_purpose_1_1;
         //temporary state
- std::pair<std::string, std::string>
- name;
- std::pair<std::vector<std::string>, std::string>
- copyright;
- std::string doc_category;
+ docinfo_string doc_id_tmp;
+ author name;
+ copyright_item copyright;
+ docinfo_string doc_category;
 
 
     // main output stream
@@ -118,17 +118,17 @@
     // actions
     ///////////////////////////////////////////////////////////////////////////
         error_action error;
- phrase_to_string_action extract_doc_title;
- phrase_to_string_action extract_doc_license;
- phrase_to_string_action extract_doc_purpose;
- phrase_to_string_action extract_doc_version;
- phrase_to_string_action extract_doc_id;
- phrase_to_string_action extract_doc_dirname;
- phrase_to_string_action extract_copyright_second;
- phrase_to_string_action extract_name_second;
- phrase_to_string_action extract_name_first;
- phrase_to_string_action extract_doc_last_revision;
- phrase_to_string_action extract_doc_category;
+ phrase_to_docinfo_action extract_doc_title;
+ phrase_to_docinfo_action extract_doc_license;
+ phrase_to_docinfo_action extract_doc_purpose;
+ phrase_to_docinfo_action extract_doc_version;
+ phrase_to_docinfo_action extract_doc_id;
+ phrase_to_docinfo_action extract_doc_dirname;
+ phrase_to_docinfo_action extract_copyright_second;
+ phrase_to_docinfo_action extract_name_second;
+ phrase_to_docinfo_action extract_name_first;
+ phrase_to_docinfo_action extract_doc_last_revision;
+ phrase_to_docinfo_action extract_doc_category;
 
         syntax_highlight syntax_p;
         code_action code;

Modified: trunk/tools/quickbook/doc/quickbook.qbk
==============================================================================
--- trunk/tools/quickbook/doc/quickbook.qbk (original)
+++ trunk/tools/quickbook/doc/quickbook.qbk 2010-08-25 16:28:15 EDT (Wed, 25 Aug 2010)
@@ -231,6 +231,8 @@
   entry has multiple values, merge them into one `listitem`.
 * Support nested code snippets.
 * Allow escapes in doc info fields (apart from `\n`).
+* Don't escape the raw markup for versions less than 1.3, for better
+ compatibility with older documentation.
 * Further work on quickbook 1.6, still not stable.
   * Allow heading to have ids, using the syntax: `[heading:id title]`.
 

Modified: trunk/tools/quickbook/doc_info.hpp
==============================================================================
--- trunk/tools/quickbook/doc_info.hpp (original)
+++ trunk/tools/quickbook/doc_info.hpp 2010-08-25 16:28:15 EDT (Wed, 25 Aug 2010)
@@ -50,8 +50,7 @@
>> (doc_types >> eps_p) [assign_a(actions.doc_type)]
>> hard_space
>> ( *(~eps_p(ch_p('[') | ']' | eol_p) >> char_)
- ) [assign_a(actions.doc_title_raw)]
- [actions.extract_doc_title]
+ ) [actions.extract_doc_title]
>> !(
                             space >> '[' >>
                                 quickbook_version
@@ -65,10 +64,10 @@
                             | doc_id
                             | doc_dirname
                             | doc_copyright [push_back_a(actions.doc_copyrights, actions.copyright)]
- | doc_purpose [actions.extract_doc_purpose]
+ | doc_purpose
                             | doc_category
                             | doc_authors
- | doc_license [actions.extract_doc_license]
+ | doc_license
                             | doc_last_revision
                             | doc_source_mode
                             )
@@ -113,7 +112,7 @@
 
                 doc_purpose =
                         "purpose" >> hard_space
- >> phrase [assign_a(actions.doc_purpose_1_1)]
+ >> phrase [actions.extract_doc_purpose]
                     ;
 
                 doc_category =
@@ -143,7 +142,7 @@
 
                 doc_license =
                         "license" >> hard_space
- >> phrase [assign_a(actions.doc_license_1_1)]
+ >> phrase [actions.extract_doc_license]
                     ;
 
                 doc_last_revision =

Modified: trunk/tools/quickbook/test/xml-escape_1_2.gold
==============================================================================
--- trunk/tools/quickbook/test/xml-escape_1_2.gold (original)
+++ trunk/tools/quickbook/test/xml-escape_1_2.gold 2010-08-25 16:28:15 EDT (Wed, 25 Aug 2010)
@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN" "http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
-<library id="test_that______are_being_escaped_" name="Test that &amp;, &lt; are being escaped."
-dirname="test_that______are_being_escaped_" last-revision="DEBUG MODE Date: 2000/12/20 12:00:00 $"
+<library id="test_that__amp____lt__are_being_escaped_" name="Test that &amp;, &lt; are being escaped."
+dirname="test_that__amp____lt__are_being_escaped_" last-revision="DEBUG MODE Date: 2000/12/20 12:00:00 $"
  xmlns:xi="http://www.w3.org/2001/XInclude">
   <libraryinfo>
     <legalnotice>
@@ -14,7 +14,7 @@
     </librarypurpose>
   </libraryinfo>
   <title>Test that &amp;, &lt; are being escaped.</title>
- <section id="test_that______are_being_escaped_.escapes___explicitly_written_markup">
+ <section id="test_that__amp____lt__are_being_escaped_.escapes___explicitly_written_markup">
     <title>Escapes &amp; explicitly written markup</title>
     <itemizedlist>
       <listitem>

Modified: trunk/tools/quickbook/test/xml-escape_1_2.quickbook
==============================================================================
--- trunk/tools/quickbook/test/xml-escape_1_2.quickbook (original)
+++ trunk/tools/quickbook/test/xml-escape_1_2.quickbook 2010-08-25 16:28:15 EDT (Wed, 25 Aug 2010)
@@ -1,7 +1,7 @@
-[library Test that &, < are being escaped.
+[library Test that &amp;, &lt; are being escaped.
     [quickbook 1.2]
- [purpose & should be &amp;, < should &lt;]
- [license & should be &amp;, < should &lt;]
+ [purpose &amp; should be &amp;amp;, &lt; should &amp;lt;]
+ [license &amp; should be &amp;amp;, &lt; should &amp;lt;]
 ]
 
 [section Escapes & explicitly written markup]


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