title: BBCode to HTML transformation rules
body: <h2>Background</h2>
  
  <p>I have written very simple BBCode parser using <code>C#</code> which transforms BBCode to HTML. Currently it supports only <code>[b]</code>, <code>[i]</code> and <code>[u]</code> tags. I know that BBCode is always considered as valid regardless whatever user have typed. I cannot find strict specification how to transform BBCode to HTML</p>
  
  <h2>Question</h2>
  
  <ol>
  <li>Does standard "BBCode to HTML" specification exist?</li>
  <li>How should I handle <code>"[b][b][/b][/b]"</code>? For now parser yields <code>"&lt;b&gt;[b][/b]&lt;/b&gt;"</code>.</li>
  <li>How should I handle <code>"[b][i][u]zzz[/b][/i][/u]"</code> input? Currently my parser is smart enough to produce <code>"&lt;b&gt;&lt;i&gt;&lt;u&gt;zzz&lt;/u&gt;&lt;/i&gt;&lt;/b&gt;"</code> output for such case, but I wonder that it is "too smart" approach, or it is not?</li>
  </ol>
  
  <h2>More details</h2>
  
  <p>I have found some ready-to-use BBCode parser implementations, but they are too heavy/complex for me and, what is worse, use tons of Regular Expressions and produce not that markup what I expect. Ideally, I want to receive XHTML at the output. For inferring "BBCode to HTML" transformation rules I am using this online parser: <a href="http://www.bbcode.org/playground.php" rel="nofollow noreferrer">http://www.bbcode.org/playground.php</a>. It produces HTML that is intuitively correct on my opinion. The only thing I dislike it does not produce XHTML. For example <code>"[b][i]zzz[/b][/i]"</code> is transformed to <code>"&lt;b&gt;&lt;i&gt;zzz&lt;/b&gt;&lt;/i&gt;"</code> (note closing tags order). FireBug of course shows this as <code>"&lt;b&gt;&lt;i&gt;zzz&lt;/i&gt;&lt;/b&gt;&lt;i&gt;&lt;/i&gt;"</code>. As I understand, browsers fix such wrong closing tags order cases, but I am in doubt:</p>
  
  <ol>
  <li>Should I rely on this browsers feature and do not try to make XHTML.</li>
  <li>Maybe <code>"[b][i]zzz[/b]ccc[/i]"</code> must be understood as <code>"&lt;b&gt;[i]zzz&lt;/b&gt;ccc[/i]"</code> - looks logically for such improper formatting, but is in conflict with popular forums BBCode outputs (<strong>*zzz****ccc*, not **[i]zzzccc[/i]</strong>)</li>
  </ol>
  
  <p>Thanks.</p>