cmRST: Do not process inline markup in code-block literals

Move the ProcessDirectiveParsedLiteral and ProcessDirectiveCodeBlock
method internals into an OutputMarkupLines helper.  Pass through it a
new "inlineMarkup" parameter and teach OutputLine to understand it.
When false, do not process inline markup.  Extend the CMakeLib.testRST
test to cover the two cases.
This commit is contained in:
Brad King 2013-10-21 14:53:25 -04:00
parent bf02e75079
commit 7b9ae406f3
4 changed files with 48 additions and 31 deletions

View File

@ -222,17 +222,19 @@ void cmRST::ProcessLine(std::string const& line)
void cmRST::NormalLine(std::string const& line) void cmRST::NormalLine(std::string const& line)
{ {
this->Reset(); this->Reset();
this->OutputLine(line); this->OutputLine(line, true);
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmRST::OutputLine(std::string const& line_in) void cmRST::OutputLine(std::string const& line_in, bool inlineMarkup)
{ {
if(this->OutputLinePending) if(this->OutputLinePending)
{ {
this->OS << "\n"; this->OS << "\n";
this->OutputLinePending = false; this->OutputLinePending = false;
} }
if(inlineMarkup)
{
std::string line = this->ReplaceSubstitutions(line_in); std::string line = this->ReplaceSubstitutions(line_in);
std::string::size_type pos = 0; std::string::size_type pos = 0;
while(this->CMakeRole.find(line.c_str()+pos)) while(this->CMakeRole.find(line.c_str()+pos))
@ -252,6 +254,11 @@ void cmRST::OutputLine(std::string const& line_in)
} }
this->OS << line.substr(pos) << "\n"; this->OS << line.substr(pos) << "\n";
} }
else
{
this->OS << line_in << "\n";
}
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
std::string cmRST::ReplaceSubstitutions(std::string const& line) std::string cmRST::ReplaceSubstitutions(std::string const& line)
@ -283,6 +290,22 @@ std::string cmRST::ReplaceSubstitutions(std::string const& line)
return out; return out;
} }
//----------------------------------------------------------------------------
void cmRST::OutputMarkupLines(bool inlineMarkup)
{
for(std::vector<std::string>::iterator i = this->MarkupLines.begin();
i != this->MarkupLines.end(); ++i)
{
std::string line = *i;
if(!line.empty())
{
line = " " + line;
}
this->OutputLine(line, inlineMarkup);
}
this->OutputLinePending = true;
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
bool cmRST::ProcessInclude(std::string file, IncludeType type) bool cmRST::ProcessInclude(std::string file, IncludeType type)
{ {
@ -317,25 +340,13 @@ bool cmRST::ProcessInclude(std::string file, IncludeType type)
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmRST::ProcessDirectiveParsedLiteral() void cmRST::ProcessDirectiveParsedLiteral()
{ {
// Output markup lines as literal text. this->OutputMarkupLines(true);
for(std::vector<std::string>::iterator i = this->MarkupLines.begin();
i != this->MarkupLines.end(); ++i)
{
std::string line = *i;
if(!line.empty())
{
line = " " + line;
}
this->OutputLine(line);
}
this->OutputLinePending = true;
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void cmRST::ProcessDirectiveCodeBlock() void cmRST::ProcessDirectiveCodeBlock()
{ {
// Treat markup lines the same as a parsed literal. this->OutputMarkupLines(false);
this->ProcessDirectiveParsedLiteral();
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------

View File

@ -48,8 +48,9 @@ private:
void Reset(); void Reset();
void ProcessLine(std::string const& line); void ProcessLine(std::string const& line);
void NormalLine(std::string const& line); void NormalLine(std::string const& line);
void OutputLine(std::string const& line); void OutputLine(std::string const& line, bool inlineMarkup);
std::string ReplaceSubstitutions(std::string const& line); std::string ReplaceSubstitutions(std::string const& line);
void OutputMarkupLines(bool inlineMarkup);
bool ProcessInclude(std::string file, IncludeType type); bool ProcessInclude(std::string file, IncludeType type);
void ProcessDirectiveParsedLiteral(); void ProcessDirectiveParsedLiteral();
void ProcessDirectiveCodeBlock(); void ProcessDirectiveCodeBlock();

View File

@ -45,11 +45,13 @@ More CMake Module Content
Parsed-literal included without directive. Parsed-literal included without directive.
Common Indentation Removed Common Indentation Removed
# replaced in parsed literal
# Sample CMake code block # Sample CMake code block
if(condition) if(condition)
message(indented) message(indented)
endif() endif()
# |not replaced in literal|
substituted text with multiple lines becomes one line substituted text with multiple lines becomes one line

View File

@ -26,6 +26,7 @@ Variable :variable:`VARIABLE_<PLACEHOLDER> <target>` with trailing placeholder a
Generator :generator:`Some Generator` with space. Generator :generator:`Some Generator` with space.
.. |not replaced| replace:: not replaced through toctree .. |not replaced| replace:: not replaced through toctree
.. |not replaced in literal| replace:: replaced in parsed literal
.. toctree:: .. toctree::
:maxdepth: 2 :maxdepth: 2
@ -55,6 +56,7 @@ Generator :generator:`Some Generator` with space.
Parsed-literal included without directive. Parsed-literal included without directive.
Common Indentation Removed Common Indentation Removed
# |not replaced in literal|
.. code-block:: cmake .. code-block:: cmake
@ -62,6 +64,7 @@ Generator :generator:`Some Generator` with space.
if(condition) if(condition)
message(indented) message(indented)
endif() endif()
# |not replaced in literal|
.. |substitution| replace:: .. |substitution| replace::
|nested substitution| |nested substitution|