我遵循了关于如何在enduro.js中启用标记的指南:http://www.endurojs.com/docs/using-markdown
这工作还可以,但我想有按钮,而不是正常的锚链接。我的markdown看起来像这样:
## Title
Paragraph text
[read more](/linktofullarticle)我希望readmore链接是一个<button>而不是<a>
抽象器看起来像这样:
// placeholder abstractor
var abstractor = function () {}
// vendor dependencies
var marked = require('marked')
marked.setOptions({
renderer: new marked.Renderer(),
gfm: true,
tables: true,
breaks: false,
pedantic: true,
sanitize: true,
smartLists: true,
smartypants: false
})
abstractor.prototype.init = function(context) {
return new Promise(function(resolve, reject) {
// initialize abstractor
resolve()
})
}
abstractor.prototype.abstract = function(context) {
return new Promise(function(resolve, reject) {
context['$markdowned_text_hidden'] = true
// creates the markdowned context
context.markdowned_text = marked(context.text)
// abstract directive
return resolve()
})
}
module.exports = new abstractor()注意:我也想保留标准链接,因为有时链接应该是一个按钮,而其他时候应该是一个链接。
发布于 2016-08-09 16:53:51
我建议您在标准的markdown之上添加您的自定义markdown规则。
例如,获取按钮的markdown可能如下所示
## Title
Paragraph text
..[read more](/linktofullarticle)然后捕获它并在您的抽象器代码中替换为regex:
context.markdowned_text = marked(context.text)
context.markdowned_text = context.markdowned_text
.replace(/\.\.\[(.*?)\]\((.*?)\)/g, '<a class="btn" href="$2">$1</a>')注意:在这种情况下,使用<button>可能不起作用,因为您希望用户在单击按钮后重定向。只需在class="btn"中使用<a>并像按钮一样设置样式即可。
https://stackoverflow.com/questions/38845040
复制相似问题