dfreedm / jodoc-js

joDoc port to nodejs
http://joapp.com/#joDoc
Other
26 stars 9 forks source link

jodoc does not process js comments generated by CoffeeScript #12

Open srackham opened 13 years ago

srackham commented 13 years ago

Block comments generated by CoffeeScript are indented to align with the code rendering the Markdown unusable e.g.

###*

# Test file CoffeeScript
Lorum ipsum...

###
x = 42

Compiles to:

(function() { 
  /**

  # Test file CoffeeScript
  Lorum ipsum...

  */
  var x;
  x = 42;
}).call(this);

To fix this jodoc would need to unindent by the leading comment delimiter indent.

srackham commented 13 years ago

The following patch fixes the CoffeeScript issue, and it looks from this example http://joapp.com/docs/#joDoc like the Perl version of jodoc undents and would be fine with CoffeScript outputs, but I haven't tested it.

diff --git a/lib/jodoc-lib.js b/lib/jodoc-lib.js
index 41a7664..bfad125 100644
--- a/lib/jodoc-lib.js
+++ b/lib/jodoc-lib.js
@@ -10,14 +10,17 @@ var external_regex = /(\<a)\s+(href="(?:http[s]?|mailto|ftp)
 // input: "code"
 // output: "comments"
 function docker (input) {
-       var strip_code = /\057\*\*(?:.|[\r\n])*?\*\057/gm;
+       var strip_code = /^( *)\057\*\*(?:.|[\r\n])*?\*\057/gm;
        var strip_stars = /(\*\057|\057\*\*)/g;
        var strip_extra_whitespace = /([\r\n]+)\s/g;
+       var strip_indent;
        var output = [];
        var a;
        while ((a = strip_code.exec(input)) !== null)
        {
+               strip_indent = new RegExp("^" + a[1], "gm");
                a = a[0];
+               a = a.replace(strip_indent, '');
                a = a.replace(strip_stars,'');
                a = a.replace(strip_extra_whitespace, '$1');
                output.push(a);
srackham commented 13 years ago

Make the strip_code regexp a configuration option and jodoc should work with virtually any language with block comments.