title: Replace newlines with <p> paragraph and with <br /> tags
body: <p>So I <a href="https://stackoverflow.com/questions/238002/replace-line-breaks-in-a-string-c">know</a> how to replace newlines in my C# code. But replacing a newline for a <code>&lt;br /&gt;</code> tag isn't always very correct. </p>
  
  <p>So I was wondering what kind of strategy do others use? The correct way I guess would be to use <code>&lt;p&gt;</code> tags and <code>&lt;br /&gt;</code> tags. </p>
  
  <p>Here are some examples of the results I would like to get.</p>
  
  <p>If there is no newline I want the text to wrapped in a <code>&lt;p&gt;</code> tags. </p>
  
  <blockquote>
    <p>This text contains no newlines</p>
  </blockquote>
  
  <pre><code>&lt;p&gt;This text contains no newlines&lt;/p&gt;   
  </code></pre>
  
  <p>If the text contains a newline I want it to be replaced by a <code>&lt;br /&gt;</code> tag and be wrapped in <code>&lt;p&gt;</code> tags.</p>
  
  <blockquote>
    <p>This text contains<br>
    1 newline</p>
  </blockquote>
  
  <pre><code>&lt;p&gt;This text contains&lt;br /&gt; 1 newline.&lt;/p&gt;
  </code></pre>
  
  <p>If there are 'double newlines' I want that block to be wrapped in <code>&lt;p&gt;</code> tags.</p>
  
  <blockquote>
    <p>This is a text with 'double newlines' at the end. </p>
    
    <p>This is a text with no newline at the end.</p>
  </blockquote>
  
  <pre><code>&lt;p&gt;This a text with 'double newlines at the end.&lt;/p&gt;
  &lt;p&gt;This is a text with no newline at the end.&lt;/p&gt;
  </code></pre>
  
  <p>I could write more examples/combination but I guess it's somewhat clear what I mean. </p>
  
  <p>Thanks in advance.</p>