Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r85247 - in trunk/tools/quickbook: src test
From: dnljms_at_[hidden]
Date: 2013-08-08 17:22:52


Author: danieljames
Date: 2013-08-08 17:22:52 EDT (Thu, 08 Aug 2013)
New Revision: 85247
URL: http://svn.boost.org/trac/boost/changeset/85247

Log:
Attempt at better list markup.

Doesn't work for: templates in lists or explicit list block elements
(because it detects when it's in a list based on the parser), but it is
usually at least as good as the older version.

This kind of thing would be much easier if I represented the lists in
data rather than translating them as they are parsed. Not sure if I'll
do that soon though.

Text files modified:
   trunk/tools/quickbook/src/actions.cpp | 42 +++++++--------
   trunk/tools/quickbook/src/actions.hpp | 15 -----
   trunk/tools/quickbook/src/block_tags.hpp | 2
   trunk/tools/quickbook/src/main_grammar.cpp | 55 ++++++++++++++-------
   trunk/tools/quickbook/src/markups.cpp | 1
   trunk/tools/quickbook/src/state.cpp | 2
   trunk/tools/quickbook/src/state.hpp | 1
   trunk/tools/quickbook/test/list_test-1_6.gold | 56 ++++++++++----------
   trunk/tools/quickbook/test/list_test-1_7.gold | 102 +++++++++++++++++++--------------------
   trunk/tools/quickbook/test/templates-1_3.gold | 46 +++++++----------
   trunk/tools/quickbook/test/templates-1_5.gold | 46 +++++++----------
   trunk/tools/quickbook/test/templates-1_6.gold | 46 +++++++----------
   trunk/tools/quickbook/test/templates-1_7.gold | 46 +++++++----------
   13 files changed, 215 insertions(+), 245 deletions(-)

Modified: trunk/tools/quickbook/src/actions.cpp
==============================================================================
--- trunk/tools/quickbook/src/actions.cpp Thu Aug 8 16:30:04 2013 (r85246)
+++ trunk/tools/quickbook/src/actions.cpp 2013-08-08 17:22:52 EDT (Thu, 08 Aug 2013) (r85247)
@@ -322,29 +322,15 @@
         while(pos != end && cl::space_p.test(*pos)) ++pos;
 
         if(pos != end) {
- detail::markup markup = detail::get_markup(block_tags::paragraph);
+ detail::markup markup = state.in_list ?
+ detail::get_markup(block_tags::paragraph_in_list) :
+ detail::get_markup(block_tags::paragraph);
             state.out << markup.pre << str;
             write_anchors(state, state.out);
             state.out << markup.post;
         }
     }
 
- void list_item_action::operator()() const
- {
- // Be careful as this is sometimes called in the wrong place
- // for markup such as:
- //
- // * A
- // [endsect]
- //
- // This action is called before [endsect] (to end the list item)
- // and then also after it due to the way the parser works.
- std::string str;
- state.phrase.swap(str);
- state.out << str;
- write_anchors(state, state.out);
- }
-
     void phrase_end_action::operator()() const
     {
         write_anchors(state, state.phrase);
@@ -522,8 +508,10 @@
 
     void state::start_list(char mark)
     {
- write_anchors(*this, out);
+ write_anchors(*this, (in_list ? phrase : out));
         assert(mark == '*' || mark == '#');
+ phrase.push();
+ out.push();
         out << ((mark == '#') ? "<orderedlist>\n" : "<itemizedlist>\n");
     }
 
@@ -532,18 +520,28 @@
         write_anchors(*this, out);
         assert(mark == '*' || mark == '#');
         out << ((mark == '#') ? "\n</orderedlist>" : "\n</itemizedlist>");
+
+ std::string list_output;
+ out.swap(list_output);
+
+ out.pop();
+ phrase.pop();
+
+ (in_list ? phrase : out) << list_output;
     }
 
     void state::start_list_item()
     {
- out << "<listitem><simpara>";
- write_anchors(*this, out);
+ out << "<listitem>";
+ write_anchors(*this, phrase);
     }
 
     void state::end_list_item()
     {
- write_anchors(*this, out);
- out << "</simpara></listitem>";
+ write_anchors(*this, phrase);
+ paragraph_action para(*this);
+ para();
+ out << "</listitem>";
     }
 
     namespace

