diff --git a/lib/mmd.js b/lib/mmd.js new file mode 100644 index 0000000..539f6d3 --- /dev/null +++ b/lib/mmd.js @@ -0,0 +1,44 @@ +;function mmd(src) +{ + var h=''; + + function escape(t) + { + return new Option(t).innerHTML; + } + function inlineEscape(s) + { + return escape(s) + .replace(/!\[([^\]]*)]\(([^(]+)\)/g, '$1') + .replace(/\[([^\]]+)]\(([^(]+)\)/g, '$1'.link('$2')) + .replace(/`([^`]+)`/g, '$1') + .replace(/\*\*([^*]+)\*\*/g, '$1') + .replace(/\*([^*]+)\*/g, '$1'); + } + + src + .replace(/^\s+|\r|\s+$/g, '') + .replace(/\t/g, ' ') + .split(/\n\n+/) + .forEach(function(b, f, R) + { + f=b[0]; + R= + { + '*':[/\n\* /,''], + '1':[/\n[1-9]\d*\.? /,'
  1. ','
'], + ' ':[/\n /,'
','
','\n'], + '>':[/\n> /,'
','
','\n'] + }[f]; + h+= + R?R[1]+('\n'+b) + .split(R[0]) + .slice(1) + .map(R[3]?escape:inlineEscape) + .join(R[3]||'\n
  • ')+R[2]: + f=='#'?''+inlineEscape(b.slice(f+1))+'': + f=='<'?b: + '

    '+inlineEscape(b)+'

    '; + }); + return h; +}; \ No newline at end of file