Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Update docs/docco lib

  • Loading branch information...
commit 966600de7d1e78d27a008f2b4ff2b9d1e8ac0acd 1 parent 7c1e3b8
@justindujardin justindujardin authored
Showing with 199 additions and 42 deletions.
  1. +179 −37 index.html
  2. +20 −5 lib/docco.js
View
216 index.html
@@ -47,16 +47,28 @@
<li><p>And if you happen to be a <strong>.NET</strong>
aficionado, check out <a href="https://github.com/dontangg">Don Wilson</a>'s
<a href="http://dontangg.github.com/nocco/">Nocco</a>.</p></li>
-</ul> </div> </li> <li id="section-2"> <div class="annotation"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div> <h3>Main Documentation Generation Functions</h3> </div> </li> <li id="section-3"> <div class="annotation"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">&#182;</a> </div> <p>Generate the documentation for a source file by reading it in, splitting it
+</ul>
+
+ </div> </li> <li id="section-2"> <div class="annotation"> <div class="pilwrap"> <a class="pilcrow" href="#section-2">&#182;</a> </div>
+
+<h3>Main Documentation Generation Functions</h3>
+
+ </div> </li> <li id="section-3"> <div class="annotation"> <div class="pilwrap"> <a class="pilcrow" href="#section-3">&#182;</a> </div>
+
+<p>Generate the documentation for a source file by reading it in, splitting it
up into comment/code sections, highlighting them for the appropriate language,
-and merging them into an HTML template.</p> </div> <div class="content"><div class="highlight"><pre><span class="nv">generateDocumentation = </span><span class="nf">(source, config, callback) -&gt;</span>
+and merging them into an HTML template.</p>
+
+ </div> <div class="content"><div class="highlight"><pre><span class="nv">generateDocumentation = </span><span class="nf">(source, config, callback) -&gt;</span>
<span class="nx">fs</span><span class="p">.</span><span class="nx">readFile</span> <span class="nx">source</span><span class="p">,</span> <span class="nf">(error, buffer) -&gt;</span>
<span class="k">throw</span> <span class="nx">error</span> <span class="k">if</span> <span class="nx">error</span>
<span class="nv">code = </span><span class="nx">buffer</span><span class="p">.</span><span class="nx">toString</span><span class="p">()</span>
<span class="nv">sections = </span><span class="nx">parse</span> <span class="nx">source</span><span class="p">,</span> <span class="nx">code</span>
<span class="nx">highlight</span> <span class="nx">source</span><span class="p">,</span> <span class="nx">sections</span><span class="p">,</span> <span class="nf">-&gt;</span>
<span class="nx">generateHtml</span> <span class="nx">source</span><span class="p">,</span> <span class="nx">sections</span><span class="p">,</span> <span class="nx">config</span>
- <span class="nx">callback</span><span class="p">()</span></pre></div></div> </li> <li id="section-4"> <div class="annotation"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">&#182;</a> </div> <p>Given a string of source code, parse out each comment and the code that
+ <span class="nx">callback</span><span class="p">()</span></pre></div></div> </li> <li id="section-4"> <div class="annotation"> <div class="pilwrap"> <a class="pilcrow" href="#section-4">&#182;</a> </div>
+
+<p>Given a string of source code, parse out each comment and the code that
follows it, and create an individual <strong>section</strong> for it.
Sections take the form:</p>
@@ -66,7 +78,9 @@
codeText: ...
codeHtml: ...
}
-</code></pre> </div> <div class="content"><div class="highlight"><pre><span class="nv">parse = </span><span class="nf">(source, code) -&gt;</span>
+</code></pre>
+
+ </div> <div class="content"><div class="highlight"><pre><span class="nv">parse = </span><span class="nf">(source, code) -&gt;</span>
<span class="nv">lines = </span><span class="nx">code</span><span class="p">.</span><span class="nx">split</span> <span class="s">&#39;\n&#39;</span>
<span class="nv">sections = </span><span class="p">[]</span>
<span class="nv">language = </span><span class="nx">getLanguage</span> <span class="nx">source</span>
@@ -85,46 +99,70 @@
<span class="nv">hasCode = </span><span class="kc">yes</span>
<span class="nx">codeText</span> <span class="o">+=</span> <span class="nx">line</span> <span class="o">+</span> <span class="s">&#39;\n&#39;</span>
<span class="nx">save</span> <span class="nx">docsText</span><span class="p">,</span> <span class="nx">codeText</span>
- <span class="nx">sections</span></pre></div></div> </li> <li id="section-5"> <div class="annotation"> <div class="pilwrap"> <a class="pilcrow" href="#section-5">&#182;</a> </div> <p>Highlights a single chunk of CoffeeScript code, using <strong>Pygments</strong> over stdio,
+ <span class="nx">sections</span></pre></div></div> </li> <li id="section-5"> <div class="annotation"> <div class="pilwrap"> <a class="pilcrow" href="#section-5">&#182;</a> </div>
+
+<p>Highlights a single chunk of CoffeeScript code, using <strong>Pygments</strong> over stdio,
and runs the text of its corresponding comment through <strong>Markdown</strong>, using
<a href="http://attacklab.net/showdown/">Showdown.js</a>.</p>
-<p>We process the entire file in a single call to Pygments by inserting little
-marker comments between each section and then splitting the result string
-wherever our markers occur.</p> </div> <div class="content"><div class="highlight"><pre><span class="nv">highlight = </span><span class="nf">(source, sections, callback) -&gt;</span>
+<p>We process the entire file in single calls to Pygments and Showdown by inserting
+little marker comments between each section and then splitting the result string
+wherever our markers occur.</p>
+
+ </div> <div class="content"><div class="highlight"><pre><span class="nv">highlight = </span><span class="nf">(source, sections, callback) -&gt;</span>
<span class="nv">language = </span><span class="nx">getLanguage</span> <span class="nx">source</span>
<span class="nv">pygments = </span><span class="nx">spawn</span> <span class="s">&#39;pygmentize&#39;</span><span class="p">,</span> <span class="p">[</span>
<span class="s">&#39;-l&#39;</span><span class="p">,</span> <span class="nx">language</span><span class="p">.</span><span class="nx">name</span><span class="p">,</span>
<span class="s">&#39;-f&#39;</span><span class="p">,</span> <span class="s">&#39;html&#39;</span><span class="p">,</span>
<span class="s">&#39;-O&#39;</span><span class="p">,</span> <span class="s">&#39;encoding=utf-8,tabsize=2&#39;</span>
<span class="p">]</span>
- <span class="nv">output = </span><span class="s">&#39;&#39;</span>
+ <span class="nv">output = </span><span class="s">&#39;&#39;</span>
+ <span class="nv">code = </span><span class="p">(</span><span class="nx">section</span><span class="p">.</span><span class="nx">codeText</span> <span class="k">for</span> <span class="nx">section</span> <span class="k">in</span> <span class="nx">sections</span><span class="p">).</span><span class="nx">join</span> <span class="nx">language</span><span class="p">.</span><span class="nx">codeSplitText</span>
+ <span class="nv">docs = </span><span class="p">(</span><span class="nx">section</span><span class="p">.</span><span class="nx">docsText</span> <span class="k">for</span> <span class="nx">section</span> <span class="k">in</span> <span class="nx">sections</span><span class="p">).</span><span class="nx">join</span> <span class="nx">language</span><span class="p">.</span><span class="nx">docsSplitText</span>
<span class="nx">pygments</span><span class="p">.</span><span class="nx">stderr</span><span class="p">.</span><span class="nx">on</span> <span class="s">&#39;data&#39;</span><span class="p">,</span> <span class="nf">(error) -&gt;</span>
<span class="nx">console</span><span class="p">.</span><span class="nx">error</span> <span class="nx">error</span><span class="p">.</span><span class="nx">toString</span><span class="p">()</span> <span class="k">if</span> <span class="nx">error</span>
-
+
<span class="nx">pygments</span><span class="p">.</span><span class="nx">stdin</span><span class="p">.</span><span class="nx">on</span> <span class="s">&#39;error&#39;</span><span class="p">,</span> <span class="nf">(error) -&gt;</span>
- <span class="nx">console</span><span class="p">.</span><span class="nx">error</span> <span class="s">&#39;Could not use Pygments to highlight the source.&#39;</span>
- <span class="nx">process</span><span class="p">.</span><span class="nx">exit</span> <span class="mi">1</span>
+ <span class="nx">console</span><span class="p">.</span><span class="nx">error</span> <span class="s">&#39;Could not highlight code, using plaintext&#39;</span>
<span class="nx">pygments</span><span class="p">.</span><span class="nx">stdout</span><span class="p">.</span><span class="nx">on</span> <span class="s">&#39;data&#39;</span><span class="p">,</span> <span class="nf">(result) -&gt;</span>
<span class="nx">output</span> <span class="o">+=</span> <span class="nx">result</span> <span class="k">if</span> <span class="nx">result</span>
<span class="nx">pygments</span><span class="p">.</span><span class="nx">on</span> <span class="s">&#39;exit&#39;</span><span class="p">,</span> <span class="nf">-&gt;</span>
<span class="nv">output = </span><span class="nx">output</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="nx">highlightStart</span><span class="p">,</span> <span class="s">&#39;&#39;</span><span class="p">).</span><span class="nx">replace</span><span class="p">(</span><span class="nx">highlightEnd</span><span class="p">,</span> <span class="s">&#39;&#39;</span><span class="p">)</span>
- <span class="nv">fragments = </span><span class="nx">output</span><span class="p">.</span><span class="nx">split</span> <span class="nx">language</span><span class="p">.</span><span class="nx">dividerHtml</span>
+ <span class="k">if</span> <span class="nx">output</span> <span class="o">is</span> <span class="s">&#39;&#39;</span>
+ <span class="nv">codeFragments = </span><span class="p">(</span><span class="nx">htmlEscape</span> <span class="nx">section</span><span class="p">.</span><span class="nx">codeText</span> <span class="k">for</span> <span class="nx">section</span> <span class="k">in</span> <span class="nx">sections</span><span class="p">)</span>
+ <span class="k">else</span>
+ <span class="nv">codeFragments = </span><span class="nx">output</span><span class="p">.</span><span class="nx">split</span> <span class="nx">language</span><span class="p">.</span><span class="nx">codeSplitHtml</span>
+ <span class="nv">docsFragments = </span><span class="nx">showdown</span><span class="p">.</span><span class="nx">makeHtml</span><span class="p">(</span><span class="nx">docs</span><span class="p">).</span><span class="nx">split</span> <span class="nx">language</span><span class="p">.</span><span class="nx">docsSplitHtml</span>
+
<span class="k">for</span> <span class="nx">section</span><span class="p">,</span> <span class="nx">i</span> <span class="k">in</span> <span class="nx">sections</span>
- <span class="nv">section.codeHtml = </span><span class="nx">highlightStart</span> <span class="o">+</span> <span class="nx">fragments</span><span class="p">[</span><span class="nx">i</span><span class="p">]</span> <span class="o">+</span> <span class="nx">highlightEnd</span>
- <span class="nv">section.docsHtml = </span><span class="nx">showdown</span><span class="p">.</span><span class="nx">makeHtml</span> <span class="nx">section</span><span class="p">.</span><span class="nx">docsText</span>
+ <span class="nv">section.codeHtml = </span><span class="nx">highlightStart</span> <span class="o">+</span> <span class="nx">codeFragments</span><span class="p">[</span><span class="nx">i</span><span class="p">]</span> <span class="o">+</span> <span class="nx">highlightEnd</span>
+ <span class="nv">section.docsHtml = </span><span class="nx">docsFragments</span><span class="p">[</span><span class="nx">i</span><span class="p">]</span>
<span class="nx">callback</span><span class="p">()</span>
<span class="k">if</span> <span class="nx">pygments</span><span class="p">.</span><span class="nx">stdin</span><span class="p">.</span><span class="nx">writable</span>
- <span class="nv">text = </span><span class="p">(</span><span class="nx">section</span><span class="p">.</span><span class="nx">codeText</span> <span class="k">for</span> <span class="nx">section</span> <span class="k">in</span> <span class="nx">sections</span><span class="p">)</span>
- <span class="nx">pygments</span><span class="p">.</span><span class="nx">stdin</span><span class="p">.</span><span class="nx">write</span> <span class="nx">text</span><span class="p">.</span><span class="nx">join</span> <span class="nx">language</span><span class="p">.</span><span class="nx">dividerText</span>
+ <span class="nx">pygments</span><span class="p">.</span><span class="nx">stdin</span><span class="p">.</span><span class="nx">write</span> <span class="nx">code</span>
<span class="nx">pygments</span><span class="p">.</span><span class="nx">stdin</span><span class="p">.</span><span class="nx">end</span><span class="p">()</span>
- </pre></div></div> </li> <li id="section-6"> <div class="annotation"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">&#182;</a> </div> <p>Once all of the code is finished highlighting, we can generate the HTML file by
+ </pre></div></div> </li> <li id="section-6"> <div class="annotation"> <div class="pilwrap"> <a class="pilcrow" href="#section-6">&#182;</a> </div>
+
+<p>Escape an html string, to produce valid non-highlighted output when pygments
+is not present on the system.</p>
+
+ </div> <div class="content"><div class="highlight"><pre><span class="nv">htmlEscape = </span><span class="nf">(string) -&gt;</span>
+ <span class="nx">string</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/&amp;/g</span><span class="p">,</span> <span class="s">&#39;&amp;amp;&#39;</span><span class="p">)</span>
+ <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="s">&#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="s">&#39;&amp;gt;&#39;</span><span class="p">)</span>
+ <span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/&quot;/g</span><span class="p">,</span> <span class="s">&#39;&amp;quot;&#39;</span><span class="p">)</span>
+ <span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/&#39;/g</span><span class="p">,</span> <span class="s">&#39;&amp;#x27;&#39;</span><span class="p">)</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="s">&#39;&amp;#x2F;&#39;</span><span class="p">)</span></pre></div></div> </li> <li id="section-7"> <div class="annotation"> <div class="pilwrap"> <a class="pilcrow" href="#section-7">&#182;</a> </div>
+
+<p>Once all of the code is finished highlighting, we can generate the HTML file by
passing the completed sections into the template, and then writing the file to
-the specified output path.</p> </div> <div class="content"><div class="highlight"><pre><span class="nv">generateHtml = </span><span class="nf">(source, sections, config) -&gt;</span>
+the specified output path.</p>
+
+ </div> <div class="content"><div class="highlight"><pre><span class="nv">generateHtml = </span><span class="nf">(source, sections, config) -&gt;</span>
<span class="nv">destination = </span><span class="nf">(filepath) -&gt;</span>
<span class="nx">path</span><span class="p">.</span><span class="nx">join</span><span class="p">(</span><span class="nx">config</span><span class="p">.</span><span class="nx">output</span><span class="p">,</span> <span class="nx">path</span><span class="p">.</span><span class="nx">basename</span><span class="p">(</span><span class="nx">filepath</span><span class="p">,</span> <span class="nx">path</span><span class="p">.</span><span class="nx">extname</span><span class="p">(</span><span class="nx">filepath</span><span class="p">))</span> <span class="o">+</span> <span class="s">&#39;.html&#39;</span><span class="p">)</span>
<span class="nv">title = </span><span class="nx">path</span><span class="p">.</span><span class="nx">basename</span> <span class="nx">source</span>
@@ -138,22 +176,80 @@
<span class="nv">css : </span><span class="nx">path</span><span class="p">.</span><span class="nx">basename</span><span class="p">(</span><span class="nx">config</span><span class="p">.</span><span class="nx">css</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="s">&quot;docco: </span><span class="si">#{</span><span class="nx">source</span><span class="si">}</span><span class="s"> -&gt; </span><span class="si">#{</span><span class="nx">dest</span><span class="si">}</span><span class="s">&quot;</span>
- <span class="nx">fs</span><span class="p">.</span><span class="nx">writeFileSync</span> <span class="nx">dest</span><span class="p">,</span> <span class="nx">html</span></pre></div></div> </li> <li id="section-7"> <div class="annotation"> <div class="pilwrap"> <a class="pilcrow" href="#section-7">&#182;</a> </div> <h3>Helpers &amp; Setup</h3> </div> </li> <li id="section-8"> <div class="annotation"> <div class="pilwrap"> <a class="pilcrow" href="#section-8">&#182;</a> </div> <p>Require our external dependencies, including <strong>Showdown.js</strong>
-(the JavaScript implementation of Markdown).</p> </div> <div class="content"><div class="highlight"><pre><span class="nv">fs = </span><span class="nx">require</span> <span class="s">&#39;fs&#39;</span>
+ <span class="nx">fs</span><span class="p">.</span><span class="nx">writeFileSync</span> <span class="nx">dest</span><span class="p">,</span> <span class="nx">html</span></pre></div></div> </li> <li id="section-8"> <div class="annotation"> <div class="pilwrap"> <a class="pilcrow" href="#section-8">&#182;</a> </div>
+
+<h3>Helpers &amp; Setup</h3>
+
+ </div> </li> <li id="section-9"> <div class="annotation"> <div class="pilwrap"> <a class="pilcrow" href="#section-9">&#182;</a> </div>
+
+<p>Require our external dependencies, including <strong>Showdown.js</strong>
+(the JavaScript implementation of Markdown).</p>
+
+ </div> <div class="content"><div class="highlight"><pre><span class="nv">fs = </span><span class="nx">require</span> <span class="s">&#39;fs&#39;</span>
<span class="nv">path = </span><span class="nx">require</span> <span class="s">&#39;path&#39;</span>
<span class="nv">showdown = </span><span class="nx">require</span><span class="p">(</span><span class="s">&#39;./../vendor/showdown&#39;</span><span class="p">).</span><span class="nx">Showdown</span>
<span class="p">{</span><span class="nx">spawn</span><span class="p">,</span> <span class="nx">exec</span><span class="p">}</span> <span class="o">=</span> <span class="nx">require</span> <span class="s">&#39;child_process&#39;</span>
-<span class="nv">commander = </span><span class="nx">require</span> <span class="s">&#39;commander&#39;</span></pre></div></div> </li> <li id="section-9"> <div class="annotation"> <div class="pilwrap"> <a class="pilcrow" href="#section-9">&#182;</a> </div> <p>Read resource file and return its content.</p> </div> <div class="content"><div class="highlight"><pre><span class="nv">getResource = </span><span class="nf">(name) -&gt;</span>
+<span class="nv">commander = </span><span class="nx">require</span> <span class="s">&#39;commander&#39;</span></pre></div></div> </li> <li id="section-10"> <div class="annotation"> <div class="pilwrap"> <a class="pilcrow" href="#section-10">&#182;</a> </div>
+
+<p>Read resource file and return its content.</p>
+
+ </div> <div class="content"><div class="highlight"><pre><span class="nv">getResource = </span><span class="nf">(name) -&gt;</span>
<span class="nv">fullPath = </span><span class="nx">path</span><span class="p">.</span><span class="nx">join</span> <span class="nx">__dirname</span><span class="p">,</span> <span class="s">&#39;..&#39;</span><span class="p">,</span> <span class="s">&#39;resources&#39;</span><span class="p">,</span> <span class="nx">name</span>
- <span class="nx">fs</span><span class="p">.</span><span class="nx">readFileSync</span><span class="p">(</span><span class="nx">fullPath</span><span class="p">).</span><span class="nx">toString</span><span class="p">()</span></pre></div></div> </li> <li id="section-10"> <div class="annotation"> <div class="pilwrap"> <a class="pilcrow" href="#section-10">&#182;</a> </div> <p>Languages are stored in JSON format in the file <code>resources/languages.json</code>
+ <span class="nx">fs</span><span class="p">.</span><span class="nx">readFileSync</span><span class="p">(</span><span class="nx">fullPath</span><span class="p">).</span><span class="nx">toString</span><span class="p">()</span></pre></div></div> </li> <li id="section-11"> <div class="annotation"> <div class="pilwrap"> <a class="pilcrow" href="#section-11">&#182;</a> </div>
+
+<p>Languages are stored in JSON format in the file <code>resources/languages.json</code>
Each item maps the file extension to the name of the Pygments lexer and the
-symbol that indicates a comment. To add a new language, modify the file.</p> </div> <div class="content"><div class="highlight"><pre><span class="nv">languages = </span><span class="nx">JSON</span><span class="p">.</span><span class="nx">parse</span> <span class="nx">getResource</span> <span class="s">&#39;languages.json&#39;</span></pre></div></div> </li> <li id="section-11"> <div class="annotation"> <div class="pilwrap"> <a class="pilcrow" href="#section-11">&#182;</a> </div> <p>Build out the appropriate matchers and delimiters for each language.</p> </div> <div class="content"><div class="highlight"><pre><span class="k">for</span> <span class="nx">ext</span><span class="p">,</span> <span class="nx">l</span> <span class="k">of</span> <span class="nx">languages</span></pre></div></div> </li> <li id="section-12"> <div class="annotation"> <div class="pilwrap"> <a class="pilcrow" href="#section-12">&#182;</a> </div> <p>Does the line begin with a comment?</p> </div> <div class="content"><div class="highlight"><pre> <span class="nv">l.commentMatcher = </span><span class="sr">///^\s*</span><span class="si">#{</span><span class="nx">l</span><span class="p">.</span><span class="nx">symbol</span><span class="si">}</span><span class="sr">\s?///</span></pre></div></div> </li> <li id="section-13"> <div class="annotation"> <div class="pilwrap"> <a class="pilcrow" href="#section-13">&#182;</a> </div> <p>Ignore <a href="http://en.wikipedia.org/wiki/Shebang_(Unix)">hashbangs</a>
-and interpolations...</p> </div> <div class="content"><div class="highlight"><pre> <span class="nv">l.commentFilter = </span><span class="sr">/(^#![/]|^\s*#\{)/</span></pre></div></div> </li> <li id="section-14"> <div class="annotation"> <div class="pilwrap"> <a class="pilcrow" href="#section-14">&#182;</a> </div> <p>The dividing token we feed into Pygments, to delimit the boundaries between
-sections.</p> </div> <div class="content"><div class="highlight"><pre> <span class="nv">l.dividerText = </span><span class="s">&quot;\n</span><span class="si">#{</span><span class="nx">l</span><span class="p">.</span><span class="nx">symbol</span><span class="si">}</span><span class="s">DIVIDER\n&quot;</span></pre></div></div> </li> <li id="section-15"> <div class="annotation"> <div class="pilwrap"> <a class="pilcrow" href="#section-15">&#182;</a> </div> <p>The mirror of <code>dividerText</code> that we expect Pygments to return. We can split
+symbol that indicates a comment. To add a new language, modify the file.</p>
+
+ </div> <div class="content"><div class="highlight"><pre><span class="nv">languages = </span><span class="nx">JSON</span><span class="p">.</span><span class="nx">parse</span> <span class="nx">getResource</span> <span class="s">&#39;languages.json&#39;</span></pre></div></div> </li> <li id="section-12"> <div class="annotation"> <div class="pilwrap"> <a class="pilcrow" href="#section-12">&#182;</a> </div>
+
+<p>Build out the appropriate matchers and delimiters for each language.</p>
+
+ </div> <div class="content"><div class="highlight"><pre><span class="k">for</span> <span class="nx">ext</span><span class="p">,</span> <span class="nx">l</span> <span class="k">of</span> <span class="nx">languages</span></pre></div></div> </li> <li id="section-13"> <div class="annotation"> <div class="pilwrap"> <a class="pilcrow" href="#section-13">&#182;</a> </div>
+
+<p>Does the line begin with a comment?</p>
+
+ </div> <div class="content"><div class="highlight"><pre> <span class="nv">l.commentMatcher = </span><span class="sr">///^\s*</span><span class="si">#{</span><span class="nx">l</span><span class="p">.</span><span class="nx">symbol</span><span class="si">}</span><span class="sr">\s?///</span></pre></div></div> </li> <li id="section-14"> <div class="annotation"> <div class="pilwrap"> <a class="pilcrow" href="#section-14">&#182;</a> </div>
+
+<p>Ignore <a href="http://en.wikipedia.org/wiki/Shebang_(Unix)">hashbangs</a>
+and interpolations...</p>
+
+ </div> <div class="content"><div class="highlight"><pre> <span class="nv">l.commentFilter = </span><span class="sr">/(^#![/]|^\s*#\{)/</span></pre></div></div> </li> <li id="section-15"> <div class="annotation"> <div class="pilwrap"> <a class="pilcrow" href="#section-15">&#182;</a> </div>
+
+<p>The dividing token we feed into Pygments, to delimit the boundaries between
+sections.</p>
+
+ </div> <div class="content"><div class="highlight"><pre> <span class="nv">l.codeSplitText = </span><span class="s">&quot;\n</span><span class="si">#{</span><span class="nx">l</span><span class="p">.</span><span class="nx">symbol</span><span class="si">}</span><span class="s">DIVIDER\n&quot;</span></pre></div></div> </li> <li id="section-16"> <div class="annotation"> <div class="pilwrap"> <a class="pilcrow" href="#section-16">&#182;</a> </div>
+
+<p>The mirror of <code>codeSplitText</code> that we expect Pygments to return. We can split
on this to recover the original sections.
-Note: the class is "c" for Python and "c1" for the other languages</p> </div> <div class="content"><div class="highlight"><pre> <span class="nv">l.dividerHtml = </span><span class="sr">///\n*&lt;span\sclass=&quot;c1?&quot;&gt;</span><span class="si">#{</span><span class="nx">l</span><span class="p">.</span><span class="nx">symbol</span><span class="si">}</span><span class="sr">DIVIDER&lt;\/span&gt;\n*///</span></pre></div></div> </li> <li id="section-16"> <div class="annotation"> <div class="pilwrap"> <a class="pilcrow" href="#section-16">&#182;</a> </div> <p>Get the current language we're documenting, based on the extension.</p> </div> <div class="content"><div class="highlight"><pre><span class="nv">getLanguage = </span><span class="nf">(source) -&gt;</span> <span class="nx">languages</span><span class="p">[</span><span class="nx">path</span><span class="p">.</span><span class="nx">extname</span><span class="p">(</span><span class="nx">source</span><span class="p">)]</span></pre></div></div> </li> <li id="section-17"> <div class="annotation"> <div class="pilwrap"> <a class="pilcrow" href="#section-17">&#182;</a> </div> <p>Ensure that the destination directory exists.</p> </div> <div class="content"><div class="highlight"><pre><span class="nv">ensureDirectory = </span><span class="nf">(dir, callback) -&gt;</span>
- <span class="nx">exec</span> <span class="s">&quot;mkdir -p </span><span class="si">#{</span><span class="nx">dir</span><span class="si">}</span><span class="s">&quot;</span><span class="p">,</span> <span class="nf">-&gt;</span> <span class="nx">callback</span><span class="p">()</span></pre></div></div> </li> <li id="section-18"> <div class="annotation"> <div class="pilwrap"> <a class="pilcrow" href="#section-18">&#182;</a> </div> <p>Micro-templating, originally by John Resig, borrowed by way of
-<a href="http://documentcloud.github.com/underscore/">Underscore.js</a>.</p> </div> <div class="content"><div class="highlight"><pre><span class="nv">template = </span><span class="nf">(str) -&gt;</span>
+Note: the class is "c" for Python and "c1" for the other languages</p>
+
+ </div> <div class="content"><div class="highlight"><pre> <span class="nv">l.codeSplitHtml = </span><span class="sr">///\n*&lt;span\sclass=&quot;c1?&quot;&gt;</span><span class="si">#{</span><span class="nx">l</span><span class="p">.</span><span class="nx">symbol</span><span class="si">}</span><span class="sr">DIVIDER&lt;\/span&gt;\n*///</span></pre></div></div> </li> <li id="section-17"> <div class="annotation"> <div class="pilwrap"> <a class="pilcrow" href="#section-17">&#182;</a> </div>
+
+<p>The dividing token we feed into Showdown, to delimit the boundaries between
+sections.</p>
+
+ </div> <div class="content"><div class="highlight"><pre> <span class="nv">l.docsSplitText = </span><span class="s">&quot;\n</span><span class="err">#</span><span class="si">#{</span><span class="nx">l</span><span class="p">.</span><span class="nx">name</span><span class="si">}</span><span class="s">DOCDIVIDER\n&quot;</span></pre></div></div> </li> <li id="section-18"> <div class="annotation"> <div class="pilwrap"> <a class="pilcrow" href="#section-18">&#182;</a> </div>
+
+<p>The mirror of <code>docsSplitText</code> that we expect Showdown to return. We can split
+on this to recover the original sections.</p>
+
+ </div> <div class="content"><div class="highlight"><pre> <span class="nv">l.docsSplitHtml = </span><span class="sr">///&lt;h1&gt;</span><span class="si">#{</span><span class="nx">l</span><span class="p">.</span><span class="nx">name</span><span class="si">}</span><span class="sr">DOCDIVIDER&lt;/h1&gt;///</span></pre></div></div> </li> <li id="section-19"> <div class="annotation"> <div class="pilwrap"> <a class="pilcrow" href="#section-19">&#182;</a> </div>
+
+<p>Get the current language we're documenting, based on the extension.</p>
+
+ </div> <div class="content"><div class="highlight"><pre><span class="nv">getLanguage = </span><span class="nf">(source) -&gt;</span> <span class="nx">languages</span><span class="p">[</span><span class="nx">path</span><span class="p">.</span><span class="nx">extname</span><span class="p">(</span><span class="nx">source</span><span class="p">)]</span></pre></div></div> </li> <li id="section-20"> <div class="annotation"> <div class="pilwrap"> <a class="pilcrow" href="#section-20">&#182;</a> </div>
+
+<p>Ensure that the destination directory exists.</p>
+
+ </div> <div class="content"><div class="highlight"><pre><span class="nv">ensureDirectory = </span><span class="nf">(dir, callback) -&gt;</span>
+ <span class="nx">exec</span> <span class="s">&quot;mkdir -p </span><span class="si">#{</span><span class="nx">dir</span><span class="si">}</span><span class="s">&quot;</span><span class="p">,</span> <span class="nf">-&gt;</span> <span class="nx">callback</span><span class="p">()</span></pre></div></div> </li> <li id="section-21"> <div class="annotation"> <div class="pilwrap"> <a class="pilcrow" href="#section-21">&#182;</a> </div>
+
+<p>Micro-templating, originally by John Resig, borrowed by way of
+<a href="http://documentcloud.github.com/underscore/">Underscore.js</a>.</p>
+
+ </div> <div class="content"><div class="highlight"><pre><span class="nv">template = </span><span class="nf">(str) -&gt;</span>
<span class="k">new</span> <span class="nb">Function</span> <span class="s">&#39;obj&#39;</span><span class="p">,</span>
<span class="s">&#39;var p=[],print=function(){p.push.apply(p,arguments);};&#39;</span> <span class="o">+</span>
<span class="s">&#39;with(obj){p.push(\&#39;&#39;</span> <span class="o">+</span>
@@ -164,15 +260,39 @@
<span class="p">.</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/&lt;%=(.+?)%&gt;/g</span><span class="p">,</span> <span class="s">&quot;&#39;,$1,&#39;&quot;</span><span class="p">)</span>
<span class="p">.</span><span class="nx">split</span><span class="p">(</span><span class="s">&#39;&lt;%&#39;</span><span class="p">).</span><span class="nx">join</span><span class="p">(</span><span class="s">&quot;&#39;);&quot;</span><span class="p">)</span>
<span class="p">.</span><span class="nx">split</span><span class="p">(</span><span class="s">&#39;%&gt;&#39;</span><span class="p">).</span><span class="nx">join</span><span class="p">(</span><span class="s">&quot;p.push(&#39;&quot;</span><span class="p">)</span> <span class="o">+</span>
- <span class="s">&quot;&#39;);}return p.join(&#39;&#39;);&quot;</span></pre></div></div> </li> <li id="section-19"> <div class="annotation"> <div class="pilwrap"> <a class="pilcrow" href="#section-19">&#182;</a> </div> <p>The start of each Pygments highlight block.</p> </div> <div class="content"><div class="highlight"><pre><span class="nv">highlightStart = </span><span class="s">&#39;&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&#39;</span></pre></div></div> </li> <li id="section-20"> <div class="annotation"> <div class="pilwrap"> <a class="pilcrow" href="#section-20">&#182;</a> </div> <p>The end of each Pygments highlight block.</p> </div> <div class="content"><div class="highlight"><pre><span class="nv">highlightEnd = </span><span class="s">&#39;&lt;/pre&gt;&lt;/div&gt;&#39;</span></pre></div></div> </li> <li id="section-21"> <div class="annotation"> <div class="pilwrap"> <a class="pilcrow" href="#section-21">&#182;</a> </div> <p>Extract the docco version from <code>package.json</code></p> </div> <div class="content"><div class="highlight"><pre><span class="nv">version = </span><span class="nx">JSON</span><span class="p">.</span><span class="nx">parse</span><span class="p">(</span><span class="nx">fs</span><span class="p">.</span><span class="nx">readFileSync</span><span class="p">(</span><span class="s">&quot;</span><span class="si">#{</span><span class="nx">__dirname</span><span class="si">}</span><span class="s">/../package.json&quot;</span><span class="p">)).</span><span class="nx">version</span></pre></div></div> </li> <li id="section-22"> <div class="annotation"> <div class="pilwrap"> <a class="pilcrow" href="#section-22">&#182;</a> </div> <p>Default configuration options.</p> </div> <div class="content"><div class="highlight"><pre><span class="nv">defaults =</span>
+ <span class="s">&quot;&#39;);}return p.join(&#39;&#39;);&quot;</span></pre></div></div> </li> <li id="section-22"> <div class="annotation"> <div class="pilwrap"> <a class="pilcrow" href="#section-22">&#182;</a> </div>
+
+<p>The start of each Pygments highlight block.</p>
+
+ </div> <div class="content"><div class="highlight"><pre><span class="nv">highlightStart = </span><span class="s">&#39;&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&#39;</span></pre></div></div> </li> <li id="section-23"> <div class="annotation"> <div class="pilwrap"> <a class="pilcrow" href="#section-23">&#182;</a> </div>
+
+<p>The end of each Pygments highlight block.</p>
+
+ </div> <div class="content"><div class="highlight"><pre><span class="nv">highlightEnd = </span><span class="s">&#39;&lt;/pre&gt;&lt;/div&gt;&#39;</span></pre></div></div> </li> <li id="section-24"> <div class="annotation"> <div class="pilwrap"> <a class="pilcrow" href="#section-24">&#182;</a> </div>
+
+<p>Extract the docco version from <code>package.json</code></p>
+
+ </div> <div class="content"><div class="highlight"><pre><span class="nv">version = </span><span class="nx">JSON</span><span class="p">.</span><span class="nx">parse</span><span class="p">(</span><span class="nx">fs</span><span class="p">.</span><span class="nx">readFileSync</span><span class="p">(</span><span class="s">&quot;</span><span class="si">#{</span><span class="nx">__dirname</span><span class="si">}</span><span class="s">/../package.json&quot;</span><span class="p">)).</span><span class="nx">version</span></pre></div></div> </li> <li id="section-25"> <div class="annotation"> <div class="pilwrap"> <a class="pilcrow" href="#section-25">&#182;</a> </div>
+
+<p>Default configuration options.</p>
+
+ </div> <div class="content"><div class="highlight"><pre><span class="nv">defaults =</span>
<span class="nv">template: </span><span class="s">&quot;</span><span class="si">#{</span><span class="nx">__dirname</span><span class="si">}</span><span class="s">/../resources/docco.jst&quot;</span>
<span class="nv">css : </span><span class="s">&quot;</span><span class="si">#{</span><span class="nx">__dirname</span><span class="si">}</span><span class="s">/../resources/resources/docco.css&quot;</span>
- <span class="nv">output : </span><span class="s">&quot;docs/&quot;</span></pre></div></div> </li> <li id="section-23"> <div class="annotation"> <div class="pilwrap"> <a class="pilcrow" href="#section-23">&#182;</a> </div> <h3>Run from Commandline</h3> </div> </li> <li id="section-24"> <div class="annotation"> <div class="pilwrap"> <a class="pilcrow" href="#section-24">&#182;</a> </div> <p>Run Docco from a set of command line arguments. </p>
+ <span class="nv">output : </span><span class="s">&quot;docs/&quot;</span></pre></div></div> </li> <li id="section-26"> <div class="annotation"> <div class="pilwrap"> <a class="pilcrow" href="#section-26">&#182;</a> </div>
+
+<h3>Run from Commandline</h3>
+
+ </div> </li> <li id="section-27"> <div class="annotation"> <div class="pilwrap"> <a class="pilcrow" href="#section-27">&#182;</a> </div>
+
+<p>Run Docco from a set of command line arguments. </p>
<ol>
<li>Parse command line using <a href="https://github.com/visionmedia/commander.js">Commander JS</a>.</li>
<li>Document sources, or print the usage help if none are specified.</li>
-</ol> </div> <div class="content"><div class="highlight"><pre><span class="nv">run = </span><span class="nf">(args=process.argv) -&gt;</span>
+</ol>
+
+ </div> <div class="content"><div class="highlight"><pre><span class="nv">run = </span><span class="nf">(args=process.argv) -&gt;</span>
<span class="nx">commander</span><span class="p">.</span><span class="nx">version</span><span class="p">(</span><span class="nx">version</span><span class="p">)</span>
<span class="p">.</span><span class="nx">usage</span><span class="p">(</span><span class="s">&quot;[options] &lt;filePattern ...&gt;&quot;</span><span class="p">)</span>
<span class="p">.</span><span class="nx">option</span><span class="p">(</span><span class="s">&quot;-c, --css [file]&quot;</span><span class="p">,</span><span class="s">&quot;use a custom css file&quot;</span><span class="p">,</span><span class="nx">defaults</span><span class="p">.</span><span class="nx">css</span><span class="p">)</span>
@@ -183,7 +303,13 @@
<span class="k">if</span> <span class="nx">commander</span><span class="p">.</span><span class="nx">args</span><span class="p">.</span><span class="nx">length</span>
<span class="nb">document</span><span class="p">(</span><span class="nx">commander</span><span class="p">.</span><span class="nx">args</span><span class="p">.</span><span class="nx">slice</span><span class="p">(),</span><span class="nx">commander</span><span class="p">)</span>
<span class="k">else</span>
- <span class="nx">console</span><span class="p">.</span><span class="nx">log</span> <span class="nx">commander</span><span class="p">.</span><span class="nx">helpInformation</span><span class="p">()</span></pre></div></div> </li> <li id="section-25"> <div class="annotation"> <div class="pilwrap"> <a class="pilcrow" href="#section-25">&#182;</a> </div> <h3>Document Sources</h3> </div> </li> <li id="section-26"> <div class="annotation"> <div class="pilwrap"> <a class="pilcrow" href="#section-26">&#182;</a> </div> <p>Run Docco over a list of <code>sources</code> with the given <code>options</code>.</p>
+ <span class="nx">console</span><span class="p">.</span><span class="nx">log</span> <span class="nx">commander</span><span class="p">.</span><span class="nx">helpInformation</span><span class="p">()</span></pre></div></div> </li> <li id="section-28"> <div class="annotation"> <div class="pilwrap"> <a class="pilcrow" href="#section-28">&#182;</a> </div>
+
+<h3>Document Sources</h3>
+
+ </div> </li> <li id="section-29"> <div class="annotation"> <div class="pilwrap"> <a class="pilcrow" href="#section-29">&#182;</a> </div>
+
+<p>Run Docco over a list of <code>sources</code> with the given <code>options</code>.</p>
<ol>
<li>Construct config to use by taking <code>defaults</code> first, then merging in <code>options</code></li>
@@ -191,7 +317,9 @@
<li>Load the specified template and css files.</li>
<li>Ensure the output path is created, write out the CSS file,
document each source, and invoke the completion callback if it is specified.</li>
-</ol> </div> <div class="content"><div class="highlight"><pre><span class="nb">document</span> <span class="o">=</span> <span class="nf">(sources, options = {}, callback = null) -&gt;</span>
+</ol>
+
+ </div> <div class="content"><div class="highlight"><pre><span class="nb">document</span> <span class="o">=</span> <span class="nf">(sources, options = {}, callback = null) -&gt;</span>
<span class="nv">config = </span><span class="p">{}</span>
<span class="nx">config</span><span class="p">[</span><span class="nx">key</span><span class="p">]</span> <span class="o">=</span> <span class="nx">defaults</span><span class="p">[</span><span class="nx">key</span><span class="p">]</span> <span class="k">for</span> <span class="nx">key</span><span class="p">,</span><span class="nx">value</span> <span class="k">of</span> <span class="nx">defaults</span>
<span class="nx">config</span><span class="p">[</span><span class="nx">key</span><span class="p">]</span> <span class="o">=</span> <span class="nx">value</span> <span class="k">for</span> <span class="nx">key</span><span class="p">,</span><span class="nx">value</span> <span class="k">of</span> <span class="nx">options</span> <span class="k">if</span> <span class="nx">key</span> <span class="k">of</span> <span class="nx">defaults</span>
@@ -210,13 +338,21 @@
<span class="nv">nextFile = </span><span class="nf">-&gt;</span>
<span class="nx">callback</span><span class="p">()</span> <span class="k">if</span> <span class="nx">callback</span><span class="o">?</span> <span class="o">and</span> <span class="o">not</span> <span class="nx">files</span><span class="p">.</span><span class="nx">length</span>
<span class="nx">generateDocumentation</span> <span class="nx">files</span><span class="p">.</span><span class="nx">shift</span><span class="p">(),</span> <span class="nx">config</span><span class="p">,</span> <span class="nx">nextFile</span> <span class="k">if</span> <span class="nx">files</span><span class="p">.</span><span class="nx">length</span>
- <span class="nx">nextFile</span><span class="p">()</span></pre></div></div> </li> <li id="section-27"> <div class="annotation"> <div class="pilwrap"> <a class="pilcrow" href="#section-27">&#182;</a> </div> <h3>Resolve Wildcard Source Inputs</h3> </div> </li> <li id="section-28"> <div class="annotation"> <div class="pilwrap"> <a class="pilcrow" href="#section-28">&#182;</a> </div> <p>Resolve a wildcard <code>source</code> input to the files it matches.</p>
+ <span class="nx">nextFile</span><span class="p">()</span></pre></div></div> </li> <li id="section-30"> <div class="annotation"> <div class="pilwrap"> <a class="pilcrow" href="#section-30">&#182;</a> </div>
+
+<h3>Resolve Wildcard Source Inputs</h3>
+
+ </div> </li> <li id="section-31"> <div class="annotation"> <div class="pilwrap"> <a class="pilcrow" href="#section-31">&#182;</a> </div>
+
+<p>Resolve a wildcard <code>source</code> input to the files it matches.</p>
<ol>
<li>If the input contains no wildcard characters, just return it.</li>
<li>Convert the wildcard match to a regular expression, and return
an array of files in the path that match it.</li>
-</ol> </div> <div class="content"><div class="highlight"><pre><span class="nv">resolveSource = </span><span class="nf">(source) -&gt;</span>
+</ol>
+
+ </div> <div class="content"><div class="highlight"><pre><span class="nv">resolveSource = </span><span class="nf">(source) -&gt;</span>
<span class="k">return</span> <span class="nx">source</span> <span class="k">if</span> <span class="o">not</span> <span class="nx">source</span><span class="p">.</span><span class="nx">match</span><span class="p">(</span><span class="sr">/([\*\?])/</span><span class="p">)</span>
<span class="nv">regex_str = </span><span class="nx">path</span><span class="p">.</span><span class="nx">basename</span><span class="p">(</span><span class="nx">source</span><span class="p">)</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="s">&quot;\\$&amp;&quot;</span><span class="p">)</span>
@@ -225,7 +361,13 @@
<span class="nv">regex = </span><span class="k">new</span> <span class="nb">RegExp</span><span class="p">(</span><span class="s">&#39;^(&#39;</span> <span class="o">+</span> <span class="nx">regex_str</span> <span class="o">+</span> <span class="s">&#39;)$&#39;</span><span class="p">)</span>
<span class="nv">file_path = </span><span class="nx">path</span><span class="p">.</span><span class="nx">dirname</span><span class="p">(</span><span class="nx">source</span><span class="p">)</span>
<span class="nv">files = </span><span class="nx">fs</span><span class="p">.</span><span class="nx">readdirSync</span> <span class="nx">file_path</span>
- <span class="k">return</span> <span class="p">(</span><span class="nx">path</span><span class="p">.</span><span class="nx">join</span><span class="p">(</span><span class="nx">file_path</span><span class="p">,</span><span class="nx">file</span><span class="p">)</span> <span class="k">for</span> <span class="nx">file</span> <span class="k">in</span> <span class="nx">files</span> <span class="k">when</span> <span class="nx">file</span><span class="p">.</span><span class="nx">match</span> <span class="nx">regex</span><span class="p">)</span></pre></div></div> </li> <li id="section-29"> <div class="annotation"> <div class="pilwrap"> <a class="pilcrow" href="#section-29">&#182;</a> </div> <h3>Exports</h3> </div> </li> <li id="section-30"> <div class="annotation"> <div class="pilwrap"> <a class="pilcrow" href="#section-30">&#182;</a> </div> <p>Information about docco, and functions for programatic usage.</p> </div> <div class="content"><div class="highlight"><pre><span class="nx">exports</span><span class="p">[</span><span class="nx">key</span><span class="p">]</span> <span class="o">=</span> <span class="nx">value</span> <span class="k">for</span> <span class="nx">key</span><span class="p">,</span> <span class="nx">value</span> <span class="k">of</span> <span class="p">{</span>
+ <span class="k">return</span> <span class="p">(</span><span class="nx">path</span><span class="p">.</span><span class="nx">join</span><span class="p">(</span><span class="nx">file_path</span><span class="p">,</span><span class="nx">file</span><span class="p">)</span> <span class="k">for</span> <span class="nx">file</span> <span class="k">in</span> <span class="nx">files</span> <span class="k">when</span> <span class="nx">file</span><span class="p">.</span><span class="nx">match</span> <span class="nx">regex</span><span class="p">)</span></pre></div></div> </li> <li id="section-32"> <div class="annotation"> <div class="pilwrap"> <a class="pilcrow" href="#section-32">&#182;</a> </div>
+
+<h3>Exports</h3>
+
+ </div> </li> <li id="section-33"> <div class="annotation"> <div class="pilwrap"> <a class="pilcrow" href="#section-33">&#182;</a> </div>
+
+<p>Information about docco, and functions for programatic usage.</p> </div> <div class="content"><div class="highlight"><pre><span class="nx">exports</span><span class="p">[</span><span class="nx">key</span><span class="p">]</span> <span class="o">=</span> <span class="nx">value</span> <span class="k">for</span> <span class="nx">key</span><span class="p">,</span> <span class="nx">value</span> <span class="k">of</span> <span class="p">{</span>
<span class="nv">run : </span><span class="nx">run</span>
<span class="nb">document</span> <span class="o">:</span> <span class="nb">document</span>
<span class="nv">parse : </span><span class="nx">parse</span>
View
25 lib/docco.js
@@ -1,6 +1,6 @@
// Generated by CoffeeScript 1.3.3
(function() {
- var commander, defaults, document, ensureDirectory, exec, ext, fs, generateDocumentation, generateHtml, getLanguage, getResource, highlight, highlightEnd, highlightStart, key, l, languages, parse, path, resolveSource, run, showdown, spawn, template, value, version, _ref, _ref1,
+ var commander, defaults, document, ensureDirectory, exec, ext, fs, generateDocumentation, generateHtml, getLanguage, getResource, highlight, highlightEnd, highlightStart, htmlEscape, key, l, languages, parse, path, resolveSource, run, showdown, spawn, template, value, version, _ref, _ref1,
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
generateDocumentation = function(source, config, callback) {
@@ -76,8 +76,7 @@
}
});
pygments.stdin.on('error', function(error) {
- console.error('Could not use Pygments to highlight the source.');
- return process.exit(1);
+ return console.error('Could not highlight code, using plaintext');
});
pygments.stdout.on('data', function(result) {
if (result) {
@@ -87,7 +86,19 @@
pygments.on('exit', function() {
var codeFragments, docsFragments, i, _i, _len;
output = output.replace(highlightStart, '').replace(highlightEnd, '');
- codeFragments = output.split(language.codeSplitHtml);
+ if (output === '') {
+ codeFragments = (function() {
+ var _i, _len, _results;
+ _results = [];
+ for (_i = 0, _len = sections.length; _i < _len; _i++) {
+ section = sections[_i];
+ _results.push(htmlEscape(section.codeText));
+ }
+ return _results;
+ })();
+ } else {
+ codeFragments = output.split(language.codeSplitHtml);
+ }
docsFragments = showdown.makeHtml(docs).split(language.docsSplitHtml);
for (i = _i = 0, _len = sections.length; _i < _len; i = ++_i) {
section = sections[i];
@@ -102,6 +113,10 @@
}
};
+ htmlEscape = function(string) {
+ return string.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#x27;').replace(/\//g, '&#x2F;');
+ };
+
generateHtml = function(source, sections, config) {
var dest, destination, html, title;
destination = function(filepath) {
@@ -145,7 +160,7 @@
l.commentFilter = /(^#![/]|^\s*#\{)/;
l.codeSplitText = "\n" + l.symbol + "DIVIDER\n";
l.codeSplitHtml = RegExp("\\n*<span\\sclass=\"c1?\">" + l.symbol + "DIVIDER<\\/span>\\n*");
- l.docsSplitText = "\n# " + l.name + "DOCDIVIDER\n";
+ l.docsSplitText = "\n#" + l.name + "DOCDIVIDER\n";
l.docsSplitHtml = RegExp("<h1>" + l.name + "DOCDIVIDER</h1>");
}
Please sign in to comment.
Something went wrong with that request. Please try again.