Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOCX reader with docx+styles generate warning on commends #10571

Closed
steven-r opened this issue Jan 27, 2025 · 0 comments · Fixed by #10572
Closed

DOCX reader with docx+styles generate warning on commends #10571

steven-r opened this issue Jan 27, 2025 · 0 comments · Fixed by #10572
Labels

Comments

@steven-r
Copy link
Contributor

Explain the problem.
When using the DOCX-reader with comments included, the extension +styles creates warnings with every comment:

~/src/mybook$ pandoc text/custom-reference.docx --from=docx+styles --to=native --track-changes=all --output=test.debug --verbose 
[WARNING] Docx parser warning: Docx comment 9 will not retain formatting
~/src/mybook$

Converting without the styles-extension, no warning is given:

$ pandoc text/custom-reference.docx --from=docx --to=native --track-changes=all --output=test.debug --verbose 
~/src/mybook$ 

Pandoc version?
3.6.2

Looking at the source::

blocksToInlinesWarn cmtId blks = do
let paraOrPlain :: Block -> Bool
paraOrPlain (Para _) = True
paraOrPlain (Plain _) = True
paraOrPlain _ = False
unless (all paraOrPlain blks) $
lift $ P.report $ DocxParserWarning $
"Docx comment " <> cmtId <> " will not retain formatting"
return $ blocksToInlines' (toList blks)

only Para and Plain are considered as save block elements.

If using +styles, all block elements are pretended with a Div element, even comment texts.

Therefore the fix should be very straightforward:

  blocksToInlinesWarn cmtId blks = do
  let paraOrPlain :: Block -> Bool
      paraOrPlain (Para _)  = True
      paraOrPlain (Plain _) = True
      paraOrPlain (Div _ _) = True
      paraOrPlain _         = False
  unless (all paraOrPlain blks) $
    lift $ P.report $ DocxParserWarning $
      "Docx comment " <> cmtId <> " will not retain formatting"
  return $ blocksToInlines' (toList blks)

Example document
custom-reference.docx

@steven-r steven-r added the bug label Jan 27, 2025
steven-r added a commit to steven-r/pandoc that referenced this issue Jan 27, 2025
This fixes jgm#10571 by also allowing `Div` as a block element
jgm pushed a commit that referenced this issue Jan 30, 2025
Closes #10571.

Co-authored-by: Stephen Reindl <stephen.reindl@outlook.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant