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

Modified cover page results in IndexError #5

Closed
koenvervloesem opened this issue Oct 25, 2019 · 4 comments
Closed

Modified cover page results in IndexError #5

koenvervloesem opened this issue Oct 25, 2019 · 4 comments
Labels
bug Something isn't working libreoffice This issue happnes in LibreOffice

Comments

@koenvervloesem
Copy link

I copied style.docx to my source directory and I only changed the document title, subject and author in LibreOffice Writer 6.3.2. I saved the file and ran a make docx with a docx_style = 'style.docx' in my conf.py. This results in an exception:

# Sphinx version: 1.8.4
# Python version: 3.6.8 (CPython)
# Docutils version: 0.14
# Jinja2 version: 2.10
# Last messages:
#   processing test.docx...
#
#
#
#   resolving references...
#
#
#
#   writing...
#
# Loaded extensions:
#   sphinx.ext.mathjax (1.8.4) from /usr/local/lib/python3.6/site-packages/sphinx/ext/mathjax.py
#   alabaster (0.7.12) from /usr/local/lib/python3.6/site-packages/alabaster/__init__.py
#   sphinx.ext.todo (1.8.4) from /usr/local/lib/python3.6/site-packages/sphinx/ext/todo.py
#   docxbuilder (unknown version) from /usr/local/lib/python3.6/site-packages/docxbuilder/__init__.py
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/sphinx/cmd/build.py", line 304, in build_main
    app.build(args.force_all, filenames)
  File "/usr/local/lib/python3.6/site-packages/sphinx/application.py", line 341, in build
    self.builder.build_update()
  File "/usr/local/lib/python3.6/site-packages/sphinx/builders/__init__.py", line 342, in build_update
    self.build(['__all__'], to_build)
  File "/usr/local/lib/python3.6/site-packages/sphinx/builders/__init__.py", line 412, in build
    self.write(docnames, list(updated_docnames), method)
  File "/usr/local/lib/python3.6/site-packages/docxbuilder/builder.py", line 115, in write
    self.write_doc(docname, doctree)
  File "/usr/local/lib/python3.6/site-packages/docxbuilder/builder.py", line 122, in write_doc
    self.writer.write(doctree, destination)
  File "/usr/local/lib/python3.6/site-packages/docutils/writers/__init__.py", line 80, in write
    self.translate()
  File "/usr/local/lib/python3.6/site-packages/docxbuilder/writer.py", line 163, in translate
    visitor = self.builder.create_translator(self.document, self.builder)
  File "/usr/local/lib/python3.6/site-packages/sphinx/builders/__init__.py", line 139, in create_translator                                                                                                       
    return self.app.registry.create_translator(self, *args)
  File "/usr/local/lib/python3.6/site-packages/sphinx/registry.py", line 386, in create_translator
    translator = translator_class(*args)
  File "/usr/local/lib/python3.6/site-packages/docxbuilder/writer.py", line 832, in __init__
    self._bullet_list_id = self._docx.get_bullet_list_num_id('List Bullet')
  File "/usr/local/lib/python3.6/site-packages/docxbuilder/docx/docx.py", line 1458, in get_bullet_list_num_id                                                                                                    
    return self.style_docx.get_numbering_style_id(style_name)
  File "/usr/local/lib/python3.6/site-packages/docxbuilder/docx/docx.py", line 1236, in get_numbering_style_id                                                                                                    
    style_elem, 'w:pPr/w:numPr/w:numId')[0]
IndexError: list index out of range

Any idea what is going on? The document title, subject and author are really the only things I have changed in the style file. When I replace the file by the original one, it works, but I'd like to modify the text fields on the cover page.

@amedama41
Copy link
Owner

Hi, @koenvervloesem . Thank you for your issue report.

This issue is because LibreOffice removes relationships between styles and bullet/enumeration list definitions (Opening style.docx by LibreOffice removes numbering style from List Bullet and List Number styles).
Therefore, restoring the relationships manually avoid IndexError (Open style edition dialog from Styles pain, select Numbering style. WWNum2 is for List Bullet. WWNum1 is for List Number).

Unfortunately, LibreOffice removes also invisible cover page information from default style.docx file. So, generated document based on the style.docx modified by LibreOffice will not include cover page.
For this issue, I will add an option to use first page or section as cover page.
Tentatively, please use this style.docx instead (This includes dummy whitespace in cover page to retain cover page information).

Screen Shot 2019-10-26 at 10 32 05

Screen Shot 2019-10-26 at 10 32 24

@amedama41 amedama41 added libreoffice This issue happnes in LibreOffice bug Something isn't working labels Oct 26, 2019
@koenvervloesem
Copy link
Author

Awesome, @amedama41, that works! The only issue I have now with your new style.docx is that the sample TOC is generated in my document after the cover page, before my real TOC.

@amedama41
Copy link
Owner

@koenvervloesem LibreOffice had broken the original cover page range.
I updated style.docx (Inserting empty table between cover page and sample TOC).
Please try this style file.

@koenvervloesem
Copy link
Author

Great, this works perfectly now! Thank you!

This is really an awesome project. I have started writing a book with Sphinx in reStructuredText and the docx output of docxbuilder is amazing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working libreoffice This issue happnes in LibreOffice
Projects
None yet
Development

No branches or pull requests

2 participants