#region License Statement // Copyright (c) L.A.B.Soft. All rights reserved. // // The use and distribution terms for this software are covered by the // Common Public License 1.0 (http://opensource.org/licenses/cpl.php) // which can be found in the file CPL.TXT at the root of this distribution. // By using this software in any fashion, you are agreeing to be bound by // the terms of this license. // // You must not remove this notice, or any other, from this software. #endregion #region Using Statements using System.Text.RegularExpressions; #endregion 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; } static 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; } } }