drmacro / wordinator

Generate high-quality DOCX files using a simplified XML format (simple word processing XML).

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Don't generate extra blank paras or section breaks when there are sections.

drmacro opened this issue · comments

A SWPX with a single section gets two section-ending paragraphs. At most one is needed.

If there is exactly one section in the body then should output only one w:sectPr and no paragraph. The paragraph is only required to start a new section by ending the current one.

Turns out Word always puts a blank paragraph following a section, whether you want it or not. The way to avoid that is to put the last section's page sequence formatting on the document itself.

For this issue changed the handling of sections as follows:

  • If there are any sections, use the last section's page-sequence-properties as the document's page-sequence-properties (this also requires that you have only sections as a direct child of body (following any initial content elements--this is defined in the SWPX grammar but is not currently checked by Wordinator). In this case, any document-level page-sequence-properties are ignored (it might be better to merge them).

Fixed, or at least closer.

Main issue with this approach is that when there are sections any document-level page sequence properties are effectively ignored, especially headers.

This may not be the right thing to do

Upon reflection, reworking this to special case exactly one section so that the section's settings, if any, are merged with any document-level settings and used as the document-level settings.

This approach handles the case where the SWPX generation always puts out a section wrapper even if there is exactly one section (where normally you would not emit a section since the document-level page settings would suffice.

The main issue is where you have exactly one section but you explicitly want the section settings to be different from the document-level settings, for example because you expect the generated document of one section to be used as the basis for a document with additional sections. But that seems like an edge case.

The alternative would be to do nothing and simply require that you avoid generating a section wrapper when you don't want one.

Upon further reflection I think that the right thing to do is nothing: it's up to the SWPX generation process to no generate unwanted section elements.

Without this approach it would be necessary to make the handling of singleton sections variable based on a runtime option and I'm trying to avoid runtime options if at all possible, because the intent of Wordinator is to put all controls in the SWPX itself.

Reworked the handling of sections and document-level section properties so each section is always handled as it should be.

Corrected generation of document-level section properties to not generate an unnecessary blank paragraph at the document level or at the section level.