diff --git a/xml-light/Text/Pandoc/XML/Light/Output.hs b/xml-light/Text/Pandoc/XML/Light/Output.hs index 0caba6899..a2975ae35 100644 --- a/xml-light/Text/Pandoc/XML/Light/Output.hs +++ b/xml-light/Text/Pandoc/XML/Light/Output.hs @@ -173,13 +173,12 @@ showCDataS cd = -------------------------------------------------------------------------------- escCData :: Text -> Builder -escCData t - | "]]>" `T.isPrefixOf` t = - fromText "]]]]>" <> fromText (T.drop 3 t) -escCData t - = case T.uncons t of - Nothing -> mempty - Just (c,t') -> singleton c <> escCData t' +escCData t = + case T.breakOn "]]>" t of + (chunk, rest) + | T.null rest -> fromText chunk + | otherwise -> fromText chunk <> fromText "]]]]>" <> + escCData (T.drop 3 rest) escChar :: Char -> Builder escChar c = case c of