git.iko.soy/typeable/pandoc
on master help sign in
Docx Writer: Implement user-defined styles.

Divs with a "docx-style" key in the attributes will apply the corresponding key to the contained blocks.

commita362a62abe55873bf1944e1121fd08c12549ea5a authorJesse Rosenthal <jrosenthal@jhu.edu> dateSat 13 Aug 2016, 21:52 (10 years ago) parent347d716
1 file changed+6
src/Text/Pandoc/Writers/Docx.hs+6
src/Text/Pandoc/Writers/Docx.hs+6
@@ -722,9 +722,15 @@ getUniqueId :: MonadIO m => m String
722722-- already in word/document.xml.rel
723723getUniqueId = liftIO $ (show . (+ 20) . hashUnique) `fmap` newUnique
724724
725+-- | Key for specifying user-defined docx styles.
726+dynamicStyleKey :: String
727+dynamicStyleKey = "docx-style"
728+
725729-- | Convert a Pandoc block element to OpenXML.
726730blockToOpenXML :: WriterOptions -> Block -> WS [Element]
727731blockToOpenXML _ Null = return []
732+blockToOpenXML opts (Div (_,_,kvs) bs) | Just sty <- lookup dynamicStyleKey kvs =
733+ withParaPropM (pStyleM sty) $ blocksToOpenXML opts bs
728734blockToOpenXML opts (Div (_,["references"],_) bs) = do
729735 let (hs, bs') = span isHeaderBlock bs
730736 header <- blocksToOpenXML opts hs