Improve integration of settings from reference.docx.

The settings we can carry over from a reference.docx are
autoHyphenation, consecutiveHyphenLimit, hyphenationZone,
doNotHyphenateCap, evenAndOddHeaders, and proofState.

Previously this was implemented in a buggy way, so that the
reference doc's values AND the new values were included.

This change allows users to create a reference.docx that
sets w:proofState for spelling or grammar to "dirty,"
so that spell/grammar checking will be triggered on the
generated docx.

Closes #1209.
This commit is contained in:
John MacFarlane 2021-05-11 22:31:38 -06:00
parent a66e50840b
commit 5eb7ad7d1e
34 changed files with 14 additions and 13 deletions

View file

@ -469,12 +469,12 @@ writeDocx opts doc = do
-- adds references to footnotes or endnotes we don't have...
-- we do, however, copy some settings over from reference
let settingsPath = "word/settings.xml"
settingsList = [ "w:autoHyphenation"
, "w:consecutiveHyphenLimit"
, "w:hyphenationZone"
, "w:doNotHyphenateCap"
, "w:evenAndOddHeaders"
, "w:proofState"
settingsList = [ "autoHyphenation"
, "consecutiveHyphenLimit"
, "hyphenationZone"
, "doNotHyphenateCap"
, "evenAndOddHeaders"
, "proofState"
]
settingsEntry <- copyChildren refArchive distArchive settingsPath epochtime settingsList
@ -577,16 +577,17 @@ copyChildren :: (PandocMonad m)
copyChildren refArchive distArchive path timestamp elNames = do
ref <- parseXml refArchive distArchive path
dist <- parseXml distArchive distArchive path
let elsToCopy =
map cleanElem $ filterChildrenName (\e -> qName e `elem` elNames) ref
let elsToKeep =
[e | Elem e <- elContent dist, not (any (hasSameNameAs e) elsToCopy)]
return $ toEntry path timestamp $ renderXml dist{
elContent = elContent dist ++ copyContent ref
elContent = map Elem elsToKeep ++ map Elem elsToCopy
}
where
strName QName{qName=name, qPrefix=prefix}
| Just p <- prefix = p <> ":" <> name
| otherwise = name
shouldCopy = (`elem` elNames) . strName
cleanElem el@Element{elName=name} = Elem el{elName=name{qURI=Nothing}}
copyContent = map cleanElem . filterChildrenName shouldCopy
hasSameNameAs (Element {elName = n1}) (Element {elName = n2}) =
qName n1 == qName n2
cleanElem el@Element{elName=name} = el{elName=name{qURI=Nothing}}
-- this is the lowest number used for a list numId
baseListId :: Int

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.