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

commit3abc1021aae3cbba698ff8e27fc809647461248e authorJohn MacFarlane <jgm@berkeley.edu> dateFri 28 Sep 2012, 11:11 (14 years ago) parent4be1375
1 file changed+7−4
src/Text/Pandoc/Writers/HTML.hs+7−4
src/Text/Pandoc/Writers/HTML.hs+7−4
@@ -39,7 +39,7 @@ import Text.Pandoc.Readers.TeXMath
3939import Text.Pandoc.Slides
4040import Text.Pandoc.Highlighting ( highlight, styleToCss,
4141 formatHtmlInline, formatHtmlBlock )
42−import Text.Pandoc.XML (stripTags, escapeStringForXML, fromEntities)
42+import Text.Pandoc.XML (stripTags, fromEntities)
4343import Network.HTTP ( urlEncode )
4444import Numeric ( showHex )
4545import Data.Char ( ord, toLower )
@@ -60,7 +60,7 @@ import Text.Blaze.Renderer.String (renderHtml)
6060import Text.TeXMath
6161import Text.XML.Light.Output
6262import System.FilePath (takeExtension)
63−import Data.Monoid (mempty, mconcat)
63+import Data.Monoid
6464
6565data WriterState = WriterState
6666 { stNotes :: [Html] -- ^ List of notes
@@ -77,8 +77,11 @@ defaultWriterState = WriterState {stNotes= [], stMath = False, stQuotes = False,
7777-- Helpers to render HTML with the appropriate function.
7878
7979strToHtml :: String -> Html
80−strToHtml = preEscapedString . escapeStringForXML
81−-- strToHtml = toHtml
80+strToHtml ('\'':xs) = preEscapedString "\'" `mappend` strToHtml xs
81+strToHtml xs@(_:_) = case break (=='\'') xs of
82+ (_ ,[]) -> toHtml xs
83+ (ys,zs) -> toHtml ys `mappend` strToHtml zs
84+strToHtml [] = ""
8285
8386-- | Hard linebreak.
8487nl :: WriterOptions -> Html