namespace Textile.Blocks; public class ImageBlockModifier : BlockModifier { public override string ModifyLine(string line) { line = Regex.Replace(line, @"\!" + // opening ! @"(?\<|\=|\>)?" + // optional alignment atts Globals.BlockModifiersPattern + // optional style, public class atts @"(?:\. )?" + // optional dot-space @"(?[^\s(!]+)" + // presume this is the src @"\s?" + // optional space @"(?:\((?([^\)]+))\))?" +// optional title @"\!" + // closing @"(?::(?<href>(\S+)))?" + // optional href @"(?=\s|\.|,|;|\)|\||$)", // lookahead: space or simple punctuation or end of string new MatchEvaluator(ImageFormatMatchEvaluator) ); return line; } string ImageFormatMatchEvaluator(Match m) { var atts = BlockAttributesParser.ParseBlockAttributes(m.Groups["atts"].Value, "img"); if (m.Groups["algn"].Length > 0) atts += " align=\"" + Globals.ImageAlign[m.Groups["algn"].Value] + "\""; if (m.Groups["title"].Length > 0) { atts += " title=\"" + m.Groups["title"].Value + "\""; atts += " alt=\"" + m.Groups["title"].Value + "\""; } else { atts += " alt=\"\""; } // Get Image Size? var res = "<img src=\"" + m.Groups["url"].Value + "\"" + atts + " />"; if (m.Groups["href"].Length > 0) { var href = m.Groups["href"].Value; var end = string.Empty; var endMatch = Regex.Match(href, @"(.*)(?<end>\.|,|;|\))$"); if (m.Success && !string.IsNullOrEmpty(endMatch.Groups["end"].Value)) { href = href[0..^1]; end = endMatch.Groups["end"].Value; } res = "<a href=\"" + Globals.EncodeHTMLLink(href) + "\">" + res + "</a>" + end; } return res; } }