summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2022-03-30 09:34:16 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2022-03-30 09:34:16 -0700
commitd71d01f41a86815d355ff059a99a381da35920c4 (patch)
tree3c06f6edeea7aec6b62d024785281ce1640680cf /src
parent5fbea20e039b5b9b5d1813f1614f188a36064fd1 (diff)
HTML writer: add a performance shortcut to strToHtml.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Writers/HTML.hs8
1 files 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