http://jsfiddle.net/zsvbzwgL/1/
如何只允许更改线路和链接。禁用标记为https://github.com/chjj/marked的所有其他功能 ?
(如字体样式、标题、列表样式、图像...)
js
marked.setOptions({
renderer: new marked.Renderer(),
gfm: false,
tables: false,
breaks: false,
pedantic: false,
sanitize: true,
smartLists: true,
smartypants: false
});
$('.output').on('click', function() {
var inputVal = $('.textarea').val();
var decode = marked(inputVal);
console.log(decode);
});
html
<textarea class="textarea"></textarea>
<div class="output">output</div>
<div class="preview"></div>
更新
我尝试了以下两种方法,都不适用于强 ... // lexer.rules.strong = { exec: function() {} }; lexer.rules.strong = /(a^) (a^) (a^)/; 资源https://github.com/chjj/marked/issues/420
// d\ne\n\nf\n**c**
var lexer = new marked.Lexer();
lexer.rules.heading = /(a^) (a^) (a^)/;
lexer.rules.strong = /(a^) (a^) (a^)/; // not work
lexer.rules.em = /(a^) (a^) (a^)/;
lexer.rules.code = /(a^) (a^) (a^)/;
var b = marked.parser(lexer.lex(d));
console.log(b);
>>
<p>d
e</p>
<p>f
<strong>c</strong></p>
在marked.js中找到了这个,
var inline = {
escape: /^\\([\\`*{}\[\]()#+\-.!_>])/,
autolink: /^<([^ >]+(@|:\/)[^ >]+)>/,
url: noop,
tag: /^<!--[\s\S]*?-->|^<\/?\w+(?:"[^"]*"|'[^']*'|[^'">])*?>/,
link: /^!?\[(inside)\]\(href\)/,
reflink: /^!?\[(inside)\]\s*\[([^\]]*)\]/,
nolink: /^!?\[((?:\[[^\]]*\]|[^\[\]])*)\]/,
strong: /^__([\s\S]+?)__(?!_)|^\*\*([\s\S]+?)\*\*(?!\*)/,
em: /^\b_((?:[^_]|__)+?)_\b|^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,
code: /^(`+)\s*([\s\S]*?[^`])\s*\1(?!`)/,
br: /^ {2,}\n(?!\s*$)/,
del: noop,
text: /^[\s\S]+?(?=[\\<!\[_*`]| {2,}\n|$)/
};
但marked.InlineLexer.rules.strong = /(a^) (a^) (a^)/;
或以上方式lexer.rules.strong
都仍然无法正常工作......