diff --git a/doc/quickbook.qbk b/doc/quickbook.qbk index dbccb8a..41a9f3d 100644 --- a/doc/quickbook.qbk +++ b/doc/quickbook.qbk @@ -283,6 +283,7 @@ Boost 1.46.1: * Allow more block elements to be nested. * Go back to using invalid markup for lists. It generates better html. * Better anchor placement for lists. +* Pass-thru comments in code snippets. * Quickbook 1.6: * Scope source mode changes to the file they're made in. @@ -1937,6 +1938,18 @@ or can be used to inhibit code from passing through to quickbook. All text between the delimeters will simply be ignored. +Comments of this form: + + //=int main() {} + +or + + /*=foo()*/ + +will be displayed as code that isn't in comments. This allows you to +include some code in the snippet but not actually use it when +compiling your example. + [heading Callouts] Special comments of the form: diff --git a/src/code_snippet.cpp b/src/code_snippet.cpp index 19d5e97..10a3dab 100644 --- a/src/code_snippet.cpp +++ b/src/code_snippet.cpp @@ -99,6 +99,7 @@ namespace quickbook start_snippet [boost::bind(&actions_type::start_snippet, &actions, _1, _2)] | end_snippet [boost::bind(&actions_type::end_snippet, &actions, _1, _2)] | escaped_comment + | pass_thru_comment | ignore | cl::anychar_p [boost::bind(&actions_type::pass_thru_char, &actions, _1)] ; @@ -142,11 +143,25 @@ namespace quickbook "\"\"\"" ) ; + + // Note: Unlike escaped_comment and ignore, this doesn't + // swallow preceeding whitespace. + pass_thru_comment + = "#=" + >> ( *(cl::anychar_p - cl::eol_p) + >> (cl::eol_p | cl::end_p) + ) [boost::bind(&actions_type::pass_thru, &actions, _1, _2)] + | cl::confix_p( + "\"\"\"=", + (*cl::anychar_p) [boost::bind(&actions_type::pass_thru, &actions, _1, _2)], + "\"\"\"" + ) + ; } cl::rule start_, identifier, code_elements, start_snippet, end_snippet, - escaped_comment, ignore; + escaped_comment, pass_thru_comment, ignore; cl::rule const& start() const { return start_; } @@ -182,6 +197,7 @@ namespace quickbook | end_snippet [boost::bind(&actions_type::end_snippet, &actions, _1, _2)] | escaped_comment | ignore + | pass_thru_comment | line_callout | inline_callout | cl::anychar_p [boost::bind(&actions_type::pass_thru_char, &actions, _1)] @@ -249,11 +265,25 @@ namespace quickbook "*/" ) ; + + // Note: Unlike escaped_comment and ignore, this doesn't + // swallow preceeding whitespace. + pass_thru_comment + = "//=" + >> ( *(cl::anychar_p - cl::eol_p) + >> (cl::eol_p | cl::end_p) + ) [boost::bind(&actions_type::pass_thru, &actions, _1, _2)] + | cl::confix_p( + "/*`", + (*cl::anychar_p) [boost::bind(&actions_type::pass_thru, &actions, _1, _2)], + "*/" + ) + ; } cl::rule start_, identifier, code_elements, start_snippet, end_snippet, - escaped_comment, inline_callout, line_callout, ignore; + escaped_comment, pass_thru_comment, inline_callout, line_callout, ignore; cl::rule const& start() const { return start_; } @@ -334,7 +364,7 @@ namespace quickbook void code_snippet_actions::pass_thru(iterator first, iterator last) { if(snippet_stack.empty()) return; - code += *first; + code.append(first, last); } void code_snippet_actions::pass_thru_char(char c) diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 6244958..a5ad876 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -14,6 +14,7 @@ project test build-project doc-info ; build-project unit ; build-project command-line ; +build-project snippets ; import quickbook-testing : quickbook-test quickbook-error-test ; diff --git a/test/snippets/Jamfile.v2 b/test/snippets/Jamfile.v2 new file mode 100644 index 0000000..89f72dd --- /dev/null +++ b/test/snippets/Jamfile.v2 @@ -0,0 +1,15 @@ +# +# Copyright (c) 2011 Daniel James +# +# Distributed under the Boost Software License, Version 1.0. (See +# accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) +# + +project quickook/tests/snippets ; + +import quickbook-testing : quickbook-test quickbook-error-test ; + +test-suite quickbook.test : + [ quickbook-test pass_thru ] + ; diff --git a/test/snippets/pass_thru.cpp b/test/snippets/pass_thru.cpp new file mode 100644 index 0000000..f85522c --- /dev/null +++ b/test/snippets/pass_thru.cpp @@ -0,0 +1,14 @@ +//[foo_cpp +struct Foo{ + + Foo()//=; +//<- + : x( 10 ) + {} +//-> + +//<- + int x; +//-> +}; +//] \ No newline at end of file diff --git a/test/snippets/pass_thru.gold b/test/snippets/pass_thru.gold new file mode 100644 index 0000000..61b5b00 --- /dev/null +++ b/test/snippets/pass_thru.gold @@ -0,0 +1,21 @@ + + +
+ Pass thru test + + +struct Foo{ + + Foo(); + +}; + + + + +def foo: + print('foo') + + +
diff --git a/test/snippets/pass_thru.py b/test/snippets/pass_thru.py new file mode 100644 index 0000000..d8e847d --- /dev/null +++ b/test/snippets/pass_thru.py @@ -0,0 +1,7 @@ +#[foo_py +def foo: + #=print('foo') + #<- + print('bar') + #-> +#] \ No newline at end of file diff --git a/test/snippets/pass_thru.quickbook b/test/snippets/pass_thru.quickbook new file mode 100644 index 0000000..2f46cd5 --- /dev/null +++ b/test/snippets/pass_thru.quickbook @@ -0,0 +1,10 @@ +[article Pass thru test +[quickbook 1.5] +] + +[import pass_thru.cpp] +[import pass_thru.py] + +[foo_cpp] + +[foo_py] \ No newline at end of file diff --git a/test/snippets/pass_thru.xml b/test/snippets/pass_thru.xml new file mode 100644 index 0000000..c647d11 --- /dev/null +++ b/test/snippets/pass_thru.xml @@ -0,0 +1,21 @@ + + +
+ Pass thru test + + +struct Foo{ + + Foo()//=; + +}; + + + + +def foo: + #= print('foo') + + +