-
Notifications
You must be signed in to change notification settings - Fork 212
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
Add --cssFile
as <style>
node to SVG
#358
Add --cssFile
as <style>
node to SVG
#358
Conversation
For some reason, the tests in GitHub Actions are failing about 1/2 the time. I'm not 100% sure what the issue is, but I think it's a race condition, and page.viewport() is supposed to be `await`-ed, so maybe it's that? I've also re-arannged the test-code in case it's that too.
Adds some simple tests that check whether the backgroundColor option works. It looks like it doesn't work for PDFs. If we want to enable PDF background colors, we need to set the puppeteer option `printBackground: true`, see https://pptr.dev/api/puppeteer.pdfoptions.printbackground
If a --cssFile is given to mermaid-cli, adds it as a `<svg><style>` node. This means it's part of the `<svg>` and will get exported correctly when creating a SVG file. See https://developer.mozilla.org/en-US/docs/Web/API/SVGStyleElement for documentation on the WebAPI on the `<svg><style>` element. Co-authored-by: Joel Burton <joel@joelburton.com> Co-authored-by: Niclas Gustafsson <niclas@bitfront.se> Co-authored-by: Mindaugas Laganeckas <Mindaugas.Laganeckas@3shape.com>
Ah, the percy upload didn't work, since I'm making this PR from a fork. Maybe it's worth testing this on a local branch first, to check if the percy upload works. |
Yes, I see the problem. 😄 I have granted you Write access to the repository. I hope it is ok with you and it is enough to test the PR. |
I would really like to see Percy tests to succeed before accepting the PR 😄 Thank you again! Would you consider getting more access to the mermaid-cli repository and helping out from time to time? I have sent you an invite with the Write access to the repository. You are a very skilled developer and your contributions bring a lot of value to the community. 😄 |
Sure! I'll be happy to help out :) Although I'll probably still ask you for code reviews, so it won't change too much! Maybe the only thing I'll change is close GitHub Issues once they are solved, since you can always re-open them if you disagree.
I've managed to get the Percy upload working by pushing to a branch on this repo. All I had to do was However, it looks like the SVG to PNG conversion has gone a bit weird, see: Maybe it's due to a feature missing in Edit: It looks like |
I will not have access to a computer this weekend. I will get back to you on Monday. A conversion tool should not stand in a way to get a feature out, but is required for the regression testing. I am very happy, that you have decided to use some of your time to help mermaid-cli. I have no expectation at all regarding how much time. Sometimes we are busy and sometimes we feel like contributing 🙂 in the latter moments you are welcome to close an issue or two 🙂 let's keep the pr process going. Now that you are on board I will stop commiting directly to master/ 😀 |
[Version 0.6.0 of convert-svg][1] introduced a fix for [CVE-2021-23631][2]. Unfortunately, this fix also breaks our mermaid flowchart SVGs. [1]: https://github.com/neocotic/convert-svg/releases/tag/0.6.0 [2]: https://nvd.nist.gov/vuln/detail/CVE-2021-23631
Fixed! It looks like version 0.6.0 of convert-svg introduced a fix for I've reported it as neocotic/convert-svg#90, but I doubt it will get fixed, since it's due to a security bug. As long as we use I think the error is because inline styles are forbidden by many browser's Content Security policy, see https://dontkry.com/posts/code/disable-inline-styles.html, so may be caused by mermaid-js/mermaid#856 |
📑 Summary
If a
--cssFile
is given to mermaid-cli, adds it as a<svg><style>
node. This means it's part of the<svg>
and will get exported correctly when creating a SVG file.See https://developer.mozilla.org/en-US/docs/Web/API/SVGStyleElement for documentation on the WebAPI on the
<svg><style>
element.Fixes #55, fixes #270
I've taken content from the following PRs, so I've added the authors as
Co-authors
:Example:
![flowchart1-with-css](https://user-images.githubusercontent.com/19716675/185465983-56a22f8b-9ad2-43dd-b79a-4a7ca9d7121b.svg)
test-output/flowchart1-with-css.svg
:`flowchart1-red-background.svg`
📏 Design Decisions
I also added tests for
--backgroundColor
and I noticed that when using-o *.pdf
, the PDF background color is always white. If we want to enable PDF background colors, we need to set the puppeteer optionprintBackground: true
, see https://pptr.dev/api/puppeteer.pdfoptions.printbackgroundThe added
--backgroundColor
tests resolves #222.📋 Tasks
Make sure you
I've only added .png/.svg uploads to Percy, I haven't added anything with .pdf
master
branch