Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jodoc does not process js comments generated by CoffeeScript #12

Open
srackham opened this issue Oct 4, 2011 · 2 comments
Open

jodoc does not process js comments generated by CoffeeScript #12

srackham opened this issue Oct 4, 2011 · 2 comments

Comments

@srackham
Copy link

srackham commented Oct 4, 2011

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
Copy link
Author

srackham commented Oct 5, 2011

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
Copy link
Author

srackham commented Oct 5, 2011

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant