namespace Textile.Blocks; public class CodeBlockModifier : BlockModifier { public override string ModifyLine(string line) { // Replace "@...@" zones with "" tags. var me = new MatchEvaluator(CodeFormatMatchEvaluator); line = Regex.Replace(line, @"(?^|([\s\([{]))" + // before "@" + @"(\|(?\w+)\|)?" + // lang "(?[^@]+)" + // code "@" + @"(?$|([\]}])|(?=" + Globals.PunctuationPattern + @"{1,2}|\s|$))", // after me); // Encode the contents of the "" tags so that we don't // generate formatting out of it. line = NoTextileEncoder.EncodeNoTextileZones(line, @"(?<=(^|\s))", @"(?=)"); return line; } public override string Conclude(string line) { // Recode everything except "<" and ">"; line = NoTextileEncoder.DecodeNoTextileZones(line, @"(?<=(^|\s))", @"(?=)", new string[] { "<", ">" }); return line; } public string CodeFormatMatchEvaluator(Match m) { var res = m.Groups["before"].Value + " 0) res += " language=\"" + m.Groups["lang"].Value + "\""; res += ">" + m.Groups["code"].Value + "" + m.Groups["after"].Value; return res; } }