git.iko.soy/typeable/pandoc
on master help sign in
Docx writer: Moved invalid character stripping to `formattedString`.

This avoids an inefficient generic traversal. Updates f3aa03e. Closes #2356.

commit0ad576eb1a914104448239b0f80f6026d4b6cc54 authorJohn MacFarlane <jgm@berkeley.edu> dateMon 10 Aug 2015, 10:49 (11 years ago) parentaa08b4c
1 file changed+4−4
src/Text/Pandoc/Writers/Docx.hs+4−4
src/Text/Pandoc/Writers/Docx.hs+4−4
@@ -181,8 +181,8 @@ renumIds f renumMap = map (renumId f renumMap)
181181
182182-- | Certain characters are invalid in XML even if escaped.
183183-- See #1992
184−stripInvalidChars :: Pandoc -> Pandoc
185−stripInvalidChars = bottomUp (filter isValidChar)
184+stripInvalidChars :: String -> String
185+stripInvalidChars = filter isValidChar
186186
187187-- | See XML reference
188188isValidChar :: Char -> Bool
@@ -208,7 +208,7 @@ writeDocx :: WriterOptions -- ^ Writer options
208208 -> IO BL.ByteString
209209writeDocx opts doc@(Pandoc meta _) = do
210210 let datadir = writerUserDataDir opts
211− let doc' = stripInvalidChars . walk fixDisplayMath $ doc
211+ let doc' = walk fixDisplayMath $ doc
212212 username <- lookup "USERNAME" <$> getEnvironment
213213 utctime <- getCurrentTime
214214 distArchive <- getDefaultReferenceDocx Nothing
@@ -974,7 +974,7 @@ formattedString str = do
974974 return [ mknode "w:r" [] $
975975 props ++
976976 [ mknode (if inDel then "w:delText" else "w:t")
977− [("xml:space","preserve")] str ] ]
977+ [("xml:space","preserve")] (stripInvalidChars str) ] ]
978978
979979setFirstPara :: WS ()
980980setFirstPara = modify $ \s -> s { stFirstPara = True }