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

fix: parse <head> contents from XLS renderer #3736

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions server/lib/renderers/xls.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,16 @@ exports.render = render;
exports.extension = '.xls';
exports.headers = headers;


async function render(data, template, options) {
const htmlString = juice(await html.render(data, template, options));
return Buffer.from(htmlString, 'utf-8');

// NOTE(@jniles)
// This code replaces the <head></head> contents to avoid CSS <link> errors when
// opening in MS Excel.
const start = htmlString.substring(0, htmlString.search('<head>'));
const end = htmlString.substring(htmlString.search('</head>') + 7);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good, i would like to know what means the 7, is it possible to use a variable for that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha. 7 is the length of the string '</head>'. Since without the 7, it would leave the word </head> in the template.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have a suggestion for how to do this cleaner?


const tmpl = `${start}${end}`;

return Buffer.from(tmpl, 'utf-8');
}