codeblockhighlighter.cs

来自「Freetextbox是优秀的在线编辑器」· CS 代码 · 共 38 行

CS
38
字号
namespace CommunityServer.FreeTextBoxWrapper
{
    using Aylar.Highlight;
    using Aylar.Highlight.Extensions;
    using System;
    using System.Text.RegularExpressions;

    internal class CodeBlockHighlighter : Aylar.Highlight.Extensions.CodeBlockHighlighter
    {
        protected string CodeMatchHandler(Match m)
        {
            Highlighter highlighter1 = new Highlighter();
            string text1 = m.Groups["language"].Value;
            string text2 = m.Groups["code"].Value;
            string text3 = m.Groups["image"].Value;
            string text4 = highlighter1.Highlight(text2, text1).Replace("\n\n", "<br />").Replace("\n", "<br />");
            return string.Format("<code>{0}</code>", text4);
        }

        public string Highlight(string inCode, bool highlightBBCode)
        {
            Regex regex1;
            if (highlightBBCode)
            {
                regex1 = new Regex("\\[code[\\s]+language=\"(?'language'[^\"]*?)\"\\](?'code'[\\w\\W]*?)\\[\\/code\\]");
            }
            else
            {
                regex1 = new Regex("<code[\\s]+language=\"(?'language'[^\"]*?)\">(?'code'[\\w\\W]*?)<\\/code>");
            }
            MatchEvaluator evaluator1 = new MatchEvaluator(this.CodeMatchHandler);
            return regex1.Replace(inCode, evaluator1);
        }

    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?