为自己的网站添加Markdown功能 markedjs
Markdown几个简单的标记可以实现轻量级的代替Word方案
不多说,引入开源库js
https://github.com/chjj/marked
使用方式简单,如下
实例代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
</head>
<body>
<textarea id="oriContent" style="height:400px;width:600px;" onkeyup="convert()"></textarea>
<div id="result"></div>
<script type="text/javascript">
function convert(){
var text = document.getElementById("oriContent").value;
var html = marked(text);
document.getElementById("result").innerHTML = html;
}
</script>
</body>
</html>