Commits

David Chambers  committed 03e1bd7

Updated Showdown's annotated source.

  • Participants
  • Parent commits 4b8fff2

Comments (0)

Files changed (1)

File showdown/index.html

             <span class="s2">&quot;#{ runup }&lt;#{ list_type }&gt;\n#{ processListItems list }&lt;/#{ list_type }&gt;\n&quot;</span>
         <span class="p">)</span>
     <span class="p">)</span>
-    <span class="p">.</span><span class="nx">trim</span> <span class="sr">/~0/</span> <span class="c1"># attacklab: strip sentinel</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>Process Markdown <code>&lt;pre&gt;&lt;code&gt;</code> blocks.</p>             </td>             <td class="code">               <div class="highlight"><pre>  <span class="nv">doCodeBlocks: </span><span class="o">-&gt;</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><em>attacklab:</em> Sentinel workarounds for lack of <code>\A</code> and <code>\Z</code>,
-khtml/safari bug.</p>             </td>             <td class="code">               <div class="highlight"><pre>    <span class="nx">@after</span><span class="p">(</span><span class="s1">&#39;~0&#39;</span><span class="p">)</span>
-    <span class="p">.</span><span class="nx">replace</span><span class="p">(</span>
+    <span class="p">.</span><span class="nx">trim</span> <span class="sr">/~0/</span> <span class="c1"># attacklab: strip sentinel</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>Process Markdown <code>&lt;pre&gt;&lt;code&gt;</code> blocks.</p>             </td>             <td class="code">               <div class="highlight"><pre>  <span class="nv">doCodeBlocks: </span><span class="o">-&gt;</span>
+    <span class="nx">@replace</span><span class="p">(</span>
       <span class="err">///</span>
         <span class="p">(</span><span class="o">?:</span><span class="err">\</span><span class="nx">n</span><span class="err">\</span><span class="nx">n</span><span class="o">|^</span><span class="p">)</span>
         <span class="p">((</span><span class="o">?:</span><span class="p">(</span><span class="o">?:</span><span class="err">\</span><span class="nx">x20</span><span class="p">{</span><span class="mi">4</span><span class="p">}</span><span class="o">|</span><span class="err">\</span><span class="nx">t</span><span class="p">).</span><span class="o">*</span><span class="err">\</span><span class="nx">n</span><span class="o">+</span><span class="p">)</span><span class="o">+</span><span class="p">)</span>
         <span class="p">(</span>
           <span class="err">\</span><span class="nx">n</span><span class="o">*</span><span class="err">\</span><span class="nx">x20</span><span class="p">{</span><span class="mi">0</span><span class="p">,</span><span class="mi">3</span><span class="p">}[</span><span class="o">^</span><span class="err">\</span><span class="nx">x20</span><span class="err">\</span><span class="nx">t</span><span class="err">\</span><span class="nx">n</span><span class="p">]</span>
           <span class="o">|</span>
-          <span class="p">(</span><span class="o">?=~</span><span class="mi">0</span><span class="p">)</span>
+          <span class="nx">$</span>
         <span class="p">)</span>
       <span class="o">/</span><span class="err">//g,</span>
       <span class="nf">(_, codeblock, nextChar) -&gt;</span>
           <span class="p">.</span><span class="nx">hashBlock</span><span class="p">()</span>
           <span class="p">.</span><span class="nx">after</span><span class="p">(</span><span class="nx">nextChar</span><span class="p">)</span>
     <span class="p">)</span>
-    <span class="p">.</span><span class="nx">trim</span> <span class="sr">/~0/</span> <span class="c1"># attacklab: strip sentinel</span>
 
   <span class="nv">hashBlock: </span><span class="o">-&gt;</span>
     <span class="nx">@set</span> <span class="s2">&quot;\n\n~K#{ blocks.push(@value.trim()) - 1 }K\n\n&quot;</span>
           <span class="p">.</span><span class="nx">encodeCode</span><span class="p">()</span>
           <span class="p">.</span><span class="nx">before</span><span class="p">(</span><span class="nx">m1</span> <span class="o">+</span> <span class="s1">&#39;&lt;code&gt;&#39;</span><span class="p">)</span>
           <span class="p">.</span><span class="nx">after</span><span class="p">(</span><span class="s1">&#39;&lt;/code&gt;&#39;</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>Encode/escape certain characters inside Markdown code runs. The point
+    <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>Encode/escape certain characters inside Markdown code runs. The point
 is that in code, these characters are literals, and lose their special
-Markdown meanings.</p>             </td>             <td class="code">               <div class="highlight"><pre>  <span class="nv">encodeCode: </span><span class="o">-&gt;</span></pre></div>             </td>           </tr>                               <tr id="section-43">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-43">&#182;</a>               </div>               <p>Encode all ampersands (HTML entities are
-not entities within a Markdown code span).</p>             </td>             <td class="code">               <div class="highlight"><pre>    <span class="nx">@replace</span><span class="p">(</span><span class="sr">/&amp;/g</span><span class="p">,</span> <span class="s1">&#39;&amp;amp;&#39;</span><span class="p">)</span></pre></div>             </td>           </tr>                               <tr id="section-44">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-44">&#182;</a>               </div>               <p>Do the angle bracket song and dance.</p>             </td>             <td class="code">               <div class="highlight"><pre>    <span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/&lt;/g</span><span class="p">,</span> <span class="s1">&#39;&amp;lt;&#39;</span><span class="p">)</span>
+Markdown meanings.</p>             </td>             <td class="code">               <div class="highlight"><pre>  <span class="nv">encodeCode: </span><span class="o">-&gt;</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>Encode all ampersands (HTML entities are
+not entities within a Markdown code span).</p>             </td>             <td class="code">               <div class="highlight"><pre>    <span class="nx">@replace</span><span class="p">(</span><span class="sr">/&amp;/g</span><span class="p">,</span> <span class="s1">&#39;&amp;amp;&#39;</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>               <p>Do the angle bracket song and dance.</p>             </td>             <td class="code">               <div class="highlight"><pre>    <span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/&lt;/g</span><span class="p">,</span> <span class="s1">&#39;&amp;lt;&#39;</span><span class="p">)</span>
     <span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/&gt;/g</span><span class="p">,</span> <span class="s1">&#39;&amp;gt;&#39;</span><span class="p">)</span>
 
     <span class="p">.</span><span class="nx">escapeCharacters</span><span class="p">(</span><span class="s1">&#39;*_{}[]\\&#39;</span><span class="p">)</span>
 
-  <span class="nv">doItalicsAndBold: </span><span class="o">-&gt;</span></pre></div>             </td>           </tr>                               <tr id="section-45">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-45">&#182;</a>               </div>               <p><code>&lt;strong&gt;</code> must go first.</p>             </td>             <td class="code">               <div class="highlight"><pre>    <span class="nx">@replace</span><span class="p">(</span>
+  <span class="nv">doItalicsAndBold: </span><span class="o">-&gt;</span></pre></div>             </td>           </tr>                               <tr id="section-44">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-44">&#182;</a>               </div>               <p><code>&lt;strong&gt;</code> must go first.</p>             </td>             <td class="code">               <div class="highlight"><pre>    <span class="nx">@replace</span><span class="p">(</span>
       <span class="sr">/(\*\*|__)(?=\S)([^\r]*?\S[*_]*)\1/g</span><span class="p">,</span>
       <span class="s1">&#39;&lt;strong&gt;$2&lt;/strong&gt;&#39;</span>
     <span class="p">)</span>
 
   <span class="nv">formParagraphs: </span><span class="o">-&gt;</span>
     <span class="nv">grafs = </span><span class="nx">@value</span><span class="p">.</span><span class="nx">trim</span><span class="p">().</span><span class="nx">split</span> <span class="sr">/\n{2,}/g</span>
-    <span class="nv">grafsOut = </span><span class="p">[]</span></pre></div>             </td>           </tr>                               <tr id="section-46">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-46">&#182;</a>               </div>               <p>Wrap <code>&lt;p&gt;</code> tags.</p>             </td>             <td class="code">               <div class="highlight"><pre>    <span class="k">for</span> <span class="nx">str</span> <span class="k">in</span> <span class="nx">grafs</span>
+    <span class="nv">grafsOut = </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>               <p>Wrap <code>&lt;p&gt;</code> tags.</p>             </td>             <td class="code">               <div class="highlight"><pre>    <span class="k">for</span> <span class="nx">str</span> <span class="k">in</span> <span class="nx">grafs</span>
       <span class="k">if</span> <span class="sr">/~K(\d+)K/g</span><span class="p">.</span><span class="nx">test</span> <span class="nx">str</span> <span class="c1"># if this is an HTML marker, copy it</span>
         <span class="nx">grafsOut</span><span class="p">.</span><span class="nx">push</span> <span class="nx">str</span>
       <span class="k">else</span> <span class="k">if</span> <span class="sr">/\S/</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">runSpanGamut</span><span class="p">()</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;&lt;p&gt;&#39;</span><span class="p">)</span>
             <span class="p">.</span><span class="nx">after</span><span class="p">(</span><span class="s1">&#39;&lt;/p&gt;&#39;</span><span class="p">)</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>               <p>Unhashify HTML blocks.</p>             </td>             <td class="code">               <div class="highlight"><pre>    <span class="k">for</span> <span class="nx">value</span><span class="p">,</span> <span class="nx">index</span> <span class="k">in</span> <span class="nx">grafsOut</span></pre></div>             </td>           </tr>                               <tr id="section-48">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-48">&#182;</a>               </div>               <p>If this is a marker for an html block...</p>             </td>             <td class="code">               <div class="highlight"><pre>      <span class="k">while</span> <span class="sr">/~K(\d+)K/</span><span class="p">.</span><span class="nx">test</span> <span class="nx">grafsOut</span><span class="p">[</span><span class="nx">index</span><span class="p">]</span>
+        <span class="p">)</span></pre></div>             </td>           </tr>                               <tr id="section-46">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-46">&#182;</a>               </div>               <p>Unhashify HTML blocks.</p>             </td>             <td class="code">               <div class="highlight"><pre>    <span class="k">for</span> <span class="nx">value</span><span class="p">,</span> <span class="nx">index</span> <span class="k">in</span> <span class="nx">grafsOut</span></pre></div>             </td>           </tr>                               <tr id="section-47">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-47">&#182;</a>               </div>               <p>If this is a marker for an html block...</p>             </td>             <td class="code">               <div class="highlight"><pre>      <span class="k">while</span> <span class="sr">/~K(\d+)K/</span><span class="p">.</span><span class="nx">test</span> <span class="nx">grafsOut</span><span class="p">[</span><span class="nx">index</span><span class="p">]</span>
         <span class="nx">grafsOut</span><span class="p">[</span><span class="nx">index</span><span class="p">]</span> <span class="o">=</span>
           <span class="nx">grafsOut</span><span class="p">[</span><span class="nx">index</span><span class="p">].</span><span class="nx">replace</span><span class="p">(</span>
             <span class="sr">/~K\d+K/</span><span class="p">,</span>
             <span class="nx">blocks</span><span class="p">[</span><span class="nb">RegExp</span><span class="p">.</span><span class="nx">$1</span><span class="p">].</span><span class="nx">replace</span> <span class="sr">/\$/g</span><span class="p">,</span> <span class="s1">&#39;$$$$&#39;</span>
           <span class="p">)</span>
 
-    <span class="nx">@set</span> <span class="nx">grafsOut</span><span class="p">.</span><span class="nx">join</span> <span class="s1">&#39;\n\n&#39;</span></pre></div>             </td>           </tr>                               <tr id="section-49">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-49">&#182;</a>               </div>               <p>Smart processing for ampersands and angle brackets that must be encoded.</p>             </td>             <td class="code">               <div class="highlight"><pre>  <span class="nv">encodeAmpsAndAngles: </span><span class="o">-&gt;</span></pre></div>             </td>           </tr>                               <tr id="section-50">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-50">&#182;</a>               </div>               <p>Ampersand-encoding based entirely on Nat Irons's
-<a href="http://bumppo.net/projects/amputator/">Amputator MT plugin</a>.</p>             </td>             <td class="code">               <div class="highlight"><pre>    <span class="nx">@replace</span><span class="p">(</span><span class="sr">/&amp;(?!#?[xX]?(?:[0-9a-fA-F]+|\w+);)/g</span><span class="p">,</span> <span class="s1">&#39;&amp;amp;&#39;</span><span class="p">)</span></pre></div>             </td>           </tr>                               <tr id="section-51">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-51">&#182;</a>               </div>               <p>Encode naked <code>&lt;</code>s.</p>             </td>             <td class="code">               <div class="highlight"><pre>    <span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/&lt;(?![a-z\/?\$!])/gi</span><span class="p">,</span> <span class="s1">&#39;&amp;lt;&#39;</span><span class="p">)</span>
+    <span class="nx">@set</span> <span class="nx">grafsOut</span><span class="p">.</span><span class="nx">join</span> <span class="s1">&#39;\n\n&#39;</span></pre></div>             </td>           </tr>                               <tr id="section-48">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-48">&#182;</a>               </div>               <p>Smart processing for ampersands and angle brackets that must be encoded.</p>             </td>             <td class="code">               <div class="highlight"><pre>  <span class="nv">encodeAmpsAndAngles: </span><span class="o">-&gt;</span></pre></div>             </td>           </tr>                               <tr id="section-49">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-49">&#182;</a>               </div>               <p>Ampersand-encoding based entirely on Nat Irons's
+<a href="http://bumppo.net/projects/amputator/">Amputator MT plugin</a>.</p>             </td>             <td class="code">               <div class="highlight"><pre>    <span class="nx">@replace</span><span class="p">(</span><span class="sr">/&amp;(?!#?[xX]?(?:[0-9a-fA-F]+|\w+);)/g</span><span class="p">,</span> <span class="s1">&#39;&amp;amp;&#39;</span><span class="p">)</span></pre></div>             </td>           </tr>                               <tr id="section-50">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-50">&#182;</a>               </div>               <p>Encode naked <code>&lt;</code>s.</p>             </td>             <td class="code">               <div class="highlight"><pre>    <span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/&lt;(?![a-z\/?\$!])/gi</span><span class="p">,</span> <span class="s1">&#39;&amp;lt;&#39;</span><span class="p">)</span>
 
   <span class="nv">encodeBackslashEscapes: </span><span class="o">-&gt;</span>
     <span class="nx">@replace</span><span class="p">(</span><span class="sr">/\\(\\)/g</span><span class="p">,</span> <span class="nx">escapeCharacters_callback</span><span class="p">)</span>
     <span class="p">.</span><span class="nx">replace</span><span class="p">(</span>
       <span class="sr">/&lt;(?:mailto:)?([-.\w]+\@[-a-z0-9]+(\.[-a-z0-9]+)*\.[a-z]+)&gt;/gi</span><span class="p">,</span>
       <span class="nf">(_, m1) -&gt;</span> <span class="nx">encodeEmailAddress</span> <span class="k">new</span> <span class="nx">Text</span><span class="p">(</span><span class="nx">m1</span><span class="p">).</span><span class="nx">unescapeSpecialChars</span><span class="p">().</span><span class="nx">value</span>
-    <span class="p">)</span></pre></div>             </td>           </tr>                               <tr id="section-52">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-52">&#182;</a>               </div>               <p>Swap back in all the special characters we've hidden.</p>             </td>             <td class="code">               <div class="highlight"><pre>  <span class="nv">unescapeSpecialChars: </span><span class="o">-&gt;</span>
-    <span class="nx">@replace</span> <span class="sr">/~E(\d+)E/g</span><span class="p">,</span> <span class="nf">(_, m1) -&gt;</span> <span class="nb">String</span><span class="p">.</span><span class="nx">fromCharCode</span> <span class="nb">parseInt</span> <span class="nx">m1</span><span class="p">,</span> <span class="mi">10</span></pre></div>             </td>           </tr>                               <tr id="section-53">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-53">&#182;</a>               </div>               <p>Remove one level of line-leading tabs or spaces.</p>             </td>             <td class="code">               <div class="highlight"><pre>  <span class="nv">outdent: </span><span class="o">-&gt;</span>
-    <span class="nx">@replace</span><span class="p">(</span><span class="sr">/^(\t|[ ]{1,4})/gm</span><span class="p">,</span> <span class="s1">&#39;~0&#39;</span><span class="p">).</span><span class="nx">trim</span> <span class="sr">/~0/g</span> <span class="c1"># attacklab: clean up hack</span></pre></div>             </td>           </tr>                               <tr id="section-54">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-54">&#182;</a>               </div>               <p><em>attacklab:</em> Completely rewritten for speed. In Perl we could fix it by
-anchoring the regexp with <code>\G</code>. In JavaScript we're less fortunate.</p>             </td>             <td class="code">               <div class="highlight"><pre>  <span class="nv">detab: </span><span class="o">-&gt;</span></pre></div>             </td>           </tr>                               <tr id="section-55">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-55">&#182;</a>               </div>               <p>Expand first n-1 tabs.</p>             </td>             <td class="code">               <div class="highlight"><pre>    <span class="nx">@replace</span><span class="p">(</span><span class="sr">/\t(?=\t)/g</span><span class="p">,</span> <span class="s1">&#39;    &#39;</span><span class="p">)</span></pre></div>             </td>           </tr>                               <tr id="section-56">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-56">&#182;</a>               </div>               <p>Replace the nth with two sentinels.</p>             </td>             <td class="code">               <div class="highlight"><pre>    <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;~A~B&#39;</span><span class="p">)</span></pre></div>             </td>           </tr>                               <tr id="section-57">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-57">&#182;</a>               </div>               <p>Use the sentinel to anchor our regex so it doesn't explode.</p>             </td>             <td class="code">               <div class="highlight"><pre>    <span class="p">.</span><span class="nx">replace</span><span class="p">(</span>
+    <span class="p">)</span></pre></div>             </td>           </tr>                               <tr id="section-51">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-51">&#182;</a>               </div>               <p>Swap back in all the special characters we've hidden.</p>             </td>             <td class="code">               <div class="highlight"><pre>  <span class="nv">unescapeSpecialChars: </span><span class="o">-&gt;</span>
+    <span class="nx">@replace</span> <span class="sr">/~E(\d+)E/g</span><span class="p">,</span> <span class="nf">(_, m1) -&gt;</span> <span class="nb">String</span><span class="p">.</span><span class="nx">fromCharCode</span> <span class="nb">parseInt</span> <span class="nx">m1</span><span class="p">,</span> <span class="mi">10</span></pre></div>             </td>           </tr>                               <tr id="section-52">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-52">&#182;</a>               </div>               <p>Remove one level of line-leading tabs or spaces.</p>             </td>             <td class="code">               <div class="highlight"><pre>  <span class="nv">outdent: </span><span class="o">-&gt;</span>
+    <span class="nx">@replace</span><span class="p">(</span><span class="sr">/^(\t|[ ]{1,4})/gm</span><span class="p">,</span> <span class="s1">&#39;~0&#39;</span><span class="p">).</span><span class="nx">trim</span> <span class="sr">/~0/g</span> <span class="c1"># attacklab: clean up hack</span></pre></div>             </td>           </tr>                               <tr id="section-53">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-53">&#182;</a>               </div>               <p><em>attacklab:</em> Completely rewritten for speed. In Perl we could fix it by
+anchoring the regexp with <code>\G</code>. In JavaScript we're less fortunate.</p>             </td>             <td class="code">               <div class="highlight"><pre>  <span class="nv">detab: </span><span class="o">-&gt;</span></pre></div>             </td>           </tr>                               <tr id="section-54">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-54">&#182;</a>               </div>               <p>Expand first n-1 tabs.</p>             </td>             <td class="code">               <div class="highlight"><pre>    <span class="nx">@replace</span><span class="p">(</span><span class="sr">/\t(?=\t)/g</span><span class="p">,</span> <span class="s1">&#39;    &#39;</span><span class="p">)</span></pre></div>             </td>           </tr>                               <tr id="section-55">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-55">&#182;</a>               </div>               <p>Replace the nth with two sentinels.</p>             </td>             <td class="code">               <div class="highlight"><pre>    <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;~A~B&#39;</span><span class="p">)</span></pre></div>             </td>           </tr>                               <tr id="section-56">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-56">&#182;</a>               </div>               <p>Use the sentinel to anchor our regex so it doesn't explode.</p>             </td>             <td class="code">               <div class="highlight"><pre>    <span class="p">.</span><span class="nx">replace</span><span class="p">(</span>
       <span class="sr">/~B(.+?)~A/g</span><span class="p">,</span>
       <span class="nf">(_, leadingText) -&gt;</span>
         <span class="nv">numSpaces = </span><span class="mi">4</span> <span class="o">-</span> <span class="nx">leadingText</span><span class="p">.</span><span class="nx">length</span> <span class="o">%</span> <span class="mi">4</span>
     <span class="p">)</span>
     <span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/~A/g</span><span class="p">,</span> <span class="s1">&#39;    &#39;</span><span class="p">).</span><span class="nx">trim</span> <span class="sr">/~B/g</span> <span class="c1"># clean up sentinels</span>
 
-  <span class="nv">escapeCharacters: </span><span class="nf">(charsToEscape) -&gt;</span></pre></div>             </td>           </tr>                               <tr id="section-58">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-58">&#182;</a>               </div>               <p>First we have to escape the escape characters so that we can build a
+  <span class="nv">escapeCharacters: </span><span class="nf">(charsToEscape) -&gt;</span></pre></div>             </td>           </tr>                               <tr id="section-57">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-57">&#182;</a>               </div>               <p>First we have to escape the escape characters so that we can build a
 character class out of them.</p>             </td>             <td class="code">               <div class="highlight"><pre>    <span class="nx">@replace</span><span class="p">(</span>
       <span class="k">new</span> <span class="nb">RegExp</span><span class="p">(</span><span class="s2">&quot;([#{ charsToEscape.replace /[[\\\]]/g, &#39;\\$&amp;&#39; }])&quot;</span><span class="p">,</span> <span class="s1">&#39;g&#39;</span><span class="p">),</span>
       <span class="nx">escapeCharacters_callback</span>
     <span class="p">)</span>
 
 <span class="nv">hashElement = </span><span class="nf">(_, blockText) -&gt;</span>
-  <span class="nv">blockText = </span><span class="k">new</span> <span class="nx">Text</span><span class="p">(</span><span class="nx">blockText</span><span class="p">).</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/\n\n/g</span><span class="p">,</span> <span class="s1">&#39;\n&#39;</span><span class="p">).</span><span class="nx">trim</span> <span class="sr">/^\n|\n+$/g</span></pre></div>             </td>           </tr>                               <tr id="section-59">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-59">&#182;</a>               </div>               <p>Replace the element text with a marker (<code>~KxK</code> where <code>x</code> is its key).</p>             </td>             <td class="code">               <div class="highlight"><pre>  <span class="s2">&quot;\n\n~K#{ blocks.push(blockText) - 1 }K\n\n&quot;</span>
+  <span class="nv">blockText = </span><span class="k">new</span> <span class="nx">Text</span><span class="p">(</span><span class="nx">blockText</span><span class="p">).</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/\n\n/g</span><span class="p">,</span> <span class="s1">&#39;\n&#39;</span><span class="p">).</span><span class="nx">trim</span> <span class="sr">/^\n|\n+$/g</span></pre></div>             </td>           </tr>                               <tr id="section-58">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-58">&#182;</a>               </div>               <p>Replace the element text with a marker (<code>~KxK</code> where <code>x</code> is its key).</p>             </td>             <td class="code">               <div class="highlight"><pre>  <span class="s2">&quot;\n\n~K#{ blocks.push(blockText) - 1 }K\n\n&quot;</span>
 
 <span class="nv">writeAnchorTag = </span><span class="nf">(match, link_text, link_id, url, m5, m6, title) -&gt;</span>
   <span class="nv">link_id = </span><span class="nx">link_id</span><span class="p">.</span><span class="nx">toLowerCase</span><span class="p">()</span>
 
-  <span class="k">if</span> <span class="o">not</span> <span class="nx">url</span></pre></div>             </td>           </tr>                               <tr id="section-60">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-60">&#182;</a>               </div>               <p>Lower-case and turn embedded newlines into spaces.</p>             </td>             <td class="code">               <div class="highlight"><pre>    <span class="nx">link_id</span> <span class="o">or=</span> <span class="nx">link_text</span><span class="p">.</span><span class="nx">toLowerCase</span><span class="p">().</span><span class="nx">trim</span> <span class="sr">/[ ]?\n/g</span>
+  <span class="k">if</span> <span class="o">not</span> <span class="nx">url</span></pre></div>             </td>           </tr>                               <tr id="section-59">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-59">&#182;</a>               </div>               <p>Lower-case and turn embedded newlines into spaces.</p>             </td>             <td class="code">               <div class="highlight"><pre>    <span class="nx">link_id</span> <span class="o">or=</span> <span class="nx">link_text</span><span class="p">.</span><span class="nx">toLowerCase</span><span class="p">().</span><span class="nx">trim</span> <span class="sr">/[ ]?\n/g</span>
     <span class="nv">url = </span><span class="s1">&#39;#&#39;</span> <span class="o">+</span> <span class="nx">link_id</span>
 
     <span class="k">if</span> <span class="nx">urls</span><span class="p">[</span><span class="nx">link_id</span><span class="p">]</span> <span class="o">is</span> <span class="kc">undefined</span>
-      <span class="k">if</span> <span class="sr">/\(\s*\)$/m</span><span class="p">.</span><span class="nx">test</span> <span class="nx">match</span></pre></div>             </td>           </tr>                               <tr id="section-61">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-61">&#182;</a>               </div>               <p>Special case for explicit empty url.</p>             </td>             <td class="code">               <div class="highlight"><pre>        <span class="nv">url = </span><span class="s1">&#39;&#39;</span>
+      <span class="k">if</span> <span class="sr">/\(\s*\)$/m</span><span class="p">.</span><span class="nx">test</span> <span class="nx">match</span></pre></div>             </td>           </tr>                               <tr id="section-60">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-60">&#182;</a>               </div>               <p>Special case for explicit empty url.</p>             </td>             <td class="code">               <div class="highlight"><pre>        <span class="nv">url = </span><span class="s1">&#39;&#39;</span>
       <span class="k">else</span>
         <span class="k">return</span> <span class="nx">match</span>
     <span class="k">else</span>
   <span class="nv">link_id = </span><span class="nx">link_id</span><span class="p">.</span><span class="nx">toLowerCase</span><span class="p">()</span>
 
   <span class="k">if</span> <span class="nx">url</span> <span class="o">is</span> <span class="s1">&#39;&#39;</span>
-    <span class="k">if</span> <span class="nx">link_id</span> <span class="o">is</span> <span class="s1">&#39;&#39;</span></pre></div>             </td>           </tr>                               <tr id="section-62">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-62">&#182;</a>               </div>               <p>Lower-case and turn embedded newlines into spaces.</p>             </td>             <td class="code">               <div class="highlight"><pre>      <span class="nv">link_id = </span><span class="nx">alt_text</span><span class="p">.</span><span class="nx">toLowerCase</span><span class="p">().</span><span class="nx">replace</span> <span class="sr">/[ ]?\n/g</span><span class="p">,</span> <span class="s1">&#39; &#39;</span>
+    <span class="k">if</span> <span class="nx">link_id</span> <span class="o">is</span> <span class="s1">&#39;&#39;</span></pre></div>             </td>           </tr>                               <tr id="section-61">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-61">&#182;</a>               </div>               <p>Lower-case and turn embedded newlines into spaces.</p>             </td>             <td class="code">               <div class="highlight"><pre>      <span class="nv">link_id = </span><span class="nx">alt_text</span><span class="p">.</span><span class="nx">toLowerCase</span><span class="p">().</span><span class="nx">replace</span> <span class="sr">/[ ]?\n/g</span><span class="p">,</span> <span class="s1">&#39; &#39;</span>
 
     <span class="nv">url = </span><span class="s1">&#39;#&#39;</span> <span class="o">+</span> <span class="nx">link_id</span>
 
     <span class="p">.</span><span class="nx">cond</span><span class="p">(</span><span class="nx">title</span><span class="p">,</span> <span class="o">-&gt;</span>
       <span class="nx">@after</span><span class="p">(</span><span class="s1">&#39; title=&quot;&#39;</span> <span class="o">+</span> <span class="k">new</span> <span class="nx">Text</span><span class="p">(</span><span class="nx">title</span><span class="p">).</span><span class="nx">quot</span><span class="p">().</span><span class="nx">escapeCharacters</span><span class="p">(</span><span class="s1">&#39;*_&#39;</span><span class="p">)</span> <span class="o">+</span> <span class="s1">&#39;&quot;&#39;</span><span class="p">)</span>
     <span class="p">)</span>
-    <span class="p">.</span><span class="nx">after</span><span class="p">(</span><span class="s1">&#39; /&gt;&#39;</span><span class="p">)</span></pre></div>             </td>           </tr>                               <tr id="section-63">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-63">&#182;</a>               </div>               <p>Process the contents of a single ordered or unordered list, splitting it
-into individual list items.</p>             </td>             <td class="code">               <div class="highlight"><pre><span class="nv">processListItems = </span><span class="nf">(list_str) -&gt;</span></pre></div>             </td>           </tr>                               <tr id="section-64">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-64">&#182;</a>               </div>               <p><code>level</code> keeps track of when we're inside a list. Each time we enter a
+    <span class="p">.</span><span class="nx">after</span><span class="p">(</span><span class="s1">&#39; /&gt;&#39;</span><span class="p">)</span></pre></div>             </td>           </tr>                               <tr id="section-62">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-62">&#182;</a>               </div>               <p>Process the contents of a single ordered or unordered list, splitting it
+into individual list items.</p>             </td>             <td class="code">               <div class="highlight"><pre><span class="nv">processListItems = </span><span class="nf">(list_str) -&gt;</span></pre></div>             </td>           </tr>                               <tr id="section-63">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-63">&#182;</a>               </div>               <p><code>level</code> keeps track of when we're inside a list. Each time we enter a
 list, we increment it; when we leave a list, we decrement. If it's zero,
 we're not in a list anymore.</p>
 
         <span class="p">.</span><span class="nx">after</span><span class="p">(</span><span class="s1">&#39;&lt;/li&gt;\n&#39;</span><span class="p">)</span>
   <span class="p">)</span>
   <span class="nx">level</span><span class="o">--</span>
-  <span class="nx">list_str</span><span class="p">.</span><span class="nx">replace</span> <span class="sr">/~0/g</span><span class="p">,</span> <span class="s1">&#39;&#39;</span> <span class="c1"># attacklab: strip sentinel</span></pre></div>             </td>           </tr>                               <tr id="section-65">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-65">&#182;</a>               </div>               <p><em>attacklab:</em> Why can't JavaScript speak hex?</p>             </td>             <td class="code">               <div class="highlight"><pre><span class="nv">char2hex = </span><span class="nf">(ch) -&gt;</span>
+  <span class="nx">list_str</span><span class="p">.</span><span class="nx">replace</span> <span class="sr">/~0/g</span><span class="p">,</span> <span class="s1">&#39;&#39;</span> <span class="c1"># attacklab: strip sentinel</span></pre></div>             </td>           </tr>                               <tr id="section-64">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-64">&#182;</a>               </div>               <p><em>attacklab:</em> Why can't JavaScript speak hex?</p>             </td>             <td class="code">               <div class="highlight"><pre><span class="nv">char2hex = </span><span class="nf">(ch) -&gt;</span>
   <span class="nv">dec = </span><span class="nx">ch</span><span class="p">.</span><span class="nx">charCodeAt</span> <span class="mi">0</span>
   <span class="nv">hexDigits = </span><span class="s1">&#39;0123456789ABCDEF&#39;</span>
-  <span class="nx">hexDigits</span><span class="p">.</span><span class="nx">charAt</span><span class="p">(</span><span class="nx">dec</span> <span class="o">&gt;&gt;</span> <span class="mi">4</span><span class="p">)</span> <span class="o">+</span> <span class="nx">hexDigits</span><span class="p">.</span><span class="nx">charAt</span><span class="p">(</span><span class="nx">dec</span> <span class="o">&amp;</span> <span class="mi">15</span><span class="p">)</span></pre></div>             </td>           </tr>                               <tr id="section-66">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-66">&#182;</a>               </div>               <p>Each character of the address is encoded as either a decimal or hex entity,
+  <span class="nx">hexDigits</span><span class="p">.</span><span class="nx">charAt</span><span class="p">(</span><span class="nx">dec</span> <span class="o">&gt;&gt;</span> <span class="mi">4</span><span class="p">)</span> <span class="o">+</span> <span class="nx">hexDigits</span><span class="p">.</span><span class="nx">charAt</span><span class="p">(</span><span class="nx">dec</span> <span class="o">&amp;</span> <span class="mi">15</span><span class="p">)</span></pre></div>             </td>           </tr>                               <tr id="section-65">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-65">&#182;</a>               </div>               <p>Each character of the address is encoded as either a decimal or hex entity,
 in the hopes of foiling most address harvesting spam bots.</p>
 
 <p>For example:</p>
     <span class="nf">(ch) -&gt;</span> <span class="s2">&quot;&amp;#x#{ char2hex ch };&quot;</span>
   <span class="p">]</span>
   <span class="nv">addr = </span><span class="s2">&quot;mailto:#{ addr }&quot;</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="nf">(ch) -&gt;</span>
-    <span class="k">switch</span> <span class="nx">ch</span></pre></div>             </td>           </tr>                               <tr id="section-67">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-67">&#182;</a>               </div>               <p>Leave ":" alone (to spot <code>mailto:</code> later).</p>             </td>             <td class="code">               <div class="highlight"><pre>      <span class="k">when</span> <span class="s1">&#39;:&#39;</span> <span class="k">then</span> <span class="nx">ch</span></pre></div>             </td>           </tr>                               <tr id="section-68">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-68">&#182;</a>               </div>               <p>This <em>must</em> be encoded. I insist.</p>             </td>             <td class="code">               <div class="highlight"><pre>      <span class="k">when</span> <span class="s1">&#39;@&#39;</span> <span class="k">then</span> <span class="nx">encode</span><span class="p">[</span><span class="nb">Math</span><span class="p">.</span><span class="nx">floor</span> <span class="nb">Math</span><span class="p">.</span><span class="nx">random</span><span class="p">()</span><span class="o">*</span><span class="mi">2</span><span class="p">]</span> <span class="nx">ch</span></pre></div>             </td>           </tr>                               <tr id="section-69">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-69">&#182;</a>               </div>               <p>Roughly 10% raw, 45% dec, 45% hex.</p>             </td>             <td class="code">               <div class="highlight"><pre>      <span class="k">else</span>
+    <span class="k">switch</span> <span class="nx">ch</span></pre></div>             </td>           </tr>                               <tr id="section-66">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-66">&#182;</a>               </div>               <p>Leave ":" alone (to spot <code>mailto:</code> later).</p>             </td>             <td class="code">               <div class="highlight"><pre>      <span class="k">when</span> <span class="s1">&#39;:&#39;</span> <span class="k">then</span> <span class="nx">ch</span></pre></div>             </td>           </tr>                               <tr id="section-67">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-67">&#182;</a>               </div>               <p>This <em>must</em> be encoded. I insist.</p>             </td>             <td class="code">               <div class="highlight"><pre>      <span class="k">when</span> <span class="s1">&#39;@&#39;</span> <span class="k">then</span> <span class="nx">encode</span><span class="p">[</span><span class="nb">Math</span><span class="p">.</span><span class="nx">floor</span> <span class="nb">Math</span><span class="p">.</span><span class="nx">random</span><span class="p">()</span><span class="o">*</span><span class="mi">2</span><span class="p">]</span> <span class="nx">ch</span></pre></div>             </td>           </tr>                               <tr id="section-68">             <td class="docs">               <div class="pilwrap">                 <a class="pilcrow" href="#section-68">&#182;</a>               </div>               <p>Roughly 10% raw, 45% dec, 45% hex.</p>             </td>             <td class="code">               <div class="highlight"><pre>      <span class="k">else</span>
         <span class="nv">r = </span><span class="nb">Math</span><span class="p">.</span><span class="nx">random</span><span class="p">()</span>
         <span class="k">if</span> <span class="nx">r</span> <span class="o">&gt;</span> <span class="mf">0.9</span> <span class="k">then</span> <span class="nx">ch</span> <span class="k">else</span> <span class="k">if</span> <span class="nx">r</span> <span class="o">&gt;</span> <span class="mf">0.45</span> <span class="k">then</span> <span class="nx">encode</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="nx">ch</span> <span class="k">else</span> <span class="nx">encode</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="nx">ch</span>
   <span class="p">)</span>