From f40b2eb2e763ed08768e08394e5a131bd4373126 Mon Sep 17 00:00:00 2001
From: John MacFarlane <fiddlosopher@gmail.com>
Date: Sat, 14 Apr 2012 22:52:14 -0700
Subject: [PATCH] Fixed bug in fromEntities.

The previous version would turn "hi & low you know;" into "hi &".
---
 src/Text/Pandoc/XML.hs | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/Text/Pandoc/XML.hs b/src/Text/Pandoc/XML.hs
index 7a1c8bdd8..31279c3bb 100644
--- a/src/Text/Pandoc/XML.hs
+++ b/src/Text/Pandoc/XML.hs
@@ -38,7 +38,7 @@ module Text.Pandoc.XML ( stripTags,
                          fromEntities ) where
 
 import Text.Pandoc.Pretty
-import Data.Char (ord, isAscii)
+import Data.Char (ord, isAscii, isSpace)
 import Text.HTML.TagSoup.Entity (lookupEntity)
 
 -- | Remove everything between <...>
@@ -106,8 +106,8 @@ fromEntities :: String -> String
 fromEntities ('&':xs) =
   case lookupEntity ent of
         Just c  -> c : fromEntities rest
-        Nothing -> '&' : fromEntities rest
-    where (ent, rest) = case break (==';') xs of
+        Nothing -> '&' : fromEntities xs
+    where (ent, rest) = case break (\c -> isSpace c || c == ';') xs of
                              (zs,';':ys) -> (zs,ys)
                              _           -> ("",xs)
 fromEntities (x:xs) = x : fromEntities xs