git.iko.soy/typeable/pandoc
on master help sign in
XML: Added toEntities.
commitd0e70cbc29ac856b92914111ca46842aafe4b961 authorJohn MacFarlane <fiddlosopher@gmail.com> dateSat 28 Jan 2012, 09:30 (15 years ago) parent8abe08d
1 file changed+10−1
src/Text/Pandoc/XML.hs+10−1
src/Text/Pandoc/XML.hs+10−1
@@ -33,9 +33,11 @@ module Text.Pandoc.XML ( stripTags,
3333 inTags,
3434 selfClosingTag,
3535 inTagsSimple,
36− inTagsIndented ) where
36+ inTagsIndented,
37+ toEntities ) where
3738
3839import Text.Pandoc.Pretty
40+import Data.Char (ord, isAscii)
3941
4042-- | Remove everything between <...>
4143stripTags :: String -> String
@@ -89,3 +91,10 @@ inTagsSimple tagType = inTags False tagType []
8991-- | Put the supplied contents in indented block btw start and end tags.
9092inTagsIndented :: String -> Doc -> Doc
9193inTagsIndented tagType = inTags True tagType []
94+
95+-- | Escape all non-ascii characters using numerical entities.
96+toEntities :: String -> String
97+toEntities [] = ""
98+toEntities (c:cs)
99+ | isAscii c = c : toEntities cs
100+ | otherwise = "&#" ++ show (ord c) ++ ";" ++ toEntities cs