From 3abc1021aae3cbba698ff8e27fc809647461248e Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Fri, 28 Sep 2012 11:11:31 -0400 Subject: HTML writer: Use toHtml instead of pre-escaping. We work around the problem that blaze-html unnecessarily escapes `'` by pre-escaping just the `'` characters, instead of the whole string. If blaze-html later stops escaping `'` characters, we can simplify strToHtml to toHtml. Note that this change yields a significant speed boost (111ms to 94ms on one benchmark). Closes #629. --- src/Text/Pandoc/Writers/HTML.hs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/Text/Pandoc/Writers') diff --git a/src/Text/Pandoc/Writers/HTML.hs b/src/Text/Pandoc/Writers/HTML.hs index ebb705a61..66336ca81 100644 --- a/src/Text/Pandoc/Writers/HTML.hs +++ b/src/Text/Pandoc/Writers/HTML.hs @@ -39,7 +39,7 @@ import Text.Pandoc.Readers.TeXMath import Text.Pandoc.Slides import Text.Pandoc.Highlighting ( highlight, styleToCss, formatHtmlInline, formatHtmlBlock ) -import Text.Pandoc.XML (stripTags, escapeStringForXML, fromEntities) +import Text.Pandoc.XML (stripTags, fromEntities) import Network.HTTP ( urlEncode ) import Numeric ( showHex ) import Data.Char ( ord, toLower ) @@ -60,7 +60,7 @@ import Text.Blaze.Renderer.String (renderHtml) import Text.TeXMath import Text.XML.Light.Output import System.FilePath (takeExtension) -import Data.Monoid (mempty, mconcat) +import Data.Monoid data WriterState = WriterState { stNotes :: [Html] -- ^ List of notes @@ -77,8 +77,11 @@ defaultWriterState = WriterState {stNotes= [], stMath = False, stQuotes = False, -- Helpers to render HTML with the appropriate function. strToHtml :: String -> Html -strToHtml = preEscapedString . escapeStringForXML --- strToHtml = toHtml +strToHtml ('\'':xs) = preEscapedString "\'" `mappend` strToHtml xs +strToHtml xs@(_:_) = case break (=='\'') xs of + (_ ,[]) -> toHtml xs + (ys,zs) -> toHtml ys `mappend` strToHtml zs +strToHtml [] = "" -- | Hard linebreak. nl :: WriterOptions -> Html -- cgit v1.2.3