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

support paragraphs with empty comment #392

Open
cancerberoSgx opened this issue Apr 25, 2018 · 0 comments
Open

support paragraphs with empty comment #392

cancerberoSgx opened this issue Apr 25, 2018 · 0 comments

Comments

@cancerberoSgx
Copy link

Hello, This comments for generating paragraphs work OK:

// paragraph1

// paragraph2

But this code won't work OK:

// paragraph1
//
// paragraph2

And the result will be that in parallel or classic layouts the source code won't be aligned with the text.

Why this is important? because if you are writing multiple paragraphs, most editors allow you to select lots of text and comment it all automatically and editors use the second style (adding a comment for empty lines.

I'm short of time now for a PR, but evertheless I was able to fix the problem in docco.js. Basically I added a group at the end of the lines in the regex and changing a little the condition to detect code lines from text lines in the parser:

@@ -155,7 +155,8 @@
     }
     for (k = 0, len1 = lines.length; k < len1; k++) {
       line = lines[k];
-      if (line.match(lang.commentMatcher) && !line.match(lang.commentFilter)) {
+      var commentMatch = lang.commentMatcher.exec(line)
+      if (commentMatch && commentMatch[1] && !line.match(lang.commentFilter)) {
         if (hasCode) {
           save();
         }
@@ -164,8 +165,10 @@
           save();
         }
       } else {
-        hasCode = true;
-        codeText += line + '\n';
+        if(!commentMatch || commentMatch[1]){
+          hasCode = true;
+          codeText += line + '\n';
+        }  
       }
     }
     save();
@@ -332,7 +335,7 @@
     for (ext in languages) {
       l = languages[ext];
       // Does the line begin with a comment?
-      l.commentMatcher = RegExp(`^\\s*${l.symbol}\\s?`);
+      l.commentMatcher = RegExp(`^\\s*${l.symbol}\\s?([^a.*z]?)`);
       // Ignore [hashbangs](http://en.wikipedia.org/wiki/Shebang_%28Unix%29) and interpolations...
       l.commentFilter = /(^#![\/]|^\s*#\{)/;
     }
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