情况一:直接写md内容
const app = getApp()
const _ts = this;
var content = '# test' + _ts.data.number ; //markdown 内容
let data = app.towxml.toJson(content, 'markdown')
data.theme = 'light';
_ts.setData({
article: data
});
情况二:后台传md内容
const app = getApp();
// 解析md
const _ts = this;
//请求markdown文件,并转换为内容
wx.request({
url: 'http://xxx/doc.md',
header: {
'content-type': 'application/x-www-form-urlencoded'
},
success: (res) => {
//将markdown内容转换为towxml数据
let data = app.towxml.toJson(res.data, 'markdown');
//设置文档显示主题,默认'light'
data.theme = 'dark';
//设置数据
_ts.setData({
article: data
});
}
});
参考:
https://www.jianshu.com/p/c4e819e110cb
https://www.jianshu.com/p/7ea8a55645cc
https://www.sohu.com/a/239990290_739982