From d71d01f41a86815d355ff059a99a381da35920c4 Mon Sep 17 00:00:00 2001 From: John MacFarlane <jgm@berkeley.edu> Date: Wed, 30 Mar 2022 09:34:16 -0700 Subject: [PATCH] HTML writer: add a performance shortcut to strToHtml. --- src/Text/Pandoc/Writers/HTML.hs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Text/Pandoc/Writers/HTML.hs b/src/Text/Pandoc/Writers/HTML.hs index 25a978e24..f62da8058 100644 --- a/src/Text/Pandoc/Writers/HTML.hs +++ b/src/Text/Pandoc/Writers/HTML.hs @@ -113,7 +113,9 @@ defaultWriterState = WriterState {stNotes= [], stEmittedNotes = 0, stMath = Fals -- Helpers to render HTML with the appropriate function. strToHtml :: Text -> Html -strToHtml = strToHtml' . T.unpack +strToHtml t + | T.any isSpecial t = strToHtml' $ T.unpack t + | otherwise = toHtml t where strToHtml' ('\'':xs) = preEscapedString "\'" `mappend` strToHtml' xs strToHtml' ('"' :xs) = preEscapedString "\"" `mappend` strToHtml' xs @@ -122,11 +124,11 @@ strToHtml = strToHtml' . T.unpack case xs of ('\xFE0E':ys) -> strToHtml' ys _ -> strToHtml' xs - strToHtml' xs@(_:_) = case break (\c -> c == '\'' || c == '"' || - needsVariationSelector c) xs of + strToHtml' xs@(_:_) = case break isSpecial xs of (_ ,[]) -> toHtml xs (ys,zs) -> toHtml ys `mappend` strToHtml' zs strToHtml' [] = "" + isSpecial c = c == '\'' || c == '"' || needsVariationSelector c -- See #5469: this prevents iOS from substituting emojis. needsVariationSelector :: Char -> Bool