Created
June 24, 2014 14:57
-
-
Save lnicola/159f02eae063dc71f587 to your computer and use it in GitHub Desktop.
Textile test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment