diff options
author | Ted Kremenek <kremenek@apple.com> | 2008-03-19 05:07:26 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2008-03-19 05:07:26 +0000 |
commit | d6c1360c2bf234c73572a865f119d0518aca8154 (patch) | |
tree | 8e752d3708d1321bd3fab74280471cd4c2128171 /lib/Rewrite/HTMLRewrite.cpp | |
parent | 329f0f5df1a4b45740312a53b8d01e32a76c91a5 (diff) |
More cleanups to the HTML rewriter (with line formatting), with better
pretty-printing of line numbers.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@48533 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Rewrite/HTMLRewrite.cpp')
-rw-r--r-- | lib/Rewrite/HTMLRewrite.cpp | 34 |
1 files changed, 26 insertions, 8 deletions
diff --git a/lib/Rewrite/HTMLRewrite.cpp b/lib/Rewrite/HTMLRewrite.cpp index ddf427f1ad..9bd18109bb 100644 --- a/lib/Rewrite/HTMLRewrite.cpp +++ b/lib/Rewrite/HTMLRewrite.cpp @@ -49,16 +49,26 @@ void html::EscapeText(Rewriter& R, unsigned FileID, bool EscapeSpaces) { static void AddLineNumber(Rewriter& R, unsigned LineNo, SourceLocation B, SourceLocation E) { - // Surround the line with a span tag. + // Surround the line text with a div tag. - R.InsertTextBefore(E, "</span>", 7); - R.InsertTextBefore(B, "<span class=lines>", 18); + if (B == E) // Handle empty lines. + R.InsertCStrBefore(B, "<div class=\"lines\"> </div>"); + else { + R.InsertCStrBefore(E, "</div>"); + R.InsertCStrBefore(B, "<div class=\"lines\">"); + } + + // Insert a div tag for the line number. - // Insert a span tag for the line number. - std::ostringstream os; - os << "<span class=nums>" << LineNo << "</span>"; - R.InsertTextBefore(B, os.str().c_str(), os.str().size()); + os << "<div class=\"nums\">" << LineNo << "</div>"; + + R.InsertStrBefore(B, os.str()); + + // Now surround the whole line with another div tag. + + R.InsertCStrBefore(B, "<div class=\"codeline\">"); + R.InsertCStrAfter(E, "</div>"); } void html::AddLineNumbers(Rewriter& R, unsigned FileID) { @@ -98,5 +108,13 @@ void html::AddLineNumbers(Rewriter& R, unsigned FileID) { ++C; ++FilePos; } - } + } + + // Add one big div tag that surrounds all of the code. + + R.InsertCStrBefore(SourceLocation::getFileLoc(FileID, 0), + "<div id=\"codeblock\">"); + + R.InsertCStrAfter(SourceLocation::getFileLoc(FileID, FileEnd - FileBeg), + "</div>"); } |