summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2013-10-21 18:53:25 (GMT)
committerBrad King <brad.king@kitware.com>2013-10-21 18:56:26 (GMT)
commit7b9ae406f3f2fbe4de9d075a50ec0daae4fa1274 (patch)
treeb525f98d473db4ff36f499fd0652ba136824c210
parentbf02e750796c6b42b0e9d39ba322cd5191489a0e (diff)
downloadCMake-7b9ae406f3f2fbe4de9d075a50ec0daae4fa1274.zip
CMake-7b9ae406f3f2fbe4de9d075a50ec0daae4fa1274.tar.gz
CMake-7b9ae406f3f2fbe4de9d075a50ec0daae4fa1274.tar.bz2
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.
-rw-r--r--Source/cmRST.cxx71
-rw-r--r--Source/cmRST.h3
-rw-r--r--Tests/CMakeLib/testRST.expect2
-rw-r--r--Tests/CMakeLib/testRST.rst3
4 files changed, 48 insertions, 31 deletions
diff --git a/Source/cmRST.cxx b/Source/cmRST.cxx
index 18a197b..b64887d 100644
--- a/Source/cmRST.cxx
+++ b/Source/cmRST.cxx
@@ -222,35 +222,42 @@ void cmRST::ProcessLine(std::string const& line)
void cmRST::NormalLine(std::string const& line)
{
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)
{
this->OS << "\n";
this->OutputLinePending = false;
}
- std::string line = this->ReplaceSubstitutions(line_in);
- std::string::size_type pos = 0;
- while(this->CMakeRole.find(line.c_str()+pos))
+ if(inlineMarkup)
{
- this->OS << line.substr(pos, this->CMakeRole.start());
- std::string text = this->CMakeRole.match(3);
- // If a command reference has no explicit target and
- // no explicit "(...)" then add "()" to the text.
- if(this->CMakeRole.match(2) == "command" &&
- this->CMakeRole.match(5).empty() &&
- text.find_first_of("()") == text.npos)
+ std::string line = this->ReplaceSubstitutions(line_in);
+ std::string::size_type pos = 0;
+ while(this->CMakeRole.find(line.c_str()+pos))
{
- text += "()";
+ this->OS << line.substr(pos, this->CMakeRole.start());
+ std::string text = this->CMakeRole.match(3);
+ // If a command reference has no explicit target and
+ // no explicit "(...)" then add "()" to the text.
+ if(this->CMakeRole.match(2) == "command" &&
+ this->CMakeRole.match(5).empty() &&
+ text.find_first_of("()") == text.npos)
+ {
+ text += "()";
+ }
+ this->OS << "``" << text << "``";
+ pos += this->CMakeRole.end();
}
- this->OS << "``" << text << "``";
- pos += this->CMakeRole.end();
+ this->OS << line.substr(pos) << "\n";
+ }
+ else
+ {
+ this->OS << line_in << "\n";
}
- this->OS << line.substr(pos) << "\n";
}
//----------------------------------------------------------------------------
@@ -284,6 +291,22 @@ std::string cmRST::ReplaceSubstitutions(std::string const& line)
}
//----------------------------------------------------------------------------
+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 found = false;
@@ -317,25 +340,13 @@ bool cmRST::ProcessInclude(std::string file, IncludeType type)
//----------------------------------------------------------------------------
void cmRST::ProcessDirectiveParsedLiteral()
{
- // Output markup lines as literal text.
- 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;
+ this->OutputMarkupLines(true);
}
//----------------------------------------------------------------------------
void cmRST::ProcessDirectiveCodeBlock()
{
- // Treat markup lines the same as a parsed literal.
- this->ProcessDirectiveParsedLiteral();
+ this->OutputMarkupLines(false);
}
//----------------------------------------------------------------------------
diff --git a/Source/cmRST.h b/Source/cmRST.h
index 9352941..a3b9c32 100644
--- a/Source/cmRST.h
+++ b/Source/cmRST.h
@@ -48,8 +48,9 @@ private:
void Reset();
void ProcessLine(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);
+ void OutputMarkupLines(bool inlineMarkup);
bool ProcessInclude(std::string file, IncludeType type);
void ProcessDirectiveParsedLiteral();
void ProcessDirectiveCodeBlock();
diff --git a/Tests/CMakeLib/testRST.expect b/Tests/CMakeLib/testRST.expect
index 6a89002..28981bf 100644
--- a/Tests/CMakeLib/testRST.expect
+++ b/Tests/CMakeLib/testRST.expect
@@ -45,11 +45,13 @@ More CMake Module Content
Parsed-literal included without directive.
Common Indentation Removed
+ # replaced in parsed literal
# Sample CMake code block
if(condition)
message(indented)
endif()
+ # |not replaced in literal|
substituted text with multiple lines becomes one line
diff --git a/Tests/CMakeLib/testRST.rst b/Tests/CMakeLib/testRST.rst
index f7059cf..46ec771 100644
--- a/Tests/CMakeLib/testRST.rst
+++ b/Tests/CMakeLib/testRST.rst
@@ -26,6 +26,7 @@ Variable :variable:`VARIABLE_<PLACEHOLDER> <target>` with trailing placeholder a
Generator :generator:`Some Generator` with space.
.. |not replaced| replace:: not replaced through toctree
+.. |not replaced in literal| replace:: replaced in parsed literal
.. toctree::
:maxdepth: 2
@@ -55,6 +56,7 @@ Generator :generator:`Some Generator` with space.
Parsed-literal included without directive.
Common Indentation Removed
+ # |not replaced in literal|
.. code-block:: cmake
@@ -62,6 +64,7 @@ Generator :generator:`Some Generator` with space.
if(condition)
message(indented)
endif()
+ # |not replaced in literal|
.. |substitution| replace::
|nested substitution|