本文整理汇总了C#中ColorCode.CodeColorizer类的典型用法代码示例。如果您正苦于以下问题:C# CodeColorizer类的具体用法?C# CodeColorizer怎么用?C# CodeColorizer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CodeColorizer类属于ColorCode命名空间,在下文中一共展示了CodeColorizer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SyntaxHighlight
/// <summary>
/// The syntax highlight.
/// </summary>
/// <param name="code">
/// The code.
/// </param>
/// <param name="language">
/// The language.
/// </param>
/// <returns>
/// The System.String.
/// </returns>
private static string SyntaxHighlight(string code, string language)
{
CodeColorizer colorizer = new CodeColorizer();
ILanguage lang = Languages.CSharp;
switch (language)
{
case "C#":
lang = Languages.CSharp;
break;
case "HTML":
lang = Languages.Html;
break;
case "VB.NET":
lang = Languages.VbDotNet;
break;
case "XML":
lang = Languages.Xml;
break;
case "SQL":
lang = Languages.Sql;
break;
case "JScript":
lang = Languages.JavaScript;
break;
}
return colorizer.Colorize(code, lang);
}
示例2: Will_throw_if_the_style_sheet_is_null
public void Will_throw_if_the_style_sheet_is_null()
{
CodeColorizer codeColorizer = new CodeColorizer(new StubLanguageParser());
Exception ex = Record.Exception(() => codeColorizer.Colorize(string.Empty, new StubLanguage(), new StubFormatter(), null, new StubTextWriter()));
Assert.IsType<ArgumentNullException>(ex);
Assert.Equal("styleSheet", ((ArgumentNullException)ex).ParamName);
}
示例3: WillColorizeASingleLineStyleComment
public void WillColorizeASingleLineStyleComment()
{
const string source = @"//comment";
var expected = AcceptanceHelper.BuildExpected(@"<span style=""color:Green;"">//comment</span>");
var actual = new CodeColorizer().Colorize(source, Languages.Java);
Assert.Equal(expected, actual);
}
示例4: WillColorizeAKeywordWithNoSurroundingText
public void WillColorizeAKeywordWithNoSurroundingText(string keyword)
{
var source = keyword;
var exepected = AcceptanceHelper.BuildExpected(@"<span style=""color:Blue;"">{0}</span>", keyword);
var actual = new CodeColorizer().Colorize(source, Languages.Java);
Assert.Equal(exepected, actual);
}
示例5: WillColorizeAKeywordWithPrecedingAndSucceedingText
public void WillColorizeAKeywordWithPrecedingAndSucceedingText(string keyword)
{
var source = string.Format("fnord {0} fnord", keyword);
var exepected = AcceptanceHelper.BuildExpected(@"fnord <span style=""color:Blue;"">{0}</span> fnord", keyword);
var actual = new CodeColorizer().Colorize(source, Languages.Java);
Assert.Equal(exepected, actual);
}
示例6: Will_throw_if_the_language_is_null_using_defaults_without_text_writer
public void Will_throw_if_the_language_is_null_using_defaults_without_text_writer()
{
CodeColorizer codeColorizer = new CodeColorizer();
Exception ex = Record.Exception(() => codeColorizer.Colorize(string.Empty, null));
Assert.IsType<ArgumentNullException>(ex);
Assert.Equal("language", ((ArgumentNullException)ex).ParamName);
}
示例7: WillColorizeAMultieLineStyleCommentOnOneLine
public void WillColorizeAMultieLineStyleCommentOnOneLine()
{
const string source = @"/*comment*/";
var expected = AcceptanceHelper.BuildExpected(@"<span style=""color:Green;"">/*comment*/</span>");
var actual = new CodeColorizer().Colorize(source, Languages.Cpp);
Assert.Equal(expected, actual);
}
示例8: TransformWillCommentMultipleCommentsCorrectly
public void TransformWillCommentMultipleCommentsCorrectly()
{
string source = "<!-- test --><root><elment><!-- comment inside of element --></element></root>";
string expected =
"<div style=\"color:Black;background-color:White;\"><pre>\r\n<span style=\"color:Green;\"><!-- test --></span><span style=\"color:Blue;\"><</span><span style=\"color:#A31515;\">root</span><span style=\"color:Blue;\">></span><span style=\"color:Blue;\"><</span><span style=\"color:#A31515;\">elment</span><span style=\"color:Blue;\">></span><span style=\"color:Green;\"><!-- comment inside of element --></span><span style=\"color:Blue;\"></</span><span style=\"color:#A31515;\">element</span><span style=\"color:Blue;\">></span><span style=\"color:Blue;\"></</span><span style=\"color:#A31515;\">root</span><span style=\"color:Blue;\">></span>\r\n</pre></div>";
string actual = new CodeColorizer().Colorize(source, Languages.Xml);
Assert.Equal(expected, actual);
}
示例9: ColorCode_will_colorize_source_code
public void ColorCode_will_colorize_source_code(string languageId, string sourceFileName, string expectedFileName)
{
ILanguage language = Languages.FindById(languageId);
string sourceCode = File.ReadAllText(sourceFileName);
string expectedHtml = File.ReadAllText(expectedFileName);
string actualHtml = new CodeColorizer().Colorize(sourceCode, language);
File.WriteAllText(expectedFileName.Replace(".expected.", ".actual."), actualHtml);
Assert.Equal(expectedHtml, actualHtml);
}
示例10: GenericSampleView
public GenericSampleView()
{
InitializeComponent();
Loaded += (sender, args) =>
{
var code = (DataContext as ISample).Code;
var html = new CodeColorizer().Colorize(code, Languages.CSharp);
html = "<body style=\"background-color:#FFFFFF;\">" + html + "</body>";
Browser.NavigateToString(html);
};
}
示例11: Will_parse_the_source_code
public void Will_parse_the_source_code()
{
StubLanguageParser stubLanguageParser = new StubLanguageParser();
CodeColorizer codeColorizer = new CodeColorizer(stubLanguageParser);
const string sourceCode = "fnord";
StubLanguage stubLanguage = new StubLanguage();
codeColorizer.Colorize(sourceCode, stubLanguage, new StubFormatter(), new StubStyleSheet(), new StubTextWriter());
Assert.Equal(sourceCode, stubLanguageParser.Parse__sourceCode);
Assert.Equal(stubLanguage, stubLanguageParser.Parse__language);
}
示例12: TransformWillStyleDoubleQuotedString
public void TransformWillStyleDoubleQuotedString()
{
string source =
@"var variableName = ""aString"";";
string expected =
@"<div style=""color:Black;background-color:White;""><pre>
<span style=""color:Blue;"">var</span> variableName = <span style=""color:#A31515;"">"aString"</span>;
</pre></div>";
string actual = new CodeColorizer().Colorize(source, Languages.JavaScript);
Assert.Equal(expected, actual);
}
示例13: TransformWillNotAddColorToDollarSignMethod
public void TransformWillNotAddColorToDollarSignMethod()
{
string source =
@"var variableName = $(""aString"");";
string expected =
@"<div style=""color:Black;background-color:White;""><pre>
<span style=""color:Blue;"">var</span> variableName = $(<span style=""color:#A31515;"">"aString"</span>);
</pre></div>";
string actual = new CodeColorizer().Colorize(source, Languages.JavaScript);
Assert.Equal(expected, actual);
}
示例14: TransformWillStyleAddHandlerStatement
public void TransformWillStyleAddHandlerStatement()
{
string source =
@"AddHandler event, AddressOf eventHandler";
string expected =
@"<div style=""color:Black;background-color:White;""><pre>
<span style=""color:Blue;"">AddHandler</span> <span style=""color:Blue;"">event</span>, <span style=""color:Blue;"">AddressOf</span> eventHandler
</pre></div>";
string actual = new CodeColorizer().Colorize(source, Languages.VbDotNet);
Assert.Equal(expected, actual);
}
示例15: TransformWillStylAnElementWithAttributes
public void TransformWillStylAnElementWithAttributes()
{
string source =
@"<anElement anAttribute=""anAttributeValue"" />";
string expected =
@"<div style=""color:Black;background-color:White;""><pre>
<span style=""color:Blue;""><</span><span style=""color:#A31515;"">anElement</span> <span style=""color:Red;"">anAttribute</span><span style=""color:Blue;"">=</span><span style=""color:Blue;"">"anAttributeValue"</span> <span style=""color:Blue;"">/></span>
</pre></div>";
string actual = new CodeColorizer().Colorize(source, Languages.Html);
Assert.Equal(expected, actual);
}