Smarter use of paragraphs with templates.

Use the new paragraph output system to avoid expanding block templates
inside paragraphs. Refs #4302

[SVN r63162]
This commit is contained in:
Daniel James
2010-06-20 20:30:32 +00:00
parent 0083abffe5
commit 01850ea92b
9 changed files with 197 additions and 222 deletions

View File

@@ -25,7 +25,7 @@ namespace quickbook
break_ process(quickbook::state&, break_ const&);
boost::variant<formatted, block_formatted> 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

View File

@@ -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

View File

@@ -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();
}
}

View File

@@ -9,67 +9,61 @@
Example 1:
</para>
<para>
<para>
Now we can define a function that simulates an ordinary six-sided die.
</para>
<para>
Now we can define a function that simulates an ordinary six-sided die.
</para>
<para>
<programlisting><phrase role="keyword">int</phrase> <phrase role="identifier">roll_die</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
<phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">uniform_int</phrase><phrase role="special">&lt;&gt;</phrase> <phrase role="identifier">dist</phrase><phrase role="special">(</phrase><phrase role="number">1</phrase><phrase role="special">,</phrase> <phrase role="number">6</phrase><phrase role="special">);</phrase> <co id="callout_tests0co" linkends="callout_tests0" />
<phrase role="special">}</phrase>
</programlisting>
</para>
<calloutlist>
<callout arearefs="callout_tests0co" id="callout_tests0">
<para>
create a uniform_int distribution
</para>
</callout>
</calloutlist>
</para>
<calloutlist>
<callout arearefs="callout_tests0co" id="callout_tests0">
<para>
create a uniform_int distribution
</para>
</callout>
</calloutlist>
<para>
Example 2:
</para>
<para>
<para>
<programlisting><phrase role="keyword">int</phrase> <phrase role="identifier">roll_die</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
<co id="callout_tests1co" linkends="callout_tests1" /><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">variate_generator</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">mt19937</phrase><phrase role="special">&amp;,</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">uniform_int</phrase><phrase role="special">&lt;&gt;</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">die</phrase><phrase role="special">(</phrase><phrase role="identifier">gen</phrase><phrase role="special">,</phrase> <phrase role="identifier">dist</phrase><phrase role="special">);</phrase>
<phrase role="special">}</phrase>
</programlisting>
</para>
<calloutlist>
<callout arearefs="callout_tests1co" id="callout_tests1">
<important>
<para>
test
</para>
</important>
</callout>
</calloutlist>
</para>
<calloutlist>
<callout arearefs="callout_tests1co" id="callout_tests1">
<important>
<para>
test
</para>
</important>
</callout>
</calloutlist>
<para>
Example 3:
</para>
<para>
<para>
<programlisting><phrase role="keyword">int</phrase> <phrase role="identifier">roll_die</phrase><phrase role="special">()</phrase> <phrase role="special">{</phrase>
<co id="callout_tests2co" linkends="callout_tests2" /><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">variate_generator</phrase><phrase role="special">&lt;</phrase><phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">mt19937</phrase><phrase role="special">&amp;,</phrase> <phrase role="identifier">boost</phrase><phrase role="special">::</phrase><phrase role="identifier">uniform_int</phrase><phrase role="special">&lt;&gt;</phrase> <phrase role="special">&gt;</phrase> <phrase role="identifier">die</phrase><phrase role="special">(</phrase><phrase role="identifier">gen</phrase><phrase role="special">,</phrase> <phrase role="identifier">dist</phrase><phrase role="special">);</phrase>
<phrase role="special">}</phrase>
</programlisting>
</para>
<calloutlist>
<callout arearefs="callout_tests2co" id="callout_tests2">
<important>
<para>
test
</para>
</important>
</callout>
</calloutlist>
</para>
<calloutlist>
<callout arearefs="callout_tests2co" id="callout_tests2">
<important>
<para>
test
</para>
</important>
</callout>
</calloutlist>
</article>

View File

