Skip to content

Commit

Permalink
Add background color style to output svg's
Browse files Browse the repository at this point in the history
  • Loading branch information
jg123 authored and MindaugasLaganeckas committed Jan 14, 2022
1 parent e371751 commit 46e3b70
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src-test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ async function compileDiagram(file, format) {
"-o",
out + "/" + result,
"-c",
workflows + "/config.json"
workflows + "/config.json",
"-b",
"lightgray"
], { timeout: 5000 });

const stdout = child.stdout.toString('utf8').trim()
Expand Down
14 changes: 13 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ const error = message => {
process.exit(1)
}

const warn = message => {
console.log(chalk.yellow(`\n${message}\n`))
}

const checkConfigFile = file => {
if (!fs.existsSync(file)) {
error(`Configuration file "${file}" doesn't exist`)
Expand Down Expand Up @@ -167,7 +171,15 @@ const parseMMD = async (browser, definition, output) => {
}

if (output.endsWith('svg')) {
const svg = await page.$eval('#container', container => container.innerHTML)
const svg = await page.$eval('#container', (container, backgroundColor) => {
const svg = container.getElementsByTagName?.('svg')?.[0]
if (svg.style) {
svg.style.backgroundColor = backgroundColor
} else {
warn("svg not found. Not applying background color.")
}
return container.innerHTML
}, backgroundColor)
const svg_xml = convertToValidXML(svg)
fs.writeFileSync(output, svg_xml)
} else if (output.endsWith('png')) {
Expand Down

0 comments on commit 46e3b70

Please sign in to comment.