Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You could install the web-encodings package, take the Sourcecode of the decodeHtml function and add the characters you need (works for me). This is all you need:</p> <pre><code>import Data.Maybe import qualified Web.Encodings.StringLike as SL import Web.Encodings.StringLike (StringLike) import Data.Char (ord) -- | Decode HTML-encoded content into plain content. -- -- Note: this does not support all HTML entities available. It also swallows -- all failures. decodeHtml :: StringLike s =&gt; s -&gt; s decodeHtml s = case SL.uncons s of Nothing -&gt; SL.empty Just ('&amp;', xs) -&gt; fromMaybe ('&amp;' `SL.cons` decodeHtml xs) $ do (before, after) &lt;- SL.breakCharMaybe ';' xs c &lt;- case SL.unpack before of -- this are small enough that unpack is ok "lt" -&gt; return '&lt;' "gt" -&gt; return '&gt;' "amp" -&gt; return '&amp;' "quot" -&gt; return '"' '#' : 'x' : hex -&gt; readHexChar hex '#' : 'X' : hex -&gt; readHexChar hex '#' : dec -&gt; readDecChar dec _ -&gt; Nothing -- just to shut up a warning return $ c `SL.cons` decodeHtml after Just (x, xs) -&gt; x `SL.cons` decodeHtml xs readHexChar :: String -&gt; Maybe Char readHexChar s = helper 0 s where helper i "" = return $ toEnum i helper i (c:cs) = do c' &lt;- hexVal c helper (i * 16 + c') cs hexVal :: Char -&gt; Maybe Int hexVal c | '0' &lt;= c &amp;&amp; c &lt;= '9' = Just $ ord c - ord '0' | 'A' &lt;= c &amp;&amp; c &lt;= 'F' = Just $ ord c - ord 'A' + 10 | 'a' &lt;= c &amp;&amp; c &lt;= 'f' = Just $ ord c - ord 'a' + 10 | otherwise = Nothing readDecChar :: String -&gt; Maybe Char readDecChar s = do case reads s of (i, _):_ -&gt; Just $ toEnum (i :: Int) _ -&gt; Nothing </code></pre> <p>I did not test performance though. But it might be a nice sample if you this can be done without regexps as well.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload