繁体   English   中英

使用enduro.js在markdown中的按钮

[英]button in markdown using enduro.js

我按照本指南关于如何在enduro.js中启用markdown: http ://www.endurojs.com/docs/using-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()

注意:我还想保留标准链接,因为有时链接应该是一个按钮,有时则是链接。

我建议您在标准降价之上添加自定义降价规则。

例如,获取按钮的降价可能如下所示

## Title
Paragraph text

..[read more](/linktofullarticle)

然后抓住它并在您的抽象代码中用正则表达式替换:

context.markdowned_text = marked(context.text)
context.markdowned_text = context.markdowned_text
    .replace(/\.\.\[(.*?)\]\((.*?)\)/g, '<a class="btn" href="$2">$1</a>')

注意:在这种情况下使用<button>可能不起作用,因为您希望用户在单击按钮后重定向。 只需使用<a> with class="btn"并将其设置为按钮。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM