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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add background color style to output svg's #214

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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