markdown转HTML
markdown转HTML样式 (md转换HTML样式)
插件
npm install marked -S //node框架
样式
npm install github-markdown-css -S //代码块样式
.markdown-body { //css总体样式
padding: 20px;
font-size: 12px;
}
.markdown-body h2 {
font-size: 18px;
margin: 1em 0 15px;
padding-top: 0.8em;
padding-bottom: 0.8em;
}
.markdown-body h3 {
font-size: 14px;
margin: 22px 0 16px;
}
.markdown-body h4 {
font-size: 13px;
margin: 20px 0 16px;
}
.markdown-body h5 {
font-size: 12px;
margin: 16px 0 16px;
font-weight: 700;
}
.markdown-body p {
font-size: 16px;
line-height: 24px;
color: #666666;
margin-top: 0px;
margin: 8px 0;
margin: 14px 0 14px;
}
.markdown-body pre {
background-color: #eee;
margin-bottom: 8px;
margin-top: 8px;
margin: 12px 0 12px;
}
.markdown-body blockquote {
margin-bottom: 8px;
margin-top: 8px;
margin: 14px 0 14px;
background-color: #eee;
padding: 16px 16px;
}
.markdown-body tr {
background-color: #f5f5f5;
}
.markdown-body code {
background-color: #eee;
}
.markdown-body ul,
.markdown-body ol,
.markdown-body li {
list-style: unset;
font-size: 14px;
line-height: 20px;
color: #666666;
margin-top: 0px;
margin: 8px 0;
}
.markdown-body blockquote {
border-color: #48b6e2;
}
.markdown-body table {
display: table;
width: 100%;
max-width: 100%;
margin-bottom: 20px;
}
完整代码
后台
router.get('/markdown',ctx=>{
const marked = require('marked');
ctx.body = marked.parse('### hello');
})
前端
<div class="markdown-body" id="markdown"></div> //引入上面那个样式即可,可以去网上搜索自己喜欢的样式
axios.get('/markdown').then(res=>{
document.getElementById('markdown').innerHTML = res.data;
console.log(res.data) //<h3>hello</h3>
})
本文来自博客园,作者:默永,转载请注明原文链接:https://www.cnblogs.com/Lmyong/p/16874453.html