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

Prevent adding empty paragraph if cell contains altChunk #233

Closed
wants to merge 1 commit into from

Conversation

pkozul
Copy link

@pkozul pkozul commented Aug 20, 2021

I used docx-templates to generate a Word document with embedded HTML (altchunks) within cells of a table. In the generated document, I found that each of these cells ended up with extra whitespace beneath the HTML content.

image

I tracked it down to the code that adds a <w:p/> if it finds that the table cell does not already contain a <w:p/>. This PR builds on that, by also checking to make sure the table cell does also not already contain a <w:altChunk>.

After generating the same Word document again, using this PR, the embedded HTML no longer contains extra whitespace beneath the HTML content.

@jjhbw
Copy link
Collaborator

jjhbw commented Aug 24, 2021

Hi, thanks for contributing. Can you think of a test case for this that I can include in the project's test suite? Just a template with (a screenshot of) the before and after behaviour is fine, i'll make the snapshot test.

@pkozul
Copy link
Author

pkozul commented Aug 25, 2021

Here is a test case.

I created a new Word document, and added a table with the following content:

image

As you can see, I am using the following template to insert HTML:

+++HTML '<body>John</body>'+++

Using the current version of docx-templates, below is the Word document that gets created. You can see whitespace was added just below the HTML (under the word 'John').

image

Using the proposed code from this PR, below is the Word document that gets created. As you can see, no extra whitespace gets added.

image

@jjhbw
Copy link
Collaborator

jjhbw commented Sep 28, 2021

Thanks, this makes sense! Sorry for the late reply. Merged manually in 653059a.

@jjhbw jjhbw closed this Sep 28, 2021
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.

2 participants