I just thought that unformatted code does not look so nice in my wordpress posts and because I am a self-maker and did not want to install any syntax highlighter I just wrote a little C# program which generates HTML code out of richText code. So I can simply paste code from Visual Studio and then I receive the HTML code to display my code from Visual Studio on any HTML page.
Here you can see the source code of this little tool as an example:
//C# Program that generates HTML-Code out of any programming code using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } string Code; private void button1_Click(object sender, EventArgs e) { Code = ""; Code += "<div class=\"coloredCode\""; Code += " style=\"font-family: "+richTextBox1.SelectionFont.FontFamily.Name+";\""; Code += "><pre style=\"white-space: pre-wrap;\">"; System.Drawing.Color oldColor = System.Drawing.Color.Black; bool opened = false; for (int i = 0; i < richTextBox1.TextLength; i++) { richTextBox1.Select(i, 1); if (richTextBox1.SelectionColor != oldColor) { if (i != 0 && opened) { Code += "</span>"; opened = false; } if (i != richTextBox1.TextLength - 1 && richTextBox1.SelectionColor!=System.Drawing.Color.Black) { Code += "<span style=\"color: " + System.Drawing.ColorTranslator.ToHtml(richTextBox1.SelectionColor) + ";\">"; opened = true; } } Code += System.Web.HttpUtility.HtmlEncode(richTextBox1.SelectedText); oldColor = richTextBox1.SelectionColor; } if (opened) { Code += "</span>"; } Code += "</pre></div>"; System.Windows.Forms.TextBox textbox=new System.Windows.Forms.TextBox(); textbox.Text = Code; textbox.SelectAll(); textbox.Copy(); MessageBox.Show("Your HTML-Code was copied to the clipboard", "Copied", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
The program can be downloaded here
