"<pre>" and "_pre_"?

What does "<pre>" and "_pre_" respectively mean in the following code The code is at:

http://west-wind.com/weblog/posts/1499.aspx

 

public static string DisplayMemoEncoded(string Text)

{

      bool PreTag = false;

      if (Text.IndexOf("<pre>") > -1)

      {

            Text = Text.Replace("<pre>","__pre__");

            Text = Text.Replace("</pre>","__/pre__");

            PreTag = true;

      }

 

      // *** fix up line breaks into <br><p>

      Text = Westwind.Tools.wwUtils.DisplayMemo( HttpUtility.HtmlEncode(Text) );

 

      if (PreTag)

      {

            Text = Text.Replace("__pre__","<pre>");

            Text = Text.Replace("__/pre__","</pre>");

      }

 

      return Text;

}




Answer this question

"<pre>" and "_pre_"?

  • Omar Fawzi

    >> __pre__ is what the user enterd so convert it to html tag <pre> and vis versa

    Not exactly. The user enters <pre> & </pre> as part of normal HTML. For some reason, the developer does not want <pre> processed by DisplayMemo(), so he temporarily removes them, and then later replaces them.



  • MFZ

    professional remark, thks.

  • Mindy Riddick

    <pre> is html tag that defines preformatted text

    __pre__ is what the user enterd so convert it to html tag <pre> and vis versa

    to display text input by users properly in HTML



  • Nikhil - MSFT

    OK, now that I've read the blog you cited, I now understand the method.

    Overall, it takes a string and adds <br> at the appropriate spots. (That's DisplayMemo).

    DisplayMemoEncoded add a call to HttpUtility.HtmlEncode before calling DisplayMemo. This translates < and > to &lt; and &gt;. The problem is, if there is an embed HTML section is the text (surrounded by <pre> ... </pre>) those < and >s will converted also, and suddenly, it's no longer a preformmated section, so he changes the <pre> tag to something that won't be affected by HttpUtility.HtmlEncode, and then later changes it back.



  • "<pre>" and "_pre_"?