Skip to content

Instantly share code, notes, and snippets.

@ismnoiet

ismnoiet/index.js

Created Apr 7, 2016
Embed
What would you like to do?
requirebin sketch
var markdown = require( "markdown" ).markdown;
var markdownStr = ['#Hello World','somethig else','#another title'].join("\n");
var htmlResult= markdown.toHTML(markdownStr);
var finalResult = htmlResult.replace(/<h1>/g,'<h3>');
finalResult.replace(/<\/h1>/g,'</h3>');
console.log(htmlResult);
console.log(finalResult); // <h3>Hello World</h3>
setTimeout(function(){require=function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module,exports){(function(expose){var Markdown=expose.Markdown=function(dialect){switch(typeof dialect){case"undefined":this.dialect=Markdown.dialects.Gruber;break;case"object":this.dialect=dialect;break;default:if(dialect in Markdown.dialects){this.dialect=Markdown.dialects[dialect]}else{throw new Error("Unknown Markdown dialect '"+String(dialect)+"'")}break}this.em_state=[];this.strong_state=[];this.debug_indent=""};expose.parse=function(source,dialect){var md=new Markdown(dialect);return md.toTree(source)};expose.toHTML=function toHTML(source,dialect,options){var input=expose.toHTMLTree(source,dialect,options);return expose.renderJsonML(input)};expose.toHTMLTree=function toHTMLTree(input,dialect,options){if(typeof input==="string")input=this.parse(input,dialect);var attrs=extract_attr(input),refs={};if(attrs&&attrs.references){refs=attrs.references}var html=convert_tree_to_html(input,refs,options);merge_text_nodes(html);return html};function mk_block_toSource(){return"Markdown.mk_block( "+uneval(this.toString())+", "+uneval(this.trailing)+", "+uneval(this.lineNumber)+" )"}function mk_block_inspect(){var util=require("util");return"Markdown.mk_block( "+util.inspect(this.toString())+", "+util.inspect(this.trailing)+", "+util.inspect(this.lineNumber)+" )"}var mk_block=Markdown.mk_block=function(block,trail,line){if(arguments.length==1)trail="\n\n";var s=new String(block);s.trailing=trail;s.inspect=mk_block_inspect;s.toSource=mk_block_toSource;if(line!=undefined)s.lineNumber=line;return s};function count_lines(str){var n=0,i=-1;while((i=str.indexOf("\n",i+1))!==-1)n++;return n}Markdown.prototype.split_blocks=function splitBlocks(input,startLine){input=input.replace(/(\r\n|\n|\r)/g,"\n");var re=/([\s\S]+?)($|\n#|\n(?:\s*\n|$)+)/g,blocks=[],m;var line_no=1;if((m=/^(\s*\n)/.exec(input))!=null){line_no+=count_lines(m[0]);re.lastIndex=m[0].length}while((m=re.exec(input))!==null){if(m[2]=="\n#"){m[2]="\n";re.lastIndex--}blocks.push(mk_block(m[1],m[2],line_no));line_no+=count_lines(m[0])}return blocks};Markdown.prototype.processBlock=function processBlock(block,next){var cbs=this.dialect.block,ord=cbs.__order__;if("__call__"in cbs){return cbs.__call__.call(this,block,next)}for(var i=0;i<ord.length;i++){var res=cbs[ord[i]].call(this,block,next);if(res){if(!isArray(res)||res.length>0&&!isArray(res[0]))this.debug(ord[i],"didn't return a proper array");return res}}return[]};Markdown.prototype.processInline=function processInline(block){return this.dialect.inline.__call__.call(this,String(block))};Markdown.prototype.toTree=function toTree(source,custom_root){var blocks=source instanceof Array?source:this.split_blocks(source);var old_tree=this.tree;try{this.tree=custom_root||this.tree||["markdown"];blocks:while(blocks.length){var b=this.processBlock(blocks.shift(),blocks);if(!b.length)continue blocks;this.tree.push.apply(this.tree,b)}return this.tree}finally{if(custom_root){this.tree=old_tree}}};Markdown.prototype.debug=function(){var args=Array.prototype.slice.call(arguments);args.unshift(this.debug_indent);if(typeof print!=="undefined")print.apply(print,args);if(typeof console!=="undefined"&&typeof console.log!=="undefined")console.log.apply(null,args)};Markdown.prototype.loop_re_over_block=function(re,block,cb){var m,b=block.valueOf();while(b.length&&(m=re.exec(b))!=null){b=b.substr(m[0].length);cb.call(this,m)}return b};Markdown.dialects={};Markdown.dialects.Gruber={block:{atxHeader:function atxHeader(block,next){var m=block.match(/^(#{1,6})\s*(.*?)\s*#*\s*(?:\n|$)/);if(!m)return undefined;var header=["header",{level:m[1].length}];Array.prototype.push.apply(header,this.processInline(m[2]));if(m[0].length<block.length)next.unshift(mk_block(block.substr(m[0].length),block.trailing,block.lineNumber+2));return[header]},setextHeader:function setextHeader(block,next){var m=block.match(/^(.*)\n([-=])\2\2+(?:\n|$)/);if(!m)return undefined;var level=m[2]==="="?1:2;var header=["header",{level:level},m[1]];if(m[0].length<block.length)next.unshift(mk_block(block.substr(m[0].length),block.trailing,block.lineNumber+2));return[header]},code:function code(block,next){var ret=[],re=/^(?: {0,3}\t| {4})(.*)\n?/,lines;if(!block.match(re))return undefined;block_search:do{var b=this.loop_re_over_block(re,block.valueOf(),function(m){ret.push(m[1])});if(b.length){next.unshift(mk_block(b,block.trailing));break block_search}else if(next.length){if(!next[0].match(re))break block_search;ret.push(block.trailing.replace(/[^\n]/g,"").substring(2));block=next.shift()}else{break block_search}}while(true);return[["code_block",ret.join("\n")]]},horizRule:function horizRule(block,next){var m=block.match(/^(?:([\s\S]*?)\n)?[ \t]*([-_*])(?:[ \t]*\2){2,}[ \t]*(?:\n([\s\S]*))?$/);if(!m){return undefined}var jsonml=[["hr"]];if(m[1]){jsonml.unshift.apply(jsonml,this.processBlock(m[1],[]))}if(m[3]){next.unshift(mk_block(m[3]))}return jsonml},lists:function(){var any_list="[*+-]|\\d+\\.",bullet_list=/[*+-]/,number_list=/\d+\./,is_list_re=new RegExp("^( {0,3})("+any_list+")[ ]+"),indent_re="(?: {0,3}\\t| {4})";function regex_for_depth(depth){return new RegExp("(?:^("+indent_re+"{0,"+depth+"} {0,3})("+any_list+")\\s+)|"+"(^"+indent_re+"{0,"+(depth-1)+"}[ ]{0,4})")}function expand_tab(input){return input.replace(/ {0,3}\t/g," ")}function add(li,loose,inline,nl){if(loose){li.push(["para"].concat(inline));return}var add_to=li[li.length-1]instanceof Array&&li[li.length-1][0]=="para"?li[li.length-1]:li;if(nl&&li.length>1)inline.unshift(nl);for(var i=0;i<inline.length;i++){var what=inline[i],is_str=typeof what=="string";if(is_str&&add_to.length>1&&typeof add_to[add_to.length-1]=="string"){add_to[add_to.length-1]+=what}else{add_to.push(what)}}}function get_contained_blocks(depth,blocks){var re=new RegExp("^("+indent_re+"{"+depth+"}.*?\\n?)*$"),replace=new RegExp("^"+indent_re+"{"+depth+"}","gm"),ret=[];while(blocks.length>0){if(re.exec(blocks[0])){var b=blocks.shift(),x=b.replace(replace,"");ret.push(mk_block(x,b.trailing,b.lineNumber))}else{break}}return ret}function paragraphify(s,i,stack){var list=s.list;var last_li=list[list.length-1];if(last_li[1]instanceof Array&&last_li[1][0]=="para"){return}if(i+1==stack.length){last_li.push(["para"].concat(last_li.splice(1,last_li.length-1)))}else{var sublist=last_li.pop();last_li.push(["para"].concat(last_li.splice(1,last_li.length-1)),sublist)}}return function(block,next){var m=block.match(is_list_re);if(!m)return undefined;function make_list(m){var list=bullet_list.exec(m[2])?["bulletlist"]:["numberlist"];stack.push({list:list,indent:m[1]});return list}var stack=[],list=make_list(m),last_li,loose=false,ret=[stack[0].list],i;loose_search:while(true){var lines=block.split(/(?=\n)/);var li_accumulate="";tight_search:for(var line_no=0;line_no<lines.length;line_no++){var nl="",l=lines[line_no].replace(/^\n/,function(n){nl=n;return""});var line_re=regex_for_depth(stack.length);m=l.match(line_re);if(m[1]!==undefined){if(li_accumulate.length){add(last_li,loose,this.processInline(li_accumulate),nl);loose=false;li_accumulate=""}m[1]=expand_tab(m[1]);var wanted_depth=Math.floor(m[1].length/4)+1;if(wanted_depth>stack.length){list=make_list(m);last_li.push(list);last_li=list[1]=["listitem"]}else{var found=false;for(i=0;i<stack.length;i++){if(stack[i].indent!=m[1])continue;list=stack[i].list;stack.splice(i+1,stack.length-(i+1));found=true;break}if(!found){wanted_depth++;if(wanted_depth<=stack.length){stack.splice(wanted_depth,stack.length-wanted_depth);list=stack[wanted_depth-1].list}else{list=make_list(m);last_li.push(list)}}last_li=["listitem"];list.push(last_li)}nl=""}if(l.length>m[0].length){li_accumulate+=nl+l.substr(m[0].length)}}if(li_accumulate.length){add(last_li,loose,this.processInline(li_accumulate),nl);loose=false;li_accumulate=""}var contained=get_contained_blocks(stack.length,next);if(contained.length>0){forEach(stack,paragraphify,this);last_li.push.apply(last_li,this.toTree(contained,[]))}var next_block=next[0]&&next[0].valueOf()||"";if(next_block.match(is_list_re)||next_block.match(/^ /)){block=next.shift();var hr=this.dialect.block.horizRule(block,next);if(hr){ret.push.apply(ret,hr);break}forEach(stack,paragraphify,this);loose=true;continue loose_search}break}return ret}}(),blockquote:function blockquote(block,next){if(!block.match(/^>/m))return undefined;var jsonml=[];if(block[0]!=">"){var lines=block.split(/\n/),prev=[],line_no=block.lineNumber;while(lines.length&&lines[0][0]!=">"){prev.push(lines.shift());line_no++}var abutting=mk_block(prev.join("\n"),"\n",block.lineNumber);jsonml.push.apply(jsonml,this.processBlock(abutting,[]));block=mk_block(lines.join("\n"),block.trailing,line_no)}while(next.length&&next[0][0]==">"){var b=next.shift();block=mk_block(block+block.trailing+b,b.trailing,block.lineNumber)}var input=block.replace(/^> ?/gm,""),old_tree=this.tree,processedBlock=this.toTree(input,["blockquote"]),attr=extract_attr(processedBlock);if(attr&&attr.references){delete attr.references;if(isEmpty(attr)){processedBlock.splice(1,1)}}jsonml.push(processedBlock);return jsonml},referenceDefn:function referenceDefn(block,next){var re=/^\s*\[(.*?)\]:\s*(\S+)(?:\s+(?:(['"])(.*?)\3|\((.*?)\)))?\n?/;if(!block.match(re))return undefined;if(!extract_attr(this.tree)){this.tree.splice(1,0,{})}var attrs=extract_attr(this.tree);if(attrs.references===undefined){attrs.references={}}var b=this.loop_re_over_block(re,block,function(m){if(m[2]&&m[2][0]=="<"&&m[2][m[2].length-1]==">")m[2]=m[2].substring(1,m[2].length-1);var ref=attrs.references[m[1].toLowerCase()]={href:m[2]};if(m[4]!==undefined)ref.title=m[4];else if(m[5]!==undefined)ref.title=m[5]});if(b.length)next.unshift(mk_block(b,block.trailing));return[]},para:function para(block,next){return[["para"].concat(this.processInline(block))]}}};Markdown.dialects.Gruber.inline={__oneElement__:function oneElement(text,patterns_or_re,previous_nodes){var m,res,lastIndex=0;patterns_or_re=patterns_or_re||this.dialect.inline.__patterns__;var re=new RegExp("([\\s\\S]*?)("+(patterns_or_re.source||patterns_or_re)+")");m=re.exec(text);if(!m){return[text.length,text]}else if(m[1]){return[m[1].length,m[1]]}var res;if(m[2]in this.dialect.inline){res=this.dialect.inline[m[2]].call(this,text.substr(m.index),m,previous_nodes||[])}res=res||[m[2].length,m[2]];return res},__call__:function inline(text,patterns){var out=[],res;function add(x){if(typeof x=="string"&&typeof out[out.length-1]=="string")out[out.length-1]+=x;else out.push(x)}while(text.length>0){res=this.dialect.inline.__oneElement__.call(this,text,patterns,out);text=text.substr(res.shift());forEach(res,add)}return out},"]":function(){},"}":function(){},__escape__:/^\\[\\`\*_{}\[\]()#\+.!\-]/,"\\":function escaped(text){if(this.dialect.inline.__escape__.exec(text))return[2,text.charAt(1)];else return[1,"\\"]},"![":function image(text){var m=text.match(/^!\[(.*?)\][ \t]*\([ \t]*([^")]*?)(?:[ \t]+(["'])(.*?)\3)?[ \t]*\)/);if(m){if(m[2]&&m[2][0]=="<"&&m[2][m[2].length-1]==">")m[2]=m[2].substring(1,m[2].length-1);m[2]=this.dialect.inline.__call__.call(this,m[2],/\\/)[0];var attrs={alt:m[1],href:m[2]||""};if(m[4]!==undefined)attrs.title=m[4];return[m[0].length,["img",attrs]]}m=text.match(/^!\[(.*?)\][ \t]*\[(.*?)\]/);if(m){return[m[0].length,["img_ref",{alt:m[1],ref:m[2].toLowerCase(),original:m[0]}]]}return[2,"!["]},"[":function link(text){var orig=String(text);var res=Markdown.DialectHelpers.inline_until_char.call(this,text.substr(1),"]");if(!res)return[1,"["];var consumed=1+res[0],children=res[1],link,attrs;text=text.substr(consumed);var m=text.match(/^\s*\([ \t]*([^"']*)(?:[ \t]+(["'])(.*?)\2)?[ \t]*\)/);if(m){var url=m[1];consumed+=m[0].length;if(url&&url[0]=="<"&&url[url.length-1]==">")url=url.substring(1,url.length-1);if(!m[3]){var open_parens=1;for(var len=0;len<url.length;len++){switch(url[len]){case"(":open_parens++;break;case")":if(--open_parens==0){consumed-=url.length-len;url=url.substring(0,len)}break}}}url=this.dialect.inline.__call__.call(this,url,/\\/)[0];attrs={href:url||""};if(m[3]!==undefined)attrs.title=m[3];link=["link",attrs].concat(children);return[consumed,link]}m=text.match(/^\s*\[(.*?)\]/);if(m){consumed+=m[0].length;attrs={ref:(m[1]||String(children)).toLowerCase(),original:orig.substr(0,consumed)};link=["link_ref",attrs].concat(children);return[consumed,link]}if(children.length==1&&typeof children[0]=="string"){attrs={ref:children[0].toLowerCase(),original:orig.substr(0,consumed)};link=["link_ref",attrs,children[0]];return[consumed,link]}return[1,"["]},"<":function autoLink(text){var m;if((m=text.match(/^<(?:((https?|ftp|mailto):[^>]+)|(.*?@.*?\.[a-zA-Z]+))>/))!=null){if(m[3]){return[m[0].length,["link",{href:"mailto:"+m[3]},m[3]]]}else if(m[2]=="mailto"){return[m[0].length,["link",{href:m[1]},m[1].substr("mailto:".length)]]}else return[m[0].length,["link",{href:m[1]},m[1]]]}return[1,"<"]},"`":function inlineCode(text){var m=text.match(/(`+)(([\s\S]*?)\1)/);if(m&&m[2])return[m[1].length+m[2].length,["inlinecode",m[3]]];else{return[1,"`"]}}," \n":function lineBreak(text){return[3,["linebreak"]]}};function strong_em(tag,md){var state_slot=tag+"_state",other_slot=tag=="strong"?"em_state":"strong_state";function CloseTag(len){this.len_after=len;this.name="close_"+md}return function(text,orig_match){if(this[state_slot][0]==md){this[state_slot].shift();return[text.length,new CloseTag(text.length-md.length)]}else{var other=this[other_slot].slice(),state=this[state_slot].slice();this[state_slot].unshift(md);var res=this.processInline(text.substr(md.length));var last=res[res.length-1];var check=this[state_slot].shift();if(last instanceof CloseTag){res.pop();var consumed=text.length-last.len_after;return[consumed,[tag].concat(res)]}else{this[other_slot]=other;this[state_slot]=state;return[md.length,md]}}}}Markdown.dialects.Gruber.inline["**"]=strong_em("strong","**");Markdown.dialects.Gruber.inline["__"]=strong_em("strong","__");Markdown.dialects.Gruber.inline["*"]=strong_em("em","*");Markdown.dialects.Gruber.inline["_"]=strong_em("em","_");Markdown.buildBlockOrder=function(d){var ord=[];for(var i in d){if(i=="__order__"||i=="__call__")continue;ord.push(i)}d.__order__=ord};Markdown.buildInlinePatterns=function(d){var patterns=[];for(var i in d){if(i.match(/^__.*__$/))continue;var l=i.replace(/([\\.*+?|()\[\]{}])/g,"\\$1").replace(/\n/,"\\n");patterns.push(i.length==1?l:"(?:"+l+")")}patterns=patterns.join("|");d.__patterns__=patterns;var fn=d.__call__;d.__call__=function(text,pattern){if(pattern!=undefined){return fn.call(this,text,pattern)}else{return fn.call(this,text,patterns)}}};Markdown.DialectHelpers={};Markdown.DialectHelpers.inline_until_char=function(text,want){var consumed=0,nodes=[];while(true){if(text.charAt(consumed)==want){consumed++;return[consumed,nodes]}if(consumed>=text.length){return null}var res=this.dialect.inline.__oneElement__.call(this,text.substr(consumed));consumed+=res[0];nodes.push.apply(nodes,res.slice(1))}};Markdown.subclassDialect=function(d){function Block(){}Block.prototype=d.block;function Inline(){}Inline.prototype=d.inline;return{block:new Block,inline:new Inline}};Markdown.buildBlockOrder(Markdown.dialects.Gruber.block);Markdown.buildInlinePatterns(Markdown.dialects.Gruber.inline);Markdown.dialects.Maruku=Markdown.subclassDialect(Markdown.dialects.Gruber);Markdown.dialects.Maruku.processMetaHash=function processMetaHash(meta_string){var meta=split_meta_hash(meta_string),attr={};for(var i=0;i<meta.length;++i){if(/^#/.test(meta[i])){attr.id=meta[i].substring(1)}else if(/^\./.test(meta[i])){if(attr["class"]){attr["class"]=attr["class"]+meta[i].replace(/./," ")}else{attr["class"]=meta[i].substring(1)}}else if(/\=/.test(meta[i])){var s=meta[i].split(/\=/);attr[s[0]]=s[1]}}return attr};function split_meta_hash(meta_string){var meta=meta_string.split(""),parts=[""],in_quotes=false;while(meta.length){var letter=meta.shift();switch(letter){case" ":if(in_quotes){parts[parts.length-1]+=letter}else{parts.push("")}break;case"'":case'"':in_quotes=!in_quotes;break;case"\\":letter=meta.shift();default:parts[parts.length-1]+=letter;break}}return parts}Markdown.dialects.Maruku.block.document_meta=function document_meta(block,next){if(block.lineNumber>1)return undefined;if(!block.match(/^(?:\w+:.*\n)*\w+:.*$/))return undefined;if(!extract_attr(this.tree)){this.tree.splice(1,0,{})}var pairs=block.split(/\n/);for(p in pairs){var m=pairs[p].match(/(\w+):\s*(.*)$/),key=m[1].toLowerCase(),value=m[2];this.tree[1][key]=value}return[]};Markdown.dialects.Maruku.block.block_meta=function block_meta(block,next){var m=block.match(/(^|\n) {0,3}\{:\s*((?:\\\}|[^\}])*)\s*\}$/);if(!m)return undefined;var attr=this.dialect.processMetaHash(m[2]);var hash;if(m[1]===""){var node=this.tree[this.tree.length-1];hash=extract_attr(node);if(typeof node==="string")return undefined;if(!hash){hash={};node.splice(1,0,hash)}for(a in attr){hash[a]=attr[a]}return[]}var b=block.replace(/\n.*$/,""),result=this.processBlock(b,[]);hash=extract_attr(result[0]);if(!hash){hash={};result[0].splice(1,0,hash)}for(a in attr){hash[a]=attr[a]}return result};Markdown.dialects.Maruku.block.definition_list=function definition_list(block,next){var tight=/^((?:[^\s:].*\n)+):\s+([\s\S]+)$/,list=["dl"],i,m;if(m=block.match(tight)){var blocks=[block];while(next.length&&tight.exec(next[0])){blocks.push(next.shift())}for(var b=0;b<blocks.length;++b){var m=blocks[b].match(tight),terms=m[1].replace(/\n$/,"").split(/\n/),defns=m[2].split(/\n:\s+/);for(i=0;i<terms.length;++i){list.push(["dt",terms[i]])}for(i=0;i<defns.length;++i){list.push(["dd"].concat(this.processInline(defns[i].replace(/(\n)\s+/,"$1"))))}}}else{return undefined}return[list]};Markdown.dialects.Maruku.block.table=function table(block,next){var _split_on_unescaped=function(s,ch){ch=ch||"\\s";if(ch.match(/^[\\|\[\]{}?*.+^$]$/)){ch="\\"+ch}var res=[],r=new RegExp("^((?:\\\\.|[^\\\\"+ch+"])*)"+ch+"(.*)"),m;while(m=s.match(r)){res.push(m[1]);s=m[2]}res.push(s);return res};var leading_pipe=/^ {0,3}\|(.+)\n {0,3}\|\s*([\-:]+[\-| :]*)\n((?:\s*\|.*(?:\n|$))*)(?=\n|$)/,no_leading_pipe=/^ {0,3}(\S(?:\\.|[^\\|])*\|.*)\n {0,3}([\-:]+\s*\|[\-| :]*)\n((?:(?:\\.|[^\\|])*\|.*(?:\n|$))*)(?=\n|$)/,i,m;if(m=block.match(leading_pipe)){m[3]=m[3].replace(/^\s*\|/gm,"")}else if(!(m=block.match(no_leading_pipe))){return undefined}var table=["table",["thead",["tr"]],["tbody"]];m[2]=m[2].replace(/\|\s*$/,"").split("|");var html_attrs=[];forEach(m[2],function(s){if(s.match(/^\s*-+:\s*$/))html_attrs.push({align:"right"});else if(s.match(/^\s*:-+\s*$/))html_attrs.push({align:"left"});else if(s.match(/^\s*:-+:\s*$/))html_attrs.push({align:"center"});else html_attrs.push({})});m[1]=_split_on_unescaped(m[1].replace(/\|\s*$/,""),"|");for(i=0;i<m[1].length;i++){table[1][1].push(["th",html_attrs[i]||{}].concat(this.processInline(m[1][i].trim())))}forEach(m[3].replace(/\|\s*$/gm,"").split("\n"),function(row){var html_row=["tr"];row=_split_on_unescaped(row,"|");for(i=0;i<row.length;i++){html_row.push(["td",html_attrs[i]||{}].concat(this.processInline(row[i].trim())))}table[2].push(html_row)},this);return[table]};Markdown.dialects.Maruku.inline["{:"]=function inline_meta(text,matches,out){if(!out.length){return[2,"{:"]}var before=out[out.length-1];if(typeof before==="string"){return[2,"{:"]}var m=text.match(/^\{:\s*((?:\\\}|[^\}])*)\s*\}/);if(!m){return[2,"{:"]}var meta=this.dialect.processMetaHash(m[1]),attr=extract_attr(before);if(!attr){attr={};before.splice(1,0,attr)}for(var k in meta){attr[k]=meta[k]}return[m[0].length,""]};Markdown.dialects.Maruku.inline.__escape__=/^\\[\\`\*_{}\[\]()#\+.!\-|:]/;Markdown.buildBlockOrder(Markdown.dialects.Maruku.block);Markdown.buildInlinePatterns(Markdown.dialects.Maruku.inline);var isArray=Array.isArray||function(obj){return Object.prototype.toString.call(obj)=="[object Array]"};var forEach;if(Array.prototype.forEach){forEach=function(arr,cb,thisp){return arr.forEach(cb,thisp)}}else{forEach=function(arr,cb,thisp){for(var i=0;i<arr.length;i++){cb.call(thisp||arr,arr[i],i,arr)}}}var isEmpty=function(obj){for(var key in obj){if(hasOwnProperty.call(obj,key)){return false}}return true};function extract_attr(jsonml){return isArray(jsonml)&&jsonml.length>1&&typeof jsonml[1]==="object"&&!isArray(jsonml[1])?jsonml[1]:undefined}expose.renderJsonML=function(jsonml,options){options=options||{};options.root=options.root||false;var content=[];if(options.root){content.push(render_tree(jsonml))}else{jsonml.shift();if(jsonml.length&&typeof jsonml[0]==="object"&&!(jsonml[0]instanceof Array)){jsonml.shift()}while(jsonml.length){content.push(render_tree(jsonml.shift()))}}return content.join("\n\n")};function escapeHTML(text){return text.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")}function render_tree(jsonml){if(typeof jsonml==="string"){return escapeHTML(jsonml)}var tag=jsonml.shift(),attributes={},content=[];if(jsonml.length&&typeof jsonml[0]==="object"&&!(jsonml[0]instanceof Array)){attributes=jsonml.shift()}while(jsonml.length){content.push(render_tree(jsonml.shift()))}var tag_attrs="";for(var a in attributes){tag_attrs+=" "+a+'="'+escapeHTML(attributes[a])+'"'}if(tag=="img"||tag=="br"||tag=="hr"){return"<"+tag+tag_attrs+"/>"}else{return"<"+tag+tag_attrs+">"+content.join("")+"</"+tag+">"}}function convert_tree_to_html(tree,references,options){var i;options=options||{};var jsonml=tree.slice(0);if(typeof options.preprocessTreeNode==="function"){jsonml=options.preprocessTreeNode(jsonml,references)}var attrs=extract_attr(jsonml);if(attrs){jsonml[1]={};for(i in attrs){jsonml[1][i]=attrs[i]}attrs=jsonml[1]}if(typeof jsonml==="string"){return jsonml}switch(jsonml[0]){case"header":jsonml[0]="h"+jsonml[1].level;delete jsonml[1].level;break;case"bulletlist":jsonml[0]="ul";break;case"numberlist":jsonml[0]="ol";break;case"listitem":jsonml[0]="li";break;case"para":jsonml[0]="p";break;case"markdown":jsonml[0]="html";if(attrs)delete attrs.references;break;case"code_block":jsonml[0]="pre";i=attrs?2:1;var code=["code"];code.push.apply(code,jsonml.splice(i,jsonml.length-i));jsonml[i]=code;break;case"inlinecode":jsonml[0]="code";break;case"img":jsonml[1].src=jsonml[1].href;delete jsonml[1].href;break;case"linebreak":jsonml[0]="br";break;case"link":jsonml[0]="a";break;case"link_ref":jsonml[0]="a";var ref=references[attrs.ref];if(ref){delete attrs.ref;attrs.href=ref.href;if(ref.title){attrs.title=ref.title}delete attrs.original}else{return attrs.original}break;case"img_ref":jsonml[0]="img";var ref=references[attrs.ref];if(ref){delete attrs.ref;attrs.src=ref.href;if(ref.title){attrs.title=ref.title}delete attrs.original}else{return attrs.original}break}i=1;if(attrs){for(var key in jsonml[1]){i=2;break}if(i===1){jsonml.splice(i,1)}}for(;i<jsonml.length;++i){jsonml[i]=convert_tree_to_html(jsonml[i],references,options)}return jsonml}function merge_text_nodes(jsonml){var i=extract_attr(jsonml)?2:1;while(i<jsonml.length){if(typeof jsonml[i]==="string"){if(i+1<jsonml.length&&typeof jsonml[i+1]==="string"){jsonml[i]+=jsonml.splice(i+1,1)[0]}else{++i}}else{merge_text_nodes(jsonml[i]);++i}}}})(function(){if(typeof exports==="undefined"){window.markdown={};return window.markdown}else{return exports}}())},{util:5}],2:[function(require,module,exports){if(typeof Object.create==="function"){module.exports=function inherits(ctor,superCtor){ctor.super_=superCtor;ctor.prototype=Object.create(superCtor.prototype,{constructor:{value:ctor,enumerable:false,writable:true,configurable:true}})}}else{module.exports=function inherits(ctor,superCtor){ctor.super_=superCtor;var TempCtor=function(){};TempCtor.prototype=superCtor.prototype;ctor.prototype=new TempCtor;ctor.prototype.constructor=ctor}}},{}],3:[function(require,module,exports){var process=module.exports={};process.nextTick=function(){var canSetImmediate=typeof window!=="undefined"&&window.setImmediate;var canPost=typeof window!=="undefined"&&window.postMessage&&window.addEventListener;if(canSetImmediate){return function(f){return window.setImmediate(f)}}if(canPost){var queue=[];window.addEventListener("message",function(ev){var source=ev.source;if((source===window||source===null)&&ev.data==="process-tick"){ev.stopPropagation();if(queue.length>0){var fn=queue.shift();fn()}}},true);return function nextTick(fn){queue.push(fn);window.postMessage("process-tick","*")}}return function nextTick(fn){setTimeout(fn,0)}}();process.title="browser";process.browser=true;process.env={};process.argv=[];function noop(){}process.on=noop;process.addListener=noop;process.once=noop;process.off=noop;process.removeListener=noop;process.removeAllListeners=noop;process.emit=noop;process.binding=function(name){throw new Error("process.binding is not supported")};process.cwd=function(){return"/"};process.chdir=function(dir){throw new Error("process.chdir is not supported")}},{}],4:[function(require,module,exports){module.exports=function isBuffer(arg){return arg&&typeof arg==="object"&&typeof arg.copy==="function"&&typeof arg.fill==="function"&&typeof arg.readUInt8==="function"}},{}],5:[function(require,module,exports){(function(process,global){var formatRegExp=/%[sdj%]/g;exports.format=function(f){if(!isString(f)){var objects=[];for(var i=0;i<arguments.length;i++){objects.push(inspect(arguments[i]))}return objects.join(" ")}var i=1;var args=arguments;var len=args.length;var str=String(f).replace(formatRegExp,function(x){if(x==="%%")return"%";if(i>=len)return x;switch(x){case"%s":return String(args[i++]);case"%d":return Number(args[i++]);case"%j":try{return JSON.stringify(args[i++])}catch(_){return"[Circular]"}default:return x}});for(var x=args[i];i<len;x=args[++i]){if(isNull(x)||!isObject(x)){str+=" "+x}else{str+=" "+inspect(x)}}return str};exports.deprecate=function(fn,msg){if(isUndefined(global.process)){return function(){return exports.deprecate(fn,msg).apply(this,arguments)}}if(process.noDeprecation===true){return fn}var warned=false;function deprecated(){if(!warned){if(process.throwDeprecation){throw new Error(msg)}else if(process.traceDeprecation){console.trace(msg)}else{console.error(msg)}warned=true}return fn.apply(this,arguments)}return deprecated};var debugs={};var debugEnviron;exports.debuglog=function(set){if(isUndefined(debugEnviron))debugEnviron=process.env.NODE_DEBUG||"";set=set.toUpperCase();if(!debugs[set]){if(new RegExp("\\b"+set+"\\b","i").test(debugEnviron)){var pid=process.pid;debugs[set]=function(){var msg=exports.format.apply(exports,arguments);console.error("%s %d: %s",set,pid,msg)}}else{debugs[set]=function(){}}}return debugs[set]};function inspect(obj,opts){var ctx={seen:[],stylize:stylizeNoColor};if(arguments.length>=3)ctx.depth=arguments[2];if(arguments.length>=4)ctx.colors=arguments[3];if(isBoolean(opts)){ctx.showHidden=opts}else if(opts){exports._extend(ctx,opts)}if(isUndefined(ctx.showHidden))ctx.showHidden=false;if(isUndefined(ctx.depth))ctx.depth=2;if(isUndefined(ctx.colors))ctx.colors=false;if(isUndefined(ctx.customInspect))ctx.customInspect=true;if(ctx.colors)ctx.stylize=stylizeWithColor;return formatValue(ctx,obj,ctx.depth)}exports.inspect=inspect;inspect.colors={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]};inspect.styles={special:"cyan",number:"yellow","boolean":"yellow",undefined:"grey","null":"bold",string:"green",date:"magenta",regexp:"red"};function stylizeWithColor(str,styleType){var style=inspect.styles[styleType];if(style){return"["+inspect.colors[style][0]+"m"+str+"["+inspect.colors[style][1]+"m"}else{return str}}function stylizeNoColor(str,styleType){return str}function arrayToHash(array){var hash={};array.forEach(function(val,idx){hash[val]=true});return hash}function formatValue(ctx,value,recurseTimes){if(ctx.customInspect&&value&&isFunction(value.inspect)&&value.inspect!==exports.inspect&&!(value.constructor&&value.constructor.prototype===value)){var ret=value.inspect(recurseTimes,ctx);if(!isString(ret)){ret=formatValue(ctx,ret,recurseTimes)}return ret}var primitive=formatPrimitive(ctx,value);if(primitive){return primitive}var keys=Object.keys(value);var visibleKeys=arrayToHash(keys);if(ctx.showHidden){keys=Object.getOwnPropertyNames(value)}if(isError(value)&&(keys.indexOf("message")>=0||keys.indexOf("description")>=0)){return formatError(value)}if(keys.length===0){if(isFunction(value)){var name=value.name?": "+value.name:"";return ctx.stylize("[Function"+name+"]","special")}if(isRegExp(value)){return ctx.stylize(RegExp.prototype.toString.call(value),"regexp")}if(isDate(value)){return ctx.stylize(Date.prototype.toString.call(value),"date")}if(isError(value)){return formatError(value)}}var base="",array=false,braces=["{","}"];if(isArray(value)){array=true;braces=["[","]"]}if(isFunction(value)){var n=value.name?": "+value.name:"";base=" [Function"+n+"]"}if(isRegExp(value)){base=" "+RegExp.prototype.toString.call(value)}if(isDate(value)){base=" "+Date.prototype.toUTCString.call(value)}if(isError(value)){base=" "+formatError(value)}if(keys.length===0&&(!array||value.length==0)){return braces[0]+base+braces[1]}if(recurseTimes<0){if(isRegExp(value)){return ctx.stylize(RegExp.prototype.toString.call(value),"regexp")}else{return ctx.stylize("[Object]","special")}}ctx.seen.push(value);var output;if(array){output=formatArray(ctx,value,recurseTimes,visibleKeys,keys)}else{output=keys.map(function(key){return formatProperty(ctx,value,recurseTimes,visibleKeys,key,array)})}ctx.seen.pop();return reduceToSingleString(output,base,braces)}function formatPrimitive(ctx,value){if(isUndefined(value))return ctx.stylize("undefined","undefined");if(isString(value)){var simple="'"+JSON.stringify(value).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return ctx.stylize(simple,"string")}if(isNumber(value))return ctx.stylize(""+value,"number");if(isBoolean(value))return ctx.stylize(""+value,"boolean");if(isNull(value))return ctx.stylize("null","null")}function formatError(value){return"["+Error.prototype.toString.call(value)+"]"}function formatArray(ctx,value,recurseTimes,visibleKeys,keys){var output=[];for(var i=0,l=value.length;i<l;++i){if(hasOwnProperty(value,String(i))){output.push(formatProperty(ctx,value,recurseTimes,visibleKeys,String(i),true))}else{output.push("")}}keys.forEach(function(key){if(!key.match(/^\d+$/)){output.push(formatProperty(ctx,value,recurseTimes,visibleKeys,key,true))}});return output}function formatProperty(ctx,value,recurseTimes,visibleKeys,key,array){var name,str,desc;desc=Object.getOwnPropertyDescriptor(value,key)||{value:value[key]};if(desc.get){if(desc.set){str=ctx.stylize("[Getter/Setter]","special")}else{str=ctx.stylize("[Getter]","special")}}else{if(desc.set){str=ctx.stylize("[Setter]","special")}}if(!hasOwnProperty(visibleKeys,key)){name="["+key+"]"}if(!str){if(ctx.seen.indexOf(desc.value)<0){if(isNull(recurseTimes)){str=formatValue(ctx,desc.value,null)}else{str=formatValue(ctx,desc.value,recurseTimes-1)}if(str.indexOf("\n")>-1){if(array){str=str.split("\n").map(function(line){return" "+line}).join("\n").substr(2)}else{str="\n"+str.split("\n").map(function(line){return" "+line}).join("\n")}}}else{str=ctx.stylize("[Circular]","special")}}if(isUndefined(name)){if(array&&key.match(/^\d+$/)){return str}name=JSON.stringify(""+key);if(name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)){name=name.substr(1,name.length-2);name=ctx.stylize(name,"name")}else{name=name.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'");name=ctx.stylize(name,"string");
}}return name+": "+str}function reduceToSingleString(output,base,braces){var numLinesEst=0;var length=output.reduce(function(prev,cur){numLinesEst++;if(cur.indexOf("\n")>=0)numLinesEst++;return prev+cur.replace(/\u001b\[\d\d?m/g,"").length+1},0);if(length>60){return braces[0]+(base===""?"":base+"\n ")+" "+output.join(",\n ")+" "+braces[1]}return braces[0]+base+" "+output.join(", ")+" "+braces[1]}function isArray(ar){return Array.isArray(ar)}exports.isArray=isArray;function isBoolean(arg){return typeof arg==="boolean"}exports.isBoolean=isBoolean;function isNull(arg){return arg===null}exports.isNull=isNull;function isNullOrUndefined(arg){return arg==null}exports.isNullOrUndefined=isNullOrUndefined;function isNumber(arg){return typeof arg==="number"}exports.isNumber=isNumber;function isString(arg){return typeof arg==="string"}exports.isString=isString;function isSymbol(arg){return typeof arg==="symbol"}exports.isSymbol=isSymbol;function isUndefined(arg){return arg===void 0}exports.isUndefined=isUndefined;function isRegExp(re){return isObject(re)&&objectToString(re)==="[object RegExp]"}exports.isRegExp=isRegExp;function isObject(arg){return typeof arg==="object"&&arg!==null}exports.isObject=isObject;function isDate(d){return isObject(d)&&objectToString(d)==="[object Date]"}exports.isDate=isDate;function isError(e){return isObject(e)&&(objectToString(e)==="[object Error]"||e instanceof Error)}exports.isError=isError;function isFunction(arg){return typeof arg==="function"}exports.isFunction=isFunction;function isPrimitive(arg){return arg===null||typeof arg==="boolean"||typeof arg==="number"||typeof arg==="string"||typeof arg==="symbol"||typeof arg==="undefined"}exports.isPrimitive=isPrimitive;exports.isBuffer=require("./support/isBuffer");function objectToString(o){return Object.prototype.toString.call(o)}function pad(n){return n<10?"0"+n.toString(10):n.toString(10)}var months=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function timestamp(){var d=new Date;var time=[pad(d.getHours()),pad(d.getMinutes()),pad(d.getSeconds())].join(":");return[d.getDate(),months[d.getMonth()],time].join(" ")}exports.log=function(){console.log("%s - %s",timestamp(),exports.format.apply(exports,arguments))};exports.inherits=require("inherits");exports._extend=function(origin,add){if(!add||!isObject(add))return origin;var keys=Object.keys(add);var i=keys.length;while(i--){origin[keys[i]]=add[keys[i]]}return origin};function hasOwnProperty(obj,prop){return Object.prototype.hasOwnProperty.call(obj,prop)}}).call(this,require("_process"),typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{"./support/isBuffer":4,_process:3,inherits:2}],markdown:[function(require,module,exports){exports.markdown=require("./markdown");exports.parse=exports.markdown.toHTML},{"./markdown":1}]},{},[]);var markdown=require("markdown").markdown;var markdownStr=["#Hello World","somethig else","#another title"].join("\n");var htmlResult=markdown.toHTML(markdownStr);var finalResult=htmlResult.replace(/<h1>/g,"<h3>");finalResult.replace(/<\/h1>/g,"</h3>");console.log(htmlResult);console.log(finalResult)},0);
{
"name": "requirebin-sketch",
"version": "1.0.0",
"dependencies": {
"markdown": "0.5.0"
}
}
<!-- contents of this file will be placed inside the <body> -->
<!-- contents of this file will be placed inside the <head> -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment