aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Text/Pandoc/XML.hs11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/Text/Pandoc/XML.hs b/src/Text/Pandoc/XML.hs
index e21525018..1532e790b 100644
--- a/src/Text/Pandoc/XML.hs
+++ b/src/Text/Pandoc/XML.hs
@@ -33,9 +33,11 @@ module Text.Pandoc.XML ( stripTags,
inTags,
selfClosingTag,
inTagsSimple,
- inTagsIndented ) where
+ inTagsIndented,
+ toEntities ) where
import Text.Pandoc.Pretty
+import Data.Char (ord, isAscii)
-- | Remove everything between <...>
stripTags :: String -> String
@@ -89,3 +91,10 @@ inTagsSimple tagType = inTags False tagType []
-- | Put the supplied contents in indented block btw start and end tags.
inTagsIndented :: String -> Doc -> Doc
inTagsIndented tagType = inTags True tagType []
+
+-- | Escape all non-ascii characters using numerical entities.
+toEntities :: String -> String
+toEntities [] = ""
+toEntities (c:cs)
+ | isAscii c = c : toEntities cs
+ | otherwise = "&#" ++ show (ord c) ++ ";" ++ toEntities cs