/// <summary> /// Set html syntax color text on the RTF html editor. /// </summary> private void SetColoredText(string text, bool color) { var selectionStart = _htmlEditor.CaretPosition; _htmlEditor.Text = color ? HtmlSyntaxHighlighter.Process(text) : text.Replace("\n", "\\par "); _htmlEditor.CaretPosition = selectionStart; }
public static void Main() { var assemblyLocation = Assembly.GetEntryAssembly()?.Location ?? ""; var assemblyDirectoryName = Path.GetDirectoryName(assemblyLocation) ?? ""; var samplesPath = Path.Combine(assemblyDirectoryName, "samples"); var files = Directory.EnumerateFiles(samplesPath, "*.cs", SearchOption.TopDirectoryOnly); // Next line is used when debugging. //files = files.Where(x => x.EndsWith("Inheritance.cs")); foreach (var file in files) { var source = File.ReadAllText(file); var syntaxHtml = HtmlSyntaxHighlighter.TransformCSharp(source); var html = $@"<!DOCTYPE html> <html> <head> <style> { HtmlSyntaxHighlighter.GetCssStyles() } </style> </head> <body> <pre> <code>{syntaxHtml}</code> </pre> </body> </html>"; File.WriteAllText(Path.Combine(samplesPath, Path.GetFileNameWithoutExtension(file) + ".html"), html); } }
/// <summary> /// Set html syntax color text on the RTF html editor. /// </summary> private void SetColoredText(string text) { var selectionStart = _htmlEditor.SelectionStart; _htmlEditor.Clear(); _htmlEditor.Rtf = HtmlSyntaxHighlighter.Process(text); _htmlEditor.SelectionStart = selectionStart; }
private void HtmlSourceForm_Load(object sender, EventArgs e) { richTextBox1.Rtf = HtmlSyntaxHighlighter.Process(richTextBox1.Text); }