markmap.js html 案例
时间: 2023-08-10 14:43:08 浏览: 60
以下是一个简单的 `markmap.js` HTML 案例:
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Markmap.js</title>
<script src="https://unpkg.com/d3@5.15.0/dist/d3.min.js"></script>
<script src="https://unpkg.com/markmap-lib/dist/view.js"></script>
<script src="https://unpkg.com/markmap-view/dist/markmap-view.min.js"></script>
<style>
.markmap {
height: 100%;
width: 100%;
}
</style>
</head>
<body>
<div id="mindmap" class="markmap"></div>
<script>
const input = '# Hello, Markmap!\n\nThis is a simple example of using Markmap to visualize markdown.';
const svg = d3.select('#mindmap')
.datum(input)
.call(markmap.view());
// You can also use JSON to generate the mind map
const json = {
"id": "1",
"value": "Hello, Markmap",
"children": [{
"id": "2",
"value": "This is a simple example of using Markmap to visualize markdown."
}]
};
const svg2 = d3.select('#mindmap')
.datum(json)
.call(markmap.view());
</script>
</body>
</html>
```
这个例子在 `body` 标签中添加了一个 `div` 元素,并在 `script` 中使用 `markmap.view()` 函数来渲染 markdown 和 JSON 数据。注意,我们使用了 D3.js 库和 Markmap 库的两个不同的版本。你可以将此代码保存为 `index.html` 并在浏览器中打开它,以查看它的效果。