Quickbook: Don't unindent code blocks in code snippets.

Because code blocks are added in sections, a nested section could be
unindented too far. Code is unindented in the main quickbook actions, so
there's actually no need to do it when extracting code snippets.

But this lead to left over whitespace that would have been stripped. So
change the `start_snippet` and `end_snippet` grammars to swallow up the
line they're on.

I also added a newline before the end of the snippet, this cleaned up
the occasional syntax error.

But due to these changes there is more leading and trailing whitespace
in the generated code blocks, so I just changed the code block grammar
to strip them out. This means there are no newlines at the beginning or
end of code blocks, but that should be fine.

[SVN r75613]
This commit is contained in:
Daniel James
2011-11-22 23:45:16 +00:00
parent 43f9288487
commit a26a70fc7b
8 changed files with 85 additions and 90 deletions

View File

@@ -123,12 +123,19 @@ namespace quickbook
;
start_snippet =
"#[" >> *cl::space_p
>> identifier [cl::assign_a(actions.id)]
*cl::blank_p
>> !(cl::eol_p >> *cl::blank_p)
>> "#["
>> *cl::blank_p
>> identifier [cl::assign_a(actions.id)]
>> *(cl::anychar_p - cl::eol_p)
;
end_snippet =
cl::str_p("#]")
*cl::blank_p
>> !(cl::eol_p >> *cl::blank_p)
>> "#]"
>> *(cl::anychar_p - cl::eol_p)
;
ignore
@@ -222,16 +229,45 @@ namespace quickbook
;
start_snippet =
"//[" >> *cl::space_p
>> identifier [cl::assign_a(actions.id)]
*cl::blank_p
>> !(cl::eol_p >> *cl::blank_p)
>> "//["
>> *cl::blank_p
>> identifier [cl::assign_a(actions.id)]
>> *(cl::anychar_p - cl::eol_p)
|
"/*[" >> *cl::space_p
>> identifier [cl::assign_a(actions.id)]
>> *cl::space_p >> "*/"
*cl::blank_p
>> cl::eol_p
>> *cl::blank_p
>> "/*["
>> *cl::space_p
>> identifier [cl::assign_a(actions.id)]
>> *cl::space_p
>> "*/"
>> *cl::blank_p
>> cl::eps_p(cl::eol_p)
|
"/*["
>> *cl::space_p
>> identifier [cl::assign_a(actions.id)]
>> *cl::space_p
>> "*/"
;
end_snippet =
cl::str_p("//]") | "/*]*/"
*cl::blank_p
>> !(cl::eol_p >> *cl::blank_p)
>> "//]"
>> *(cl::anychar_p - cl::eol_p)
|
*cl::blank_p
>> cl::eol_p
>> *cl::blank_p
>> "/*]*/"
>> *cl::blank_p
>> cl::eps_p(cl::eol_p)
|
"/*[*/"
;
inline_callout
@@ -345,8 +381,6 @@ namespace quickbook
if (!code.empty())
{
detail::unindent(code); // remove all indents
if(snippet.content.empty())
{
snippet.start_code = true;
@@ -357,7 +391,7 @@ namespace quickbook
snippet.content += source_type;
snippet.content += "```\n";
}
snippet.content += code;
snippet.end_code = true;
@@ -372,7 +406,7 @@ namespace quickbook
if(snippet.end_code)
{
snippet.content += "```\n\n";
snippet.content += "\n```\n\n";
snippet.end_code = false;
}
}
@@ -449,7 +483,7 @@ namespace quickbook
}
body += snippet->content;
if(snippet->end_code) {
body += "```\n\n";
body += "\n```\n\n";
}
std::vector<std::string> params;