Modified: trunk/tools/quickbook/src/actions.hpp
==============================================================================
--- trunk/tools/quickbook/src/actions.hpp Thu Aug 8 16:30:04 2013 (r85246)
+++ trunk/tools/quickbook/src/actions.hpp 2013-08-08 17:22:52 EDT (Thu, 08 Aug 2013) (r85247)
@@ -119,21 +119,6 @@
         quickbook::state& state;
     };
 
- struct list_item_action
- {
- // implicit paragraphs
- // doesn't output the paragraph if it's only whitespace.
-
- list_item_action(
- quickbook::state& state)
- : state(state) {}
-
- void operator()() const;
- void operator()(parse_iterator, parse_iterator) const { (*this)(); }
-
- quickbook::state& state;
- };
-
     struct phrase_end_action
     {
         phrase_end_action(quickbook::state& state) :

Modified: trunk/tools/quickbook/src/block_tags.hpp
==============================================================================
--- trunk/tools/quickbook/src/block_tags.hpp Thu Aug 8 16:30:04 2013 (r85246)
+++ trunk/tools/quickbook/src/block_tags.hpp 2013-08-08 17:22:52 EDT (Thu, 08 Aug 2013) (r85247)
@@ -22,7 +22,7 @@
         (macro_definition)(template_definition)
         (variable_list)(table)
         (xinclude)(import)(include)
- (paragraph)
+ (paragraph)(paragraph_in_list)
         (ordered_list)(itemized_list)
         (hr)
     )

Modified: trunk/tools/quickbook/src/main_grammar.cpp
==============================================================================
--- trunk/tools/quickbook/src/main_grammar.cpp Thu Aug 8 16:30:04 2013 (r85246)
+++ trunk/tools/quickbook/src/main_grammar.cpp 2013-08-08 17:22:52 EDT (Thu, 08 Aug 2013) (r85247)
@@ -160,6 +160,16 @@
             , mark('\0')
             , state_(state)
             {}
+
+ void push_list_item(list_stack_item const& item) {
+ list_stack.push(item);
+ state_.in_list = !list_stack.top().root;
+ }
+
+ void pop_list_item() {
+ list_stack.pop();
+ state_.in_list = !list_stack.empty() && !list_stack.top().root;
+ }
     };
 
     struct process_element_impl : scoped_action_base {
@@ -252,7 +262,8 @@
             l(l) {}
 
         bool operator()() const {
- return !l.list_stack.top().root;
+ //return !l.list_stack.top().root;
+ return l.state_.in_list;
         }
     };
 
@@ -300,7 +311,6 @@
         // Global Actions
         quickbook::element_action element_action(state);
         quickbook::paragraph_action paragraph_action(state);
- quickbook::list_item_action list_item_action(state);
 
         phrase_end_action end_phrase(state);
         raw_char_action raw_char(state.phrase);
@@ -462,7 +472,10 @@
             ;
 
         local.paragraph =
- scoped_context(element_info::in_top_level)
+ // Usually superfluous call
+ // for paragraphs in lists.
+ cl::eps_p [paragraph_action]
+ >> scoped_context(element_info::in_top_level)
             [ scoped_still_in_block(true)
                 [ local.syntactic_block_item(element_info::is_contextual_block)
>> *( cl::eps_p(ph::var(local.still_in_block))
@@ -482,9 +495,7 @@
>> local.syntactic_block_item(element_info::is_block)
                         )
                     ]
- ] [list_item_action]
- // TODO: `list_item_action` is sometimes called in the wrong
- // place. Currently harmless.
+ ]
             ;
 
         local.syntactic_block_item =
@@ -1017,18 +1028,18 @@
 
     void main_grammar_local::start_blocks_impl(parse_iterator, parse_iterator)
     {
- list_stack.push(list_stack_item(list_stack_item::top_root));
+ push_list_item(list_stack_item(list_stack_item::top_root));
     }
 
     void main_grammar_local::start_nested_blocks_impl(parse_iterator, parse_iterator)
     {
- list_stack.push(list_stack_item(list_stack_item::nested_root));
+ push_list_item(list_stack_item(list_stack_item::nested_root));
     }
 
     void main_grammar_local::end_blocks_impl(parse_iterator, parse_iterator)
     {
         clear_stack();
- list_stack.pop();
+ pop_list_item();
     }
 
     void main_grammar_local::check_indentation_impl(parse_iterator first_, parse_iterator last_)
@@ -1071,9 +1082,11 @@
             else {
                 while (!list_stack.top().root && new_indent < list_stack.top().indent)
                 {
+ char mark = list_stack.top().mark;
+
                     state_.end_list_item();
- state_.end_list(list_stack.top().mark);
- list_stack.pop();
+ pop_list_item();
+ state_.end_list(mark);
                     list_indent = list_stack.top().indent;
                 }
 
@@ -1098,19 +1111,21 @@
                     // Back to Level 1
                 
                     list_stack_item save = list_stack.top();
- list_stack.pop();
+ pop_list_item();
 
                     assert(list_stack.top().root ?
                         new_indent >= list_stack.top().indent :
                         new_indent > list_stack.top().indent);
 
                     if (new_indent <= list_stack.top().indent2) {
+ push_list_item(save);
                         state_.end_list_item();
+ pop_list_item();
                         state_.end_list(save.mark);
                         list_indent = list_stack.top().indent;
                     }
                     else {
- list_stack.push(save);
+ push_list_item(save);
                     }
                 }
 
@@ -1150,8 +1165,8 @@
         }
 
         if (list_stack.top().root || new_indent > list_indent) {
- list_stack.push(list_stack_item(mark, new_indent, new_indent2));
             state_.start_list(mark);
+ push_list_item(list_stack_item(mark, new_indent, new_indent2));
         }
         else if (new_indent == list_indent) {
             state_.end_list_item();
@@ -1161,9 +1176,11 @@
             // has indentation 0.
             while(!list_stack.top().root && new_indent < list_stack.top().indent)
             {
+ char mark = list_stack.top().mark;
+
                 state_.end_list_item();
- state_.end_list(list_stack.top().mark);
- list_stack.pop();
+ pop_list_item();
+ state_.end_list(mark);
             }
 
             state_.end_list_item();
@@ -1187,9 +1204,11 @@
     void main_grammar_local::clear_stack()
     {
         while (!list_stack.top().root) {
+ char mark = list_stack.top().mark;
+
             state_.end_list_item();
- state_.end_list(list_stack.top().mark);
- list_stack.pop();
+ pop_list_item();
+ state_.end_list(mark);
         }
     }
 }

