forked from p01/mmd.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mmd.min.js
1 lines (1 loc) · 809 Bytes
/
mmd.min.js
1
;function mmd(s){var h='';function E(s){return new Option(s).innerHTML}function I(s){return E(s).replace(/!\[([^\]]*)]\(([^(]+)\)/g,'<img alt="$1"src="$2">').replace(/\[([^\]]+)]\(([^(]+)\)/g,'$1'.link('$2')).replace(/`([^`]+)`/g,'<code>$1</code>').replace(/\*\*([^*]+)\*\*/g,'<strong>$1</strong>').replace(/\*([^*]+)\*/g,'<em>$1</em>')}s.replace(/^\s+|\r|\s+$/g,'').replace(/\t/g,' ').split(/\n\n+/).forEach(function(b,f,R){R={'*':[/\n\* /,'<ul><li>','</li></ul>'],1:[/\n[1-9]\d*\.? /,'<ol><li>','</li></ol>'],' ':[/\n /,'<pre><code>','</pre></code>','\n'],'>':[/\n> /,'<blockquote>','</blockquote>','\n']}[f=b[0]];h+=R?R[1]+('\n'+b).split(R[0]).slice(1).map(R[3]?E:I).join(R[3]||'</li>\n<li>')+R[2]:f=='#'?'<h'+(f=b.indexOf(' '))+'>'+I(b.slice(f+1))+'</h'+f+'>':f=='<'?b:'<p>'+I(b)+'</p>'});return h};