diff options
author | fiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> | 2008-07-27 03:54:07 +0000 |
---|---|---|
committer | fiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> | 2008-07-27 03:54:07 +0000 |
commit | 57df7f5eb6c7d9e258ffc017380efd3b3422add9 (patch) | |
tree | e0b2d07abd6d1ff3eb57b8f0b45ebd8438218813 /Text | |
parent | ddaec05d8f49308363c694718240bdaf58466659 (diff) | |
download | pandoc-57df7f5eb6c7d9e258ffc017380efd3b3422add9.tar.gz |
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
Diffstat (limited to 'Text')
-rw-r--r-- | Text/Pandoc/Writers/HTML.hs | 16 |
1 files changed, 15 insertions, 1 deletions
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 = |