cmRST: Process literal blocks after paragraphs ending in '::'

Teach cmRST to recognize non-markup lines ending in '::' followed by a
blank line as starting a literal block.  Record the whole block as if it
were a literal block directive and print it just like a code block.
Extend the CMakeLib.testRST test to cover such cases.
This commit is contained in:
Brad King 2013-10-21 15:31:44 -04:00
parent 7b9ae406f3
commit 2d0287dd5e
4 changed files with 59 additions and 0 deletions

View File

@ -22,6 +22,7 @@ cmRST::cmRST(std::ostream& os, std::string const& docroot):
DocRoot(docroot), DocRoot(docroot),
IncludeDepth(0), IncludeDepth(0),
OutputLinePending(false), OutputLinePending(false),
LastLineEndedInColonColon(false),
Markup(MarkupNone), Markup(MarkupNone),
Directive(DirectiveNone), Directive(DirectiveNone),
CMakeDirective("^.. (cmake:)?(" CMakeDirective("^.. (cmake:)?("
@ -125,6 +126,7 @@ void cmRST::Reset()
{ {
case DirectiveNone: break; case DirectiveNone: break;
case DirectiveParsedLiteral: this->ProcessDirectiveParsedLiteral(); break; case DirectiveParsedLiteral: this->ProcessDirectiveParsedLiteral(); break;
case DirectiveLiteralBlock: this->ProcessDirectiveLiteralBlock(); break;
case DirectiveCodeBlock: this->ProcessDirectiveCodeBlock(); break; case DirectiveCodeBlock: this->ProcessDirectiveCodeBlock(); break;
case DirectiveReplace: this->ProcessDirectiveReplace(); break; case DirectiveReplace: this->ProcessDirectiveReplace(); break;
case DirectiveTocTree: this->ProcessDirectiveTocTree(); break; case DirectiveTocTree: this->ProcessDirectiveTocTree(); break;
@ -137,6 +139,9 @@ void cmRST::Reset()
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmRST::ProcessLine(std::string const& line) void cmRST::ProcessLine(std::string const& line)
{ {
bool lastLineEndedInColonColon = this->LastLineEndedInColonColon;
this->LastLineEndedInColonColon = false;
// A line starting in .. is an explicit markup start. // A line starting in .. is an explicit markup start.
if(line == ".." || (line.size() >= 3 && line[0] == '.' && if(line == ".." || (line.size() >= 3 && line[0] == '.' &&
line[1] == '.' && isspace(line[2]))) line[1] == '.' && isspace(line[2])))
@ -211,10 +216,21 @@ void cmRST::ProcessLine(std::string const& line)
this->MarkupLines.push_back(line); this->MarkupLines.push_back(line);
} }
} }
// A blank line following a paragraph ending in "::" starts a literal block.
else if(lastLineEndedInColonColon && line.empty())
{
// Record the literal lines to output after whole block.
this->Markup = MarkupNormal;
this->Directive = DirectiveLiteralBlock;
this->MarkupLines.push_back("");
this->OutputLine("", false);
}
// Print non-markup lines. // Print non-markup lines.
else else
{ {
this->NormalLine(line); this->NormalLine(line);
this->LastLineEndedInColonColon = (line.size() >= 2
&& line[line.size()-2] == ':' && line[line.size()-1] == ':');
} }
} }
@ -343,6 +359,12 @@ void cmRST::ProcessDirectiveParsedLiteral()
this->OutputMarkupLines(true); this->OutputMarkupLines(true);
} }
//----------------------------------------------------------------------------
void cmRST::ProcessDirectiveLiteralBlock()
{
this->OutputMarkupLines(false);
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmRST::ProcessDirectiveCodeBlock() void cmRST::ProcessDirectiveCodeBlock()
{ {

View File

@ -38,6 +38,7 @@ private:
{ {
DirectiveNone, DirectiveNone,
DirectiveParsedLiteral, DirectiveParsedLiteral,
DirectiveLiteralBlock,
DirectiveCodeBlock, DirectiveCodeBlock,
DirectiveReplace, DirectiveReplace,
DirectiveTocTree DirectiveTocTree
@ -53,6 +54,7 @@ private:
void OutputMarkupLines(bool inlineMarkup); void OutputMarkupLines(bool inlineMarkup);
bool ProcessInclude(std::string file, IncludeType type); bool ProcessInclude(std::string file, IncludeType type);
void ProcessDirectiveParsedLiteral(); void ProcessDirectiveParsedLiteral();
void ProcessDirectiveLiteralBlock();
void ProcessDirectiveCodeBlock(); void ProcessDirectiveCodeBlock();
void ProcessDirectiveReplace(); void ProcessDirectiveReplace();
void ProcessDirectiveTocTree(); void ProcessDirectiveTocTree();
@ -62,6 +64,7 @@ private:
std::string DocRoot; std::string DocRoot;
int IncludeDepth; int IncludeDepth;
bool OutputLinePending; bool OutputLinePending;
bool LastLineEndedInColonColon;
MarkupType Markup; MarkupType Markup;
DirectiveType Directive; DirectiveType Directive;
cmsys::RegularExpression CMakeDirective; cmsys::RegularExpression CMakeDirective;

View File

@ -53,6 +53,23 @@ More CMake Module Content
endif() endif()
# |not replaced in literal| # |not replaced in literal|
A literal block starts after a line consisting of two colons
::
Literal block.
Common Indentation Removed
# |not replaced in literal|
or after a paragraph ending in two colons::
Literal block.
Common Indentation Removed
# |not replaced in literal|
but not after a line ending in two colons::
in the middle of a paragraph.
substituted text with multiple lines becomes one line substituted text with multiple lines becomes one line
End of first include. End of first include.

View File

@ -66,6 +66,23 @@ Generator :generator:`Some Generator` with space.
endif() endif()
# |not replaced in literal| # |not replaced in literal|
A literal block starts after a line consisting of two colons
::
Literal block.
Common Indentation Removed
# |not replaced in literal|
or after a paragraph ending in two colons::
Literal block.
Common Indentation Removed
# |not replaced in literal|
but not after a line ending in two colons::
in the middle of a paragraph.
.. |substitution| replace:: .. |substitution| replace::
|nested substitution| |nested substitution|
with multiple lines becomes one line with multiple lines becomes one line