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>
アップデート
私は以下の2つの方法を試しましたが、どちらも強力では機能しません... // 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
は、両方ともまだ機能しません...