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

New line character is not working in Repeat Tag #95

Open
dhruvak26 opened this issue Feb 20, 2025 · 10 comments
Open

New line character is not working in Repeat Tag #95

dhruvak26 opened this issue Feb 20, 2025 · 10 comments
Labels
bug Something isn't working help wanted Extra attention is needed Word Word related tasks

Comments

@dhruvak26
Copy link

dhruvak26 commented Feb 20, 2025

Hi @sergey-tihon and @MalcolmJohnston
We are facing an issue regarding the new line character in the payload.

The templateData is as follows:

"optionNotes": [
{
"note": "Sample Engine Model X™ 8.0l Engine in-line 6 cylinders.\n\nEngine power (rated) at 2100 rpm (ECE R120): 250 kW (335 hp / 340 PS)\n\nEngine power (max) at 2000 rpm (ECE R120): 270 kW (362 hp / 367 PS)"
},
{
"note": "Sample Cutterhead Model Y™ \n700 mm width, 680 mm diameter"
},
{
"note": "Sample Cutterhead Model Z™ \n7000 mm width, 680 mm diameter"
}
]

In the above payload, inside optionNotes, the \n character is present.

While using the Repeat tag, the team is facing issues with duplicate data in the Repeat iteration.

Example template tag:

<# <Repeat Select="./optionNotes" Optional="true" /> #>

<# <Content Select="./note" /> #>
------------------
<# <EndRepeat/> #>
However, after document conversion, it is printing as follows:

Sample Engine Model X™ 8.0l Engine in-line 6 cylinders.
Engine power (rated) at 2100 rpm (ECE R120): 250 kW (335 hp / 340 PS)
Engine power (max) at 2000 rpm (ECE R120): 270 kW (362 hp / 367 PS)


Sample Cutterhead Model Y™
700 mm width, 680 mm diameter
Engine power (rated) at 2100 rpm (ECE R120): 250 kW (335 hp / 340 PS)
Engine power (max) at 2000 rpm (ECE R120): 270 kW (362 hp / 367 PS)


Sample Cutterhead Model Z™
7000 mm width, 680 mm diameter
700 mm width, 680 mm diameter
Engine power (rated) at 2100 rpm (ECE R120): 250 kW (335 hp / 340 PS)
Engine power (max) at 2000 rpm (ECE R120): 270 kW (362 hp / 367 PS)


Could you please look into this issue and provide a solution?

@sergey-tihon sergey-tihon added bug Something isn't working help wanted Extra attention is needed Word Word related tasks labels Feb 21, 2025
@MalcolmJohnston
Copy link
Contributor

Hello @dhruvak26 and @sergey-tihon I will see if I can take a look at this next week. Feels like something fairly minor.

@dhruvak26
Copy link
Author

Hi @MalcolmJohnston,

Could you please expedite this issue? It is causing a significant performance impact on our API. The response time has increased from less than 1 second to over 120 seconds. Additionally, the duplication issue in each repeat iteration is inflating the document size to over 300 pages, whereas it originally had only 18 pages. As we have lot of \n in our payload that cannot be changed in multiple templates.

Thank you for your prompt attention to this matter.

@sergey-tihon
Copy link
Owner

@dhruvak26 Can you contribute the test case that reproduces this issue? It can significantly speed up the fix.

@dhruvak26
Copy link
Author

dhruvak26 commented Feb 24, 2025

Hi @sergey-tihon and @MalcolmJohnston ,

Attached is the sample template, generated docx and json payload i am using. Also we saw we are not able to use \t and ";" also along with \n issue. I added the \t also in the payload for more clarity.

Sample Template.docx

Sample_Generated_Docs.docx

Clippit_issue.json

Please let me know if this helps you to reproduce the issue.

@MalcolmJohnston
Copy link
Contributor

Hi @dhruvak26,

Thanks for sending the documents for testing that is helpful. I think in an ideal world though it would save us all time if we had a reproduction of the errors as test cases added to the solution.

Sure I can build out the tests from the information provided, but that makes it a longer process, which means I need to carve out more time to look at the problem, which in turn means I am less likely to look at it at all.

Anyway, I will try and look at it soon :)

Just to confirm the issues here are:

  1. You expect \n to be rendered as a new paragraph or soft break
  2. You expect \n\n to be rendered as two new paragraphs
  3. You expect \t to be rendered as a tab character
  4. You expect a semi-colon ; to be rendered as a well semi-colon (note that I don't see ; in your test file?)

Are these regressions? I don't remember seeing any handling for escaped characters in DocumentAssembler but could be wrong.

Cheers,
Malcolm

@dhruvak26
Copy link
Author

Hi @MalcolmJohnston ,

Yes these are regressions and I confirm the interpretation you have provided is same as we had in 2.3.0 version. I tested these in 2.3.0 version and they were working fine in that version but when i started to use later versions i got these issues.

Please let me know if you need more details from my end.

@dhruvak26
Copy link
Author

Hi @MalcolmJohnston,

Could you please let me know when can i expect this issue to be fixed.

Thanks,
Ashish Kulkarni.

@dhruvak26
Copy link
Author

@MalcolmJohnston
Any Updates you have related to this issue.

@MalcolmJohnston
Copy link
Contributor

Hello @dhruvak26,

I have had a look into the issue but I cannot reproduce it.

Please see my branch here: https://github.com/MalcolmJohnston/Clippit/tree/bug-fix/issue-95-repro

I have added a test DA_Issue_95_Repro, but I am not sure what the problem is? Please see output from the test template you send over below:

Image

Assumptions

I have made some assumptions about how you are pre-processing your JSON file, including that the escaped \n and \t will be converted to line feed and tab characters respectively. Is that correct?

If the characters remain escaped in the XML then they will just appear as escaped characters in the Word document.

I have also simplified the XML data for the purposes of the test (see DA-Issue-95-Data.xml).

Next Steps

At the moment I don't understand what the issue is to be honest. If you could create a branch and build a test case that fails, and document what the issues are then I can probably help you.

Cheers,
Malcolm

@dhruvak26
Copy link
Author

dhruvak26 commented Mar 3, 2025

@MalcolmJohnston

I am using below code to convert json to xml and sending that xml as is to document assembler:
string sanitizedTemplateData = templateData.Replace("\n", "\n");
xmlOfJsonTemplateData = JsonConvert.DeserializeXmlNode(templateData, "root") ?? throw new Exception("Invalid input! Was unable to serialize template data to xml.");
WmlDocument generatedDoc = DocumentAssembler.AssembleDocument(wlmTemplate, xmlOfJsonTemplateData, out templateError);
result.generatedDoc = generatedDoc;

Let me add my test case in here if possible

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed Word Word related tasks
Projects
None yet
Development

No branches or pull requests

3 participants