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

feat: support extra content which will be added to style tag from svg #407

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,14 @@ html2Image.toSVG(element1, { fontEmbedCss });
html2Image.toSVG(element2, { fontEmbedCss });
```

### extraStyleContent

When supplied, the library will add the given css definitions to the style tag from resulting svg.
For example the following code will change the color from scrollbars to green:
```javascript
htmlToImage.toPng(node, { extraStyleContent: '*::-webkit-scrollbar {background-color: green;}'});
```

### skipAutoScale

When supplied, the library will skip the process of scaling extra large doms into the canvas object.
Expand Down
9 changes: 7 additions & 2 deletions src/embed-webfonts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,14 @@ export async function embedWebFonts<T extends HTMLElement>(
? null
: await getWebFontCSS(clonedNode, options)

if (cssText) {
const finalCssText =
options.extraStyleContent != null
? options.extraStyleContent.concat(cssText || '')
: cssText

if (finalCssText) {
const styleNode = document.createElement('style')
const sytleContent = document.createTextNode(cssText)
const sytleContent = document.createTextNode(finalCssText)

styleNode.appendChild(sytleContent)

Expand Down
5 changes: 5 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ export interface Options {
* create embed CSS for use across multiple calls to library functions.
*/
fontEmbedCSS?: string
/**
* A CSS string to specify additional custom style content. It will be
* added to the style-tag.
*/
extraStyleContent?: string
/**
* A boolean to turn off auto scaling for truly massive images..
*/
Expand Down