Skip to content

Instantly share code, notes, and snippets.

@johnwalley
Last active October 30, 2018 09:49
Show Gist options
  • Save johnwalley/028778567cbda3bb4aec1cc210579988 to your computer and use it in GitHub Desktop.
Save johnwalley/028778567cbda3bb4aec1cc210579988 to your computer and use it in GitHub Desktop.
SVG foreignObject Markdown example
license: mit

Example of embedding Markdown output in an SVG.

See foreignObject for more details.

<!DOCTYPE html>
<meta charset="utf-8">
<body>
<script src="//d3js.org/d3.v3.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/remarkable/1.7.1/remarkable.js"></script>
<script>
var svg = d3.select("body").append("svg")
.attr("width", 960)
.attr("height", 500);
var md = new Remarkable();
var content = `# Title
Introductory **paragraph** goes _here_
* item
* item
* item`;
svg.append("foreignObject")
.attr("width", 480)
.attr("height", 500)
.append("xhtml:body")
.style("font", "14px 'Helvetica Neue'")
.html(md.render(content));
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment