summaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2022-08-27 11:19:28 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2022-08-27 11:19:28 -0700
commitd11f24331e7da0db12df0b5451a8d141bba471e3 (patch)
treedbe23db5e32d7c31bc33595e778a8197d9608f0b /src/Text
parent742613fe3c94312794c06b04092bdf7a3457178c (diff)
Fix a small space leak in HTML writer.
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/Writers/HTML.hs26
1 files changed, 13 insertions, 13 deletions
diff --git a/src/Text/Pandoc/Writers/HTML.hs b/src/Text/Pandoc/Writers/HTML.hs
index 85864b963..0610351d0 100644
--- a/src/Text/Pandoc/Writers/HTML.hs
+++ b/src/Text/Pandoc/Writers/HTML.hs
@@ -1,4 +1,5 @@
{-# LANGUAGE LambdaCase #-}
+{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
@@ -114,21 +115,20 @@ defaultWriterState = WriterState {stNotes= [], stEmittedNotes = 0, stMath = Fals
strToHtml :: Text -> Html
strToHtml t
- | T.any isSpecial t = strToHtml' $ T.unpack t
+ | T.any isSpecial t =
+ let !x = foldl' go mempty $ T.groupBy samegroup t
+ in x
| otherwise = toHtml t
where
- strToHtml' ('\'':xs) = preEscapedString "\'" `mappend` strToHtml' xs
- strToHtml' ('"' :xs) = preEscapedString "\"" `mappend` strToHtml' xs
- strToHtml' (x:xs) | needsVariationSelector x
- = preEscapedString [x, '\xFE0E'] `mappend`
- case xs of
- ('\xFE0E':ys) -> strToHtml' ys
- _ -> strToHtml' xs
- strToHtml' xs@(_:_) = case break isSpecial xs of
- (_ ,[]) -> toHtml xs
- (ys,zs) -> toHtml ys `mappend` strToHtml' zs
- strToHtml' [] = ""
- isSpecial c = c == '\'' || c == '"' || needsVariationSelector c
+ samegroup c d = d == '\xFE0E' || not (isSpecial c || isSpecial d)
+ isSpecial '\'' = True
+ isSpecial '"' = True
+ isSpecial c = needsVariationSelector c
+ go h "\'" = h <> preEscapedString "\'"
+ go h "\"" = h <> preEscapedString "\""
+ go h txt | T.length txt == 1 && T.all needsVariationSelector txt
+ = h <> preEscapedString (T.unpack txt <> "\xFE0E")
+ go h txt = h <> toHtml txt
-- See #5469: this prevents iOS from substituting emojis.
needsVariationSelector :: Char -> Bool