Skip to content

Commit

Permalink
Inline window.getComputedStyle(svg) so you can save the svg.
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerlong committed Mar 11, 2018
1 parent 35c0e2c commit edde501
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mermaid",
"version": "8.0.0-alpha.2",
"version": "8.0.0-alpha.3",
"description": "Markdownish syntax for generating flowcharts, sequence diagrams, class diagrams, gantt charts and git graphs.",
"main": "dist/mermaid.core.js",
"keywords": [
Expand Down
16 changes: 13 additions & 3 deletions src/mermaidAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -428,9 +428,19 @@ const render = function (id, txt, cb, container) {

// insert inline style into svg
const svg = element.firstChild
const s = document.createElement('style')
s.innerHTML = scope(themes[config.theme] || defaultTheme, `#${id}`)
svg.insertBefore(s, svg.firstChild)
const firstChild = svg.firstChild

const style1 = document.createElement('style')
style1.innerHTML = scope(themes[config.theme] || defaultTheme, `#${id}`)
svg.insertBefore(style1, firstChild)

const style2 = document.createElement('style')
const cs = window.getComputedStyle(svg)
style2.innerHTML = `#${id} {
color: ${cs.color};
font: ${cs.font};
}`
svg.insertBefore(style2, firstChild)

d3.select('#' + id).selectAll('foreignobject > *').attr('xmlns', 'http://www.w3.org/1999/xhtml')

Expand Down
2 changes: 2 additions & 0 deletions todo.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
- https://bl.ocks.org/wboykinm/34627426d84f3242e0e6ecb2339e9065
- Some one created a great PR: https://github.com/knsv/mermaid/pull/624
- Flowchart `interpolate` is useless because there is no rendering code using it
- mermaid live editor saved svg file has different font-size.
- Should not have removed this part: https://github.com/knsv/mermaid/pull/577#issuecomment-372116281

0 comments on commit edde501

Please sign in to comment.