Modified: trunk/tools/quickbook/src/markups.cpp
==============================================================================
--- trunk/tools/quickbook/src/markups.cpp Thu Aug 8 16:30:04 2013 (r85246)
+++ trunk/tools/quickbook/src/markups.cpp 2013-08-08 17:22:52 EDT (Thu, 08 Aug 2013) (r85247)
@@ -26,6 +26,7 @@
         {
             markup init_markups[] = {
                 { block_tags::paragraph, "<para>\n", "</para>\n" },
+ { block_tags::paragraph_in_list, "<simpara>\n", "</simpara>\n" },
                 { block_tags::blurb, "<sidebar role=\"blurb\">\n", "</sidebar>\n" },
                 { block_tags::blockquote, "<blockquote>", "</blockquote>" },
                 { block_tags::preformatted, "<programlisting>", "</programlisting>" },

Modified: trunk/tools/quickbook/src/state.cpp
==============================================================================
--- trunk/tools/quickbook/src/state.cpp Thu Aug 8 16:30:04 2013 (r85246)
+++ trunk/tools/quickbook/src/state.cpp 2013-08-08 17:22:52 EDT (Thu, 08 Aug 2013) (r85247)
@@ -39,6 +39,8 @@
         , ids(ids)
         , callouts()
         , callout_depth(0)
+ , dependencies()
+ , in_list(false)
 
         , imported(false)
         , macro()

Modified: trunk/tools/quickbook/src/state.hpp
==============================================================================
--- trunk/tools/quickbook/src/state.hpp Thu Aug 8 16:30:04 2013 (r85246)
+++ trunk/tools/quickbook/src/state.hpp 2013-08-08 17:22:52 EDT (Thu, 08 Aug 2013) (r85247)
@@ -52,6 +52,7 @@
         value_builder callouts; // callouts are global as
         int callout_depth; // they don't nest.
         dependency_tracker dependencies;
+ bool in_list;
 
     // state saved for files and templates.
         bool imported;

Modified: trunk/tools/quickbook/test/list_test-1_6.gold
==============================================================================
--- trunk/tools/quickbook/test/list_test-1_6.gold Thu Aug 8 16:30:04 2013 (r85246)
+++ trunk/tools/quickbook/test/list_test-1_6.gold 2013-08-08 17:22:52 EDT (Thu, 08 Aug 2013) (r85247)
@@ -310,29 +310,29 @@
       </simpara>
     </listitem>
     <listitem>
+ <informaltable frame="all">
+ <tgroup cols="1">
+ <thead>
+ <row>
+ <entry>
+ <simpara>
+ Heading
+ </simpara>
+ </entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>
+ <simpara>
+ Cell
+ </simpara>
+ </entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </informaltable>
       <simpara>
- <informaltable frame="all">
- <tgroup cols="1">
- <thead>
- <row>
- <entry>
- <para>
- Heading
- </para>
- </entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>
- <para>
- Cell
- </para>
- </entry>
- </row>
- </tbody>
- </tgroup>
- </informaltable>
         Some text.
       </simpara>
     </listitem>
@@ -343,17 +343,17 @@
     </listitem>
     <listitem>
       <simpara>
- <para>
- Paragraph cheat 1.
- </para>
+ Paragraph cheat 1.
+ </simpara>
+ <simpara>
         Paragraph cheat 2.
       </simpara>
     </listitem>
     <listitem>
       <simpara>
- <para>
- Paragraph cheat 3.
- </para>
+ Paragraph cheat 3.
+ </simpara>
+ <simpara>
         Paragraph cheat 4.
       </simpara>
     </listitem>

Modified: trunk/tools/quickbook/test/list_test-1_7.gold
==============================================================================
--- trunk/tools/quickbook/test/list_test-1_7.gold Thu Aug 8 16:30:04 2013 (r85246)
+++ trunk/tools/quickbook/test/list_test-1_7.gold 2013-08-08 17:22:52 EDT (Thu, 08 Aug 2013) (r85247)
@@ -310,40 +310,36 @@
       </simpara>
     </listitem>
     <listitem>
- <simpara>
- <informaltable frame="all">
- <tgroup cols="1">
- <thead>
- <row>
- <entry>
- <para>
- Heading
- </para>
- </entry>
- </row>
- </thead>
- <tbody>
- <row>
- <entry>
- <para>
- Cell
- </para>
- </entry>
- </row>
- </tbody>
- </tgroup>
- </informaltable>
- </simpara>
+ <informaltable frame="all">
+ <tgroup cols="1">
+ <thead>
+ <row>
+ <entry>
+ <para>
+ Heading
+ </para>
+ </entry>
+ </row>
+ </thead>
+ <tbody>
+ <row>
+ <entry>
+ <para>
+ Cell
+ </para>
+ </entry>
+ </row>
+ </tbody>
+ </tgroup>
+ </informaltable>
     </listitem>
     <listitem>
+ <bridgehead renderas="sect2" id="list_test.h0">
+ <phrase id="list_test.the_heading_for_a_list_item"/><link linkend="list_test.the_heading_for_a_list_item">The
+ heading for a list item</link>
+ </bridgehead>
       <simpara>
- <bridgehead renderas="sect2" id="list_test.h0">
- <phrase id="list_test.the_heading_for_a_list_item"/><link linkend="list_test.the_heading_for_a_list_item">The
- heading for a list item</link>
- </bridgehead>
- <para>
- The content of the list item.
- </para>
+ The content of the list item.
       </simpara>
     </listitem>
   </itemizedlist>
@@ -406,9 +402,9 @@
       <listitem>
         <simpara>
           A1
- <para>
- A2
- </para>
+ </simpara>
+ <simpara>
+ A2
         </simpara>
       </listitem>
       <listitem>
@@ -418,15 +414,15 @@
             <listitem>
               <simpara>
                 C1
- <para>
- C2
- </para>
+ </simpara>
+ <simpara>
+ C2
               </simpara>
             </listitem>
           </itemizedlist>
- <para>
- B2
- </para>
+ </simpara>
+ <simpara>
+ B2
         </simpara>
       </listitem>
       <listitem>
@@ -436,18 +432,18 @@
             <listitem>
               <simpara>
                 E1
- <para>
- E2
- </para>
- <para>
- E3
- </para>
+ </simpara>
+ <simpara>
+ E2
+ </simpara>
+ <simpara>
+ E3
               </simpara>
             </listitem>
           </itemizedlist>
- <para>
- D2
- </para>
+ </simpara>
+ <simpara>
+ D2
         </simpara>
       </listitem>
     </itemizedlist>
@@ -459,19 +455,19 @@
       <listitem>
         <simpara>
           A
+ </simpara>
 <programlisting><phrase role="identifier">B</phrase>
 </programlisting>
- <para>
- C
- </para>
+ <simpara>
+ C
         </simpara>
       </listitem>
       <listitem>
         <simpara>
           D
+ </simpara>
 <programlisting><phrase role="identifier">E</phrase>
 </programlisting>
- </simpara>
       </listitem>
       <listitem>
         <simpara>

Modified: trunk/tools/quickbook/test/templates-1_3.gold
==============================================================================
--- trunk/tools/quickbook/test/templates-1_3.gold Thu Aug 8 16:30:04 2013 (r85246)
+++ trunk/tools/quickbook/test/templates-1_3.gold 2013-08-08 17:22:52 EDT (Thu, 08 Aug 2013) (r85247)
@@ -151,40 +151,32 @@
     </para>
     <itemizedlist>
       <listitem>
- <simpara>
- <itemizedlist>
- <listitem>
- <simpara>
- a
- </simpara>
- </listitem>
- <listitem>
- <simpara>
- b
- </simpara>
- </listitem>
- </itemizedlist>
- </simpara>
+ <itemizedlist>
+ <listitem>
+ <simpara>
+ a
+ </simpara>
+ </listitem>
+ <listitem>
+ <simpara>
+ b
+ </simpara>
+ </listitem>
+ </itemizedlist>
       </listitem>
       <listitem>
- <simpara>
- <para/>
- </simpara>
+ <para/>
       </listitem>
       <listitem>
- <simpara>
 <programlisting><phrase role="keyword">int</phrase> <phrase role="identifier">main</phrase><phrase role="special">()</phrase> <phrase role="special">{}</phrase></programlisting>
- </simpara>
       </listitem>
       <listitem>
- <simpara>
- <para>
- Paragraphs 1
- </para>
- <para>
- Paragraphs 2
- </para>
- </simpara>
+ <para>
+ Paragraphs 1
+ </para>
+ <para>
+ Paragraphs 2
+ </para>
       </listitem>
     </itemizedlist>
   </section>

Modified: trunk/tools/quickbook/test/templates-1_5.gold
==============================================================================
--- trunk/tools/quickbook/test/templates-1_5.gold Thu Aug 8 16:30:04 2013 (r85246)
+++ trunk/tools/quickbook/test/templates-1_5.gold 2013-08-08 17:22:52 EDT (Thu, 08 Aug 2013) (r85247)
@@ -152,40 +152,32 @@
     </para>
     <itemizedlist>
       <listitem>
- <simpara>
- <itemizedlist>
- <listitem>
- <simpara>
- a
- </simpara>
- </listitem>
- <listitem>
- <simpara>
- b
- </simpara>
- </listitem>
- </itemizedlist>
- </simpara>
+ <itemizedlist>
+ <listitem>
+ <simpara>
+ a
+ </simpara>
+ </listitem>
+ <listitem>
+ <simpara>
+ b
+ </simpara>
+ </listitem>
+ </itemizedlist>
       </listitem>
       <listitem>
- <simpara>
- <para/>
- </simpara>
+ <para/>
       </listitem>
       <listitem>
- <simpara>
 <programlisting><phrase role="keyword">int</phrase> <phrase role="identifier">main</phrase><phrase role="special">()</phrase> <phrase role="special">{}</phrase></programlisting>
- </simpara>
       </listitem>
       <listitem>
- <simpara>
- <para>
- Paragraphs 1
- </para>
- <para>
- Paragraphs 2
- </para>
- </simpara>
+ <para>
+ Paragraphs 1
+ </para>
+ <para>
+ Paragraphs 2
+ </para>
       </listitem>
     </itemizedlist>
   </section>

Modified: trunk/tools/quickbook/test/templates-1_6.gold
==============================================================================
--- trunk/tools/quickbook/test/templates-1_6.gold Thu Aug 8 16:30:04 2013 (r85246)
+++ trunk/tools/quickbook/test/templates-1_6.gold 2013-08-08 17:22:52 EDT (Thu, 08 Aug 2013) (r85247)
@@ -152,40 +152,32 @@
     </para>
     <itemizedlist>
       <listitem>
- <simpara>
- <itemizedlist>
- <listitem>
- <simpara>
- a
- </simpara>
- </listitem>
- <listitem>
- <simpara>
- b
- </simpara>
- </listitem>
- </itemizedlist>
- </simpara>
+ <itemizedlist>
+ <listitem>
+ <simpara>
+ a
+ </simpara>
+ </listitem>
+ <listitem>
+ <simpara>
+ b
+ </simpara>
+ </listitem>
+ </itemizedlist>
       </listitem>
       <listitem>
- <simpara>
- <para/>
- </simpara>
+ <para/>
       </listitem>
       <listitem>
- <simpara>
 <programlisting><phrase role="keyword">int</phrase> <phrase role="identifier">main</phrase><phrase role="special">()</phrase> <phrase role="special">{}</phrase></programlisting>
- </simpara>
       </listitem>
       <listitem>
- <simpara>
- <para>
- Paragraphs 1
- </para>
- <para>
- Paragraphs 2
- </para>
- </simpara>
+ <para>
+ Paragraphs 1
+ </para>
+ <para>
+ Paragraphs 2
+ </para>
       </listitem>
     </itemizedlist>
   </section>

Modified: trunk/tools/quickbook/test/templates-1_7.gold
==============================================================================
--- trunk/tools/quickbook/test/templates-1_7.gold Thu Aug 8 16:30:04 2013 (r85246)
+++ trunk/tools/quickbook/test/templates-1_7.gold 2013-08-08 17:22:52 EDT (Thu, 08 Aug 2013) (r85247)
@@ -146,40 +146,32 @@
     </para>
     <itemizedlist>
       <listitem>
- <simpara>
- <itemizedlist>
- <listitem>
- <simpara>
- a
- </simpara>
- </listitem>
- <listitem>
- <simpara>
- b
- </simpara>
- </listitem>
- </itemizedlist>
- </simpara>
+ <itemizedlist>
+ <listitem>
+ <simpara>
+ a
+ </simpara>
+ </listitem>
+ <listitem>
+ <simpara>
+ b
+ </simpara>
+ </listitem>
+ </itemizedlist>
       </listitem>
       <listitem>
- <simpara>
- <para/>
- </simpara>
+ <para/>
       </listitem>
       <listitem>
- <simpara>
 <programlisting><phrase role="keyword">int</phrase> <phrase role="identifier">main</phrase><phrase role="special">()</phrase> <phrase role="special">{}</phrase></programlisting>
- </simpara>
       </listitem>
       <listitem>
- <simpara>
- <para>
- Paragraphs 1
- </para>
- <para>
- Paragraphs 2
- </para>
- </simpara>
+ <para>
+ Paragraphs 1
+ </para>
+ <para>
+ Paragraphs 2
+ </para>
       </listitem>
     </itemizedlist>
   </section>


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