diff options
-rw-r--r-- | Text/Pandoc/Writers/HTML.hs | 16 | ||||
-rw-r--r-- | tests/writer.html | 6 |
2 files changed, 18 insertions, 4 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 = diff --git a/tests/writer.html b/tests/writer.html index 4a7c384ee..8a4f62fee 100644 --- a/tests/writer.html +++ b/tests/writer.html @@ -412,7 +412,7 @@ These should not be escaped: \$ \\ \> \[ \{ ><p >Should not be a list item:</p ><p - >M.A. 2007</p + >M.A. 2007</p ><p >B. Williams</p ><hr @@ -678,7 +678,7 @@ Blah >hello</em ></sup > a<sup - >hello there</sup + >hello there</sup >.</p ><p >Subscripts: H<sub @@ -686,7 +686,7 @@ Blah >O, H<sub >23</sub >O, H<sub - >many of them</sub + >many of them</sub >O.</p ><p >These should not be superscripts or subscripts, because of the unescaped spaces: a^b c^d, a~b c~d.</p |