summaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2022-05-16 17:56:43 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2022-05-16 17:56:43 -0700
commit6eb77586b4f98324cde85f2a3006b45c5490e7cb (patch)
treeecdf7b8b0eecf0de07a91429369c92eb45441876 /src/Text
parent3df55b4a4ad14f984bcdd7296944b18b354ab122 (diff)
Docx writer: add w:lang to rPr for Span and Div with lang attribute.
So that Word can know that "Apfel" is not a spelling error. Closes #8026.
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/Writers/Docx.hs19
-rw-r--r--src/Text/Pandoc/Writers/Docx/Types.hs2
2 files changed, 17 insertions, 4 deletions
diff --git a/src/Text/Pandoc/Writers/Docx.hs b/src/Text/Pandoc/Writers/Docx.hs
index 38401052a..7b4a056b6 100644
--- a/src/Text/Pandoc/Writers/Docx.hs
+++ b/src/Text/Pandoc/Writers/Docx.hs
@@ -823,8 +823,11 @@ blockToOpenXML' opts (Div (ident,_classes,kvs) bs) = do
let bibmod = if ident == "refs"
then withParaPropM (pStyleM "Bibliography")
else id
+ let langmod = case lookup "lang" kvs of
+ Nothing -> id
+ Just lang -> local (\env -> env{envLang = Just lang})
header <- dirmod $ stylemod $ blocksToOpenXML opts hs
- contents <- dirmod $ bibmod $ stylemod $ blocksToOpenXML opts bs'
+ contents <- dirmod $ bibmod $ stylemod $ langmod $ blocksToOpenXML opts bs'
wrapBookmark ident $ header <> contents
blockToOpenXML' opts (Header lev (ident,_,kvs) lst) = do
setFirstPara
@@ -1015,7 +1018,12 @@ asList = local $ \env -> env{ envListLevel = envListLevel env + 1 }
getTextProps :: (PandocMonad m) => WS m [Element]
getTextProps = do
props <- asks envTextProperties
- let squashed = squashProps props
+ mblang <- asks envLang
+ let langnode = case mblang of
+ Nothing -> mempty
+ Just l -> EnvProps Nothing
+ [mknode "w:lang" [("w:val", l)] ()]
+ let squashed = squashProps (props <> langnode)
return [mknode "w:rPr" [] squashed | (not . null) squashed]
withTextProp :: PandocMonad m => Element -> WS m a -> WS m a
@@ -1150,8 +1158,11 @@ inlineToOpenXML' opts (Span (ident,classes,kvs) ils) = do
return [Elem $ mknode "w:del"
(("w:id", tshow delId) : changeAuthorDate) x]
else return id
- contents <- insmod $ delmod $ dirmod $ stylemod $ pmod
- $ inlinesToOpenXML opts ils
+ let langmod = case lookup "lang" kvs of
+ Nothing -> id
+ Just lang -> local (\env -> env{envLang = Just lang})
+ contents <- insmod $ delmod $ dirmod $ stylemod $ pmod $
+ langmod $ inlinesToOpenXML opts ils
wrapBookmark ident contents
inlineToOpenXML' opts (Strong lst) =
withTextProp (mknode "w:b" [] ()) $
diff --git a/src/Text/Pandoc/Writers/Docx/Types.hs b/src/Text/Pandoc/Writers/Docx/Types.hs
index 967976ac8..443d2cc3b 100644
--- a/src/Text/Pandoc/Writers/Docx/Types.hs
+++ b/src/Text/Pandoc/Writers/Docx/Types.hs
@@ -84,6 +84,7 @@ data WriterEnv = WriterEnv
, envChangesAuthor :: Text
, envChangesDate :: Text
, envPrintWidth :: Integer
+ , envLang :: Maybe Text
}
defaultWriterEnv :: WriterEnv
@@ -97,6 +98,7 @@ defaultWriterEnv = WriterEnv
, envChangesAuthor = "unknown"
, envChangesDate = "1969-12-31T19:00:00Z"
, envPrintWidth = 1
+ , envLang = Nothing
}