Skip to content

Commit

Permalink
Properly handling <br> tags
Browse files Browse the repository at this point in the history
  • Loading branch information
daladim committed Nov 25, 2020
1 parent c117ee2 commit 63dfcc8
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ const getInputData = async inputFile => new Promise((resolve, reject) => {
})
})

const convertToValidXML = html => {
xml = html

// <br> tags in valid HTML (from innerHTML) look like <br>, but they must look like <br/> to be valid XML (such as SVG)
xml.replace(/<br>/gi, '<br/>')

return xml
}



commander
.version(pkg.version)
.option('-t, --theme [theme]', 'Theme of the chart, could be default, forest, dark or neutral. Optional. Default: default', /^default|forest|dark|neutral$/, 'default')
Expand Down Expand Up @@ -156,7 +167,8 @@ const deviceScaleFactor = parseInt(scale || 1, 10);

if (output.endsWith('svg')) {
const svg = await page.$eval('#container', container => container.innerHTML)
fs.writeFileSync(output, svg)
svg_xml = convertToValidXML(svg)
fs.writeFileSync(output, svg_xml)
} else if (output.endsWith('png')) {
const clip = await page.$eval('svg', svg => {
const react = svg.getBoundingClientRect()
Expand Down

0 comments on commit 63dfcc8

Please sign in to comment.