@@ -5,99 +5,93 @@
<articleinfo>
</articleinfo>
<para>
<para>
This is the <emphasis role="bold"><emphasis>foo</emphasis></emphasis> function.
</para>
<para>
This description can have paragraphs...
</para>
<itemizedlist>
<listitem>
<simpara>
lists
</simpara>
</listitem>
<listitem>
<simpara>
etc.
</simpara>
</listitem>
</itemizedlist>
<para>
And any quickbook block markup.
</para>
<para>
This is the <emphasis role="bold"><emphasis>foo</emphasis></emphasis> function.
</para>
<para>
This description can have paragraphs...
</para>
<itemizedlist>
<listitem>
<simpara>
lists
</simpara>
</listitem>
<listitem>
<simpara>
etc.
</simpara>
</listitem>
</itemizedlist>
<para>
And any quickbook block markup.
</para>
<para>
<programlisting><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</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">&quot;foo&quot;</phrase><phrase role="special">;</phrase>
<phrase role="special">}</phrase>
</programlisting>
</para>
</para>
<para>
<para>
This is the Python <emphasis role="bold"><emphasis>foo</emphasis></emphasis>
function.
</para>
<para>
This description can have paragraphs...
</para>
<itemizedlist>
<listitem>
<simpara>
lists
</simpara>
</listitem>
<listitem>
<simpara>
etc.
</simpara>
</listitem>
</itemizedlist>
<para>
And any quickbook block markup.
</para>
<para>
This is the Python <emphasis role="bold"><emphasis>foo</emphasis></emphasis>
function.
</para>
<para>
This description can have paragraphs...
</para>
<itemizedlist>
<listitem>
<simpara>
lists
</simpara>
</listitem>
<listitem>
<simpara>
etc.
</simpara>
</listitem>
</itemizedlist>
<para>
And any quickbook block markup.
</para>
<para>
<programlisting><phrase role="keyword">def</phrase> <phrase role="identifier">foo</phrase><phrase role="special">():</phrase>
<phrase role="comment"># return 'em, foo man!
</phrase> <phrase role="keyword">return</phrase> <phrase role="string">&quot;foo&quot;</phrase>
</programlisting>
</para>
</para>
<para>
<para>
This is the C <emphasis role="bold"><emphasis>foo</emphasis></emphasis> function.
</para>
<para>
This description can have paragraphs...
</para>
<itemizedlist>
<listitem>
<simpara>
lists
</simpara>
</listitem>
<listitem>
<simpara>
etc.
</simpara>
</listitem>
</itemizedlist>
<para>
And any quickbook block markup.
</para>
<para>
This is the C <emphasis role="bold"><emphasis>foo</emphasis></emphasis> function.
</para>
<para>
This description can have paragraphs...
</para>
<itemizedlist>
<listitem>
<simpara>
lists
</simpara>
</listitem>
<listitem>
<simpara>
etc.
</simpara>
</listitem>
</itemizedlist>
<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">&quot;foo&quot;</phrase><phrase role="special">;</phrase>
<phrase role="special">}</phrase>
</programlisting>
</para>
</para>
</article>

View File

@@ -2060,12 +2060,12 @@ replacement text...
Which will expand to:
</para>
<para>
<para>
Hi, my name is James Bond. I am 39 years old. I am a Spy.
</para>
<para>
Hi, my name is Santa Clause. I am 87 years old. I am a Big Red Fatso.
</para>
Hi, my name is James Bond. I am 39 years old. I am a Spy.
</para>
<para>
</para>
<para>
Hi, my name is Santa Clause. I am 87 years old. I am a Big Red Fatso.
</para>
<caution>
<para>
@@ -2689,52 +2689,50 @@ for the journey to old age.]]]
And the result is:
</para>
<para>
<para>
This is the <emphasis role="bold"><emphasis>foo</emphasis></emphasis>
function.
</para>
<para>
This description can have paragraphs...
</para>
<itemizedlist>
<listitem>
<simpara>
lists
</simpara>
</listitem>
<listitem>
<simpara>
etc.
</simpara>
</listitem>
</itemizedlist>
<para>
And any quickbook block markup.
</para>
<para>
This is the <emphasis role="bold"><emphasis>foo</emphasis></emphasis> function.
</para>
<para>
This description can have paragraphs...
</para>
<itemizedlist>
<listitem>
<simpara>
lists
</simpara>
</listitem>
<listitem>
<simpara>
etc.
</simpara>
</listitem>
</itemizedlist>
<para>
And any quickbook block markup.
</para>
<para>
<programlisting><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</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">&quot;foo&quot;</phrase><phrase role="special">;</phrase>
<phrase role="special">}</phrase>
</programlisting>
</para>
<para>
This is the <emphasis role="bold"><emphasis>bar</emphasis></emphasis>
function
</para>
<para>
</para>
<para>
</para>
<para>
This is the <emphasis role="bold"><emphasis>bar</emphasis></emphasis> function
</para>
<para>
<programlisting><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="identifier">bar</phrase><phrase role="special">()</phrase>
<phrase role="special">{</phrase>
<phrase role="comment">// return 'em, bar man!
</phrase> <phrase role="keyword">return</phrase> <phrase role="string">&quot;bar&quot;</phrase><phrase role="special">;</phrase>
<phrase role="special">}</phrase></programlisting>
</para>
<para>
Some trailing text here
</para>
</para>
<para>
Some trailing text here
</para>
<anchor id="quickbook.syntax.block.import.code_snippet_markup"/>
<bridgehead renderas="sect5">
@@ -2798,28 +2796,26 @@ for the journey to old age.]]]
for details. Example:
</para>
<para>
<para>
<programlisting><phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">string</phrase> <phrase role="identifier">foo_bar</phrase><phrase role="special">()</phrase> <co id="quickbook0co" linkends="quickbook0" />
<phrase role="special">{</phrase>
<phrase role="keyword">return</phrase> <phrase role="string">&quot;foo-bar&quot;</phrase><phrase role="special">;</phrase> <co id="quickbook1co" linkends="quickbook1" />
<phrase role="special">}</phrase>
</programlisting>
</para>
<calloutlist>
<callout arearefs="quickbook0co" id="quickbook0">
<para>
The <emphasis>Mythical</emphasis> FooBar. See <ulink url="http://en.wikipedia.org/wiki/Foobar">Foobar
for details</ulink>
</para>
</callout>
<callout arearefs="quickbook1co" id="quickbook1">
<para>
return 'em, foo-bar man!
</para>
</callout>
</calloutlist>
</para>
<calloutlist>
<callout arearefs="quickbook0co" id="quickbook0">
<para>
The <emphasis>Mythical</emphasis> FooBar. See <ulink url="http://en.wikipedia.org/wiki/Foobar">Foobar
for details</ulink>
</para>
</callout>
<callout arearefs="quickbook1co" id="quickbook1">
<para>
return 'em, foo-bar man!
</para>
</callout>
</calloutlist>
<para>
Checkout <ulink url="../../test/stub.cpp">stub.cpp</ulink> to see the actual
code.
@@ -3740,13 +3736,11 @@ boostbook standalone
</para>
</entry>
<entry>
<para>
<programlisting><!--quickbook-escape-prefix--># one
# two
# three
<!--quickbook-escape-postfix--></programlisting>
</para>
</entry>
<entry>
<para>
@@ -3762,13 +3756,11 @@ boostbook standalone
</para>
</entry>
<entry>
<para>
<programlisting><!--quickbook-escape-prefix-->* one
* two
* three
<!--quickbook-escape-postfix--></programlisting>
</para>
</entry>
<entry>
<para>
@@ -4005,14 +3997,12 @@ boostbook standalone
</para>
</entry>
<entry>
<para>
<programlisting><!--quickbook-escape-prefix-->[table Title
[[a][b][c]]
[[a][b][c]]
]
<!--quickbook-escape-postfix--></programlisting>
</para>
</entry>
<entry>
<para>
@@ -4027,14 +4017,12 @@ boostbook standalone
</para>
</entry>
<entry>
<para>
<programlisting><!--quickbook-escape-prefix-->[variablelist Title
[[a][b]]
[[a][b]]
]
<!--quickbook-escape-postfix--></programlisting>
</para>
</entry>
<entry>
<para>

