summaryrefslogtreecommitdiffstats
path: root/Source/cmRST.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'Source/cmRST.cxx')
-rw-r--r--Source/cmRST.cxx145
1 files changed, 104 insertions, 41 deletions
diff --git a/Source/cmRST.cxx b/Source/cmRST.cxx
index 72c42d6..6d4e281 100644
--- a/Source/cmRST.cxx
+++ b/Source/cmRST.cxx
@@ -12,6 +12,7 @@
#include "cmRST.h"
#include "cmSystemTools.h"
+#include "cmVersion.h"
#include <ctype.h>
@@ -21,6 +22,7 @@ cmRST::cmRST(std::ostream& os, std::string const& docroot):
DocRoot(docroot),
IncludeDepth(0),
OutputLinePending(false),
+ LastLineEndedInColonColon(false),
Markup(MarkupNone),
Directive(DirectiveNone),
CMakeDirective("^.. (cmake:)?("
@@ -32,6 +34,7 @@ cmRST::cmRST(std::ostream& os, std::string const& docroot):
ReplaceDirective("^.. (\\|[^|]+\\|) replace::[ \t]*(.*)$"),
IncludeDirective("^.. include::[ \t]+([^ \t\n]+)$"),
TocTreeDirective("^.. toctree::[ \t]*(.*)$"),
+ ModuleRST("^#\\[(=*)\\[\\.rst:$"),
CMakeRole("(:cmake)?:("
"command|generator|variable|module|policy|"
"prop_cache|prop_dir|prop_gbl|prop_sf|prop_test|prop_tgt|"
@@ -41,6 +44,7 @@ cmRST::cmRST(std::ostream& os, std::string const& docroot):
"((\\|[^| \t\r\n]([^|\r\n]*[^| \t\r\n])?\\|)(__|_|))"
"([^A-Za-z0-9_]|$)")
{
+ this->Replace["|release|"] = cmVersion::GetCMakeVersion();
}
//----------------------------------------------------------------------------
@@ -82,28 +86,55 @@ void cmRST::ProcessModule(std::istream& is)
std::string rst;
while(cmSystemTools::GetLineFromStream(is, line))
{
- if(rst == "#")
+ if(!rst.empty() && rst != "#")
{
- if(line == "#")
+ // Bracket mode: check for end bracket
+ std::string::size_type pos = line.find(rst);
+ if(pos == line.npos)
{
- this->ProcessLine("");
- continue;
- }
- else if(line.substr(0, 2) == "# ")
- {
- this->ProcessLine(line.substr(2, line.npos));
- continue;
+ this->ProcessLine(line);
}
else
{
+ if(line[0] != '#')
+ {
+ this->ProcessLine(line.substr(0, pos));
+ }
rst = "";
this->Reset();
this->OutputLinePending = true;
}
}
- if(line == "#.rst:")
+ else
{
- rst = "#";
+ // Line mode: check for .rst start (bracket or line)
+ if(rst == "#")
+ {
+ if(line == "#")
+ {
+ this->ProcessLine("");
+ continue;
+ }
+ else if(line.substr(0, 2) == "# ")
+ {
+ this->ProcessLine(line.substr(2, line.npos));
+ continue;
+ }
+ else
+ {
+ rst = "";
+ this->Reset();
+ this->OutputLinePending = true;
+ }
+ }
+ if(line == "#.rst:")
+ {
+ rst = "#";
+ }
+ else if(this->ModuleRST.find(line))
+ {
+ rst = "]" + this->ModuleRST.match(1) + "]";
+ }
}
}
if(rst == "#")
@@ -123,6 +154,7 @@ void cmRST::Reset()
{
case DirectiveNone: break;
case DirectiveParsedLiteral: this->ProcessDirectiveParsedLiteral(); break;
+ case DirectiveLiteralBlock: this->ProcessDirectiveLiteralBlock(); break;
case DirectiveCodeBlock: this->ProcessDirectiveCodeBlock(); break;
case DirectiveReplace: this->ProcessDirectiveReplace(); break;
case DirectiveTocTree: this->ProcessDirectiveTocTree(); break;
@@ -135,6 +167,9 @@ void cmRST::Reset()
//----------------------------------------------------------------------------
void cmRST::ProcessLine(std::string const& line)
{
+ bool lastLineEndedInColonColon = this->LastLineEndedInColonColon;
+ this->LastLineEndedInColonColon = false;
+
// A line starting in .. is an explicit markup start.
if(line == ".." || (line.size() >= 3 && line[0] == '.' &&
line[1] == '.' && isspace(line[2])))
@@ -209,10 +244,21 @@ void cmRST::ProcessLine(std::string const& 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.
else
{
this->NormalLine(line);
+ this->LastLineEndedInColonColon = (line.size() >= 2
+ && line[line.size()-2] == ':' && line[line.size()-1] == ':');
}
}
@@ -220,35 +266,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";
}
//----------------------------------------------------------------------------
@@ -282,6 +335,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;
@@ -315,25 +384,19 @@ 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::ProcessDirectiveLiteralBlock()
+{
+ this->OutputMarkupLines(false);
}
//----------------------------------------------------------------------------
void cmRST::ProcessDirectiveCodeBlock()
{
- // Treat markup lines the same as a parsed literal.
- this->ProcessDirectiveParsedLiteral();
+ this->OutputMarkupLines(false);
}
//----------------------------------------------------------------------------