Skip to content

Docx writer: fix empty keywords in core document properties#11666

Merged
jgm merged 3 commits into
jgm:mainfrom
SAY-5:fix-docx-keywords-empty
May 25, 2026
Merged

Docx writer: fix empty keywords in core document properties#11666
jgm merged 3 commits into
jgm:mainfrom
SAY-5:fix-docx-keywords-empty

Conversation

@SAY-5
Copy link
Copy Markdown
Contributor

@SAY-5 SAY-5 commented May 24, 2026

Fixes #11665.

When keywords are supplied as a metadata list, every entry in <cp:keywords> of docProps/core.xml was rendered empty:

$ echo test | pandoc -s -M keywords:a -M keywords:b -M keywords:c -o test.docx
$ unzip -p test.docx docProps/core.xml | grep -o '<cp:keywords>.*</cp:keywords>'
<cp:keywords>, , </cp:keywords>

The list elements are MetaString values, and stringify returns the empty string for a MetaString (it only collects Inlines). The fix converts each element the same way lookupMetaString does, so MetaString/MetaInlines/MetaBlocks are all handled.

Verified the repro and the fix output against pandoc 3.9. I was not able to run the docx golden-test harness locally (no GHC toolchain available); happy to add a core.xml properties test if you'd like one.

stringify returns the empty string for a MetaString, so each keyword
in the cp:keywords list of docProps/core.xml was rendered as empty.
Convert each metadata value like lookupMetaString does instead.
Comment on lines +741 to +745
let metaValueToText (MetaString s) = s
metaValueToText (MetaInlines ils) = stringify ils
metaValueToText (MetaBlocks bs) = stringify bs
metaValueToText (MetaBool b) = T.pack (show b)
metaValueToText _ = ""
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just use lookupMetaString from T.P.Writers.Shared, instead of reproducing the code?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. Replaced the local helper with lookupMetaString "x" (Meta $ M.singleton "x" v) so the conversion logic lives in one place. Pushed.

Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
Comment thread src/Text/Pandoc/Writers/Docx.hs Outdated
Comment on lines +747 to +743
Just (MetaList xs) -> map metaValueToText xs
Just (MetaList xs) -> map toText xs
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, when I made my suggestion I hadn't taken into account the need to create these singleton Meta values, which is going to introduce unnecessary allocations. I now think it's cleaner to use the original approach, or we could provide metaValueToText as an exported function in T.P.Writers.Shared and use it both here and in the definition of lookupMetaString.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted to the local helper. Thanks for the clarification.

Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
@jgm jgm merged commit 8922be0 into jgm:main May 25, 2026
7 of 10 checks passed
smc181002 pushed a commit to smc181002/pandoc that referenced this pull request May 29, 2026
`stringify` returns the empty string for a MetaString, so each keyword
in the `cp:keywords` list of `docProps/core.xml` was rendered as empty.
Convert each metadata value like `lookupMetaString` does instead.

Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--to=docx keywords all there, but each one empty

2 participants