diff --git a/README.md b/README.md index ae97eef..8bc5dfe 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ In the browser:

Hello, World!

My tasks for today:

@@ -76,8 +76,8 @@ In the terminal: ``` bash # provide HTML to be converted and print it back out to stdout: -$ md -ep "I love html.md" -I _love_ **html.md** +$ md -epi "I love html.md" +I **love** [html.md](http://neocotic.com/html.md) # convert HTML files and output them into another directory: $ md -o ./markdown ./html/*.html # convert all HTML files in the current directory into Markdown files: @@ -95,6 +95,7 @@ $ md -l . -a, --absolute always use absolute URLs for links -d, --debug print additional debug information -e, --eval pass a string from the command line as input + -i, --inline generate inline style links -l, --long-ext use long extension for Markdown files -o, --output set the output directory for converted Markdown -p, --print print out the converted Markdown @@ -127,6 +128,10 @@ The following options are recognised by this method (all of which are optional); debug Prepends additional debug information to the Markdown output + + inline + All links are generated using the inline style + ### Miscellaneous diff --git a/dist/md.min.js b/dist/md.min.js index 3e6cc8d..a437882 100644 --- a/dist/md.min.js +++ b/dist/md.min.js @@ -1,3 +1,3 @@ /*! html-md v2.1.0 | (c) 2013 Alasdair Mercer | MIT License Make.text v1.5 | (c) 2007 Trevor Jim -*/ (function(){var t,e,i,s,n,r,o,h,a,u,p,l,c,f,d,E,y,N,m,g,T,b={}.hasOwnProperty,L=this;t={absolute:!1,debug:!1},s=this.md,r={"\\\\":"\\\\","\\[":"\\[","\\]":"\\]",">":"\\>",_:"\\_","\\*":"\\*","`":"\\`","#":"\\#","([0-9])\\.(\\s|$)":"$1\\.$2","©":"(c)","®":"(r)","™":"(tm)"," ":" ","·":"\\*"," ":" "," ":" "," ":" ","‘":"'","’":"'","“":'"',"”":'"',"…":"...","–":"--","—":"---"},o=/(display|visibility)\s*:\s*[a-z]+/gi,h=/(none|hidden)\s*$/i,a=/^(APPLET|AREA|AUDIO|BUTTON|CANVAS|COMMAND|DATALIST|EMBED|HEAD|INPUT|KEYGEN|MAP|MENU|METER|NOFRAMES|NOSCRIPT|OBJECT|OPTGROUP|OPTION|PARAM|PROGRESS|RP|RT|RUBY|SCRIPT|SELECT|SOURCE|STYLE|TEXTAREA|TITLE|TRACK|VIDEO)$/,u=/^(ADDRESS|ARTICLE|ASIDE|DIV|FIELDSET|FOOTER|HEADER|NAV|P|SECTION)$/,n=function(){E={};for(c in r)b.call(r,c)&&(E[c]=RegExp(c,"g"));return E}(),N="undefined"!=typeof window&&null!==window?window:null,null==N&&(l=require("jsdom"),p=l.jsdom(null,null,{features:{FetchExternalResources:!1}}),N=p.createWindow()),i=null!=(m=N.Node)?m:{},null==(g=i.ELEMENT_NODE)&&(i.ELEMENT_NODE=1),null==(T=i.TEXT_NODE)&&(i.TEXT_NODE=3),d=function(t,e,i){var s,n;if(null==t&&(t=""),null==e&&(e=0),null==i&&(i=" "),!i)return t;for(s=n=0;e>=0?e>n:n>e;s=e>=0?++n:--n)t=i+t;return t},y=function(t){return null==t&&(t=""),t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")},e=function(){function e(e,i){var s;this.html=null!=e?e:"",this.options=null!=i?i:{},this.atLeft=this.atNoWS=this.atP=!0,this.buffer="",this.exceptions=[],this.order=1,this.listDepth=0,this.inCode=this.inPre=this.inOrderedList=!1,this.last=null,this.left="\n",this.links=[],this.linkMap={},this.unhandled={},"object"!=typeof this.options&&(this.options={});for(c in t)b.call(t,c)&&(s=t[c],this.options.hasOwnProperty(c)||(this.options[c]=s))}return e.prototype.append=function(t){return null!=this.last&&(this.buffer+=this.last),this.last=t},e.prototype.attr=function(t,e,i){var s;return null==i&&(i=!0),s=i||"function"!=typeof t.getAttribute?t[e]:t.getAttribute(e),null!=s?s:""},e.prototype.br=function(){return this.append(" "+this.left),this.atLeft=this.atNoWS=!0},e.prototype.code=function(){var t,e=this;return t=this.inCode,this.inCode=!0,function(){return e.inCode=t}},e.prototype.has=function(t,e,i){return null==i&&(i=!0),i||"function"!=typeof t.hasAttribute?t.hasOwnProperty(e):t.hasAttribute(e)},e.prototype.inCodeProcess=function(t){return t.replace(/`/g,"\\`")},e.prototype.isVisible=function(t){var e,i,s,n,r,a,u,p,l;if(r=this.attr(t,"style",!1),s=null!=r?r.match(o):void 0,u=!0,null!=s)for(p=0,l=s.length;l>p;p++)n=s[p],u=!h.test(n);if(u&&"function"==typeof N.getComputedStyle)try{r=N.getComputedStyle(t,null),"function"==typeof(null!=r?r.getPropertyValue:void 0)&&(e=r.getPropertyValue("display"),a=r.getPropertyValue("visibility"),u="none"!==e&&"hidden"!==a)}catch(c){i=c,this.thrown(i,"getComputedStyle")}return u},e.prototype.li=function(){var t;return t=this.inOrderedList?""+this.order++ +". ":"* ",t=d(t,2*(this.listDepth-1)),this.append(t)},e.prototype.nonPreProcess=function(t){var e;t=t.replace(/\n([ \t]*\n)+/g,"\n"),t=t.replace(/\n[ \t]+/g,"\n"),t=t.replace(/[ \t]+/g," ");for(c in r)b.call(r,c)&&(e=r[c],t=t.replace(n[c],e));return t},e.prototype.ol=function(){var t,e,i=this;return 0===this.listDepth&&this.p(),t=this.inOrderedList,e=this.order,this.inOrderedList=!0,this.order=1,this.listDepth++,function(){return i.inOrderedList=t,i.order=e,i.listDepth--}},e.prototype.output=function(t){return t&&(this.inPre||(t=this.atNoWS?t.replace(/^[ \t\n]+/,""):/^[ \t]*\n/.test(t)?t.replace(/^[ \t\n]+/,"\n"):t.replace(/^[ \t]+/," ")),""!==t)?(this.atP=/\n\n$/.test(t),this.atLeft=/\n$/.test(t),this.atNoWS=/[ \t\n]$/.test(t),this.append(t.replace(/\n/g,this.left))):void 0},e.prototype.outputLater=function(t){var e=this;return function(){return e.output(t)}},e.prototype.p=function(){return this.atP?void 0:(this.atLeft||(this.append(this.left),this.atLeft=!0),this.append(this.left),this.atNoWS=this.atP=!0)},e.prototype.parse=function(){var t,e,i,s,n,r,o,h;if(this.buffer="",!this.html)return this.buffer;if(t=N.document.createElement("div"),"string"==typeof this.html?t.innerHTML=this.html:t.appendChild(this.html),this.process(t),this.links.length)for(this.append("\n\n"),h=this.links,e=r=0,o=h.length;o>r;e=++r)i=h[e],i&&this.append("["+e+"]: "+i+"\n");return this.options.debug&&(n=function(){var t,e;t=this.unhandled,e=[];for(s in t)b.call(t,s)&&e.push(s);return e}.call(this).sort(),console.log(n.length?"Ignored tags;\n"+n.join(", "):"No tags were ignored"),console.log(this.exceptions.length?"Exceptions;\n"+this.exceptions.join("\n"):"No exceptions were thrown")),this.append(""),this.buffer=y(this.buffer)},e.prototype.pre=function(){var t,e=this;return t=this.inPre,this.inPre=!0,function(){return e.inPre=t}},e.prototype.process=function(t){var e,s,n,r,o,h,p,l,c,f,d,E,y,N,m,g,T;if(this.isVisible(t)){if(t.nodeType===i.ELEMENT_NODE){f=!1;try{if(a.test(t.tagName))f=!0;else if(/^H[1-6]$/.test(t.tagName))c=parseInt(t.tagName.match(/([1-6])$/)[1]),this.p(),this.output(""+function(){var t,e;for(e=[],p=t=1;c>=1?c>=t:t>=c;p=c>=1?++t:--t)e.push("#");return e}().join("")+" ");else if(u.test(t.tagName))this.p();else switch(t.tagName){case"BODY":case"FORM":break;case"DETAILS":this.p(),this.has(t,"open",!1)||(f=!0,E=t.getElementsByTagName("summary")[0],E&&this.process(E));break;case"BR":this.br();break;case"HR":this.p(),this.output("---"),this.p();break;case"CITE":case"DFN":case"EM":case"I":case"U":case"VAR":this.output("_"),this.atNoWS=!0,e=this.outputLater("_");break;case"DT":case"B":case"STRONG":"DT"===t.tagName&&this.p(),this.output("**"),this.atNoWS=!0,e=this.outputLater("**");break;case"Q":this.output('"'),this.atNoWS=!0,e=this.outputLater('"');break;case"OL":case"UL":e="OL"===t.tagName?this.ol():this.ul();break;case"LI":this.li();break;case"PRE":s=this.pushLeft(" "),n=this.pre(),e=function(){return s(),n()};break;case"CODE":case"KBD":case"SAMP":if(this.inPre)break;this.output("`"),s=this.code(),n=this.outputLater("`"),e=function(){return s(),n()};break;case"BLOCKQUOTE":case"DD":e=this.pushLeft("> ");break;case"A":if(h=this.attr(t,"href",this.options.absolute),!h)break;y=this.attr(t,"title"),y&&(h+=' "'+y+'"'),null!=this.linkMap[h]?l=this.linkMap[h]:(l=this.links.push(h)-1,this.linkMap[h]=l),this.output("["),this.atNoWS=!0,e=this.outputLater("]["+l+"]");break;case"IMG":if(f=!0,d=this.attr(t,"src",this.options.absolute),!d)break;this.output("!["+this.attr(t,"alt")+"]("+d+")");break;case"FRAME":case"IFRAME":f=!0;try{(null!=(g=t.contentDocument)?g.documentElement:void 0)&&this.process(t.contentDocument.documentElement)}catch(b){o=b,this.thrown(o,"contentDocument")}break;case"TR":e=this.p;break;default:this.options.debug&&(this.unhandled[t.tagName]=null)}}catch(b){o=b,this.thrown(o,t.tagName)}if(!f)for(T=t.childNodes,N=0,m=T.length;m>N;N++)r=T[N],this.process(r);return null!=e?e.call(this):void 0}return t.nodeType===i.TEXT_NODE?this.output(this.inPre?t.nodeValue:this.inCode?this.inCodeProcess(t.nodeValue):this.nonPreProcess(t.nodeValue)):void 0}},e.prototype.pushLeft=function(t){var e,i=this;return e=this.left,this.left+=t,this.atP?this.append(t):this.p(),function(){return i.left=e,i.atLeft=i.atP=!1,i.p()}},e.prototype.replaceLeft=function(t){return this.atLeft?this.last?this.last=this.last.replace(/[ ]{2,4}$/,t):void 0:(this.append(this.left.replace(/[ ]{2,4}$/,t)),this.atLeft=this.atNoWS=this.atP=!0)},e.prototype.thrown=function(t,e){return this.options.debug?this.exceptions.push(""+e+": "+t):void 0},e.prototype.ul=function(){var t,e,i=this;return 0===this.listDepth&&this.p(),t=this.inOrderedList,e=this.order,this.inOrderedList=!1,this.order=1,this.listDepth++,function(){return i.inOrderedList=t,i.order=e,i.listDepth--}},e}(),this.md=f=function(t,i){return new e(t,i).parse()},("undefined"!=typeof module&&null!==module?module.exports:void 0)?module.exports=f:"function"==typeof define&&define.amd&&define("md",function(){return f}),f.version=f.VERSION="2.1.0",f.noConflict=function(){return L.md=s,f}}).call(this); \ No newline at end of file +*/ (function(){var t,e,i,s,n,r,o,h,a,u,l,p,c,f,d,E,y,N,m,g,T,b={}.hasOwnProperty,L=this;t={absolute:!1,debug:!1,inline:!1},s=this.md,r={"\\\\":"\\\\","\\[":"\\[","\\]":"\\]",">":"\\>",_:"\\_","\\*":"\\*","`":"\\`","#":"\\#","([0-9])\\.(\\s|$)":"$1\\.$2","©":"(c)","®":"(r)","™":"(tm)"," ":" ","·":"\\*"," ":" "," ":" "," ":" ","‘":"'","’":"'","“":'"',"”":'"',"…":"...","–":"--","—":"---"},o=/(display|visibility)\s*:\s*[a-z]+/gi,h=/(none|hidden)\s*$/i,a=/^(APPLET|AREA|AUDIO|BUTTON|CANVAS|COMMAND|DATALIST|EMBED|HEAD|INPUT|KEYGEN|MAP|MENU|METER|NOFRAMES|NOSCRIPT|OBJECT|OPTGROUP|OPTION|PARAM|PROGRESS|RP|RT|RUBY|SCRIPT|SELECT|SOURCE|STYLE|TEXTAREA|TITLE|TRACK|VIDEO)$/,u=/^(ADDRESS|ARTICLE|ASIDE|DIV|FIELDSET|FOOTER|HEADER|NAV|P|SECTION)$/,n=function(){E={};for(c in r)b.call(r,c)&&(E[c]=RegExp(c,"g"));return E}(),N="undefined"!=typeof window&&null!==window?window:null,null==N&&(p=require("jsdom"),l=p.jsdom(null,null,{features:{FetchExternalResources:!1}}),N=l.createWindow()),i=null!=(m=N.Node)?m:{},null==(g=i.ELEMENT_NODE)&&(i.ELEMENT_NODE=1),null==(T=i.TEXT_NODE)&&(i.TEXT_NODE=3),d=function(t,e,i){var s,n;if(null==t&&(t=""),null==e&&(e=0),null==i&&(i=" "),!i)return t;for(s=n=0;e>=0?e>n:n>e;s=e>=0?++n:--n)t=i+t;return t},y=function(t){return null==t&&(t=""),t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")},e=function(){function e(e,i){var s;this.html=null!=e?e:"",this.options=null!=i?i:{},this.atLeft=this.atNoWS=this.atP=!0,this.buffer="",this.exceptions=[],this.order=1,this.listDepth=0,this.inCode=this.inPre=this.inOrderedList=!1,this.last=null,this.left="\n",this.links=[],this.linkMap={},this.unhandled={},"object"!=typeof this.options&&(this.options={});for(c in t)b.call(t,c)&&(s=t[c],this.options[c]===void 0&&(this.options[c]=s))}return e.prototype.append=function(t){return null!=this.last&&(this.buffer+=this.last),this.last=t},e.prototype.attr=function(t,e,i){var s;return null==i&&(i=!0),s=i||"function"!=typeof t.getAttribute?t[e]:t.getAttribute(e),null!=s?s:""},e.prototype.br=function(){return this.append(" "+this.left),this.atLeft=this.atNoWS=!0},e.prototype.code=function(){var t,e=this;return t=this.inCode,this.inCode=!0,function(){return e.inCode=t}},e.prototype.has=function(t,e,i){return null==i&&(i=!0),i||"function"!=typeof t.hasAttribute?t.hasOwnProperty(e):t.hasAttribute(e)},e.prototype.inCodeProcess=function(t){return t.replace(/`/g,"\\`")},e.prototype.isVisible=function(t){var e,i,s,n,r,a,u,l,p;if(r=this.attr(t,"style",!1),s=null!=r?r.match(o):void 0,u=!0,null!=s)for(l=0,p=s.length;p>l;l++)n=s[l],u=!h.test(n);if(u&&"function"==typeof N.getComputedStyle)try{r=N.getComputedStyle(t,null),"function"==typeof(null!=r?r.getPropertyValue:void 0)&&(e=r.getPropertyValue("display"),a=r.getPropertyValue("visibility"),u="none"!==e&&"hidden"!==a)}catch(c){i=c,this.thrown(i,"getComputedStyle")}return u},e.prototype.li=function(){var t;return t=this.inOrderedList?""+this.order++ +". ":"* ",t=d(t,2*(this.listDepth-1)),this.append(t)},e.prototype.nonPreProcess=function(t){var e;t=t.replace(/\n([ \t]*\n)+/g,"\n"),t=t.replace(/\n[ \t]+/g,"\n"),t=t.replace(/[ \t]+/g," ");for(c in r)b.call(r,c)&&(e=r[c],t=t.replace(n[c],e));return t},e.prototype.ol=function(){var t,e,i=this;return 0===this.listDepth&&this.p(),t=this.inOrderedList,e=this.order,this.inOrderedList=!0,this.order=1,this.listDepth++,function(){return i.inOrderedList=t,i.order=e,i.listDepth--}},e.prototype.output=function(t){return t&&(this.inPre||(t=this.atNoWS?t.replace(/^[ \t\n]+/,""):/^[ \t]*\n/.test(t)?t.replace(/^[ \t\n]+/,"\n"):t.replace(/^[ \t]+/," ")),""!==t)?(this.atP=/\n\n$/.test(t),this.atLeft=/\n$/.test(t),this.atNoWS=/[ \t\n]$/.test(t),this.append(t.replace(/\n/g,this.left))):void 0},e.prototype.outputLater=function(t){var e=this;return function(){return e.output(t)}},e.prototype.p=function(){return this.atP?void 0:(this.atLeft||(this.append(this.left),this.atLeft=!0),this.append(this.left),this.atNoWS=this.atP=!0)},e.prototype.parse=function(){var t,e,i,s,n,r,o,h;if(this.buffer="",!this.html)return this.buffer;if(t=N.document.createElement("div"),"string"==typeof this.html?t.innerHTML=this.html:t.appendChild(this.html),this.process(t),this.links.length)for(this.append("\n\n"),h=this.links,e=r=0,o=h.length;o>r;e=++r)i=h[e],i&&this.append("["+e+"]: "+i+"\n");return this.options.debug&&(n=function(){var t,e;t=this.unhandled,e=[];for(s in t)b.call(t,s)&&e.push(s);return e}.call(this).sort(),console.log(n.length?"Ignored tags;\n"+n.join(", "):"No tags were ignored"),console.log(this.exceptions.length?"Exceptions;\n"+this.exceptions.join("\n"):"No exceptions were thrown")),this.append(""),this.buffer=y(this.buffer)},e.prototype.pre=function(){var t,e=this;return t=this.inPre,this.inPre=!0,function(){return e.inPre=t}},e.prototype.process=function(t){var e,s,n,r,o,h,l,p,c,f,d,E,y,N,m,g,T,b,L;if(this.isVisible(t)){if(t.nodeType===i.ELEMENT_NODE){c=!1;try{if(a.test(t.tagName))c=!0;else if(/^H[1-6]$/.test(t.tagName))p=parseInt(t.tagName.match(/([1-6])$/)[1]),this.p(),this.output(""+function(){var t,e;for(e=[],l=t=1;p>=1?p>=t:t>=p;l=p>=1?++t:--t)e.push("#");return e}().join("")+" ");else if(u.test(t.tagName))this.p();else switch(t.tagName){case"BODY":case"FORM":break;case"DETAILS":this.p(),this.has(t,"open",!1)||(c=!0,E=t.getElementsByTagName("summary")[0],E&&this.process(E));break;case"BR":this.br();break;case"HR":this.p(),this.output("---"),this.p();break;case"CITE":case"DFN":case"EM":case"I":case"U":case"VAR":this.output("_"),this.atNoWS=!0,e=this.outputLater("_");break;case"DT":case"B":case"STRONG":"DT"===t.tagName&&this.p(),this.output("**"),this.atNoWS=!0,e=this.outputLater("**");break;case"Q":this.output('"'),this.atNoWS=!0,e=this.outputLater('"');break;case"OL":case"UL":e="OL"===t.tagName?this.ol():this.ul();break;case"LI":this.li();break;case"PRE":s=this.pushLeft(" "),n=this.pre(),e=function(){return s(),n()};break;case"CODE":case"KBD":case"SAMP":if(this.inPre)break;this.output("`"),s=this.code(),n=this.outputLater("`"),e=function(){return s(),n()};break;case"BLOCKQUOTE":case"DD":e=this.pushLeft("> ");break;case"A":if(h=this.attr(t,"href",this.options.absolute),!h)break;y=this.attr(t,"title"),y&&(h+=' "'+y+'"'),d=this.options.inline?"("+h+")":"["+(null!=(T=(N=this.linkMap)[h])?T:N[h]=this.links.push(h)-1)+"]",this.output("["),this.atNoWS=!0,e=this.outputLater("]"+d);break;case"IMG":if(c=!0,f=this.attr(t,"src",this.options.absolute),!f)break;this.output("!["+this.attr(t,"alt")+"]("+f+")");break;case"FRAME":case"IFRAME":c=!0;try{(null!=(b=t.contentDocument)?b.documentElement:void 0)&&this.process(t.contentDocument.documentElement)}catch(O){o=O,this.thrown(o,"contentDocument")}break;case"TR":e=this.p;break;default:this.options.debug&&(this.unhandled[t.tagName]=null)}}catch(O){o=O,this.thrown(o,t.tagName)}if(!c)for(L=t.childNodes,m=0,g=L.length;g>m;m++)r=L[m],this.process(r);return null!=e?e.call(this):void 0}return t.nodeType===i.TEXT_NODE?this.output(this.inPre?t.nodeValue:this.inCode?this.inCodeProcess(t.nodeValue):this.nonPreProcess(t.nodeValue)):void 0}},e.prototype.pushLeft=function(t){var e,i=this;return e=this.left,this.left+=t,this.atP?this.append(t):this.p(),function(){return i.left=e,i.atLeft=i.atP=!1,i.p()}},e.prototype.replaceLeft=function(t){return this.atLeft?this.last?this.last=this.last.replace(/[ ]{2,4}$/,t):void 0:(this.append(this.left.replace(/[ ]{2,4}$/,t)),this.atLeft=this.atNoWS=this.atP=!0)},e.prototype.thrown=function(t,e){return this.options.debug?this.exceptions.push(""+e+": "+t):void 0},e.prototype.ul=function(){var t,e,i=this;return 0===this.listDepth&&this.p(),t=this.inOrderedList,e=this.order,this.inOrderedList=!1,this.order=1,this.listDepth++,function(){return i.inOrderedList=t,i.order=e,i.listDepth--}},e}(),this.md=f=function(t,i){return new e(t,i).parse()},("undefined"!=typeof module&&null!==module?module.exports:void 0)?module.exports=f:"function"==typeof define&&define.amd&&define("md",function(){return f}),f.version=f.VERSION="2.1.0",f.noConflict=function(){return L.md=s,f}}).call(this); \ No newline at end of file diff --git a/docs/command.html b/docs/command.html index b000e25..68c6c64 100644 --- a/docs/command.html +++ b/docs/command.html @@ -44,36 +44,37 @@ throw err if err

Treat the files contents as HTML and try to parse it using md.

        parseHtml source, html.toString(), base
     else

Doesn't appear to have a recognizable HTML file extension so just ignore the file and remove it from the list of sources.

      sources.splice sources.indexOf(source), 1

Parse the HTML input and write it out accordingly.

parseHtml = (file, input, base) ->
-  try

Let md work its magic on the HTML input.

    output = md input, program

Either write the output to stdout or to a corresponding Markdown file depending on whether + try

Extract only relevant options from program.

    {absolute, debug, inline} = program

Let md work its magic on the HTML input.

    output                    = md input, {absolute, debug, inline}

Either write the output to stdout or to a corresponding Markdown file depending on whether the print option was enabled.

    if program.print then console.log output
     else if file     then writeMarkdown file, output, base
-  catch err

An error occured while parsing input, so stop processing all sources and exit, while also -letting the user know why.

    exit 1, err

Parse the options that could have been provided at runtime.

parseOptions = ->

Parse the specified options/switches/flags/whatever.

  program
+  catch err

An error occured while parsing input, so stop processing all sources and exit, while also +letting the user know why.

    exit 1, err

Parse the options that could have been provided at runtime.

parseOptions = ->

Parse the specified options/switches/flags/whatever.

  program
     .version(md.version)
     .usage('Usage: md [options] [ -e html | <file ...> ]')
     .option('-a, --absolute',     'always use absolute URLs for links')
     .option('-d, --debug',        'print additional debug information')
     .option('-e, --eval',         'pass a string from the command line as input')
+    .option('-i, --inline',       'generate inline style links')
     .option('-l, --long-ext',     'use long extension for Markdown files')
     .option('-o, --output <dir>', 'set the output directory for converted Markdown')
     .option('-p, --print',        'print out the converted Markdown')
-    .parse process.argv

Ensure that the longer Markdown file extension is used if/when the associated option is -enabled.

  extension = '.markdown' if program.longExt

All left-over arguments are considered potential HTML source files/input and will be handled as -such.

  sources   = program.args[..]

No additional arguments were specified? Then simply print out the usage as the user might not -know how to use this command.

  program.help() unless sources.length

Write the markdown converted from source to its relative output file.

writeMarkdown = (source, markdown, base) ->

Derive the best output file path based on the name of the source file.

  mdPath = outputPath source, base
-  mdDir  = path.dirname mdPath

Write markdown to its corresponding output file.

  write = (err) ->
-    throw err if err

Ensure something is always written in the file.

    markdown = ' ' if markdown.length <= 0
+    .parse process.argv

Ensure that the longer Markdown file extension is used if/when the associated option is +enabled.

  extension = '.markdown' if program.longExt

All left-over arguments are considered potential HTML source files/input and will be handled as +such.

  sources   = program.args[..]

No additional arguments were specified? Then simply print out the usage as the user might not +know how to use this command.

  program.help() unless sources.length

Write the markdown converted from source to its relative output file.

writeMarkdown = (source, markdown, base) ->

Derive the best output file path based on the name of the source file.

  mdPath = outputPath source, base
+  mdDir  = path.dirname mdPath

Write markdown to its corresponding output file.

  write = (err) ->
+    throw err if err

Ensure something is always written in the file.

    markdown = ' ' if markdown.length <= 0
     fs.writeFile mdPath, markdown, (err) ->
-      throw err if err

If the target files parent directory doesn't already exists, create it before writing to the + throw err if err

If the target files parent directory doesn't already exists, create it before writing to the file itself.

  fs.exists mdDir, (exists) ->
-    if exists then do write else fs.mkdirs mdDir, write

Public API

Handle the runtime arguments accordingly.

exports.run = ->

Try to ensure graceful exits whenever possible.

  unless process.platform is 'win32'
+    if exists then do write else fs.mkdirs mdDir, write

Public API

Handle the runtime arguments accordingly.

exports.run = ->

Try to ensure graceful exits whenever possible.

  unless process.platform is 'win32'
     process.on 'SIGTERM', ->
       do exit
 
-  try

Parse the arguments passed in at runtime as options/switches.

    do parseOptions
+  try

Parse the arguments passed in at runtime as options/switches.

    do parseOptions
 
-    if program.eval

Parse the arguments as direct HTML input and print the output to stdout.

      parseHtml null, sources[0], process.cwd()
-    else

Read each of the relevant targeted source files and parse them into HTML, sending each + if program.eval

Parse the arguments as direct HTML input and print the output to stdout.

      parseHtml null, sources[0], process.cwd()
+    else

Read each of the relevant targeted source files and parse them into HTML, sending each output either to stdout or a corresponding Markdown file, depending on what options are enabled.

      parsePath source, yes, path.normalize source for source in sources
   catch err
diff --git a/docs/md.html b/docs/md.html
index ca6171e..6285aca 100644
--- a/docs/md.html
+++ b/docs/md.html
@@ -5,8 +5,9 @@
 (c) 2007 Trevor Jim 
For all details and documentation:
http://neocotic.com/html.md

Private constants

Default option values.

DEFAULT_OPTIONS   =
-  absolute: off
-  debug:    off

Save the previous value of the global md variable for noConflict mode.

PREVIOUS_MD       = @md

Map of replacement strings for special Markdown characters.

REPLACEMENTS      =
+  absolute: no
+  debug:    no
+  inline:   no

Save the previous value of the global md variable for noConflict mode.

PREVIOUS_MD       = @md

Map of replacement strings for special Markdown characters.

REPLACEMENTS      =
   '\\\\':              '\\\\'
   '\\[':               '\\['
   '\\]':               '\\]'
@@ -107,7 +108,7 @@
     @linkMap    = {}
     @unhandled  = {}
     @options    = {} if typeof @options isnt 'object'

Copy all default option values across to options only where they were not specified.

    for own key, defaultValue of DEFAULT_OPTIONS
-      @options[key] = defaultValue unless @options.hasOwnProperty key

Append str to the buffer string.

  append: (str) ->
+      @options[key] = defaultValue if typeof @options[key] is 'undefined'

Append str to the buffer string.

  append: (str) ->
     @buffer += @last if @last?
     @last    = str

Access the value of attribute either directly or using getAttribute if possible.

  attr: (ele, attribute, direct = yes) ->
     value = if direct or typeof ele.getAttribute isnt 'function'
@@ -271,44 +272,48 @@
 Links with no URLs are treated just like text-containing elements (e.g. span). 
a.href always returns an absolute URL while a.getAttribute('href') always returns the exact value of the href attribute. For this reason we need to be sure -that we extract the URL correctly based on the state of absolute option.

              href = @attr ele, 'href', @options.absolute
+that we extract the URL correctly based on the state of the absolute option.

              href = @attr ele, 'href', @options.absolute
               break unless href

Be sure to include the title after each link reference that will be displayed at -the end of the Markdown output, where possible.

              title = @attr ele, 'title'
-              href += " \"#{title}\"" if title

Try to avoid any duplicate link references.

              if @linkMap[href]?
-                index          = @linkMap[href]
-              else
-                index          = @links.push(href) - 1
-                @linkMap[href] = index
+the end of the Markdown output, where possible.

              title  = @attr ele, 'title'
+              href  += " \"#{title}\"" if title

Determine what style the link should be generated in (i.e. inline or +reference) depending on the state of the inline option.

              suffix = if @options.inline

Inline style means all links have their URLs (and possible titles) included +immediately after their contents (e.g. +[my link](/path/to/page.html "My title")).

                "(#{href})"
+              else

Reference style means all links have an index included immediately after their +contents that directly maps to their URL (and possible title) which are displayed +at the end of the buffer string (e.g. [my link][0] and then later +[0]: /path/to/page.html "My title").
+Duplicate link/title combination references are avoided for a cleaner result.

                "[#{@linkMap[href] ?= @links.push(href) - 1}]"
 
               @output '['
               @atNoWS = yes
-              after   = @outputLater "][#{index}]"

Images are very similar to links, just without the added complexity of references.

            when 'IMG'

Extract the image URL from ele.
+ after = @outputLater "]#{suffix}"

Images are very similar to links, just without the added complexity of references.

            when 'IMG'

Extract the image URL from ele.
Unlike links, any image without a URL is just ignored. Obviously, any contents of an img element are always ignored since they can never contain anything valid.
img.src always returns an absolute URL while img.getAttribute('src') always returns the exact value of the src attribute. For this reason we need to be sure -that we extract the URL correctly based on the state of absolute option.

              skipChildren = yes
+that we extract the URL correctly based on the state of the absolute option.

              skipChildren = yes
               src          = @attr ele, 'src', @options.absolute
               break unless src
 
-              @output "![#{@attr ele, 'alt'}](#{src})"

Frames are HELL (fact!), but we'll do our best to support their contents.

            when 'FRAME', 'IFRAME'
+              @output "![#{@attr ele, 'alt'}](#{src})"

Frames are HELL (fact!), but we'll do our best to support their contents.

            when 'FRAME', 'IFRAME'
               skipChildren = yes
 
               try
                 if ele.contentDocument?.documentElement
                   @process ele.contentDocument.documentElement
               catch err
-                @thrown err, 'contentDocument'

Table rows should just be separated, that's all.

            when 'TR' then after = @p

Couldn't find a suitable match for ele so let's ignore it, but we'll still process + @thrown err, 'contentDocument'

Table rows should just be separated, that's all.

            when 'TR' then after = @p

Couldn't find a suitable match for ele so let's ignore it, but we'll still process any children it has.

            else
               @unhandled[ele.tagName] = null if @options.debug
       catch err
-        @thrown err, ele.tagName

Process all child elements of ele if it has any and we've not been told to ignore them.

      @process childNode for childNode in ele.childNodes unless skipChildren

Ensure any callback are invoked being proceeding if they are specified.

      after?.call this
-    else if ele.nodeType is Node.TEXT_NODE

Handle simple text nodes (e.g. "foo bar") according to the current context.

      @output if @inPre
+        @thrown err, ele.tagName

Process all child elements of ele if it has any and we've not been told to ignore them.

      @process childNode for childNode in ele.childNodes unless skipChildren

Ensure any callback are invoked being proceeding if they are specified.

      after?.call this
+    else if ele.nodeType is Node.TEXT_NODE

Handle simple text nodes (e.g. "foo bar") according to the current context.

      @output if @inPre
         ele.nodeValue
       else if @inCode
         @inCodeProcess ele.nodeValue
       else
-        @nonPreProcess ele.nodeValue

Attach str to the start of the current line.

  pushLeft: (str) ->
+        @nonPreProcess ele.nodeValue

Attach str to the start of the current line.

  pushLeft: (str) ->
     old    = @left
     @left += str
 
@@ -318,15 +323,15 @@
       @left   = old
       @atLeft = @atP = no
 
-      do @p

Replace the left indent with str.

  replaceLeft: (str) ->
+      do @p

Replace the left indent with str.

  replaceLeft: (str) ->
     unless @atLeft
       @append @left.replace /[ ]{2,4}$/, str
 
       @atLeft = @atNoWS = @atP = yes
     else if @last
-      @last   = @last.replace /[ ]{2,4}$/, str

Ensure that the exception and the corresponding message is logged if the debug option is + @last = @last.replace /[ ]{2,4}$/, str

Ensure that the exception and the corresponding message is logged if the debug option is enabled.

  thrown: (exception, message) ->
-    @exceptions.push "#{message}: #{exception}" if @options.debug

Prepare the parser for a ul element.

  ul: ->
+    @exceptions.push "#{message}: #{exception}" if @options.debug

Prepare the parser for a ul element.

  ul: ->
     do @p if @listDepth is 0
 
     inOrderedList  = @inOrderedList
@@ -338,11 +343,11 @@
     =>
       @inOrderedList = inOrderedList
       @order         = order
-      @listDepth--

html.md setup

Build the publicly exposed API.

@md = md = (html, options) ->
-  new HtmlParser(html, options).parse()

Export md for NodeJS and CommonJS.

if module?.exports
+      @listDepth--

html.md setup

Build the publicly exposed API.

@md = md = (html, options) ->
+  new HtmlParser(html, options).parse()

Export md for NodeJS and CommonJS.

if module?.exports
   module.exports = md
 else if typeof define is 'function' and define.amd
-  define 'md', -> md

Public constants

Current version of html.md.

md.version = md.VERSION = '2.1.0'

Public functions

Run html.md in noConflict mode, returning the md variable to its previous owner.
+ define 'md', -> md

Public constants

Current version of html.md.

md.version = md.VERSION = '2.1.0'

Public functions

Run html.md in noConflict mode, returning the md variable to its previous owner.
Returns a reference to our md.

md.noConflict = =>
   @md = PREVIOUS_MD
   md
diff --git a/lib/command.js b/lib/command.js
index 32ea155..6b45208 100644
--- a/lib/command.js
+++ b/lib/command.js
@@ -87,10 +87,15 @@
   };
 
   parseHtml = function(file, input, base) {
-    var err, output;
+    var absolute, debug, err, inline, output;
 
     try {
-      output = md(input, program);
+      absolute = program.absolute, debug = program.debug, inline = program.inline;
+      output = md(input, {
+        absolute: absolute,
+        debug: debug,
+        inline: inline
+      });
       if (program.print) {
         return console.log(output);
       } else if (file) {
@@ -103,7 +108,7 @@
   };
 
   parseOptions = function() {
-    program.version(md.version).usage('Usage: md [options] [ -e html |  ]').option('-a, --absolute', 'always use absolute URLs for links').option('-d, --debug', 'print additional debug information').option('-e, --eval', 'pass a string from the command line as input').option('-l, --long-ext', 'use long extension for Markdown files').option('-o, --output ', 'set the output directory for converted Markdown').option('-p, --print', 'print out the converted Markdown').parse(process.argv);
+    program.version(md.version).usage('Usage: md [options] [ -e html |  ]').option('-a, --absolute', 'always use absolute URLs for links').option('-d, --debug', 'print additional debug information').option('-e, --eval', 'pass a string from the command line as input').option('-i, --inline', 'generate inline style links').option('-l, --long-ext', 'use long extension for Markdown files').option('-o, --output ', 'set the output directory for converted Markdown').option('-p, --print', 'print out the converted Markdown').parse(process.argv);
     if (program.longExt) {
       extension = '.markdown';
     }
diff --git a/lib/md.js b/lib/md.js
index adf0e64..2e2ee1b 100644
--- a/lib/md.js
+++ b/lib/md.js
@@ -5,7 +5,8 @@
 
   DEFAULT_OPTIONS = {
     absolute: false,
-    debug: false
+    debug: false,
+    inline: false
   };
 
   PREVIOUS_MD = this.md;
@@ -131,7 +132,7 @@
       for (key in DEFAULT_OPTIONS) {
         if (!__hasProp.call(DEFAULT_OPTIONS, key)) continue;
         defaultValue = DEFAULT_OPTIONS[key];
-        if (!this.options.hasOwnProperty(key)) {
+        if (typeof this.options[key] === 'undefined') {
           this.options[key] = defaultValue;
         }
       }
@@ -345,7 +346,7 @@
     };
 
     HtmlParser.prototype.process = function(ele) {
-      var after, after1, after2, childNode, err, href, i, index, level, skipChildren, src, summary, title, _i, _len, _ref3, _ref4;
+      var after, after1, after2, childNode, err, href, i, level, skipChildren, src, suffix, summary, title, _base, _i, _len, _ref3, _ref4, _ref5;
 
       if (!this.isVisible(ele)) {
         return;
@@ -459,15 +460,10 @@
                 if (title) {
                   href += " \"" + title + "\"";
                 }
-                if (this.linkMap[href] != null) {
-                  index = this.linkMap[href];
-                } else {
-                  index = this.links.push(href) - 1;
-                  this.linkMap[href] = index;
-                }
+                suffix = this.options.inline ? "(" + href + ")" : "[" + ((_ref3 = (_base = this.linkMap)[href]) != null ? _ref3 : _base[href] = this.links.push(href) - 1) + "]";
                 this.output('[');
                 this.atNoWS = true;
-                after = this.outputLater("][" + index + "]");
+                after = this.outputLater("]" + suffix);
                 break;
               case 'IMG':
                 skipChildren = true;
@@ -481,7 +477,7 @@
               case 'IFRAME':
                 skipChildren = true;
                 try {
-                  if ((_ref3 = ele.contentDocument) != null ? _ref3.documentElement : void 0) {
+                  if ((_ref4 = ele.contentDocument) != null ? _ref4.documentElement : void 0) {
                     this.process(ele.contentDocument.documentElement);
                   }
                 } catch (_error) {
@@ -503,9 +499,9 @@
           this.thrown(err, ele.tagName);
         }
         if (!skipChildren) {
-          _ref4 = ele.childNodes;
-          for (_i = 0, _len = _ref4.length; _i < _len; _i++) {
-            childNode = _ref4[_i];
+          _ref5 = ele.childNodes;
+          for (_i = 0, _len = _ref5.length; _i < _len; _i++) {
+            childNode = _ref5[_i];
             this.process(childNode);
           }
         }
diff --git a/man/md.1 b/man/md.1
index 414a86a..ce2d84e 100644
--- a/man/md.1
+++ b/man/md.1
@@ -8,7 +8,7 @@
 
 .B md
 [
-.B \-adlp
+.B \-adilp
 ]
 [
 .B \-o
@@ -54,6 +54,10 @@ to print debugging messages about its progress.
 .br
 Specifies the HTML string to be evaluated.
 
+.TP
+.B \-i/\-\-inline
+Always generate Markdown links using inline style.
+
 .TP
 .B \-l/\-\-long-ext
 Generated Markdown files should have the long file
diff --git a/src/command.coffee b/src/command.coffee
index af62ee5..43ddf43 100644
--- a/src/command.coffee
+++ b/src/command.coffee
@@ -103,8 +103,10 @@ parsePath = (source, topLevel, base) ->
 # Parse the HTML `input` and write it out accordingly.
 parseHtml = (file, input, base) ->
   try
+    # Extract only relevant options from `program`.
+    {absolute, debug, inline} = program
     # Let `md` work its magic on the HTML `input`.
-    output = md input, program
+    output                    = md input, {absolute, debug, inline}
 
     # Either write the output to `stdout` or to a corresponding Markdown file depending on whether
     # the `print` option was enabled.
@@ -124,6 +126,7 @@ parseOptions = ->
     .option('-a, --absolute',     'always use absolute URLs for links')
     .option('-d, --debug',        'print additional debug information')
     .option('-e, --eval',         'pass a string from the command line as input')
+    .option('-i, --inline',       'generate inline style links')
     .option('-l, --long-ext',     'use long extension for Markdown files')
     .option('-o, --output ', 'set the output directory for converted Markdown')
     .option('-p, --print',        'print out the converted Markdown')
diff --git a/src/md.coffee b/src/md.coffee
index a3420e6..dc9f17d 100644
--- a/src/md.coffee
+++ b/src/md.coffee
@@ -11,8 +11,9 @@
 
 # Default option values.
 DEFAULT_OPTIONS   =
-  absolute: off
-  debug:    off
+  absolute: no
+  debug:    no
+  inline:   no
 # Save the previous value of the global `md` variable for *noConflict* mode.
 PREVIOUS_MD       = @md
 # Map of replacement strings for *special* Markdown characters.
@@ -157,7 +158,7 @@ class HtmlParser
 
     # Copy all default option values across to `options` only where they were not specified.
     for own key, defaultValue of DEFAULT_OPTIONS
-      @options[key] = defaultValue unless @options.hasOwnProperty key
+      @options[key] = defaultValue if typeof @options[key] is 'undefined'
 
   # Append `str` to the buffer string.
   append: (str) ->
@@ -441,25 +442,33 @@ class HtmlParser
               # Links with no URLs are treated just like text-containing elements (e.g. `span`).  
               # `a.href` always returns an absolute URL while `a.getAttribute('href')` always
               # returns the exact value of the `href` attribute. For this reason we need to be sure
-              # that we extract the URL correctly based on the state of `absolute` option.
+              # that we extract the URL correctly based on the state of the `absolute` option.
               href = @attr ele, 'href', @options.absolute
               break unless href
 
               # Be sure to include the title after each link reference that will be displayed at
               # the end of the Markdown output, where possible.
-              title = @attr ele, 'title'
-              href += " \"#{title}\"" if title
-
-              # Try to avoid any duplicate link references.
-              if @linkMap[href]?
-                index          = @linkMap[href]
+              title  = @attr ele, 'title'
+              href  += " \"#{title}\"" if title
+
+              # Determine what style the link should be generated in (i.e. *inline* or
+              # *reference*) depending on the state of the `inline` option.
+              suffix = if @options.inline
+                # *Inline* style means all links have their URLs (and possible titles) included
+                # immediately after their contents (e.g.
+                # `[my link](/path/to/page.html "My title")`).
+                "(#{href})"
               else
-                index          = @links.push(href) - 1
-                @linkMap[href] = index
+                # *Reference* style means all links have an index included immediately after their
+                # contents that directly maps to their URL (and possible title) which are displayed
+                # at the end of the buffer string (e.g. `[my link][0]` and then later
+                # `[0]: /path/to/page.html "My title"`).  
+                # Duplicate link/title combination references are avoided for a cleaner result.
+                "[#{@linkMap[href] ?= @links.push(href) - 1}]"
 
               @output '['
               @atNoWS = yes
-              after   = @outputLater "][#{index}]"
+              after   = @outputLater "]#{suffix}"
             # Images are very similar to links, just without the added complexity of references.
             when 'IMG'
               # Extract the image URL from `ele`.  
@@ -467,7 +476,7 @@ class HtmlParser
               # an `img` element are always ignored since they can never contain anything valid.  
               # `img.src` always returns an absolute URL while `img.getAttribute('src')` always
               # returns the exact value of the `src` attribute. For this reason we need to be sure
-              # that we extract the URL correctly based on the state of `absolute` option.
+              # that we extract the URL correctly based on the state of the `absolute` option.
               skipChildren = yes
               src          = @attr ele, 'src', @options.absolute
               break unless src
diff --git a/test/cli_test.coffee b/test/cli_test.coffee
index 75156e1..eafe236 100755
--- a/test/cli_test.coffee
+++ b/test/cli_test.coffee
@@ -27,6 +27,7 @@ USAGE        = """
     -a, --absolute      always use absolute URLs for links
     -d, --debug         print additional debug information
     -e, --eval          pass a string from the command line as input
+    -i, --inline        generate inline style links
     -l, --long-ext      use long extension for Markdown files
     -o, --output   set the output directory for converted Markdown
     -p, --print         print out the converted Markdown
@@ -158,6 +159,43 @@ exports.absolute = do ->
 
   """, 'Image should be absolute', '-epa')
 
+exports.inline = do ->
+  testInline = (command, expected, desc, flags) ->
+    (test) ->
+      test.expect 2
+
+      exec command, (err, stdout) ->
+        test.ifError err, "Error should not be thrown using '#{flags}' flags"
+        test.equal stdout, expected, "#{desc} using #{flags} flags"
+
+        test.done()
+
+  referenceLink: testInline("#{COMMAND} -ep \"anchor\"", """
+    [anchor][0]
+
+    [0]: mock
+
+  """, 'Link should be in reference style', '-ep')
+
+  referenceLinkWithTitle: testInline("#{COMMAND} -ep \"anchor\"",
+    """
+      [anchor][0]
+
+      [0]: mock "mocker"
+
+    """, 'Link should be in reference style with title', '-ep')
+
+  inlineLink: testInline("#{COMMAND} -epi \"anchor\"", """
+    [anchor](mock)
+
+  """, 'Link should be in inline style', '-epi')
+
+  inlineLinkWithTitle: testInline("#{COMMAND} -epi \"anchor\"",
+    """
+      [anchor](mock "mocker")
+
+    """, 'Link should be in inline style with title', '-epi')
+
 exports.stdio = (test) ->
   test.expect 2
 
diff --git a/test/core_test.coffee b/test/core_test.coffee
index e7baf73..f67d1f9 100755
--- a/test/core_test.coffee
+++ b/test/core_test.coffee
@@ -82,6 +82,29 @@ exports.options =
 
     test.done()
 
+  inline: (test) ->
+    options = inline: on
+
+    test.equal md('anchor'), """
+      [anchor][0]
+
+      [0]: mock
+    """, 'Link should be in reference style'
+
+    test.equal md('anchor'), """
+      [anchor][0]
+
+      [0]: mock "mocker"
+    """, 'Link should be in reference style with title'
+
+    test.equal md('anchor', options), '[anchor](mock)',
+      'Link should be in inline style'
+
+    test.equal md('anchor', options), '[anchor](mock "mocker")',
+      'Link should be in inline style with title'
+
+    test.done()
+
 exports.version = (test) ->
   test.equal md.version, getPackage().version, 'Version should match descriptor'
   test.done()