@@ -45,7 +45,7 @@ import Text.Pandoc.Definition
4545import Text.Pandoc.Logging
4646import Text.Pandoc.Options
4747import Text.Pandoc.Pretty
48−import Text.Pandoc.Shared (linesToPara)
48+import Text.Pandoc.Shared (linesToPara, splitBy)
4949import Text.Pandoc.Templates (renderTemplate')
5050import Text.Pandoc.Writers.Math
5151import Text.Pandoc.Writers.Shared
@@ -75,6 +75,8 @@ data WriterState =
7575 , stTight :: Bool
7676 , stFirstPara :: Bool
7777 , stImageId :: Int
78+ , stLang :: Maybe String
79+ , stCountry :: Maybe String
7880 }
7981
8082defaultWriterState :: WriterState
@@ -90,6 +92,8 @@ defaultWriterState =
9092 , stTight = False
9193 , stFirstPara = False
9294 , stImageId = 1
95+ , stLang = Nothing
96+ , stCountry = Nothing
9397 }
9498
9599when :: Bool -> Doc -> Doc
@@ -155,6 +159,10 @@ withTextStyle s f = do
155159inTextStyle :: PandocMonad m => Doc -> OD m Doc
156160inTextStyle d = do
157161 at <- gets stTextStyleAttr
162+ mblang <- gets stLang
163+ mbcountry <- gets stCountry
164+ let langat = maybe [] (\la -> [("fo:language", la)]) mblang
165+ let countryat = maybe [] (\co -> [("fo:country", co)]) mbcountry
158166 if Set.null at
159167 then return d
160168 else do
@@ -168,8 +176,9 @@ inTextStyle d = do
168176 inTags False "style:style"
169177 [("style:name", styleName)
170178 ,("style:family", "text")]
171− $ selfClosingTag "style:text-properties"
172− (concatMap textStyleAttr (Set.toList at)))
179+ $ selfClosingTag "style:text-properties"
180+ (langat ++ countryat ++
181+ concatMap textStyleAttr (Set.toList at)))
173182 return $ inTags False
174183 "text:span" [("text:style-name",styleName)] d
175184
@@ -203,8 +212,10 @@ writeOpenDocument opts (Pandoc meta blocks) = do
203212 else Nothing
204213 let render' :: Doc -> Text
205214 render' = render colwidth
215+ let lang = getLang opts meta
216+ (mblang, mbcountry) <- maybe (return (Nothing, Nothing)) splitLang lang
206217 ((body, metadata),s) <- flip runStateT
207− defaultWriterState $ do
218+ defaultWriterState{ stLang = mblang, stCountry = mbcountry } $ do
208219 m <- metaToJSON opts
209220 (fmap render' . blocksToOpenDocument opts)
210221 (fmap render' . inlinesToOpenDocument opts)
@@ -326,7 +337,8 @@ blockToOpenDocument o bs
326337 then return empty
327338 else inParagraphTags =<< inlinesToOpenDocument o b
328339 | LineBlock b <- bs = blockToOpenDocument o $ linesToPara b
329− | Div _ xs <- bs = blocksToOpenDocument o xs
340+ | Div attr xs <- bs = withLangFromAttr attr
341+ (blocksToOpenDocument o xs)
330342 | Header i _ b <- bs = setFirstPara >>
331343 (inHeaderTags i =<< inlinesToOpenDocument o b)
332344 | BlockQuote b <- bs = setFirstPara >> mkBlockQuote b
@@ -444,7 +456,7 @@ inlineToOpenDocument o ils
444456 | writerWrapText o == WrapPreserve
445457 -> return $ preformatted "\n"
446458 | otherwise -> return $ space
447− Span _ xs -> inlinesToOpenDocument o xs
459+ Span attr xs -> withLangFromAttr attr (inlinesToOpenDocument o xs)
448460 LineBreak -> return $ selfClosingTag "text:line-break" []
449461 Str s -> return $ handleSpaces $ escapeStringForXML s
450462 Emph l -> withTextStyle Italic $ inlinesToOpenDocument o l
@@ -625,3 +637,14 @@ textStyleAttr s
625637 ,("style:font-name-asian" ,"Courier New")
626638 ,("style:font-name-complex" ,"Courier New")]
627639 | otherwise = []
640+
641+withLangFromAttr :: PandocMonad m => Attr -> OD m a -> OD m a
642+withLangFromAttr (_,_,kvs) action = do
643+ oldlang <- gets stLang
644+ case lookup "lang" kvs of
645+ Nothing -> action
646+ Just l -> do
647+ modify (\st -> st{ stLang = Just l})
648+ result <- action
649+ modify (\st -> st{ stLang = oldlang})
650+ return result