git.iko.soy/typeable/pandoc
on master help sign in
Fixed handling of soft hyphen (0173) in docx writer.

Closes #3691.

commit8edeaa9349474e3c87b9515664e597db2d32df8f authorJohn MacFarlane <jgm@berkeley.edu> dateTue 23 May 2017, 16:58 (9 years ago) parent66fa38e
1 file changed+19−7
src/Text/Pandoc/Writers/Docx.hs+19−7
src/Text/Pandoc/Writers/Docx.hs+19−7
@@ -1059,13 +1059,24 @@ withParaPropM :: PandocMonad m => WS m Element -> WS m a -> WS m a
10591059withParaPropM = (. flip withParaProp) . (>>=)
10601060
10611061formattedString :: PandocMonad m => String -> WS m [Element]
1062−formattedString str = do
1063− props <- getTextProps
1062+formattedString str =
1063+ -- properly handle soft hyphens
1064+ case splitBy (=='\173') str of
1065+ [w] -> formattedString' w
1066+ ws -> do
1067+ sh <- formattedRun [mknode "w:softHyphen" [] ()]
1068+ (intercalate sh) <$> mapM formattedString' ws
1069+
1070+formattedString' :: PandocMonad m => String -> WS m [Element]
1071+formattedString' str = do
10641072 inDel <- asks envInDel
1065− return [ mknode "w:r" [] $
1066− props ++
1067− [ mknode (if inDel then "w:delText" else "w:t")
1068− [("xml:space","preserve")] (stripInvalidChars str) ] ]
1073+ formattedRun [ mknode (if inDel then "w:delText" else "w:t")
1074+ [("xml:space","preserve")] (stripInvalidChars str) ]
1075+
1076+formattedRun :: PandocMonad m => [Element] -> WS m [Element]
1077+formattedRun els = do
1078+ props <- getTextProps
1079+ return [ mknode "w:r" [] $ props ++ els ]
10691080
10701081setFirstPara :: PandocMonad m => WS m ()
10711082setFirstPara = modify $ \s -> s { stFirstPara = True }
@@ -1075,7 +1086,8 @@ inlineToOpenXML :: PandocMonad m => WriterOptions -> Inline -> WS m [Element]
10751086inlineToOpenXML opts il = withDirection $ inlineToOpenXML' opts il
10761087
10771088inlineToOpenXML' :: PandocMonad m => WriterOptions -> Inline -> WS m [Element]
1078−inlineToOpenXML' _ (Str str) = formattedString str
1089+inlineToOpenXML' _ (Str str) =
1090+ formattedString str
10791091inlineToOpenXML' opts Space = inlineToOpenXML opts (Str " ")
10801092inlineToOpenXML' opts SoftBreak = inlineToOpenXML opts (Str " ")
10811093inlineToOpenXML' opts (Span (ident,classes,kvs) ils) = do