git.iko.soy/typeable/pandoc
on master help sign in
Docx writer: Inject text properties as well.
2870c9bJesse Rosenthal
src/Text/Pandoc/Writers/Docx.hs+20−3
@@ -407,13 +407,21 @@ writeDocx opts doc@(Pandoc meta _) = do
407 $ renderXml $ mknode "Relationships" [("xmlns","http://schemas.openxmlformats.org/package/2006/relationships")]
407 $ renderXml $ mknode "Relationships" [("xmlns","http://schemas.openxmlformats.org/package/2006/relationships")]
408 linkrels
408 linkrels
409
409
410+ -- styles
411+
410− -- styles We only want to inject paragraph properties that are not
412+ -- We only want to inject paragraph and text properties that
411− -- already in the style map. Note that keys in the stylemap are
413+ -- are not already in the style map. Note that keys in the stylemap
412− -- normalized as lowercase.
414+ -- are normalized as lowercase.
413 let newDynamicParaProps = filter
415 let newDynamicParaProps = filter
414 (\sty -> isNothing $ M.lookup (toLower <$> sty) $ getMap $ sParaStyleMap styleMaps)
416 (\sty -> isNothing $ M.lookup (toLower <$> sty) $ getMap $ sParaStyleMap styleMaps)
415 (stDynamicParaProps st)
417 (stDynamicParaProps st)
418+
419+ newDynamicTextProps = filter
420+ (\sty -> isNothing $ M.lookup (toLower <$> sty) $ getMap $ sCharStyleMap styleMaps)
421+ (stDynamicTextProps st)
422+
416 let newstyles = map newParaPropToOpenXml newDynamicParaProps ++
423 let newstyles = map newParaPropToOpenXml newDynamicParaProps ++
424+ map newTextPropToOpenXml newDynamicTextProps ++
417 (styleToOpenXml styleMaps $ writerHighlightStyle opts)
425 (styleToOpenXml styleMaps $ writerHighlightStyle opts)
418 let styledoc' = styledoc{ elContent = modifyContent (elContent styledoc) }
426 let styledoc' = styledoc{ elContent = modifyContent (elContent styledoc) }
419 where
427 where
@@ -521,6 +529,15 @@ newParaPropToOpenXml s =
521 , mknode "w:qFormat" [] ()
529 , mknode "w:qFormat" [] ()
522 ]
530 ]
523
531
532+newTextPropToOpenXml :: String -> Element
533+newTextPropToOpenXml s =
534+ let styleId = filter (not . isSpace) s
535+ in mknode "w:style" [ ("w:type", "character")
536+ , ("w:customStyle", "1")
537+ , ("w:styleId", styleId)]
538+ [ mknode "w:name" [("w:val", s)] ()
539+ , mknode "w:basedOn" [("w:val","BodyTextChar")] ()
540+ ]
524
541
525styleToOpenXml :: StyleMaps -> Style -> [Element]
542styleToOpenXml :: StyleMaps -> Style -> [Element]
526styleToOpenXml sm style =
543styleToOpenXml sm style =