Example #1
0
        public void Linkify(string text, Action<string> onSuccess)
        {
            text = Regex.Replace(text, @"(http\://|https\://|www.)\S*", match => {
            if (match.Index != 0)
            {
               var previousChar = text[match.Index - 1];

               if (!char.IsWhiteSpace(previousChar))
                  return match.Value;
            }

            var value = match.Value;
            var path = new UriBuilder(value).Uri.AbsolutePath;

            if (match.Groups[1].Value == "www.")
               value = "http://" + value;

            return path.EndsWith("jpg") || path.EndsWith("gif") || path.EndsWith("png")
                  ? "![Inline Image](" + value + ")"
                  : "[" + value + "](" + value + ")";
             });
             text = new MarkdownDeep.Markdown {
            ExtraMode = true,
            NewWindowForExternalLinks = true,
            NewWindowForLocalLinks = true,
             }.Transform(text);
             text = text.Replace("\n", "");
             text = text.Replace(@"\", @"\\");

             onSuccess(text);
        }