aboutsummaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2012-09-28 11:11:31 -0400
committerJohn MacFarlane <jgm@berkeley.edu>2012-09-28 11:11:31 -0400
commit3abc1021aae3cbba698ff8e27fc809647461248e (patch)
treed27a3ff3f531029196e9462e2e1f792fb1c826e2 /src/Text
parent4be137509ea98a68dd557b982e5cb7cbad7a3062 (diff)
downloadpandoc-3abc1021aae3cbba698ff8e27fc809647461248e.tar.gz
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.
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/Writers/HTML.hs11
1 files changed, 7 insertions, 4 deletions
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