Created
June 28, 2012 17:29
-
-
Save rickbarrette/3012696 to your computer and use it in GitHub Desktop.
A simple program I used to convert my jeep build thread from a forum to a wordpress friendly format
This file contains 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
/** | |
* converter.cs | |
* @date June 27, 2012 | |
* @author rickbarrette@gmail.com | |
* | |
* Copyright 2012 Richard Barrette | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software | |
* distributed under the License is distributed on an "AS IS" BASIS, | |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
* See the License for the specific language governing permissions and | |
* limitations under the License | |
*/ | |
using System; | |
using System.IO; | |
using System.Text.RegularExpressions; | |
/** | |
* This is a simple program that I will use to convert my build thread posts | |
* from an online forum to a format that is usable by wordpress | |
*/ | |
namespace Converter { | |
class Program{ | |
/** | |
* Main Method | |
*/ | |
static void Main(string[] args) { | |
try { | |
Console.WriteLine("Ricky's Build Thread Converter"); | |
// Read the post file that is in the current working dir | |
string FILE = @"post"; | |
string text = File.ReadAllText(FILE); | |
// IMG | |
Regex regex = new Regex(@"(?<A>\[img width=\d+ height=\d+\])(?<IMG>.*)(?<B>\[\/img\])", RegexOptions.IgnoreCase); | |
text = regex.Replace(text, "<img class=\"alignnone\" src=\"" + "${IMG}" + "\"alt=\"\" width=\"1010\" height=\"758\" />"); | |
// IMG | |
regex = new Regex(@"(?<A>\[img height=\d+ width=\d+\])(?<IMG>.*)(?<B>\[\/img\])", RegexOptions.IgnoreCase); | |
text = regex.Replace(text, "<img class=\"alignnone\" src=\"" + "${IMG}" + "\"alt=\"\" width=\"1010\" height=\"758\" />"); | |
// IMG | |
regex = new Regex(@"(?<A>\[img\])(?<IMG>.*)(?<B>\[\/img\])", RegexOptions.IgnoreCase); | |
text = regex.Replace(text, "<img class=\"alignnone\" src=\"" + "${IMG}" + "\"alt=\"\" width=\"1010\" height=\"758\" />"); | |
// underline [u] | |
regex = new Regex(@"(?<A>\[u\])(?<B>.*)(?<C>\[\/u\])", RegexOptions.IgnoreCase); | |
text = regex.Replace(text, "<u>" + "${B}" + "</u>"); | |
// bold [b] | |
regex = new Regex(@"(?<A>\[b\])(?<B>.*)(?<C>\[\/b\])", RegexOptions.IgnoreCase); | |
text = regex.Replace(text, "<strong>" + "${B}" + "</strong>"); | |
// URL [url=http://]text[/url] | |
regex = new Regex(@"(?<A>\[url=)(?<URL>.*)(?<B>\])(?<TEXT>.*)(?<C>\[\/url\])", RegexOptions.IgnoreCase); | |
text = regex.Replace(text, "<a href=\"" + "${URL}" +"\">" + "${TEXT}" +"</a>"); | |
// URL [url]http://[/url] | |
regex = new Regex(@"(?<A>\[url\])(?<URL>.*)(?<B>\[\/url\])", RegexOptions.IgnoreCase); | |
text = regex.Replace(text, "<a href=\"" + "${URL}" +"\">" + "${URL}" +"</a>"); | |
//write the changes to the file | |
File.WriteAllText(FILE, text); | |
} | |
catch { } | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment