当前位置: 首页>>代码示例>>C#>>正文


C# ColorCode.CodeColorizer类代码示例

本文整理汇总了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);
        }
开发者ID:pickup,项目名称:PickupBlog,代码行数:40,代码来源:SyntaxHighlighter.cs

示例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);
            }
开发者ID:RichardSlater,项目名称:ColorCodePortable,代码行数:9,代码来源:CodeColorizerFacts.cs

示例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);
            }
开发者ID:RichardSlater,项目名称:ColorCodePortable,代码行数:9,代码来源:JavaAcceptanceTests.cs

示例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);
            }
开发者ID:RichardSlater,项目名称:ColorCodePortable,代码行数:9,代码来源:JavaAcceptanceTests.cs

示例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);
            }
开发者ID:RichardSlater,项目名称:ColorCodePortable,代码行数:9,代码来源:JavaAcceptanceTests.cs

示例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);
            }
开发者ID:RichardSlater,项目名称:ColorCodePortable,代码行数:9,代码来源:CodeColorizerFacts.cs

示例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);
            }
开发者ID:RichardSlater,项目名称:ColorCodePortable,代码行数:9,代码来源:CppAcceptanceTests.cs

示例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;\">&lt;!-- test --&gt;</span><span style=\"color:Blue;\">&lt;</span><span style=\"color:#A31515;\">root</span><span style=\"color:Blue;\">&gt;</span><span style=\"color:Blue;\">&lt;</span><span style=\"color:#A31515;\">elment</span><span style=\"color:Blue;\">&gt;</span><span style=\"color:Green;\">&lt;!-- comment inside of element --&gt;</span><span style=\"color:Blue;\">&lt;/</span><span style=\"color:#A31515;\">element</span><span style=\"color:Blue;\">&gt;</span><span style=\"color:Blue;\">&lt;/</span><span style=\"color:#A31515;\">root</span><span style=\"color:Blue;\">&gt;</span>\r\n</pre></div>";

            string actual = new CodeColorizer().Colorize(source, Languages.Xml);

            Assert.Equal(expected, actual);
        }
开发者ID:RichardSlater,项目名称:ColorCodePortable,代码行数:10,代码来源:XmlAcceptanceTests.cs

示例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);
        }
开发者ID:RichardSlater,项目名称:ColorCodePortable,代码行数:11,代码来源:ColorizeTests.cs

示例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);
     };
 }
开发者ID:hispafox,项目名称:CMContrib,代码行数:11,代码来源:GenericSampleView.xaml.cs

示例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);
            }
开发者ID:RichardSlater,项目名称:ColorCodePortable,代码行数:12,代码来源:CodeColorizerFacts.cs

示例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;"">&quot;aString&quot;</span>;
            </pre></div>";

            string actual = new CodeColorizer().Colorize(source, Languages.JavaScript);

            Assert.Equal(expected, actual);
        }
开发者ID:RichardSlater,项目名称:ColorCodePortable,代码行数:13,代码来源:JavaScriptAcceptanceTests.cs

示例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;"">&quot;aString&quot;</span>);
            </pre></div>";

            string actual = new CodeColorizer().Colorize(source, Languages.JavaScript);

            Assert.Equal(expected, actual);
        }
开发者ID:RichardSlater,项目名称:ColorCodePortable,代码行数:13,代码来源:JavaScriptAcceptanceTests.cs

示例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);
        }
开发者ID:cpancake,项目名称:ColorCode,代码行数:13,代码来源:VbDotNetAcceptanceTests.cs

示例15: TransformWillStylAnElementWithAttributes

        public void TransformWillStylAnElementWithAttributes()
        {
            string source =
            @"<anElement anAttribute=""anAttributeValue"" />";
            string expected =
            @"<div style=""color:Black;background-color:White;""><pre>
            <span style=""color:Blue;"">&lt;</span><span style=""color:#A31515;"">anElement</span> <span style=""color:Red;"">anAttribute</span><span style=""color:Blue;"">=</span><span style=""color:Blue;"">&quot;anAttributeValue&quot;</span> <span style=""color:Blue;"">/&gt;</span>
            </pre></div>";

            string actual = new CodeColorizer().Colorize(source, Languages.Html);

            Assert.Equal(expected, actual);
        }
开发者ID:RichardSlater,项目名称:ColorCodePortable,代码行数:13,代码来源:HtmlAcceptanceTests.cs


注:本文中的ColorCode.CodeColorizer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。