git.iko.soy/typeable/pandoc
on master help sign in
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.

commit5eb7ad7d1ebbfe27a282a2d75f199bacf2052be3 authorJohn MacFarlane <jgm@berkeley.edu> dateTue 11 May 2021, 22:31 (5 years ago) parenta66e508
34 files changed+14−13
src/Text/Pandoc/Writers/Docx.hs+14−13 test/docx/golden/block_quotes.docx test/docx/golden/codeblock.docx test/docx/golden/comments.docx test/docx/golden/custom_style_no_reference.docx test/docx/golden/custom_style_preserve.docx test/docx/golden/custom_style_reference.docx test/docx/golden/definition_list.docx test/docx/golden/document-properties-short-desc.docx test/docx/golden/document-properties.docx test/docx/golden/headers.docx test/docx/golden/image.docx test/docx/golden/inline_code.docx test/docx/golden/inline_formatting.docx test/docx/golden/inline_images.docx test/docx/golden/link_in_notes.docx test/docx/golden/links.docx test/docx/golden/lists.docx test/docx/golden/lists_continuing.docx test/docx/golden/lists_multiple_initial.docx test/docx/golden/lists_restarting.docx test/docx/golden/nested_anchors_in_header.docx test/docx/golden/notes.docx test/docx/golden/raw-blocks.docx test/docx/golden/raw-bookmarks.docx test/docx/golden/table_one_row.docx test/docx/golden/table_with_list_cell.docx test/docx/golden/tables.docx test/docx/golden/track_changes_deletion.docx test/docx/golden/track_changes_insertion.docx test/docx/golden/track_changes_move.docx test/docx/golden/track_changes_scrubbed_metadata.docx test/docx/golden/unicode.docx test/docx/golden/verbatim_subsuper.docx
src/Text/Pandoc/Writers/Docx.hs+14−13
@@ -469,12 +469,12 @@ writeDocx opts doc = do
469469 -- adds references to footnotes or endnotes we don't have...
470470 -- we do, however, copy some settings over from reference
471471 let settingsPath = "word/settings.xml"
472− settingsList = [ "w:autoHyphenation"
473− , "w:consecutiveHyphenLimit"
474− , "w:hyphenationZone"
475− , "w:doNotHyphenateCap"
476− , "w:evenAndOddHeaders"
477− , "w:proofState"
472+ settingsList = [ "autoHyphenation"
473+ , "consecutiveHyphenLimit"
474+ , "hyphenationZone"
475+ , "doNotHyphenateCap"
476+ , "evenAndOddHeaders"
477+ , "proofState"
478478 ]
479479 settingsEntry <- copyChildren refArchive distArchive settingsPath epochtime settingsList
480480
@@ -577,16 +577,17 @@ copyChildren :: (PandocMonad m)
577577copyChildren refArchive distArchive path timestamp elNames = do
578578 ref <- parseXml refArchive distArchive path
579579 dist <- parseXml distArchive distArchive path
580+ let elsToCopy =
581+ map cleanElem $ filterChildrenName (\e -> qName e `elem` elNames) ref
582+ let elsToKeep =
583+ [e | Elem e <- elContent dist, not (any (hasSameNameAs e) elsToCopy)]
580584 return $ toEntry path timestamp $ renderXml dist{
581− elContent = elContent dist ++ copyContent ref
585+ elContent = map Elem elsToKeep ++ map Elem elsToCopy
582586 }
583587 where
584− strName QName{qName=name, qPrefix=prefix}
585− | Just p <- prefix = p <> ":" <> name
586− | otherwise = name
587− shouldCopy = (`elem` elNames) . strName
588− cleanElem el@Element{elName=name} = Elem el{elName=name{qURI=Nothing}}
589− copyContent = map cleanElem . filterChildrenName shouldCopy
588+ hasSameNameAs (Element {elName = n1}) (Element {elName = n2}) =
589+ qName n1 == qName n2
590+ cleanElem el@Element{elName=name} = el{elName=name{qURI=Nothing}}
590591
591592-- this is the lowest number used for a list numId
592593baseListId :: Int
test/docx/golden/block_quotes.docx

Binary file not shown.

test/docx/golden/codeblock.docx

Binary file not shown.

test/docx/golden/comments.docx

Binary file not shown.

test/docx/golden/custom_style_no_reference.docx

Binary file not shown.

test/docx/golden/custom_style_preserve.docx

Binary file not shown.

test/docx/golden/custom_style_reference.docx

Binary file not shown.

test/docx/golden/definition_list.docx

Binary file not shown.

test/docx/golden/document-properties-short-desc.docx

Binary file not shown.

test/docx/golden/document-properties.docx

Binary file not shown.

test/docx/golden/headers.docx

Binary file not shown.

test/docx/golden/image.docx

Binary file not shown.

test/docx/golden/inline_code.docx

Binary file not shown.

test/docx/golden/inline_formatting.docx

Binary file not shown.

test/docx/golden/inline_images.docx

Binary file not shown.

test/docx/golden/link_in_notes.docx

Binary file not shown.

test/docx/golden/links.docx

Binary file not shown.

test/docx/golden/lists.docx

Binary file not shown.

test/docx/golden/lists_continuing.docx

Binary file not shown.

test/docx/golden/lists_multiple_initial.docx

Binary file not shown.

test/docx/golden/lists_restarting.docx

Binary file not shown.

test/docx/golden/nested_anchors_in_header.docx

Binary file not shown.

test/docx/golden/notes.docx

Binary file not shown.

test/docx/golden/raw-blocks.docx

Binary file not shown.

test/docx/golden/raw-bookmarks.docx

Binary file not shown.

test/docx/golden/table_one_row.docx

Binary file not shown.

test/docx/golden/table_with_list_cell.docx

Binary file not shown.

test/docx/golden/tables.docx

Binary file not shown.

test/docx/golden/track_changes_deletion.docx

Binary file not shown.

test/docx/golden/track_changes_insertion.docx

Binary file not shown.

test/docx/golden/track_changes_move.docx

Binary file not shown.

test/docx/golden/track_changes_scrubbed_metadata.docx

Binary file not shown.

test/docx/golden/unicode.docx

Binary file not shown.

test/docx/golden/verbatim_subsuper.docx

Binary file not shown.