git.iko.soy/typeable/pandoc
on master help sign in
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

commit57df7f5eb6c7d9e258ffc017380efd3b3422add9 authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> dateSun 27 Jul 2008, 03:54 (18 years ago) parentddaec05
2 files changed+18−4
Text/Pandoc/Writers/HTML.hs+15−1 tests/writer.html+3−3
Text/Pandoc/Writers/HTML.hs+15−1
@@ -39,7 +39,7 @@ import Data.Char ( ord, toLower, isAlpha )
3939import Data.List ( isPrefixOf, intersperse )
4040import qualified Data.Set as S
4141import Control.Monad.State
42−import Text.XHtml.Transitional
42+import Text.XHtml.Transitional hiding ( stringToHtml )
4343
4444data WriterState = WriterState
4545 { stNotes :: [Html] -- ^ List of notes
@@ -62,6 +62,20 @@ renderFragment opts = if writerWrapText opts
6262 then renderHtmlFragment
6363 else showHtmlFragment
6464
65+-- | Slightly modified version of Text.XHtml's stringToHtml.
66+-- Only uses numerical entities for 0xff and greater.
67+-- Adds &nbsp;.
68+stringToHtml :: String -> Html
69+stringToHtml = primHtml . concatMap fixChar
70+ where
71+ fixChar '<' = "&lt;"
72+ fixChar '>' = "&gt;"
73+ fixChar '&' = "&amp;"
74+ fixChar '"' = "&quot;"
75+ fixChar '\160' = "&nbsp;"
76+ fixChar c | ord c < 0xff = [c]
77+ fixChar c = "&#" ++ show (ord c) ++ ";"
78+
6579-- | Convert Pandoc document to Html string.
6680writeHtmlString :: WriterOptions -> Pandoc -> String
6781writeHtmlString opts =
tests/writer.html+3−3
@@ -412,7 +412,7 @@ These should not be escaped: \$ \\ \&gt; \[ \{
412412 ><p
413413 >Should not be a list item:</p
414414 ><p
415− >M.A. 2007</p
415+ >M.A.&nbsp;2007</p
416416 ><p
417417 >B. Williams</p
418418 ><hr
@@ -678,7 +678,7 @@ Blah
678678 >hello</em
679679 ></sup
680680 > a<sup
681− >hello there</sup
681+ >hello&nbsp;there</sup
682682 >.</p
683683 ><p
684684 >Subscripts: H<sub
@@ -686,7 +686,7 @@ Blah
686686 >O, H<sub
687687 >23</sub
688688 >O, H<sub
689− >many of them</sub
689+ >many&nbsp;of&nbsp;them</sub
690690 >O.</p
691691 ><p
692692 >These should not be superscripts or subscripts, because of the unescaped spaces: a^b c^d, a~b c~d.</p