View File

@@ -6,22 +6,20 @@
<articleinfo>
</articleinfo>
<para>
<para>
It's a pity if the whole template is wrapped in a paragraph.
</para>
<section id="section_in_a_template.test">
<title><link linkend="section_in_a_template.test">Test</link></title>
<para>
Hello.
</para>
<anchor id="section_in_a_template.test.just_to_test_id_generation"/>
<bridgehead renderas="sect3">
<link linkend="section_in_a_template.test.just_to_test_id_generation">Just
to test id generation</link>
</bridgehead>
<para>
Goodbye.
</para>
</section>
Some text before the section.
</para>
<section id="section_in_a_template.test">
<title><link linkend="section_in_a_template.test">Test</link></title>
<para>
Hello.
</para>
<anchor id="section_in_a_template.test.just_to_test_id_generation"/>
<bridgehead renderas="sect3">
<link linkend="section_in_a_template.test.just_to_test_id_generation">Just
to test id generation</link>
</bridgehead>
<para>
Goodbye.
</para>
</section>
</article>

View File

@@ -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]

View File

@@ -13,24 +13,18 @@
foo baz
</para>
<para>
<para>
foo baz
</para>
foo baz
</para>
<para>
<para>
This is a complete paragraph. kalamazoo kalamazoo kalamazoo kalamazoo kalamazoo
kalamazoo kalamazoo kalamazoo kalamazoo.... blah blah blah......
</para>
This is a complete paragraph. kalamazoo kalamazoo kalamazoo kalamazoo kalamazoo
kalamazoo kalamazoo kalamazoo kalamazoo.... blah blah blah......
</para>
<para>
<hey>baz</hey>
</para>
<para>
<para>
This is a complete paragraph. madagascar madagascar madagascar madagascar
madagascar madagascar madagascar madagascar madagascar.... blah blah blah......
</para>
This is a complete paragraph. madagascar madagascar madagascar madagascar madagascar
madagascar madagascar madagascar madagascar.... blah blah blah......
</para>
<para>
zoom peanut zoom
@@ -44,14 +38,12 @@
<para>
wxyz wxyz trail
</para>
<para>
<programlisting><phrase role="keyword">int</phrase> <phrase role="identifier">main</phrase><phrase role="special">()</phrase>
<phrase role="special">{</phrase>
<phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">cout</phrase> <phrase role="special">&lt;&lt;</phrase> &quot;Hello, World&quot; <phrase role="special">&lt;&lt;</phrase> <phrase role="identifier">std</phrase><phrase role="special">::</phrase><phrase role="identifier">endl</phrase><phrase role="special">;</phrase>
<phrase role="special">}</phrase>
</programlisting>
</para>
<para>
x<superscript>2</superscript>
</para>