From 01850ea92bfe1fa4000bc82d2db3bf4d9abe00f3 Mon Sep 17 00:00:00 2001 From: Daniel James Date: Sun, 20 Jun 2010 20:30:32 +0000 Subject: [PATCH] Smarter use of paragraphs with templates. Use the new paragraph output system to avoid expanding block templates inside paragraphs. Refs #4302 [SVN r63162] --- phrase_actions.hpp | 2 +- phrase_grammar.cpp | 2 +- template.cpp | 27 ++++-- test/callouts.gold | 68 +++++++--------- test/import.gold | 140 +++++++++++++++----------------- test/quickbook-manual.gold | 126 +++++++++++++--------------- test/template-section.gold | 32 ++++---- test/template-section.quickbook | 2 +- test/templates.gold | 20 ++--- 9 files changed, 197 insertions(+), 222 deletions(-) diff --git a/phrase_actions.hpp b/phrase_actions.hpp index 875a08b..06fa2df 100644 --- a/phrase_actions.hpp +++ b/phrase_actions.hpp @@ -25,7 +25,7 @@ namespace quickbook break_ process(quickbook::state&, break_ const&); boost::variant process(quickbook::state&, code const&); image2 process(quickbook::state&, image const&); - std::string process(quickbook::state&, call_template const&); + nothing process(quickbook::state&, call_template const&); } #endif diff --git a/phrase_grammar.cpp b/phrase_grammar.cpp index 98bc6b2..799ae19 100644 --- a/phrase_grammar.cpp +++ b/phrase_grammar.cpp @@ -110,7 +110,7 @@ namespace quickbook ] ; - simple_format_multiple_char + simple_format_chars = *( qi::char_ - ( (qi::graph >> qi::lit(qi::_r1)) | simple_phrase_end // Make sure that we don't go diff --git a/template.cpp b/template.cpp index 68270ba..7316269 100644 --- a/template.cpp +++ b/template.cpp @@ -354,6 +354,7 @@ namespace quickbook ++first; // skip initial newlines r = boost::spirit::qi::parse(first, last, g.block) && first == last; + state.paragraph_output(); state.block.swap(result); } @@ -361,7 +362,7 @@ namespace quickbook } } - std::string process(quickbook::state& state, call_template const& x) + nothing process(quickbook::state& state, call_template const& x) { ++state.template_depth; if (state.template_depth > state.max_template_depth) @@ -370,7 +371,7 @@ namespace quickbook << "Infinite loop detected" << std::endl; --state.template_depth; ++state.error_count; - return ""; + return nothing(); } // The template arguments should have the scope that the template was @@ -403,7 +404,7 @@ namespace quickbook state.pop(); // restore the state --state.template_depth; ++state.error_count; - return ""; + return nothing(); } /////////////////////////////////// @@ -418,7 +419,7 @@ namespace quickbook { state.pop(); // restore the state --state.template_depth; - return ""; + return nothing(); } /////////////////////////////////// @@ -436,7 +437,7 @@ namespace quickbook state.pop(); // restore the state --state.template_depth; ++state.error_count; - return ""; + return nothing(); } if (state.section_level != state.min_section_level) @@ -446,7 +447,7 @@ namespace quickbook state.pop(); // restore the actions' states --state.template_depth; ++state.error_count; - return ""; + return nothing(); } } @@ -470,7 +471,7 @@ namespace quickbook << "Error expanding callout." << std::endl; ++state.error_count; - return ""; + return nothing(); } list.push_back(item); @@ -484,8 +485,16 @@ namespace quickbook result += state.block.str(); state.pop(); } - - return result; + + if(x.symbol->is_block) { + state.paragraph_output(); + state.block << result; + } + else { + state.phrase << result; + } + + return nothing(); } } diff --git a/test/callouts.gold b/test/callouts.gold index ee41292..08d8b5a 100644 --- a/test/callouts.gold +++ b/test/callouts.gold @@ -9,67 +9,61 @@ Example 1: - - Now we can define a function that simulates an ordinary six-sided die. - - - + Now we can define a function that simulates an ordinary six-sided die. + + + int roll_die() { boost::uniform_int<> dist(1, 6); } - - - - - create a uniform_int distribution - - - + + + + create a uniform_int distribution + + + Example 2: - - + int roll_die() { boost::variate_generator<boost::mt19937&, boost::uniform_int<> > die(gen, dist); } - - - - - - test - - - - + + + + + test + + + + Example 3: - - + int roll_die() { boost::variate_generator<boost::mt19937&, boost::uniform_int<> > die(gen, dist); } - - - - - - test - - - - + + + + + test + + + + diff --git a/test/import.gold b/test/import.gold index 983380c..1f5ec8a 100644 --- a/test/import.gold +++ b/test/import.gold @@ -5,99 +5,93 @@ - - This is the foo function. - - - This description can have paragraphs... - - - - - lists - - - - - etc. - - - - - And any quickbook block markup. - - - + This is the foo function. + + + This description can have paragraphs... + + + + + lists + + + + + etc. + + + + + And any quickbook block markup. + + + std::string foo() { // return 'em, foo man! return "foo"; } - - - This is the Python foo - function. - - - This description can have paragraphs... - - - - - lists - - - - - etc. - - - - - And any quickbook block markup. - - - + This is the Python foo + function. + + + This description can have paragraphs... + + + + + lists + + + + + etc. + + + + + And any quickbook block markup. + + + def foo(): # return 'em, foo man! return "foo" - - - This is the C foo function. - - - This description can have paragraphs... - - - - - lists - - - - - etc. - - - - - And any quickbook block markup. - - - + This is the C foo function. + + + This description can have paragraphs... + + + + + lists + + + + + etc. + + + + + And any quickbook block markup. + + + char* foo() { // return 'em, foo man! return "foo"; } - diff --git a/test/quickbook-manual.gold b/test/quickbook-manual.gold index c8ceaa5..4849729 100644 --- a/test/quickbook-manual.gold +++ b/test/quickbook-manual.gold @@ -2060,12 +2060,12 @@ replacement text... Which will expand to: - - Hi, my name is James Bond. I am 39 years old. I am a Spy. - - - Hi, my name is Santa Clause. I am 87 years old. I am a Big Red Fatso. - + Hi, my name is James Bond. I am 39 years old. I am a Spy. + + + + + Hi, my name is Santa Clause. I am 87 years old. I am a Big Red Fatso. @@ -2689,52 +2689,50 @@ for the journey to old age.]]] And the result is: - - This is the foo - function. - - - This description can have paragraphs... - - - - - lists - - - - - etc. - - - - - And any quickbook block markup. - - - + This is the foo function. + + + This description can have paragraphs... + + + + + lists + + + + + etc. + + + + + And any quickbook block markup. + + + std::string foo() { // return 'em, foo man! return "foo"; } - - - This is the bar - function - - - + + + + + This is the bar function + + + std::string bar() { // return 'em, bar man! return "bar"; } - - - Some trailing text here - + + + Some trailing text here @@ -2798,28 +2796,26 @@ for the journey to old age.]]] for details. Example: - - + std::string foo_bar() { return "foo-bar"; } - - - - - The Mythical FooBar. See Foobar - for details - - - - - return 'em, foo-bar man! - - - + + + + The Mythical FooBar. See Foobar + for details + + + + + return 'em, foo-bar man! + + + Checkout stub.cpp to see the actual code. @@ -3740,13 +3736,11 @@ boostbook standalone - - + # one # two # three - @@ -3762,13 +3756,11 @@ boostbook standalone - - + * one * two * three - @@ -4005,14 +3997,12 @@ boostbook standalone - - + [table Title [[a][b][c]] [[a][b][c]] ] - @@ -4027,14 +4017,12 @@ boostbook standalone - - + [variablelist Title [[a][b]] [[a][b]] ] - diff --git a/test/template-section.gold b/test/template-section.gold index 748900c..16a0adc 100644 --- a/test/template-section.gold +++ b/test/template-section.gold @@ -6,22 +6,20 @@ - - It's a pity if the whole template is wrapped in a paragraph. - -
- <link linkend="section_in_a_template.test">Test</link> - - Hello. - - - - Just - to test id generation - - - Goodbye. - -
+ Some text before the section.
+
+ <link linkend="section_in_a_template.test">Test</link> + + Hello. + + + + Just + to test id generation + + + Goodbye. + +
diff --git a/test/template-section.quickbook b/test/template-section.quickbook index 0f88d71..670654a 100644 --- a/test/template-section.quickbook +++ b/test/template-section.quickbook @@ -4,7 +4,7 @@ [template nestedsection[] -It's a pity if the whole template is wrapped in a paragraph. +Some text before the section. [section Test] diff --git a/test/templates.gold b/test/templates.gold index fa8cd60..2b9e584 100644 --- a/test/templates.gold +++ b/test/templates.gold @@ -13,24 +13,18 @@ foo baz
- - foo baz - + foo baz - - This is a complete paragraph. kalamazoo kalamazoo kalamazoo kalamazoo kalamazoo - kalamazoo kalamazoo kalamazoo kalamazoo.... blah blah blah...... - + This is a complete paragraph. kalamazoo kalamazoo kalamazoo kalamazoo kalamazoo + kalamazoo kalamazoo kalamazoo kalamazoo.... blah blah blah...... baz - - This is a complete paragraph. madagascar madagascar madagascar madagascar - madagascar madagascar madagascar madagascar madagascar.... blah blah blah...... - + This is a complete paragraph. madagascar madagascar madagascar madagascar madagascar + madagascar madagascar madagascar madagascar.... blah blah blah...... zoom peanut zoom @@ -44,14 +38,12 @@ wxyz wxyz trail - - + int main() { std::cout << "Hello, World" << std::endl; } - x2