title: Transform HTML in Haskell
body: <p>I want to transform a valid HTML with not very deep level of nesting into another HTML with more restricted rules.</p>
  
  <p>Only the following tags are supported in the resulting HTML:</p>
  
  <pre><code>&lt;b&gt;&lt;/b&gt;, &lt;strong&gt;&lt;/strong&gt;, &lt;i&gt;&lt;/i&gt;, &lt;em&gt;&lt;/em&gt;, &lt;a
  href="URL"&gt;&lt;/a&gt;, &lt;code&gt;&lt;/code&gt;, &lt;pre&gt;&lt;/pre&gt;
  </code></pre>
  
  <p>Nested tags are not allowed at all.</p>
  
  <p>For the rest of the tags and their combinations I have to create some sort of rules how to handle each.
  So I have to convert something like: </p>
  
  <p><code>&lt;p&gt;text&lt;/p&gt;</code> into simple string <code>text</code> with linebreak,</p>
  
  <p><code>&lt;b&gt;text &lt;a href="url"&gt;link&lt;/a&gt; text&lt;/b&gt;</code> into <code>text link text</code></p>
  
  <p><code>&lt;a href="url"&gt;text&lt;code&gt; code here&lt;/code&gt;&lt;/a&gt;</code> into <code>&lt;a href="url"&gt;text code here&lt;/a&gt;</code> because <code>&lt;code&gt;</code> is nested inside <code>&lt;a&gt;</code> and so on. </p>
  
  <p>For example HTML (linebreaks are only for convenience):</p>
  
  <pre><code>&lt;p&gt;long paragraph &lt;a href="url"&gt;link&lt;/a&gt; &lt;/p&gt;
  &lt;p&gt;another text &lt;pre&gt;&lt;code&gt;my code block&lt;/code&gt;&lt;/pre&gt; the rest of description&lt;/p&gt;
  &lt;p&gt;&lt;code&gt;inline monospaced text with &lt;a href="url"&gt;link&lt;/a&gt;&lt;/code&gt;&lt;/p&gt;
  </code></pre>
  
  <p>Should be transformed into:</p>
  
  <pre><code>long paragraph &lt;a href="url"&gt;link&lt;/a&gt;
  
  another text &lt;code&gt;my code block&lt;/code&gt; the rest of description
  
  &lt;code&gt;inline monospaced text with link&lt;/code&gt;
  </code></pre>
  
  <p>Any suggestion on the way to solve that?</p>