jsreport / jsreport

javascript based business reporting platform :rocket:
https://jsreport.net
GNU Lesser General Public License v3.0
1.16k stars 223 forks source link

docxHtml inline elements breaks with tables #1148

Open ml653 opened 2 weeks ago

ml653 commented 2 weeks ago

Attempting to render html into the docxHtml recipe will break if you have two inline tags before a table like this.

<div>
  <span>HELLO</span>
  <span>HELLO</span>
</div>
<table>
</table>

It looks like what is happening is that span tags are not closed properly by parseHtmlToDocxMeta.js and it throws the following error, thinking we are putting a table inside of a paragraph.

[winston] Unknown logger level: {
  error: [Error],
  level: 'error',
  message: 'uncaughtException: Error while executing docx recipe\n' +
    '(because) invalid docx meta child "table" found in paragraph\n' +
    'Error: Invalid docx meta child "table" found in paragraph\n' +
    '  at convertDocxMetaToNodes (/Users/stevenli/git/jsreport/node_modules/@jsreport/jsreport-docx/lib/postprocess/html/convertDocxMetaToNodes.js:85:15)\n' +
    '  at processParagraphHtmlEmbedContainer (/Users/stevenli/git/jsreport/node_modules/@jsreport/jsreport-docx/lib/postprocess/html/index.js:130:28)\n' +
    '  at /Users/stevenli/git/jsreport/node_modules/@jsreport/jsreport-docx/lib/postprocess/html/index.js:35:39\n' +
    '  at doReplace (/Users/stevenli/git/jsreport/node_modules/@jsreport/jsreport-docx/lib/recursiveStringReplaceAsync.js:139:21)\n' +
    '  at replacerFn (/Users/stevenli/git/jsreport/node_modules/@jsreport/jsreport-docx/lib/recursiveStringReplaceAsync.js:148:14)\n' +
    '  at assignReplacement (/Users/stevenli/git/jsreport/node_modules/@jsreport/jsreport-docx/lib/recursiveStringReplaceAsync.js:102:10)\n' +
    '  at /Users/stevenli/git/jsreport/node_modules/@jsreport/jsreport-docx/lib/recursiveStringReplaceAsync.js:110:12\n' +
    '  at Array.map (<anonymous>)\n' +
    '  at execute (/Users/stevenli/git/jsreport/node_modules/@jsreport/jsreport-docx/lib/recursiveStringReplaceAsync.js:109:28)\n' +
    '  at processString (/Users/stevenli/git/jsreport/node_modules/@jsreport/jsreport-docx/lib/recursiveStringReplaceAsync.js:152:10)\n' +
    '  at recursiveStringReplaceAsync (/Users/stevenli/git/jsreport/node_modules/@jsreport/jsreport-docx/lib/recursiveStringReplaceAsync.js:159:10)\n' +
    '  at module.exports (/Users/stevenli/git/jsreport/node_modules/@jsreport/jsreport-docx/lib/postprocess/html/index.js:22:29)\n' +
    '  at module.exports (/Users/stevenli/git/jsreport/node_modules/@jsreport/jsreport-docx/lib/postprocess/postprocess.js:27:9)\n' +
    '  at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n' +
    '  at async module.exports (/Users/stevenli/git/jsreport/node_modules/@jsreport/jsreport-docx/lib/processDocx.js:92:5)\n' +
    '  at async module.exports (/Users/stevenli/git/jsreport/node_modules/@jsreport/jsreport-docx/lib/recipe.js:35:28)\n' +
    'wrapped by:\n' +
    'Error: Error while executing docx recipe\n' +
bjrmatos commented 2 weeks ago

thanks for the bug report, we are going to check this soon