From 57df7f5eb6c7d9e258ffc017380efd3b3422add9 Mon Sep 17 00:00:00 2001 From: fiddlosopher Date: Sun, 27 Jul 2008 03:54:07 +0000 Subject: HTML writer: override Text.XHtml's stringToHtml function, so that characters below 0xff are not converted to numerical entity references. Also convert '\160' to " ". This should aid readability and editability of the HTML source. It does presuppose that the HTML will be served as UTF-8. git-svn-id: https://pandoc.googlecode.com/svn/trunk@1338 788f1e2b-df1e-0410-8736-df70ead52e1b --- Text/Pandoc/Writers/HTML.hs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'Text/Pandoc/Writers/HTML.hs') diff --git a/Text/Pandoc/Writers/HTML.hs b/Text/Pandoc/Writers/HTML.hs index d0c45bec1..d31ebfb85 100644 --- a/Text/Pandoc/Writers/HTML.hs +++ b/Text/Pandoc/Writers/HTML.hs @@ -39,7 +39,7 @@ import Data.Char ( ord, toLower, isAlpha ) import Data.List ( isPrefixOf, intersperse ) import qualified Data.Set as S import Control.Monad.State -import Text.XHtml.Transitional +import Text.XHtml.Transitional hiding ( stringToHtml ) data WriterState = WriterState { stNotes :: [Html] -- ^ List of notes @@ -62,6 +62,20 @@ renderFragment opts = if writerWrapText opts then renderHtmlFragment else showHtmlFragment +-- | Slightly modified version of Text.XHtml's stringToHtml. +-- Only uses numerical entities for 0xff and greater. +-- Adds  . +stringToHtml :: String -> Html +stringToHtml = primHtml . concatMap fixChar + where + fixChar '<' = "<" + fixChar '>' = ">" + fixChar '&' = "&" + fixChar '"' = """ + fixChar '\160' = " " + fixChar c | ord c < 0xff = [c] + fixChar c = "&#" ++ show (ord c) ++ ";" + -- | Convert Pandoc document to Html string. writeHtmlString :: WriterOptions -> Pandoc -> String writeHtmlString opts = -- cgit v1.2.3