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

Rendering html tags as cell content and formatting of cell content #1029

Open
martineisenberg opened this issue Feb 2, 2024 · 1 comment

Comments

@martineisenberg
Copy link

martineisenberg commented Feb 2, 2024

Hi,

I was wondering if it is possible to render HTML tags, e.g., <b>, <p>,<ul>, etc. as cell content, as part of the array passed to the "body" parameter?

So far I only managed to obtain the raw tags in the generated pdf. I also played around with the "didParseCell" hook and tried to replace tags and introduce newline characters, i.e, "\r\n" etc. to achieve simple line breaks in the cell, but without success. The "\r\n" seems to be removed before the rendering, and
also remain as raw output. If linebreaks and other formatting is possible, is there a collection/doc for these options?

On the side, thank you very much for this valuable plugin!

EDIT: I have seen in #364 that it should work to have some tags like <br> as content, and that to be rendered as a line break. It is not the case for me, could this raise from a lack of configuration of the jspdf object on my end? Further, could the suggestion in #364 from @arjunkolagatla be a solution for me, that is, to intercept the case of HTML elements with Regex and treat them separately with "parseHTML" in some way?

@simonbengtsson
Copy link
Owner

The only tag that is handled in a special way during html parsing is <br> (in addition to css styles). Everything else is converted to text using https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent. If you need more complex html parsing you can parse html yourself and pass data to the plugin directly. There are no plans to expand the the html parsing right now and doing so would be a breaking change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants