在 another SO question on this topic 的帮助下,我正在尝试一个无法在 html 上运行的 Showdown.js 扩展(如果我只想替换文本,但我想修改 html,它可以正常工作)。
我想改变
<img src="/path/to/image/image1.jpg" alt="bloo bap" title="" />
<img src="/path/to/image/image2.jpg" alt="shoo ba doo" title="" />
到
<img class="foo" src="/path/to/image/image1.jpg" alt="bloo bap" title="" />
<img class="foo" src="/path/to/image/image2.jpg" alt="shoo ba doo" title="" />
我的扩展是
var demo = function(converter) {
return [
{
type : 'lang',
regex : '<img src=(.*)\/>',
replace : '<img class="foo" src=$1>'
}
];
}
var converter = new Showdown.converter({extensions: [demo]});
但没有雪茄。
最佳答案
Showdown 扩展适用于 html。试试这个:
type: 'html',
regex: '<img src=(.*)\/>',
replace: '<img class="foo" src=$1>'
关于javascript - Showdown.js 扩展修改 html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21517760/