git.iko.soy/typeable/pandoc
on master help sign in
Docx Writer: Copy hyphenation settings from reference.docx
commit6ba37909fee80c9ee910644c25dbca1561056ccd authorNikolay Yakimov <root@livid.pp.ru> dateSun 29 Mar 2015, 11:43 (12 years ago) parent2707898
1 file changed+26−3
src/Text/Pandoc/Writers/Docx.hs+26−3
src/Text/Pandoc/Writers/Docx.hs+26−3
@@ -432,6 +432,17 @@ writeDocx opts doc@(Pandoc meta _) = do
432432 ]
433433 let relsEntry = toEntry relsPath epochtime $ renderXml rels
434434
435+ -- we use dist archive for settings.xml, because Word sometimes
436+ -- adds references to footnotes or endnotes we don't have...
437+ -- we do, however, copy some settings over from reference
438+ let settingsPath = "word/settings.xml"
439+ settingsList = [ "w:autoHyphenation"
440+ , "w:consecutiveHyphenLimit"
441+ , "w:hyphenationZone"
442+ , "w:doNotHyphenateCap"
443+ ]
444+ settingsEntry <- copyChildren refArchive distArchive settingsPath epochtime settingsList
445+
435446 let entryFromArchive arch path =
436447 maybe (fail $ path ++ " corrupt or missing in reference docx")
437448 return
@@ -439,9 +450,6 @@ writeDocx opts doc@(Pandoc meta _) = do
439450 docPropsAppEntry <- entryFromArchive refArchive "docProps/app.xml"
440451 themeEntry <- entryFromArchive refArchive "word/theme/theme1.xml"
441452 fontTableEntry <- entryFromArchive refArchive "word/fontTable.xml"
442− -- we use dist archive for settings.xml, because Word sometimes
443− -- adds references to footnotes or endnotes we don't have...
444− settingsEntry <- entryFromArchive distArchive "word/settings.xml"
445453 webSettingsEntry <- entryFromArchive refArchive "word/webSettings.xml"
446454 headerFooterEntries <- mapM (entryFromArchive refArchive) $
447455 mapMaybe (fmap ("word/" ++) . extractTarget)
@@ -504,6 +512,21 @@ styleToOpenXml sm style =
504512 $ backgroundColor style )
505513 ]
506514
515+copyChildren :: Archive -> Archive -> String -> Integer -> [String] -> IO Entry
516+copyChildren refArchive distArchive path timestamp elNames = do
517+ ref <- parseXml refArchive distArchive path
518+ dist <- parseXml distArchive distArchive path
519+ return $ toEntry path timestamp $ renderXml dist{
520+ elContent = elContent dist ++ copyContent ref
521+ }
522+ where
523+ strName QName{qName=name, qPrefix=prefix}
524+ | Just p <- prefix = p++":"++name
525+ | otherwise = name
526+ shouldCopy = (`elem` elNames) . strName
527+ cleanElem el@Element{elName=name} = Elem el{elName=name{qURI=Nothing}}
528+ copyContent = map cleanElem . filterChildrenName shouldCopy
529+
507530-- this is the lowest number used for a list numId
508531baseListId :: Int
509532baseListId = 1000