Skip to content

Commit

Permalink
Add a button to download SVG
Browse files Browse the repository at this point in the history
Fixes #144
  • Loading branch information
spect88 committed Oct 24, 2015
1 parent 62902f9 commit 9f8dedb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
6 changes: 4 additions & 2 deletions live_editor/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@
<div class="card-content">
<span class="card-title grey-text" ng-show="showform">Generated diagram</span><br/>
<span id="mermaidholder"></span>
<span ng-show="showform"><a ng-href="{{viewlink}}">LINK TO VIEW</a>
<span ng-show="showform"><a ng-href="{{editlink}}">LINK TO EDIT</a>
<span ng-show="showform">
<a ng-href="{{viewlink}}">LINK TO VIEW</a>
<a ng-href="{{editlink}}">LINK TO EDIT</a>
<a ng-href="{{svglink}}" download="diagram.svg">DOWNLOAD SVG</a>
</span>
</div>
</div>
Expand Down
5 changes: 4 additions & 1 deletion live_editor/scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@
* Main module of the application.
*/
angular
.module('angularMermaidApp', ['ngSanitize', 'ab-base64']);
.module('angularMermaidApp', ['ngSanitize', 'ab-base64'])
.config(['$compileProvider', function ($compileProvider) {
$compileProvider.aHrefSanitizationWhitelist(/^\s*(https?|local|data):/);
}]);
11 changes: 10 additions & 1 deletion live_editor/scripts/controllers/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ angular.module('angularMermaidApp')
'C->> B: Response\n' +
'B->> A: Forward response\n';

$scope.diaglink = '';
$scope.viewlink = '';
$scope.editlink = '';
$scope.svglink = '';
$scope.showerror = false;

$scope.checkUpdate = function() {
Expand All @@ -40,9 +42,11 @@ angular.module('angularMermaidApp')
mermaidnode.appendChild(document.createTextNode($sce.trustAsHtml($scope.mermaidsyntax)));
mermaidholder.appendChild(mermaidnode);
mermaid.init(); // jshint ignore:line
$scope.svglink = buildSVGURL();
} else {
$scope.showerror = true;
}
$scope.$apply();
}, 1000);
};

Expand Down Expand Up @@ -93,4 +97,9 @@ angular.module('angularMermaidApp')
function buildURL(action, code) {
return absurl + '#/' + action + '/' + base64.urlencode(code);
}

function buildSVGURL() {
var svg = document.querySelector('svg').outerHTML;
return 'data:image/svg+xml;base64,' + base64.encode(svg);
}
}]);

0 comments on commit 9f8dedb

Please sign in to comment.