ASP.NET 3.5 and above only

HTML Editor - Knowledge Base

« Back to Knowledge Base list

Custom 'get plain text' function

Q:

When the user enters in multiple line breaks then the editor.PlainText translates any group of line breaks (<br />) to a single break (\n).
Is there any way for this to match up one to one?

A:

Use the following function instead of the PlainText property:

using System.Text.RegularExpressions;
...
private string MyGetPlainText(Obout.Ajax.UI.HTMLEditor.Editor editor)
{
  // save the original HTML code
  string originalHtml = editor.EditPanel.Content;
  // get a random <br/> replacer content
  string dummyReplacer = (new Random()).Next().ToString();
  // replace all <br /> tags in the content with the dummy replacers
  editor.EditPanel.Content = Regex.Replace(editor.EditPanel.Content, @"<br[\s]*[/]*>[\n\r]*",
                                         "[---" + dummyReplacer + "---]", RegexOptions.IgnoreCase);
  // get plain text and replace the dummy replacers with the "new line" characters
  string plainText = Regex.Replace(editor.EditPanel.PlainText, @"\[---" + dummyReplacer + @"---\]",
                            "\n", RegexOptions.IgnoreCase);
  // restore the original HTML code
  editor.EditPanel.Content = originalHtml;
  // return the plain text
  return plainText;
}

"The grid itself is excellent. I'm amazed by what you have accomplished with it. It has become the main control for our pages due to our customers responses to layouts with it."

Mark Butler
Achieve Technology

Random testimonial   All testimonials