Javascript 使用enduro.js标记中的按钮
关于如何在enduro.js中启用标记,我遵循了以下指南: 这工作正常,但我想有按钮,而不是正常的锚链接。我的降价是这样的:Javascript 使用enduro.js标记中的按钮,javascript,markdown,enduro.js,Javascript,Markdown,Enduro.js,关于如何在enduro.js中启用标记,我遵循了以下指南: 这工作正常,但我想有按钮,而不是正常的锚链接。我的降价是这样的: ## Title Paragraph text [read more](/linktofullarticle) // placeholder abstractor var abstractor = function () {} // vendor dependencies var marked = require('marked') marked.setOption
## Title
Paragraph text
[read more](/linktofullarticle)
// 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()
我希望readmore链接是
而不是
抽象器如下所示:
## Title
Paragraph text
[read more](/linktofullarticle)
// 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()
注意:我还希望保留标准链接,因为有时链接应该是按钮,而其他时候应该是链接。我建议您在标准标记的顶部添加自定义标记规则 例如,获得按钮的降价可以如下所示
## Title
Paragraph text
..[read more](/linktofullarticle)
然后,只需捕获它并在您的abstractor代码中替换为正则表达式:
context.markdowned_text = marked(context.text)
context.markdowned_text = context.markdowned_text
.replace(/\.\.\[(.*?)\]\((.*?)\)/g, '<a class="btn" href="$2">$1</a>')
context.markdowned\u text=marked(context.text)
context.markdowned_text=context.markdowned_text
.替换(/\.\.\[(.*?)\]\(.*?)/g',)
注意:在这种情况下,使用
可能不起作用,因为您希望用户在单击按钮后重定向。只需将
与class=“btn”
一起使用,并将其设置为按钮样式。我建议您在标准标记的顶部添加自定义标记规则
例如,获得按钮的降价可以如下所示
## Title
Paragraph text
..[read more](/linktofullarticle)
然后,只需捕获它并在您的abstractor代码中替换为正则表达式:
context.markdowned_text = marked(context.text)
context.markdowned_text = context.markdowned_text
.replace(/\.\.\[(.*?)\]\((.*?)\)/g, '<a class="btn" href="$2">$1</a>')
context.markdowned\u text=marked(context.text)
context.markdowned_text=context.markdowned_text
.替换(/\.\.\[(.*?)\]\(.*?)/g',)
注意:在这种情况下,使用
可能不起作用,因为您希望用户在单击按钮后重定向。只需将
与class=“btn”
一起使用,并将其设置为按钮样式