📄 transforms.cs
字号:
}
}
return tranforms;
}
#endregion
#region FormatEditNotes()
private static string FormatEditNotes2(string stringToTransform) {
Match match;
StringBuilder editTable = null;
match = Regex.Match(stringToTransform, ".Edit by="(?<Editor>(.|\\n)*?)".(?<Notes>(.|\\n)*?)./Edit.", RegexOptions.IgnoreCase | RegexOptions.Compiled);
if (match.Captures.Count > 0) {
editTable = new StringBuilder();
editTable.Append( "<table>" );
editTable.Append( "<tr>" );
editTable.Append( "<td>" );
editTable.Append( match.Groups["Editor"].ToString() );
editTable.Append( "</td>" );
editTable.Append( "</tr>" );
editTable.Append( "<tr>" );
editTable.Append( "<td>" );
editTable.Append( match.Groups["Notes"].ToString() );
editTable.Append( "</td>" );
editTable.Append( "</tr>" );
editTable.Append( "</table>" );
}
if (editTable != null)
return stringToTransform.Replace(match.ToString(), editTable.ToString());
else
return stringToTransform;
}
#endregion
#region SourceCodeMarkup
private static string SourceCodeMarkup(string stringToTransform) {
StringBuilder formattedSource = new StringBuilder();
string[] table = new string[3];
table[0] = "<table border=\"0\" cellspacing=\"0\" width=\"100%\">";
table[1] = "<tr><td width=\"15\"></td><td bgcolor=\"lightgrey\" width=\"15\"></td><td bgcolor=\"lightgrey\"><br>";
table[2] = "<br> </td></tr></table>";
MatchCollection matchs;
// Look for code
//
matchs = Regex.Matches(stringToTransform, "\\[code language=\"(?<lang>(.|\\n)*?)\"\\](?<code>(.|\\n)*?)\\[/code\\]", RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.Compiled);
foreach (Match match in matchs) {
// Remove HTML formatting code
//
string codeToFormat = match.Groups["code"].ToString().Replace("</P>\r\n", "<br>").Replace("<P>","");
// Get the formatted source code
//
formattedSource.Append(table[0]);
formattedSource.Append(table[1]);
formattedSource.Append(FormatSource(codeToFormat, GetLanguageType(match.Groups["lang"].ToString())).Replace(Globals.HtmlNewLine, ""));
formattedSource.Append(table[2]);
// Update the main string
//
stringToTransform = stringToTransform.Replace(match.ToString(), formattedSource.ToString());
formattedSource.Remove( 0, formattedSource.Length );
}
return stringToTransform;
}
#endregion
#region PerformSpecializedTransforms
private static string PerformSpecializedTransforms(string stringToTransform) {
StringBuilder stringToReturn = new StringBuilder();
// MatchCollection matchs;
stringToTransform = SourceCodeMarkup(stringToTransform);
return stringToTransform;
// TDD 3/16/2004
// commenting out the rest of this code since it's unreachable. If not needed after release then we can remove it.
// // First we need to crack the string into segments to be transformed
// // there is only 1 special marker we care about: [code language="xxx"][/code]
// matchs = Regex.Matches(stringToTransform, "\\[code language="(?<lang>(.|\\n)*?)"\\](?<code>(.|\\n)*?)\\[/code\\]", RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.Compiled);
//
// // Get the full string that we intend to return
// //
// stringToReturn.Append(stringToTransform);
//
// foreach (Match match in matchs) {
// char[] charCode = new char[] {'\r', '\n'};
// string sourceCodeToMarkup;
// string markedUpSourceCode;
//
// // Code/Markup content
// //
// sourceCodeToMarkup = match.Groups["code"].ToString().TrimStart(charCode).TrimEnd(charCode);
// // markedUpSourceCode = FormatSource(sourceCodeToMarkup, ));
//
// // Replace marked up code
// //
// string openTable = "<table width=\"100%\"><tr><td width=\"15\"></td><td bgcolor=\"lightgrey\">";
// string closeTable = "</td></tr></table>";
// stringToReturn = stringToReturn.Replace(sourceCodeToMarkup, openTable + markedUpSourceCode + closeTable);
//
// // Remove the code tags
// //
// string openCodeTag = "[code language="" + match.Groups["lang"] + ""]";
// string closeCodeTag = "[/code]";
//
// stringToReturn = stringToReturn.Replace(openCodeTag, "");
// stringToReturn = stringToReturn.Replace(closeCodeTag, "");
//
// }
//
// return stringToReturn.ToString();
//
}
#endregion
#region Private vars, enums, and helper functions
static Language GetLanguageType(string language) {
switch (language.ToUpper()) {
case "VB" :
return Language.VB;
case "JS" :
return Language.JScript;
case "JScript" :
return Language.JScript;
default :
return Language.CS;
}
}
public enum Language {
CS,
VB,
JScript
}
const int _fontsize = 2;
const string TAG_FNTRED = "<font color= \"red\">";
const string TAG_FNTBLUE = "<font color= \"blue\">" ;
const string TAG_FNTGRN = "<font color= \"green\">" ;
const string TAG_FNTMRN = "<font color=\"maroon\">" ;
const string TAG_EFONT = "</font>" ;
public static string FormatSource(string htmlEncodedSource, Language language) {
StringWriter textBuffer = new StringWriter();
textBuffer.Write("<font face=\"Lucida Console\" size=\"" + _fontsize + "\">");
if(language == Language.CS) {
textBuffer.Write(FixCSLine(htmlEncodedSource)) ;
} else if(language == Language.JScript) {
textBuffer.Write(FixJSLine(htmlEncodedSource)) ;
} else if(language == Language.VB) {
textBuffer.Write(FixVBLine(htmlEncodedSource)) ;
}
textBuffer.Write("</font>");
return textBuffer.ToString();
}
static string FixCSLine(string source) {
if (source == null)
return null;
source = Regex.Replace(source, @"(\<br(\s*|(\ )*)\/{0,1}\>)", @"<br/>");
return source;
/*
// TDD I'm commenting this out for now for the 2.0.1 release. At a later point we'll figure out what is wrong with the color
// syntax hightlighting.
source = Regex.Replace(source, "(?i)(\\t)", " ");
source = Regex.Replace(source, "(?i) ", " ");
String[] keywords = new String[] {
"private", "protected", "public", "namespace", "class", "break",
"for", "if", "else", "while", "switch", "case", "using",
"return", "null", "void", "int", "bool", "string", "float",
"this", "new", "true", "false", "const", "static", "base",
"foreach", "in", "try", "catch", "finally", "get", "set", "char", "default"};
String CombinedKeywords = "(?<keyword>" + String.Join("|", keywords) + ")";
source = Regex.Replace(source, "\\b" + CombinedKeywords + "\\b(?<!//.*)", TAG_FNTBLUE + "${keyword}" + TAG_EFONT);
source = Regex.Replace(source, "(?<comment>//.*$)", TAG_FNTGRN + "${comment}" + TAG_EFONT);
return source;
*/
}
static string FixJSLine(string source) {
if (source == null)
return null;
source = Regex.Replace(source, @"(\<br(\s*|(\ )*)\/{0,1}\>)", @"<br/>");
return source;
/*
// TDD I'm commenting this out for now for the 2.0.1 release. At a later point we'll figure out what is wrong with the color
// syntax hightlighting.
source = Regex.Replace(source, "(?i)(\\t)", " ");
String[] keywords = new String[] {
"private", "protected", "public", "namespace", "class", "var",
"for", "if", "else", "while", "switch", "case", "using", "get",
"return", "null", "void", "int", "string", "float", "this", "set",
"new", "true", "false", "const", "static", "package", "function",
"internal", "extends", "super", "import", "default", "break", "try",
"catch", "finally" };
String CombinedKeywords = "(?<keyword>" + String.Join("|", keywords) + ")";
source = Regex.Replace(source, "\\b" + CombinedKeywords + "\\b(?<!//.*)", TAG_FNTBLUE + "${keyword}" + TAG_EFONT);
source = Regex.Replace(source, "(?<comment>//.*$)", TAG_FNTGRN + "${comment}" + TAG_EFONT);
return source;
*/
}
static string FixVBLine(string source) {
if (source == null)
return null;
source = Regex.Replace(source, @"(\<br(\s*|(\ )*)\/{0,1}\>)", @"<br/>");
return source;
/*
// TDD I'm commenting this out for now for the 2.0.1 release. At a later point we'll figure out what is wrong with the color
// syntax hightlighting.
source = Regex.Replace(source, "(?i)(\\t)", " ");
String[] keywords = new String[] {
"Private", "Protected", "Public", "End Namespace", "Namespace",
"End Class", "Exit", "Class", "Goto", "Try", "Catch", "End Try",
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -