Textile test
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
namespace Textile
{
static class ExtensionMethods
{
public static string RegexReplace(this string text, string pattern, string replacement)
{
return Regex.Replace(text, pattern, replacement);
}
}
class Program
{
private static string Convert(string text)
{
return text.
//RegexReplace(@"\*((?:\w+\s*)+)\*", "<strong>$1</strong>").
//RegexReplace(@"_((?:\w+\s*)+)_", "<em>$1</em>").
//RegexReplace(@"\?\?((?:\w+\s*)+)\?\?", "<cite>$1</cite>");
RegexReplace(@"\bfoo\b", "bar").
RegexReplace(@"\b\*((?:\w+\s*)+)\*\b", "<strong>$1</strong>").
RegexReplace(@"_((?:\w+\s*)+)_", "<em>$1</em>").
RegexReplace(@"\?\?((?:\w+\s*)+)\?\?", "<cite>$1</cite>");
}
static void Main(string[] args)
{
var tests = new[] { " foo foo ", "*bold*", "*bold* *bold*", "_italic_ _italic_", "??foo bar baz?? ??qux quux??", "??*Cool*, eh???", "_asd asd asd_ads_" };
foreach (var test in tests)
Console.WriteLine("{0} -> {1}", test, Convert(test));
}
}
}