Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

minor code changes and added initial documentation

  • Loading branch information...
commit 0e1bf4326a0349f16f37e0b07acb9cb485730a2d 1 parent 5936abf
Alasdair Mercer authored
2  AUTHORS.md
View
@@ -1,4 +1,4 @@
# Authors ordered by first contribution
-* Trevor Jim
+* Trevor Jim <trever@research.att.com>
* Alasdair Mercer <mercer.alasdair@gmail.com>
186 docs/docco.css
View
@@ -0,0 +1,186 @@
+/*--------------------- Layout and Typography ----------------------------*/
+body {
+ font-family: 'Palatino Linotype', 'Book Antiqua', Palatino, FreeSerif, serif;
+ font-size: 15px;
+ line-height: 22px;
+ color: #252519;
+ margin: 0; padding: 0;
+}
+a {
+ color: #261a3b;
+}
+ a:visited {
+ color: #261a3b;
+ }
+p {
+ margin: 0 0 15px 0;
+}
+h1, h2, h3, h4, h5, h6 {
+ margin: 0px 0 15px 0;
+}
+ h1 {
+ margin-top: 40px;
+ }
+#container {
+ position: relative;
+}
+#background {
+ position: fixed;
+ top: 0; left: 525px; right: 0; bottom: 0;
+ background: #f5f5ff;
+ border-left: 1px solid #e5e5ee;
+ z-index: -1;
+}
+#jump_to, #jump_page {
+ background: white;
+ -webkit-box-shadow: 0 0 25px #777; -moz-box-shadow: 0 0 25px #777;
+ -webkit-border-bottom-left-radius: 5px; -moz-border-radius-bottomleft: 5px;
+ font: 10px Arial;
+ text-transform: uppercase;
+ cursor: pointer;
+ text-align: right;
+}
+#jump_to, #jump_wrapper {
+ position: fixed;
+ right: 0; top: 0;
+ padding: 5px 10px;
+}
+ #jump_wrapper {
+ padding: 0;
+ display: none;
+ }
+ #jump_to:hover #jump_wrapper {
+ display: block;
+ }
+ #jump_page {
+ padding: 5px 0 3px;
+ margin: 0 0 25px 25px;
+ }
+ #jump_page .source {
+ display: block;
+ padding: 5px 10px;
+ text-decoration: none;
+ border-top: 1px solid #eee;
+ }
+ #jump_page .source:hover {
+ background: #f5f5ff;
+ }
+ #jump_page .source:first-child {
+ }
+table td {
+ border: 0;
+ outline: 0;
+}
+ td.docs, th.docs {
+ max-width: 450px;
+ min-width: 450px;
+ min-height: 5px;
+ padding: 10px 25px 1px 50px;
+ overflow-x: hidden;
+ vertical-align: top;
+ text-align: left;
+ }
+ .docs pre {
+ margin: 15px 0 15px;
+ padding-left: 15px;
+ }
+ .docs p tt, .docs p code {
+ background: #f8f8ff;
+ border: 1px solid #dedede;
+ font-size: 12px;
+ padding: 0 0.2em;
+ }
+ .pilwrap {
+ position: relative;
+ }
+ .pilcrow {
+ font: 12px Arial;
+ text-decoration: none;
+ color: #454545;
+ position: absolute;
+ top: 3px; left: -20px;
+ padding: 1px 2px;
+ opacity: 0;
+ -webkit-transition: opacity 0.2s linear;
+ }
+ td.docs:hover .pilcrow {
+ opacity: 1;
+ }
+ td.code, th.code {
+ padding: 14px 15px 16px 25px;
+ width: 100%;
+ vertical-align: top;
+ background: #f5f5ff;
+ border-left: 1px solid #e5e5ee;
+ }
+ pre, tt, code {
+ font-size: 12px; line-height: 18px;
+ font-family: Monaco, Consolas, "Lucida Console", monospace;
+ margin: 0; padding: 0;
+ }
+
+
+/*---------------------- Syntax Highlighting -----------------------------*/
+td.linenos { background-color: #f0f0f0; padding-right: 10px; }
+span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; }
+body .hll { background-color: #ffffcc }
+body .c { color: #408080; font-style: italic } /* Comment */
+body .err { border: 1px solid #FF0000 } /* Error */
+body .k { color: #954121 } /* Keyword */
+body .o { color: #666666 } /* Operator */
+body .cm { color: #408080; font-style: italic } /* Comment.Multiline */
+body .cp { color: #BC7A00 } /* Comment.Preproc */
+body .c1 { color: #408080; font-style: italic } /* Comment.Single */
+body .cs { color: #408080; font-style: italic } /* Comment.Special */
+body .gd { color: #A00000 } /* Generic.Deleted */
+body .ge { font-style: italic } /* Generic.Emph */
+body .gr { color: #FF0000 } /* Generic.Error */
+body .gh { color: #000080; font-weight: bold } /* Generic.Heading */
+body .gi { color: #00A000 } /* Generic.Inserted */
+body .go { color: #808080 } /* Generic.Output */
+body .gp { color: #000080; font-weight: bold } /* Generic.Prompt */
+body .gs { font-weight: bold } /* Generic.Strong */
+body .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
+body .gt { color: #0040D0 } /* Generic.Traceback */
+body .kc { color: #954121 } /* Keyword.Constant */
+body .kd { color: #954121; font-weight: bold } /* Keyword.Declaration */
+body .kn { color: #954121; font-weight: bold } /* Keyword.Namespace */
+body .kp { color: #954121 } /* Keyword.Pseudo */
+body .kr { color: #954121; font-weight: bold } /* Keyword.Reserved */
+body .kt { color: #B00040 } /* Keyword.Type */
+body .m { color: #666666 } /* Literal.Number */
+body .s { color: #219161 } /* Literal.String */
+body .na { color: #7D9029 } /* Name.Attribute */
+body .nb { color: #954121 } /* Name.Builtin */
+body .nc { color: #0000FF; font-weight: bold } /* Name.Class */
+body .no { color: #880000 } /* Name.Constant */
+body .nd { color: #AA22FF } /* Name.Decorator */
+body .ni { color: #999999; font-weight: bold } /* Name.Entity */
+body .ne { color: #D2413A; font-weight: bold } /* Name.Exception */
+body .nf { color: #0000FF } /* Name.Function */
+body .nl { color: #A0A000 } /* Name.Label */
+body .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */
+body .nt { color: #954121; font-weight: bold } /* Name.Tag */
+body .nv { color: #19469D } /* Name.Variable */
+body .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */
+body .w { color: #bbbbbb } /* Text.Whitespace */
+body .mf { color: #666666 } /* Literal.Number.Float */
+body .mh { color: #666666 } /* Literal.Number.Hex */
+body .mi { color: #666666 } /* Literal.Number.Integer */
+body .mo { color: #666666 } /* Literal.Number.Oct */
+body .sb { color: #219161 } /* Literal.String.Backtick */
+body .sc { color: #219161 } /* Literal.String.Char */
+body .sd { color: #219161; font-style: italic } /* Literal.String.Doc */
+body .s2 { color: #219161 } /* Literal.String.Double */
+body .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */
+body .sh { color: #219161 } /* Literal.String.Heredoc */
+body .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */
+body .sx { color: #954121 } /* Literal.String.Other */
+body .sr { color: #BB6688 } /* Literal.String.Regex */
+body .s1 { color: #219161 } /* Literal.String.Single */
+body .ss { color: #19469D } /* Literal.String.Symbol */
+body .bp { color: #954121 } /* Name.Builtin.Pseudo */
+body .vc { color: #19469D } /* Name.Variable.Class */
+body .vg { color: #19469D } /* Name.Variable.Global */
+body .vi { color: #19469D } /* Name.Variable.Instance */
+body .il { color: #666666 } /* Literal.Number.Integer.Long */
395 docs/md.html
View
@@ -0,0 +1,395 @@
+<!DOCTYPE html> <html> <head> <title>md.js</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <link rel="stylesheet" media="all" href="docco.css" /> </head> <body> <div id="container"> <div id="background"></div> <table cellpadding="0" cellspacing="0"> <thead> <tr> <th class="docs"> <h1> md.js </h1> </th> <th class="code"> </th> </tr> </thead> <tbody> <tr id="section-1"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-1">&#182;</a> </div> <p><a href="http://neocotic.com/html.md">html.md</a> 1.0.0 <br />
+(c) 2012 Alasdair Mercer <br />
+Freely distributable under the MIT license. <br />
+Based on <a href="http://homepage.mac.com/tjim/">Make.text</a> 1.5 <br />
+(c) 2007 Trevor Jim <br />
+Licensed under the GPL Version 2 license. <br />
+For all details and documentation: <br />
+<a href="http://neocotic.com/html.md">http://neocotic.com/html.md</a></p> </td> <td class="code"> <div class="highlight"><pre><span class="p">(</span><span class="kd">function</span> <span class="p">()</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-2"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <h2>Private constants</h2> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span></pre></div> </td> </tr> <tr id="section-3"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">&#182;</a> </div> <p>Default configuration values.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">DEFAULT_CONFIG</span> <span class="o">=</span> <span class="p">{</span>
+ <span class="nx">debug</span><span class="o">:</span> <span class="kc">false</span>
+ <span class="p">},</span></pre></div> </td> </tr> <tr id="section-4"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">&#182;</a> </div> <p>Replacement strings for special Markdown characters.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">REPLACEMENTS</span> <span class="o">=</span> <span class="p">{</span>
+ <span class="s1">&#39;\\\\&#39;</span><span class="o">:</span> <span class="s1">&#39;\\\\&#39;</span><span class="p">,</span>
+ <span class="s1">&#39;\\[&#39;</span><span class="o">:</span> <span class="s1">&#39;\\[&#39;</span><span class="p">,</span>
+ <span class="s1">&#39;\\]&#39;</span><span class="o">:</span> <span class="s1">&#39;\\]&#39;</span><span class="p">,</span>
+ <span class="s1">&#39;&gt;&#39;</span><span class="o">:</span> <span class="s1">&#39;\\&gt;&#39;</span><span class="p">,</span>
+ <span class="s1">&#39;_&#39;</span><span class="o">:</span> <span class="s1">&#39;\\_&#39;</span><span class="p">,</span>
+ <span class="s1">&#39;\\*&#39;</span><span class="o">:</span> <span class="s1">&#39;\\*&#39;</span><span class="p">,</span>
+ <span class="s1">&#39;`&#39;</span><span class="o">:</span> <span class="s1">&#39;\\`&#39;</span><span class="p">,</span>
+ <span class="s1">&#39;#&#39;</span><span class="o">:</span> <span class="s1">&#39;\\#&#39;</span><span class="p">,</span>
+ <span class="s1">&#39;([0-9])\\.(\\s|$)&#39;</span><span class="o">:</span> <span class="s1">&#39;$1\\.$2&#39;</span><span class="p">,</span>
+ <span class="s1">&#39;\u00a9&#39;</span><span class="o">:</span> <span class="s1">&#39;(c)&#39;</span><span class="p">,</span>
+ <span class="s1">&#39;\u00ae&#39;</span><span class="o">:</span> <span class="s1">&#39;(r)&#39;</span><span class="p">,</span>
+ <span class="s1">&#39;\u2122&#39;</span><span class="o">:</span> <span class="s1">&#39;(tm)&#39;</span><span class="p">,</span>
+ <span class="s1">&#39;\u00a0&#39;</span><span class="o">:</span> <span class="s1">&#39; &#39;</span><span class="p">,</span>
+ <span class="s1">&#39;\u00b7&#39;</span><span class="o">:</span> <span class="s1">&#39;\\*&#39;</span><span class="p">,</span>
+ <span class="s1">&#39;\u2002&#39;</span><span class="o">:</span> <span class="s1">&#39; &#39;</span><span class="p">,</span>
+ <span class="s1">&#39;\u2003&#39;</span><span class="o">:</span> <span class="s1">&#39; &#39;</span><span class="p">,</span>
+ <span class="s1">&#39;\u2009&#39;</span><span class="o">:</span> <span class="s1">&#39; &#39;</span><span class="p">,</span>
+ <span class="s1">&#39;\u2018&#39;</span><span class="o">:</span> <span class="s1">&#39;\&#39;&#39;</span><span class="p">,</span>
+ <span class="s1">&#39;\u2019&#39;</span><span class="o">:</span> <span class="s1">&#39;\&#39;&#39;</span><span class="p">,</span>
+ <span class="s1">&#39;\u201c&#39;</span><span class="o">:</span> <span class="s1">&#39;&quot;&#39;</span><span class="p">,</span>
+ <span class="s1">&#39;\u201d&#39;</span><span class="o">:</span> <span class="s1">&#39;&quot;&#39;</span><span class="p">,</span>
+ <span class="s1">&#39;\u2026&#39;</span><span class="o">:</span> <span class="s1">&#39;...&#39;</span><span class="p">,</span>
+ <span class="s1">&#39;\u2013&#39;</span><span class="o">:</span> <span class="s1">&#39;--&#39;</span><span class="p">,</span>
+ <span class="s1">&#39;\u2014&#39;</span><span class="o">:</span> <span class="s1">&#39;---&#39;</span>
+ <span class="p">},</span></pre></div> </td> </tr> <tr id="section-5"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-5">&#182;</a> </div> <p>Create regular expressions for all of the special Markdown characters.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">REGEX</span> <span class="o">=</span> <span class="p">(</span><span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
+ <span class="kd">var</span> <span class="nx">result</span> <span class="o">=</span> <span class="p">{};</span>
+ <span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">key</span> <span class="k">in</span> <span class="nx">REPLACEMENTS</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">REPLACEMENTS</span><span class="p">.</span><span class="nx">hasOwnProperty</span><span class="p">(</span><span class="nx">key</span><span class="p">))</span> <span class="p">{</span>
+ <span class="nx">result</span><span class="p">[</span><span class="nx">key</span><span class="p">]</span> <span class="o">=</span> <span class="k">new</span> <span class="nb">RegExp</span><span class="p">(</span><span class="nx">key</span><span class="p">,</span> <span class="s1">&#39;g&#39;</span><span class="p">);</span>
+ <span class="p">}</span>
+ <span class="p">}</span>
+ <span class="k">return</span> <span class="nx">result</span><span class="p">;</span>
+ <span class="p">}());</span></pre></div> </td> </tr> <tr id="section-6"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">&#182;</a> </div> <h2>Private variables</h2> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span></pre></div> </td> </tr> <tr id="section-7"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-7">&#182;</a> </div> <p>Indicate whether or not the parser is at the beginning of a new line.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">atLeft</span> <span class="o">=</span> <span class="kc">true</span><span class="p">,</span></pre></div> </td> </tr> <tr id="section-8"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-8">&#182;</a> </div> <p>Indicate whether or not the parser is at the beginning of an indentation.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">atNoWS</span> <span class="o">=</span> <span class="kc">true</span><span class="p">,</span></pre></div> </td> </tr> <tr id="section-9"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-9">&#182;</a> </div> <p>Indicate whether or not the parser in at the beginning of a paragraph.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">atP</span> <span class="o">=</span> <span class="kc">true</span><span class="p">,</span></pre></div> </td> </tr> <tr id="section-10"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-10">&#182;</a> </div> <p>String buffer containing the parsed Markdown.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">buffer</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span><span class="p">,</span></pre></div> </td> </tr> <tr id="section-11"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-11">&#182;</a> </div> <p>Configuration, default or customized.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">config</span> <span class="o">=</span> <span class="p">{},</span></pre></div> </td> </tr> <tr id="section-12"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-12">&#182;</a> </div> <p>List of exceptions thrown while parsing the HTML. <br />
+This is only populated when debug mode is enabled.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">exceptions</span> <span class="o">=</span> <span class="p">[],</span></pre></div> </td> </tr> <tr id="section-13"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-13">&#182;</a> </div> <p>Indicate whether or not the parser is within a <code>code</code> element.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">inCode</span> <span class="o">=</span> <span class="kc">false</span><span class="p">,</span></pre></div> </td> </tr> <tr id="section-14"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-14">&#182;</a> </div> <p>Indicate whether or not the parser is within a <code>pre</code> element.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">inPre</span> <span class="o">=</span> <span class="kc">false</span><span class="p">,</span></pre></div> </td> </tr> <tr id="section-15"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-15">&#182;</a> </div> <p>Indicate whether or not the parser is within an <code>ol</code> element.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">inOrderedList</span> <span class="o">=</span> <span class="kc">false</span><span class="p">,</span></pre></div> </td> </tr> <tr id="section-16"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-16">&#182;</a> </div> <p>Markdown created from the last HTML parsed.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">last</span> <span class="o">=</span> <span class="kc">null</span><span class="p">,</span></pre></div> </td> </tr> <tr id="section-17"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-17">&#182;</a> </div> <p>Shortcut reference to append a new line.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">left</span> <span class="o">=</span> <span class="s1">&#39;\n&#39;</span><span class="p">,</span></pre></div> </td> </tr> <tr id="section-18"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-18">&#182;</a> </div> <p>List of URLs for all previously parsed unique anchors.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">links</span> <span class="o">=</span> <span class="p">[],</span></pre></div> </td> </tr> <tr id="section-19"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-19">&#182;</a> </div> <p>List of titles for all previously parsed unique anchors.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">linkTitles</span> <span class="o">=</span> <span class="p">[],</span></pre></div> </td> </tr> <tr id="section-20"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-20">&#182;</a> </div> <p>Save the previous value of the <code>md</code> variable.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">previousMd</span> <span class="o">=</span> <span class="nb">window</span><span class="p">.</span><span class="nx">md</span><span class="p">,</span></pre></div> </td> </tr> <tr id="section-21"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-21">&#182;</a> </div> <p>Map of anchor URLs to their corresponding reference index.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">rlinks</span> <span class="o">=</span> <span class="p">{},</span></pre></div> </td> </tr> <tr id="section-22"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-22">&#182;</a> </div> <p>List of tag names that were not handled by the parser. <br />
+This is only populated when debug mode is enabled.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">unhandled</span> <span class="o">=</span> <span class="p">{};</span></pre></div> </td> </tr> <tr id="section-23"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-23">&#182;</a> </div> <p>Try to ensure Node is available with the required constants.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">Node</span> <span class="o">=</span> <span class="p">(</span><span class="k">typeof</span> <span class="nx">Node</span> <span class="o">===</span> <span class="s1">&#39;undefined&#39;</span><span class="p">)</span> <span class="o">?</span> <span class="p">{}</span> <span class="o">:</span> <span class="nx">Node</span><span class="p">;</span>
+ <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">Node</span><span class="p">.</span><span class="nx">ELEMENT_NODE</span><span class="p">)</span> <span class="nx">Node</span><span class="p">.</span><span class="nx">ELEMENT_NODE</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
+ <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">Node</span><span class="p">.</span><span class="nx">TEXT_NODE</span><span class="p">)</span> <span class="nx">Node</span><span class="p">.</span><span class="nx">TEXT_NODE</span> <span class="o">=</span> <span class="mi">3</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-24"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-24">&#182;</a> </div> <h2>Private functions</h2> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-25"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-25">&#182;</a> </div> <p>Append <code>str</code> to the buffer string.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">append</span><span class="p">(</span><span class="nx">str</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">last</span> <span class="o">!=</span> <span class="kc">null</span><span class="p">)</span> <span class="nx">buffer</span> <span class="o">+=</span> <span class="nx">last</span><span class="p">;</span>
+ <span class="nx">last</span> <span class="o">=</span> <span class="nx">str</span><span class="p">;</span>
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-26"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-26">&#182;</a> </div> <p>Append a Markdown line break to the buffer string.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">br</span><span class="p">()</span> <span class="p">{</span>
+ <span class="nx">append</span><span class="p">(</span><span class="s1">&#39; &#39;</span> <span class="o">+</span> <span class="nx">left</span><span class="p">);</span>
+ <span class="nx">atLeft</span> <span class="o">=</span> <span class="nx">atNoWS</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span>
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-27"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-27">&#182;</a> </div> <p>Prepare the parser for a <code>code</code> element.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">code</span><span class="p">()</span> <span class="p">{</span>
+ <span class="kd">var</span> <span class="nx">old</span> <span class="o">=</span> <span class="nx">inCode</span><span class="p">;</span>
+ <span class="nx">inCode</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span>
+ <span class="k">return</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
+ <span class="nx">inCode</span> <span class="o">=</span> <span class="nx">old</span><span class="p">;</span>
+ <span class="p">};</span>
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-28"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-28">&#182;</a> </div> <p>Replace any special characters that can cause problems within code.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">inCodeProcess</span><span class="p">(</span><span class="nx">str</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">return</span> <span class="nx">str</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/`/g</span><span class="p">,</span> <span class="s1">&#39;\\`&#39;</span><span class="p">);</span>
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-29"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-29">&#182;</a> </div> <p>Replace any special characters that can cause problems in normal Markdown.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">nonPreProcess</span><span class="p">(</span><span class="nx">str</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">str</span> <span class="o">=</span> <span class="nx">str</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/\n([ \t]*\n)+/g</span><span class="p">,</span> <span class="s1">&#39;\n&#39;</span><span class="p">);</span>
+ <span class="nx">str</span> <span class="o">=</span> <span class="nx">str</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/\n[ \t]+/g</span><span class="p">,</span> <span class="s1">&#39;\n&#39;</span><span class="p">);</span>
+ <span class="nx">str</span> <span class="o">=</span> <span class="nx">str</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/[ \t]+/g</span><span class="p">,</span> <span class="s1">&#39; &#39;</span><span class="p">);</span>
+ <span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">key</span> <span class="k">in</span> <span class="nx">REPLACEMENTS</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">REPLACEMENTS</span><span class="p">.</span><span class="nx">hasOwnProperty</span><span class="p">(</span><span class="nx">key</span><span class="p">))</span> <span class="p">{</span>
+ <span class="nx">str</span> <span class="o">=</span> <span class="nx">str</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="nx">REGEX</span><span class="p">[</span><span class="nx">key</span><span class="p">],</span> <span class="nx">REPLACEMENTS</span><span class="p">[</span><span class="nx">key</span><span class="p">]);</span>
+ <span class="p">}</span>
+ <span class="p">}</span>
+ <span class="k">return</span> <span class="nx">str</span><span class="p">;</span>
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-30"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-30">&#182;</a> </div> <p>Prepare the parser for an <code>ol</code> element.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">ol</span><span class="p">()</span> <span class="p">{</span>
+ <span class="kd">var</span> <span class="nx">old</span> <span class="o">=</span> <span class="nx">inOrderedList</span><span class="p">;</span>
+ <span class="nx">inOrderedList</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span>
+ <span class="k">return</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
+ <span class="nx">inOrderedList</span> <span class="o">=</span> <span class="nx">old</span><span class="p">;</span>
+ <span class="p">};</span>
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-31"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-31">&#182;</a> </div> <p>Append <code>str</code> to the buffer string while keeping the parser in context.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">output</span><span class="p">(</span><span class="nx">str</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">str</span><span class="p">)</span> <span class="k">return</span><span class="p">;</span>
+ <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">inPre</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">atNoWS</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">str</span> <span class="o">=</span> <span class="nx">str</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/^[ \t\n]+/</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">);</span>
+ <span class="p">}</span> <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="sr">/^[ \t]*\n/</span><span class="p">.</span><span class="nx">test</span><span class="p">(</span><span class="nx">str</span><span class="p">))</span> <span class="p">{</span>
+ <span class="nx">str</span> <span class="o">=</span> <span class="nx">str</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/^[ \t\n]+/</span><span class="p">,</span> <span class="s1">&#39;\n&#39;</span><span class="p">);</span>
+ <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
+ <span class="nx">str</span> <span class="o">=</span> <span class="nx">str</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/^[ \t]+/</span><span class="p">,</span> <span class="s1">&#39; &#39;</span><span class="p">);</span>
+ <span class="p">}</span>
+ <span class="p">}</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">str</span> <span class="o">===</span> <span class="s1">&#39;&#39;</span><span class="p">)</span> <span class="k">return</span><span class="p">;</span>
+ <span class="nx">atP</span> <span class="o">=</span> <span class="sr">/\n\n$/</span><span class="p">.</span><span class="nx">test</span><span class="p">(</span><span class="nx">str</span><span class="p">);</span>
+ <span class="nx">atLeft</span> <span class="o">=</span> <span class="sr">/\n$/</span><span class="p">.</span><span class="nx">test</span><span class="p">(</span><span class="nx">str</span><span class="p">);</span>
+ <span class="nx">atNoWS</span> <span class="o">=</span> <span class="sr">/[ \t\n]$/</span><span class="p">.</span><span class="nx">test</span><span class="p">(</span><span class="nx">str</span><span class="p">);</span>
+ <span class="nx">append</span><span class="p">(</span><span class="nx">str</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/\n/g</span><span class="p">,</span> <span class="nx">left</span><span class="p">));</span>
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-32"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-32">&#182;</a> </div> <p>Create a function that can be called later to append <code>str</code> to the buffer
+string while keeping the parser in context.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">outputLater</span><span class="p">(</span><span class="nx">str</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">return</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
+ <span class="nx">output</span><span class="p">(</span><span class="nx">str</span><span class="p">);</span>
+ <span class="p">};</span>
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-33"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-33">&#182;</a> </div> <p>Append a Markdown paragraph to the buffer string.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">p</span><span class="p">()</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">atP</span><span class="p">)</span> <span class="k">return</span><span class="p">;</span>
+ <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">atLeft</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">append</span><span class="p">(</span><span class="nx">left</span><span class="p">);</span>
+ <span class="nx">atLeft</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span>
+ <span class="p">}</span>
+ <span class="nx">append</span><span class="p">(</span><span class="nx">left</span><span class="p">);</span>
+ <span class="nx">atNoWS</span> <span class="o">=</span> <span class="nx">atP</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span>
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-34"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-34">&#182;</a> </div> <p>Prepare the parser for a <code>pre</code> element.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">pre</span><span class="p">()</span> <span class="p">{</span>
+ <span class="kd">var</span> <span class="nx">old</span> <span class="o">=</span> <span class="nx">inPre</span><span class="p">;</span>
+ <span class="nx">inPre</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span>
+ <span class="k">return</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
+ <span class="nx">inPre</span> <span class="o">=</span> <span class="nx">old</span><span class="p">;</span>
+ <span class="p">};</span>
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-35"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-35">&#182;</a> </div> <p>Parse the specified element and append the generated Markdown to the buffer
+string.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">process</span><span class="p">(</span><span class="nx">e</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="k">typeof</span> <span class="nx">getComputedStyle</span> <span class="o">!==</span> <span class="s1">&#39;undefined&#39;</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">try</span> <span class="p">{</span>
+ <span class="kd">var</span> <span class="nx">style</span> <span class="o">=</span> <span class="nx">getComputedStyle</span><span class="p">(</span><span class="nx">e</span><span class="p">,</span> <span class="kc">null</span><span class="p">);</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">style</span> <span class="o">&amp;&amp;</span> <span class="nx">style</span><span class="p">.</span><span class="nx">getPropertyValue</span> <span class="o">&amp;&amp;</span> <span class="nx">style</span><span class="p">.</span><span class="nx">getPropertyValue</span><span class="p">(</span><span class="s1">&#39;display&#39;</span><span class="p">)</span> <span class="o">===</span> <span class="s1">&#39;none&#39;</span><span class="p">)</span> <span class="k">return</span><span class="p">;</span>
+ <span class="p">}</span> <span class="k">catch</span> <span class="p">(</span><span class="nx">ex</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">thrown</span><span class="p">(</span><span class="nx">ex</span><span class="p">,</span> <span class="s1">&#39;getComputedStyle&#39;</span><span class="p">);</span>
+ <span class="p">}</span>
+ <span class="p">}</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">e</span><span class="p">.</span><span class="nx">nodeType</span> <span class="o">===</span> <span class="nx">Node</span><span class="p">.</span><span class="nx">ELEMENT_NODE</span><span class="p">)</span> <span class="p">{</span>
+ <span class="kd">var</span>
+ <span class="nx">after</span> <span class="o">=</span> <span class="kc">null</span><span class="p">,</span>
+ <span class="nx">after1</span> <span class="o">=</span> <span class="kc">null</span><span class="p">,</span>
+ <span class="nx">after2</span> <span class="o">=</span> <span class="kc">null</span><span class="p">,</span>
+ <span class="nx">skipChildren</span> <span class="o">=</span> <span class="kc">false</span><span class="p">;</span>
+ <span class="k">try</span> <span class="p">{</span>
+ <span class="k">switch</span> <span class="p">(</span><span class="nx">e</span><span class="p">.</span><span class="nx">tagName</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">case</span> <span class="s1">&#39;HEAD&#39;</span><span class="o">:</span>
+ <span class="k">case</span> <span class="s1">&#39;STYLE&#39;</span><span class="o">:</span>
+ <span class="k">case</span> <span class="s1">&#39;SCRIPT&#39;</span><span class="o">:</span>
+ <span class="k">case</span> <span class="s1">&#39;SELECT&#39;</span><span class="o">:</span>
+ <span class="k">case</span> <span class="s1">&#39;OPTION&#39;</span><span class="o">:</span>
+ <span class="k">case</span> <span class="s1">&#39;NOSCRIPT&#39;</span><span class="o">:</span>
+ <span class="k">case</span> <span class="s1">&#39;NOFRAMES&#39;</span><span class="o">:</span>
+ <span class="k">case</span> <span class="s1">&#39;INPUT&#39;</span><span class="o">:</span>
+ <span class="k">case</span> <span class="s1">&#39;BUTTON&#39;</span><span class="o">:</span>
+ <span class="k">case</span> <span class="s1">&#39;SELECT&#39;</span><span class="o">:</span>
+ <span class="k">case</span> <span class="s1">&#39;TEXTAREA&#39;</span><span class="o">:</span>
+ <span class="k">case</span> <span class="s1">&#39;LABEL&#39;</span><span class="o">:</span>
+ <span class="nx">skipChildren</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span>
+ <span class="k">break</span><span class="p">;</span>
+ <span class="k">case</span> <span class="s1">&#39;BODY&#39;</span><span class="o">:</span>
+ <span class="k">case</span> <span class="s1">&#39;FORM&#39;</span><span class="o">:</span>
+ <span class="k">break</span><span class="p">;</span>
+ <span class="k">case</span> <span class="s1">&#39;H1&#39;</span><span class="o">:</span>
+ <span class="nx">p</span><span class="p">();</span>
+ <span class="nx">output</span><span class="p">(</span><span class="s1">&#39;# &#39;</span><span class="p">);</span>
+ <span class="k">break</span><span class="p">;</span>
+ <span class="k">case</span> <span class="s1">&#39;H2&#39;</span><span class="o">:</span>
+ <span class="nx">p</span><span class="p">();</span>
+ <span class="nx">output</span><span class="p">(</span><span class="s1">&#39;## &#39;</span><span class="p">);</span>
+ <span class="k">break</span><span class="p">;</span>
+ <span class="k">case</span> <span class="s1">&#39;H3&#39;</span><span class="o">:</span>
+ <span class="nx">p</span><span class="p">();</span>
+ <span class="nx">output</span><span class="p">(</span><span class="s1">&#39;### &#39;</span><span class="p">);</span>
+ <span class="k">break</span><span class="p">;</span>
+ <span class="k">case</span> <span class="s1">&#39;H4&#39;</span><span class="o">:</span>
+ <span class="nx">p</span><span class="p">();</span>
+ <span class="nx">output</span><span class="p">(</span><span class="s1">&#39;#### &#39;</span><span class="p">);</span>
+ <span class="k">break</span><span class="p">;</span>
+ <span class="k">case</span> <span class="s1">&#39;H5&#39;</span><span class="o">:</span>
+ <span class="nx">p</span><span class="p">();</span>
+ <span class="nx">output</span><span class="p">(</span><span class="s1">&#39;##### &#39;</span><span class="p">);</span>
+ <span class="k">break</span><span class="p">;</span>
+ <span class="k">case</span> <span class="s1">&#39;H6&#39;</span><span class="o">:</span>
+ <span class="nx">p</span><span class="p">();</span>
+ <span class="nx">output</span><span class="p">(</span><span class="s1">&#39;###### &#39;</span><span class="p">);</span>
+ <span class="k">break</span><span class="p">;</span>
+ <span class="k">case</span> <span class="s1">&#39;P&#39;</span><span class="o">:</span>
+ <span class="k">case</span> <span class="s1">&#39;DIV&#39;</span><span class="o">:</span>
+ <span class="nx">p</span><span class="p">();</span>
+ <span class="k">break</span><span class="p">;</span>
+ <span class="k">case</span> <span class="s1">&#39;BR&#39;</span><span class="o">:</span>
+ <span class="nx">br</span><span class="p">();</span>
+ <span class="k">break</span><span class="p">;</span>
+ <span class="k">case</span> <span class="s1">&#39;HR&#39;</span><span class="o">:</span>
+ <span class="nx">p</span><span class="p">();</span>
+ <span class="nx">output</span><span class="p">(</span><span class="s1">&#39;--------------------------------&#39;</span><span class="p">);</span>
+ <span class="nx">p</span><span class="p">();</span>
+ <span class="k">break</span><span class="p">;</span>
+ <span class="k">case</span> <span class="s1">&#39;EM&#39;</span><span class="o">:</span>
+ <span class="k">case</span> <span class="s1">&#39;I&#39;</span><span class="o">:</span>
+ <span class="k">case</span> <span class="s1">&#39;U&#39;</span><span class="o">:</span>
+ <span class="nx">output</span><span class="p">(</span><span class="s1">&#39;_&#39;</span><span class="p">);</span>
+ <span class="nx">atNoWS</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span>
+ <span class="nx">after</span> <span class="o">=</span> <span class="nx">outputLater</span><span class="p">(</span><span class="s1">&#39;_&#39;</span><span class="p">);</span>
+ <span class="k">break</span><span class="p">;</span>
+ <span class="k">case</span> <span class="s1">&#39;DT&#39;</span><span class="o">:</span>
+ <span class="nx">p</span><span class="p">();</span>
+ <span class="k">case</span> <span class="s1">&#39;STRONG&#39;</span><span class="o">:</span>
+ <span class="k">case</span> <span class="s1">&#39;B&#39;</span><span class="o">:</span>
+ <span class="nx">output</span><span class="p">(</span><span class="s1">&#39;**&#39;</span><span class="p">);</span>
+ <span class="nx">atNoWS</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span>
+ <span class="nx">after</span> <span class="o">=</span> <span class="nx">outputLater</span><span class="p">(</span><span class="s1">&#39;**&#39;</span><span class="p">);</span>
+ <span class="k">break</span><span class="p">;</span>
+ <span class="k">case</span> <span class="s1">&#39;OL&#39;</span><span class="o">:</span>
+ <span class="nx">after1</span> <span class="o">=</span> <span class="nx">pushLeft</span><span class="p">(</span><span class="s1">&#39; &#39;</span><span class="p">);</span>
+ <span class="nx">after2</span> <span class="o">=</span> <span class="nx">ol</span><span class="p">();</span>
+ <span class="nx">after</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
+ <span class="nx">after1</span><span class="p">();</span>
+ <span class="nx">after2</span><span class="p">();</span>
+ <span class="p">};</span>
+ <span class="k">break</span><span class="p">;</span>
+ <span class="k">case</span> <span class="s1">&#39;UL&#39;</span><span class="o">:</span>
+ <span class="nx">after1</span> <span class="o">=</span> <span class="nx">pushLeft</span><span class="p">(</span><span class="s1">&#39; &#39;</span><span class="p">);</span>
+ <span class="nx">after2</span> <span class="o">=</span> <span class="nx">ul</span><span class="p">();</span>
+ <span class="nx">after</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
+ <span class="nx">after1</span><span class="p">();</span>
+ <span class="nx">after2</span><span class="p">();</span>
+ <span class="p">};</span>
+ <span class="k">break</span><span class="p">;</span>
+ <span class="k">case</span> <span class="s1">&#39;LI&#39;</span><span class="o">:</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">inOrderedList</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">replaceLeft</span><span class="p">(</span><span class="s1">&#39;1. &#39;</span><span class="p">);</span>
+ <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
+ <span class="nx">replaceLeft</span><span class="p">(</span><span class="s1">&#39;* &#39;</span><span class="p">);</span>
+ <span class="p">}</span>
+ <span class="k">break</span><span class="p">;</span>
+ <span class="k">case</span> <span class="s1">&#39;PRE&#39;</span><span class="o">:</span>
+ <span class="nx">after1</span> <span class="o">=</span> <span class="nx">pushLeft</span><span class="p">(</span><span class="s1">&#39; &#39;</span><span class="p">);</span>
+ <span class="nx">after2</span> <span class="o">=</span> <span class="nx">pre</span><span class="p">();</span>
+ <span class="nx">after</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
+ <span class="nx">after1</span><span class="p">();</span>
+ <span class="nx">after2</span><span class="p">();</span>
+ <span class="p">};</span>
+ <span class="k">break</span><span class="p">;</span>
+ <span class="k">case</span> <span class="s1">&#39;CODE&#39;</span><span class="o">:</span>
+ <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">inPre</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">output</span><span class="p">(</span><span class="s1">&#39;`&#39;</span><span class="p">);</span>
+ <span class="nx">after1</span> <span class="o">=</span> <span class="nx">code</span><span class="p">();</span>
+ <span class="nx">after2</span> <span class="o">=</span> <span class="nx">outputLater</span><span class="p">(</span><span class="s1">&#39;`&#39;</span><span class="p">);</span>
+ <span class="nx">after</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
+ <span class="nx">after1</span><span class="p">();</span>
+ <span class="nx">after2</span><span class="p">();</span>
+ <span class="p">};</span>
+ <span class="p">}</span>
+ <span class="k">break</span><span class="p">;</span>
+ <span class="k">case</span> <span class="s1">&#39;DD&#39;</span><span class="o">:</span>
+ <span class="k">case</span> <span class="s1">&#39;BLOCKQUOTE&#39;</span><span class="o">:</span>
+ <span class="nx">after</span> <span class="o">=</span> <span class="nx">pushLeft</span><span class="p">(</span><span class="s1">&#39;&gt; &#39;</span><span class="p">);</span>
+ <span class="k">break</span><span class="p">;</span>
+ <span class="k">case</span> <span class="s1">&#39;A&#39;</span><span class="o">:</span>
+ <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">e</span><span class="p">.</span><span class="nx">href</span><span class="p">)</span> <span class="k">break</span><span class="p">;</span>
+ <span class="kd">var</span> <span class="nx">index</span><span class="p">;</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">rlinks</span><span class="p">[</span><span class="nx">e</span><span class="p">.</span><span class="nx">href</span><span class="p">])</span> <span class="p">{</span>
+ <span class="nx">index</span> <span class="o">=</span> <span class="nx">rlinks</span><span class="p">[</span><span class="nx">e</span><span class="p">.</span><span class="nx">href</span><span class="p">];</span>
+ <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
+ <span class="nx">index</span> <span class="o">=</span> <span class="nx">links</span><span class="p">.</span><span class="nx">length</span><span class="p">;</span>
+ <span class="nx">links</span><span class="p">[</span><span class="nx">index</span><span class="p">]</span> <span class="o">=</span> <span class="nx">e</span><span class="p">.</span><span class="nx">href</span><span class="p">;</span>
+ <span class="nx">rlinks</span><span class="p">[</span><span class="nx">e</span><span class="p">.</span><span class="nx">href</span><span class="p">]</span> <span class="o">=</span> <span class="nx">index</span><span class="p">;</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">e</span><span class="p">.</span><span class="nx">title</span><span class="p">)</span> <span class="nx">linkTitles</span><span class="p">[</span><span class="nx">index</span><span class="p">]</span> <span class="o">=</span> <span class="nx">e</span><span class="p">.</span><span class="nx">title</span><span class="p">;</span>
+ <span class="p">}</span>
+ <span class="nx">output</span><span class="p">(</span><span class="s1">&#39;[&#39;</span><span class="p">);</span>
+ <span class="nx">atNoWS</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span>
+ <span class="nx">after</span> <span class="o">=</span> <span class="nx">outputLater</span><span class="p">(</span><span class="s1">&#39;][&#39;</span> <span class="o">+</span> <span class="nx">index</span> <span class="o">+</span> <span class="s1">&#39;]&#39;</span><span class="p">);</span>
+ <span class="k">break</span><span class="p">;</span>
+ <span class="k">case</span> <span class="s1">&#39;IMG&#39;</span><span class="o">:</span>
+ <span class="nx">skipChildren</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span>
+ <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">e</span><span class="p">.</span><span class="nx">src</span><span class="p">)</span> <span class="k">break</span><span class="p">;</span>
+ <span class="nx">output</span><span class="p">(</span><span class="s1">&#39;![&#39;</span> <span class="o">+</span> <span class="nx">e</span><span class="p">.</span><span class="nx">alt</span> <span class="o">+</span> <span class="s1">&#39;](&#39;</span> <span class="o">+</span> <span class="nx">e</span><span class="p">.</span><span class="nx">src</span> <span class="o">+</span> <span class="s1">&#39;)&#39;</span><span class="p">);</span>
+ <span class="k">break</span><span class="p">;</span>
+ <span class="k">case</span> <span class="s1">&#39;IFRAME&#39;</span><span class="o">:</span>
+ <span class="k">case</span> <span class="s1">&#39;FRAME&#39;</span><span class="o">:</span>
+ <span class="nx">skipChildren</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span>
+ <span class="k">try</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">e</span><span class="p">.</span><span class="nx">contentDocument</span> <span class="o">&amp;&amp;</span> <span class="nx">e</span><span class="p">.</span><span class="nx">contentDocument</span><span class="p">.</span><span class="nx">documentElement</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">process</span><span class="p">(</span><span class="nx">e</span><span class="p">.</span><span class="nx">contentDocument</span><span class="p">.</span><span class="nx">documentElement</span><span class="p">);</span>
+ <span class="p">}</span>
+ <span class="p">}</span> <span class="k">catch</span> <span class="p">(</span><span class="nx">ex</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">thrown</span><span class="p">(</span><span class="nx">ex</span><span class="p">,</span> <span class="s1">&#39;contentDocument&#39;</span><span class="p">);</span>
+ <span class="p">}</span>
+ <span class="k">break</span><span class="p">;</span>
+ <span class="k">case</span> <span class="s1">&#39;TR&#39;</span><span class="o">:</span>
+ <span class="nx">after</span> <span class="o">=</span> <span class="nx">p</span><span class="p">;</span>
+ <span class="k">break</span><span class="p">;</span>
+ <span class="k">default</span><span class="o">:</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">config</span><span class="p">.</span><span class="nx">debug</span><span class="p">)</span> <span class="nx">unhandled</span><span class="p">[</span><span class="nx">e</span><span class="p">.</span><span class="nx">tagName</span><span class="p">]</span> <span class="o">=</span> <span class="kc">null</span><span class="p">;</span>
+ <span class="k">break</span><span class="p">;</span>
+ <span class="p">}</span>
+ <span class="p">}</span> <span class="k">catch</span> <span class="p">(</span><span class="nx">ex</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">thrown</span><span class="p">(</span><span class="nx">ex</span><span class="p">,</span> <span class="nx">e</span><span class="p">.</span><span class="nx">tagName</span><span class="p">);</span>
+ <span class="p">}</span>
+ <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">skipChildren</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="nx">i</span> <span class="o">&lt;</span> <span class="nx">e</span><span class="p">.</span><span class="nx">childNodes</span><span class="p">.</span><span class="nx">length</span><span class="p">;</span> <span class="nx">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">process</span><span class="p">(</span><span class="nx">e</span><span class="p">.</span><span class="nx">childNodes</span><span class="p">[</span><span class="nx">i</span><span class="p">]);</span>
+ <span class="p">}</span>
+ <span class="p">}</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">after</span><span class="p">)</span> <span class="nx">after</span><span class="p">();</span>
+ <span class="p">}</span> <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="nx">e</span><span class="p">.</span><span class="nx">nodeType</span> <span class="o">===</span> <span class="nx">Node</span><span class="p">.</span><span class="nx">TEXT_NODE</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">inPre</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">output</span><span class="p">(</span><span class="nx">e</span><span class="p">.</span><span class="nx">nodeValue</span><span class="p">);</span>
+ <span class="p">}</span> <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="nx">inCode</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">output</span><span class="p">(</span><span class="nx">inCodeProcess</span><span class="p">(</span><span class="nx">e</span><span class="p">.</span><span class="nx">nodeValue</span><span class="p">));</span>
+ <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
+ <span class="nx">output</span><span class="p">(</span><span class="nx">nonPreProcess</span><span class="p">(</span><span class="nx">e</span><span class="p">.</span><span class="nx">nodeValue</span><span class="p">));</span>
+ <span class="p">}</span>
+ <span class="p">}</span>
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-36"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-36">&#182;</a> </div> <p>Attach <code>str</code> to the start of the current line.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">pushLeft</span><span class="p">(</span><span class="nx">str</span><span class="p">)</span> <span class="p">{</span>
+ <span class="kd">var</span> <span class="nx">oldLeft</span> <span class="o">=</span> <span class="nx">left</span><span class="p">;</span>
+ <span class="nx">left</span> <span class="o">+=</span> <span class="nx">str</span><span class="p">;</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">atP</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">append</span><span class="p">(</span><span class="nx">str</span><span class="p">);</span>
+ <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
+ <span class="nx">p</span><span class="p">();</span>
+ <span class="p">}</span>
+ <span class="k">return</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
+ <span class="nx">left</span> <span class="o">=</span> <span class="nx">oldLeft</span><span class="p">;</span>
+ <span class="nx">atLeft</span> <span class="o">=</span> <span class="nx">atP</span> <span class="o">=</span> <span class="kc">false</span><span class="p">;</span>
+ <span class="nx">p</span><span class="p">();</span>
+ <span class="p">};</span>
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-37"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-37">&#182;</a> </div> <p>Replace the left indent with <code>str</code>.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">replaceLeft</span><span class="p">(</span><span class="nx">str</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">atLeft</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">append</span><span class="p">(</span><span class="nx">left</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/[ ]{4}$/</span><span class="p">,</span> <span class="nx">str</span><span class="p">));</span>
+ <span class="nx">atLeft</span> <span class="o">=</span> <span class="nx">atNoWS</span> <span class="o">=</span> <span class="nx">atP</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span>
+ <span class="p">}</span> <span class="k">else</span> <span class="k">if</span> <span class="p">(</span><span class="nx">last</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">last</span> <span class="o">=</span> <span class="nx">last</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/[ ]{4}$/</span><span class="p">,</span> <span class="nx">str</span><span class="p">);</span>
+ <span class="p">}</span>
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-38"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-38">&#182;</a> </div> <p>Reset the variables used by the parser and configure it using the <code>options</code>
+provided.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">resetAndConfigure</span><span class="p">(</span><span class="nx">options</span><span class="p">)</span> <span class="p">{</span></pre></div> </td> </tr> <tr id="section-39"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-39">&#182;</a> </div> <p>Reset necessary variables.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">atLeft</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span>
+ <span class="nx">atNoWS</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span>
+ <span class="nx">atP</span> <span class="o">=</span> <span class="kc">true</span><span class="p">;</span>
+ <span class="nx">buffer</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span><span class="p">;</span>
+ <span class="nx">exceptions</span> <span class="o">=</span> <span class="p">[];</span>
+ <span class="nx">inCode</span> <span class="o">=</span> <span class="kc">false</span><span class="p">;</span>
+ <span class="nx">inPre</span> <span class="o">=</span> <span class="kc">false</span><span class="p">;</span>
+ <span class="nx">inOrderedList</span> <span class="o">=</span> <span class="kc">false</span><span class="p">;</span>
+ <span class="nx">last</span> <span class="o">=</span> <span class="kc">null</span><span class="p">;</span>
+ <span class="nx">left</span> <span class="o">=</span> <span class="s1">&#39;\n&#39;</span><span class="p">;</span>
+ <span class="nx">links</span> <span class="o">=</span> <span class="p">[];</span>
+ <span class="nx">linkTitles</span> <span class="o">=</span> <span class="p">[];</span>
+ <span class="nx">rlinks</span> <span class="o">=</span> <span class="p">{};</span>
+ <span class="nx">unhandled</span> <span class="o">=</span> <span class="p">{};</span></pre></div> </td> </tr> <tr id="section-40"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-40">&#182;</a> </div> <p>Configure html.md.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="k">if</span> <span class="p">(</span><span class="k">typeof</span> <span class="nx">options</span> <span class="o">!==</span> <span class="s1">&#39;object&#39;</span><span class="p">)</span> <span class="nx">options</span> <span class="o">=</span> <span class="p">{};</span>
+ <span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">property</span> <span class="k">in</span> <span class="nx">DEFAULT_CONFIG</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">DEFAULT_CONFIG</span><span class="p">.</span><span class="nx">hasOwnProperty</span><span class="p">(</span><span class="nx">property</span><span class="p">))</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">options</span><span class="p">.</span><span class="nx">hasOwnProperty</span><span class="p">(</span><span class="nx">property</span><span class="p">))</span> <span class="p">{</span>
+ <span class="nx">config</span><span class="p">[</span><span class="nx">property</span><span class="p">]</span> <span class="o">=</span> <span class="nx">options</span><span class="p">[</span><span class="nx">property</span><span class="p">];</span>
+ <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
+ <span class="nx">config</span><span class="p">[</span><span class="nx">property</span><span class="p">]</span> <span class="o">=</span> <span class="nx">DEFAULT_CONFIG</span><span class="p">[</span><span class="nx">property</span><span class="p">];</span>
+ <span class="p">}</span>
+ <span class="p">}</span>
+ <span class="p">}</span>
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-41"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-41">&#182;</a> </div> <p>Log the exception and the corresponding message if debug mode is enabled.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">thrown</span><span class="p">(</span><span class="nx">exception</span><span class="p">,</span> <span class="nx">message</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">config</span><span class="p">.</span><span class="nx">debug</span><span class="p">)</span> <span class="nx">exceptions</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">message</span> <span class="o">+</span> <span class="s1">&#39;: &#39;</span> <span class="o">+</span> <span class="nx">exception</span><span class="p">);</span>
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-42"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-42">&#182;</a> </div> <p>Prepare the parser for a <code>ul</code> element.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">function</span> <span class="nx">ul</span><span class="p">()</span> <span class="p">{</span>
+ <span class="kd">var</span> <span class="nx">old</span> <span class="o">=</span> <span class="nx">inOrderedList</span><span class="p">;</span>
+ <span class="nx">inOrderedList</span> <span class="o">=</span> <span class="kc">false</span><span class="p">;</span>
+ <span class="k">return</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
+ <span class="nx">inOrderedList</span> <span class="o">=</span> <span class="nx">old</span><span class="p">;</span>
+ <span class="p">};</span>
+ <span class="p">}</span></pre></div> </td> </tr> <tr id="section-43"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-43">&#182;</a> </div> <h2>html.md setup</h2> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-44"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-44">&#182;</a> </div> <p>Build the publicly exposed API.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="kd">var</span> <span class="nx">md</span> <span class="o">=</span> <span class="nb">window</span><span class="p">.</span><span class="nx">md</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">(</span><span class="nx">html</span><span class="p">,</span> <span class="nx">options</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">html</span><span class="p">)</span> <span class="k">return</span> <span class="s1">&#39;&#39;</span><span class="p">;</span>
+ <span class="nx">resetAndConfigure</span><span class="p">(</span><span class="nx">options</span><span class="p">);</span>
+ <span class="kd">var</span> <span class="nx">container</span> <span class="o">=</span> <span class="nb">document</span><span class="p">.</span><span class="nx">createElement</span><span class="p">(</span><span class="s1">&#39;div&#39;</span><span class="p">);</span>
+ <span class="k">if</span> <span class="p">(</span><span class="k">typeof</span> <span class="nx">html</span> <span class="o">===</span> <span class="s1">&#39;string&#39;</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">container</span><span class="p">.</span><span class="nx">innerHTML</span> <span class="o">=</span> <span class="nx">html</span><span class="p">;</span>
+ <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
+ <span class="nx">container</span><span class="p">.</span><span class="nx">appendChild</span><span class="p">(</span><span class="nx">html</span><span class="p">);</span>
+ <span class="p">}</span>
+ <span class="nx">process</span><span class="p">(</span><span class="nx">container</span><span class="p">);</span>
+ <span class="nx">append</span><span class="p">(</span><span class="s1">&#39;\n\n&#39;</span><span class="p">);</span>
+ <span class="kd">var</span> <span class="nx">title</span><span class="p">;</span>
+ <span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="nx">i</span> <span class="o">&lt;</span> <span class="nx">links</span><span class="p">.</span><span class="nx">length</span><span class="p">;</span> <span class="nx">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">title</span> <span class="o">=</span> <span class="s1">&#39;\n&#39;</span><span class="p">;</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">linkTitles</span><span class="p">[</span><span class="nx">i</span><span class="p">])</span> <span class="nx">title</span> <span class="o">=</span> <span class="s1">&#39; &quot;&#39;</span> <span class="o">+</span> <span class="nx">linkTitles</span><span class="p">[</span><span class="nx">i</span><span class="p">]</span> <span class="o">+</span> <span class="s1">&#39;&quot;\n&#39;</span><span class="p">;</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">links</span><span class="p">[</span><span class="nx">i</span><span class="p">])</span> <span class="nx">append</span><span class="p">(</span><span class="s1">&#39;[&#39;</span> <span class="o">+</span> <span class="nx">i</span> <span class="o">+</span> <span class="s1">&#39;]: &#39;</span> <span class="o">+</span> <span class="nx">links</span><span class="p">[</span><span class="nx">i</span><span class="p">]</span> <span class="o">+</span> <span class="nx">title</span><span class="p">);</span>
+ <span class="p">}</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">config</span><span class="p">.</span><span class="nx">debug</span><span class="p">)</span> <span class="p">{</span>
+ <span class="kd">var</span> <span class="nx">unhandledTags</span> <span class="o">=</span> <span class="p">[];</span>
+ <span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">name</span> <span class="k">in</span> <span class="nx">unhandled</span><span class="p">)</span> <span class="p">{</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">unhandled</span><span class="p">.</span><span class="nx">hasOwnProperty</span><span class="p">(</span><span class="nx">name</span><span class="p">))</span> <span class="p">{</span>
+ <span class="nx">unhandledTags</span><span class="p">.</span><span class="nx">push</span><span class="p">(</span><span class="nx">name</span><span class="p">);</span>
+ <span class="p">}</span>
+ <span class="p">}</span>
+ <span class="nx">unhandledTags</span><span class="p">.</span><span class="nx">sort</span><span class="p">();</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">unhandledTags</span><span class="p">.</span><span class="nx">length</span><span class="p">)</span> <span class="p">{</span>
+ <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s1">&#39;Ignored tags;\n&#39;</span> <span class="o">+</span> <span class="nx">unhandledTags</span><span class="p">.</span><span class="nx">join</span><span class="p">(</span><span class="s1">&#39;, &#39;</span><span class="p">));</span>
+ <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
+ <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s1">&#39;No tags were ignored&#39;</span><span class="p">);</span>
+ <span class="p">}</span>
+ <span class="k">if</span> <span class="p">(</span><span class="nx">exceptions</span><span class="p">.</span><span class="nx">length</span><span class="p">)</span> <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">exceptions</span><span class="p">.</span><span class="nx">join</span><span class="p">(</span><span class="s1">&#39;\n&#39;</span><span class="p">));</span>
+ <span class="p">}</span>
+ <span class="nx">append</span><span class="p">(</span><span class="s1">&#39;&#39;</span><span class="p">);</span>
+ <span class="k">return</span> <span class="nx">buffer</span><span class="p">;</span>
+ <span class="p">};</span></pre></div> </td> </tr> <tr id="section-45"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-45">&#182;</a> </div> <h2>Public constants</h2> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-46"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-46">&#182;</a> </div> <p>Current version of html.md.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">md</span><span class="p">.</span><span class="nx">VERSION</span> <span class="o">=</span> <span class="s1">&#39;1.0.0&#39;</span><span class="p">;</span></pre></div> </td> </tr> <tr id="section-47"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-47">&#182;</a> </div> <h2>Public functions</h2> </td> <td class="code"> <div class="highlight"><pre></pre></div> </td> </tr> <tr id="section-48"> <td class="docs"> <div class="pilwrap"> <a class="pilcrow" href="#section-48">&#182;</a> </div> <p>Run html.md in <em>noConflict</em> mode, returning the <code>md</code> variable to its
+previous owner. <br />
+Returns a reference to <code>md</code>.</p> </td> <td class="code"> <div class="highlight"><pre> <span class="nx">md</span><span class="p">.</span><span class="nx">noConflict</span> <span class="o">=</span> <span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
+ <span class="nb">window</span><span class="p">.</span><span class="nx">md</span> <span class="o">=</span> <span class="nx">previousMd</span><span class="p">;</span>
+ <span class="k">return</span> <span class="k">this</span><span class="p">;</span>
+ <span class="p">};</span>
+
+<span class="p">}());</span>
+
+</pre></div> </td> </tr> </tbody> </table> </div> </body> </html>
159 md.js
View
@@ -2,7 +2,7 @@
// (c) 2012 Alasdair Mercer
// Freely distributable under the MIT license.
// Based on [Make.text](http://homepage.mac.com/tjim/) 1.5
-// (c) Trevor Jim
+// (c) 2007 Trevor Jim
// Licensed under the GPL Version 2 license.
// For all details and documentation:
// <http://neocotic.com/html.md>
@@ -13,11 +13,11 @@
// -----------------
var
- // TODO: Comment
+ // Default configuration values.
DEFAULT_CONFIG = {
debug: false
},
- // TODO: Comment
+ // Replacement strings for special Markdown characters.
REPLACEMENTS = {
'\\\\': '\\\\',
'\\[': '\\[',
@@ -44,7 +44,7 @@
'\u2013': '--',
'\u2014': '---'
},
- // TODO: Comment
+ // Create regular expressions for all of the special Markdown characters.
REGEX = (function () {
var result = {};
for (var key in REPLACEMENTS) {
@@ -59,37 +59,39 @@
// -----------------
var
- // TODO: Comment
+ // Indicate whether or not the parser is at the beginning of a new line.
atLeft = true,
- // TODO: Comment
+ // Indicate whether or not the parser is at the beginning of an indentation.
atNoWS = true,
- // TODO: Comment
+ // Indicate whether or not the parser in at the beginning of a paragraph.
atP = true,
- // TODO: Comment
+ // String buffer containing the parsed Markdown.
buffer = '',
- // TODO: Comment
+ // Configuration, default or customized.
config = {},
- // TODO: Comment
+ // List of exceptions thrown while parsing the HTML.
+ // This is only populated when debug mode is enabled.
exceptions = [],
- // TODO: Comment
+ // Indicate whether or not the parser is within a `code` element.
inCode = false,
- // TODO: Comment
+ // Indicate whether or not the parser is within a `pre` element.
inPre = false,
- // TODO: Comment
+ // Indicate whether or not the parser is within an `ol` element.
inOrderedList = false,
- // TODO: Comment
+ // Markdown created from the last HTML parsed.
last = null,
- // TODO: Comment
+ // Shortcut reference to append a new line.
left = '\n',
- // TODO: Comment
+ // List of URLs for all previously parsed unique anchors.
links = [],
- // TODO: Comment
+ // List of titles for all previously parsed unique anchors.
linkTitles = [],
// Save the previous value of the `md` variable.
previousMd = window.md,
- // TODO: Comment
+ // Map of anchor URLs to their corresponding reference index.
rlinks = {},
- // TODO: Comment
+ // List of tag names that were not handled by the parser.
+ // This is only populated when debug mode is enabled.
unhandled = {};
// Try to ensure Node is available with the required constants.
@@ -100,19 +102,19 @@
// Private functions
// -----------------
- // TODO: Comment
+ // Append `str` to the buffer string.
function append(str) {
if (last != null) buffer += last;
last = str;
}
- // TODO: Comment
+ // Append a Markdown line break to the buffer string.
function br() {
append(' ' + left);
atLeft = atNoWS = true;
}
- // TODO: Comment
+ // Prepare the parser for a `code` element.
function code() {
var old = inCode;
inCode = true;
@@ -121,12 +123,12 @@
};
}
- // TODO: Comment
- function inCodeProc(str) {
+ // Replace any special characters that can cause problems within code.
+ function inCodeProcess(str) {
return str.replace(/`/g, '\\`');
}
- // TODO: Comment
+ // Replace any special characters that can cause problems in normal Markdown.
function nonPreProcess(str) {
str = str.replace(/\n([ \t]*\n)+/g, '\n');
str = str.replace(/\n[ \t]+/g, '\n');
@@ -139,7 +141,7 @@
return str;
}
- // TODO: Comment
+ // Prepare the parser for an `ol` element.
function ol() {
var old = inOrderedList;
inOrderedList = true;
@@ -148,29 +150,34 @@
};
}
- // TODO: Comment
+ // Append `str` to the buffer string while keeping the parser in context.
function output(str) {
if (!str) return;
if (!inPre) {
- if (atNoWS) str = str.replace(/^[ \t\n]+/, '');
- else if (/^[ \t]*\n/.test(str)) str = str.replace(/^[ \t\n]+/, '\n');
- else str = str.replace(/^[ \t]+/, ' ');
+ if (atNoWS) {
+ str = str.replace(/^[ \t\n]+/, '');
+ } else if (/^[ \t]*\n/.test(str)) {
+ str = str.replace(/^[ \t\n]+/, '\n');
+ } else {
+ str = str.replace(/^[ \t]+/, ' ');
+ }
}
if (str === '') return;
- atP = /\n\n$/.test(str);
+ atP = /\n\n$/.test(str);
atLeft = /\n$/.test(str);
atNoWS = /[ \t\n]$/.test(str);
append(str.replace(/\n/g, left));
}
- // TODO: Comment
+ // Create a function that can be called later to append `str` to the buffer
+ // string while keeping the parser in context.
function outputLater(str) {
return function () {
output(str);
};
}
- // TODO: Comment
+ // Append a Markdown paragraph to the buffer string.
function p() {
if (atP) return;
if (!atLeft) {
@@ -181,7 +188,7 @@
atNoWS = atP = true;
}
- // TODO: Comment
+ // Prepare the parser for a `pre` element.
function pre() {
var old = inPre;
inPre = true;
@@ -190,7 +197,8 @@
};
}
- // TODO: Comment
+ // Parse the specified element and append the generated Markdown to the buffer
+ // string.
function process(e) {
if (typeof getComputedStyle !== 'undefined') {
try {
@@ -203,6 +211,8 @@
if (e.nodeType === Node.ELEMENT_NODE) {
var
after = null,
+ after1 = null,
+ after2 = null,
skipChildren = false;
try {
switch (e.tagName) {
@@ -264,7 +274,7 @@
case 'U':
output('_');
atNoWS = true;
- after = outputLater('_');
+ after = outputLater('_');
break;
case 'DT':
p();
@@ -272,22 +282,22 @@
case 'B':
output('**');
atNoWS = true;
- after = outputLater('**');
+ after = outputLater('**');
break;
case 'OL':
- var r1 = pushLeft(' ');
- var r2 = ol();
- after = function () {
- r1();
- r2();
+ after1 = pushLeft(' ');
+ after2 = ol();
+ after = function () {
+ after1();
+ after2();
};
break;
case 'UL':
- var r1 = pushLeft(' ');
- var r2 = ul();
- after = function () {
- r1();
- r2();
+ after1 = pushLeft(' ');
+ after2 = ul();
+ after = function () {
+ after1();
+ after2();
};
break;
case 'LI':
@@ -298,21 +308,21 @@
}
break;
case 'PRE':
- var r1 = pushLeft(' ');
- var r2 = pre();
- after = function () {
- r1();
- r2();
+ after1 = pushLeft(' ');
+ after2 = pre();
+ after = function () {
+ after1();
+ after2();
};
break;
case 'CODE':
if (!inPre) {
output('`');
- var r1 = code();
- var r2 = outputLater('`');
- after = function () {
- r1();
- r2();
+ after1 = code();
+ after2 = outputLater('`');
+ after = function () {
+ after1();
+ after2();
};
}
break;
@@ -322,18 +332,18 @@
break;
case 'A':
if (!e.href) break;
- var n;
+ var index;
if (rlinks[e.href]) {
- n = rlinks[e.href];
+ index = rlinks[e.href];
} else {
- n = links.length;
- links[n] = e.href;
- rlinks[e.href] = n;
- if (e.title) linkTitles[n] = e.title;
+ index = links.length;
+ links[index] = e.href;
+ rlinks[e.href] = index;
+ if (e.title) linkTitles[index] = e.title;
}
output('[');
atNoWS = true;
- after = outputLater('][' + n + ']');
+ after = outputLater('][' + index + ']');
break;
case 'IMG':
skipChildren = true;
@@ -371,14 +381,14 @@
if (inPre) {
output(e.nodeValue);
} else if (inCode) {
- output(inCodeProc(e.nodeValue));
+ output(inCodeProcess(e.nodeValue));
} else {
output(nonPreProcess(e.nodeValue));
}
}
}
- // TODO: Comment
+ // Attach `str` to the start of the current line.
function pushLeft(str) {
var oldLeft = left;
left += str;
@@ -394,19 +404,20 @@
};
}
- // TODO: Comment
+ // Replace the left indent with `str`.
function replaceLeft(str) {
if (!atLeft) {
- append(left.replace(/ $/, str));
+ append(left.replace(/[ ]{4}$/, str));
atLeft = atNoWS = atP = true;
} else if (last) {
- last = last.replace(/ $/, str);
+ last = last.replace(/[ ]{4}$/, str);
}
}
- // TODO: Comment
+ // Reset the variables used by the parser and configure it using the `options`
+ // provided.
function resetAndConfigure(options) {
- // Reset
+ // Reset necessary variables.
atLeft = true;
atNoWS = true;
atP = true;
@@ -421,7 +432,7 @@
linkTitles = [];
rlinks = {};
unhandled = {};
- // Configure
+ // Configure html.md.
if (typeof options !== 'object') options = {};
for (var property in DEFAULT_CONFIG) {
if (DEFAULT_CONFIG.hasOwnProperty(property)) {
@@ -434,12 +445,12 @@
}
}
- // TODO: Comment
+ // Log the exception and the corresponding message if debug mode is enabled.
function thrown(exception, message) {
if (config.debug) exceptions.push(message + ': ' + exception);
}
- // TODO: Comment
+ // Prepare the parser for a `ul` element.
function ul() {
var old = inOrderedList;
inOrderedList = false;
9 md.min.js
View
@@ -0,0 +1,9 @@
+// [html.md](http://neocotic.com/html.md) 1.0.0
+// (c) 2012 Alasdair Mercer
+// Freely distributable under the MIT license.
+// Based on [Make.text](http://homepage.mac.com/tjim/) 1.5
+// (c) 2007 Trevor Jim
+// Licensed under the GPL Version 2 license.
+// For all details and documentation:
+// <http://neocotic.com/html.md>
+(function(){function u(a){m!=null&&(g+=m),m=a}function v(){u(" "+n),d=e=!0}function w(){var a=j;return j=!0,function(){j=a}}function x(a){return a.replace(/`/g,"\\`")}function y(a){a=a.replace(/\n([ \t]*\n)+/g,"\n"),a=a.replace(/\n[ \t]+/g,"\n"),a=a.replace(/[ \t]+/g," ");for(var d in b)b.hasOwnProperty(d)&&(a=a.replace(c[d],b[d]));return a}function z(){var a=l;return l=!0,function(){l=a}}function A(a){if(!a)return;k||(e?a=a.replace(/^[ \t\n]+/,""):/^[ \t]*\n/.test(a)?a=a.replace(/^[ \t\n]+/,"\n"):a=a.replace(/^[ \t]+/," "));if(a==="")return;f=/\n\n$/.test(a),d=/\n$/.test(a),e=/[ \t\n]$/.test(a),u(a.replace(/\n/g,n))}function B(a){return function(){A(a)}}function C(){if(f)return;d||(u(n),d=!0),u(n),e=f=!0}function D(){var a=k;return k=!0,function(){k=a}}function E(a){if(typeof getComputedStyle!="undefined")try{var b=getComputedStyle(a,null);if(b&&b.getPropertyValue&&b.getPropertyValue("display")==="none")return}catch(c){I(c,"getComputedStyle")}if(a.nodeType===t.ELEMENT_NODE){var d=null,f=null,g=null,i=!1;try{switch(a.tagName){case"HEAD":case"STYLE":case"SCRIPT":case"SELECT":case"OPTION":case"NOSCRIPT":case"NOFRAMES":case"INPUT":case"BUTTON":case"SELECT":case"TEXTAREA":case"LABEL":i=!0;break;case"BODY":case"FORM":break;case"H1":C(),A("# ");break;case"H2":C(),A("## ");break;case"H3":C(),A("### ");break;case"H4":C(),A("#### ");break;case"H5":C(),A("##### ");break;case"H6":C(),A("###### ");break;case"P":case"DIV":C();break;case"BR":v();break;case"HR":C(),A("--------------------------------"),C();break;case"EM":case"I":case"U":A("_"),e=!0,d=B("_");break;case"DT":C();case"STRONG":case"B":A("**"),e=!0,d=B("**");break;case"OL":f=F(" "),g=z(),d=function(){f(),g()};break;case"UL":f=F(" "),g=J(),d=function(){f(),g()};break;case"LI":l?G("1. "):G("* ");break;case"PRE":f=F(" "),g=D(),d=function(){f(),g()};break;case"CODE":k||(A("`"),f=w(),g=B("`"),d=function(){f(),g()});break;case"DD":case"BLOCKQUOTE":d=F("> ");break;case"A":if(!a.href)break;var m;r[a.href]?m=r[a.href]:(m=o.length,o[m]=a.href,r[a.href]=m,a.title&&(p[m]=a.title)),A("["),e=!0,d=B("]["+m+"]");break;case"IMG":i=!0;if(!a.src)break;A("!["+a.alt+"]("+a.src+")");break;case"IFRAME":case"FRAME":i=!0;try{a.contentDocument&&a.contentDocument.documentElement&&E(a.contentDocument.documentElement)}catch(c){I(c,"contentDocument")}break;case"TR":d=C;break;default:h.debug&&(s[a.tagName]=null)}}catch(c){I(c,a.tagName)}if(!i)for(var n=0;n<a.childNodes.length;n++)E(a.childNodes[n]);d&&d()}else a.nodeType===t.TEXT_NODE&&(k?A(a.nodeValue):j?A(x(a.nodeValue)):A(y(a.nodeValue)))}function F(a){var b=n;return n+=a,f?u(a):C(),function(){n=b,d=f=!1,C()}}function G(a){d?m&&(m=m.replace(/[ ]{4}$/,a)):(u(n.replace(/[ ]{4}$/,a)),d=e=f=!0)}function H(b){d=!0,e=!0,f=!0,g="",i=[],j=!1,k=!1,l=!1,m=null,n="\n",o=[],p=[],r={},s={},typeof b!="object"&&(b={});for(var c in a)a.hasOwnProperty(c)&&(b.hasOwnProperty(c)?h[c]=b[c]:h[c]=a[c])}function I(a,b){h.debug&&i.push(b+": "+a)}function J(){var a=l;return l=!1,function(){l=a}}var a={debug:!1},b={"\\\\":"\\\\","\\[":"\\[","\\]":"\\]",">":"\\>",_:"\\_","\\*":"\\*","`":"\\`","#":"\\#","([0-9])\\.(\\s|$)":"$1\\.$2","©":"(c)","®":"(r)","™":"(tm)"," ":" ","·":"\\*"," ":" "," ":" "," ":" ","‘":"'","’":"'","“":'"',"”":'"',"…":"...","–":"--","—":"---"},c=function(){var a={};for(var c in b)b.hasOwnProperty(c)&&(a[c]=new RegExp(c,"g"));return a}(),d=!0,e=!0,f=!0,g="",h={},i=[],j=!1,k=!1,l=!1,m=null,n="\n",o=[],p=[],q=window.md,r={},s={},t=typeof t=="undefined"?{}:t;t.ELEMENT_NODE||(t.ELEMENT_NODE=1),t.TEXT_NODE||(t.TEXT_NODE=3);var K=window.md=function(a,b){if(!a)return"";H(b);var c=document.createElement("div");typeof a=="string"?c.innerHTML=a:c.appendChild(a),E(c),u("\n\n");var d;for(var e=0;e<o.length;e++)d="\n",p[e]&&(d=' "'+p[e]+'"\n'),o[e]&&u("["+e+"]: "+o[e]+d);if(h.debug){var f=[];for(var j in s)s.hasOwnProperty(j)&&f.push(j);f.sort(),f.length?console.log("Ignored tags;\n"+f.join(", ")):console.log("No tags were ignored"),i.length&&console.log(i.join("\n"))}return u(""),g};K.VERSION="1.0.0",K.noConflict=function(){return window.md=q,this}})();
14 package.json
View
@@ -0,0 +1,14 @@
+{
+ "name" : "md",
+ "description" : "Pure JavaScript library for converting HTML in to valid Markdown",
+ "version" : "1.0.0",
+ "homepage" : "http://neocotic.com/html.md",
+ "bugs" : {"url" : "https://github.com/neocotic/html.md/issues"},
+ "author" : "Alasdair Mercer <mercer.alasdair@gmail.com> (http://neocotic.com)",
+ "licenses" : [{"type" : "MIT",
+ "url" : "https://github.com/neocotic/html.md/raw/master/LICENSE.md"}],
+ "keywords" : ["html", "markdown", "convert"],
+ "repository" : {"type" : "git",
+ "url" : "git://github.com/neocotic/html.md.git"},
+ "main" : "md.js"
+}
Please sign in to comment.
Something went wrong with that request. Please try again.