aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc
diff options
context:
space:
mode:
authorJohn MacFarlane <fiddlosopher@gmail.com>2012-01-28 09:30:31 -0800
committerJohn MacFarlane <fiddlosopher@gmail.com>2012-01-28 11:43:27 -0800
commitd0e70cbc29ac856b92914111ca46842aafe4b961 (patch)
tree0120edd9557df934162225ad2cb026d0bf575ef5 /src/Text/Pandoc
parent8abe08d6d43b77fe05f3b942a28b0f1a987753bd (diff)
downloadpandoc-d0e70cbc29ac856b92914111ca46842aafe4b961.tar.gz
XML: Added toEntities.
Diffstat (limited to 'src/Text/Pandoc')
-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