只允许更改行和链接。禁用标记的所有其他功能

时间:2016-06-23 09:10:40

标签: javascript regex markdown javascript-marked

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两者仍然不起作用......

0 个答案:

没有答案