Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fixing leading interpolations ... issue #265

  • Loading branch information...
commit f1aae2167d46856a26a0c7b72228e9a34793767c 1 parent fe75e0e
@jashkenas jashkenas authored
Showing with 18 additions and 23 deletions.
  1. +11 −16 lib/docco.js
  2. +7 −7 src/docco.coffee
View
27 lib/docco.js
@@ -1,6 +1,5 @@
(function() {
var destination, docco_styles, docco_template, ensure_directory, exec, ext, fs, generate_documentation, generate_html, get_language, highlight, highlight_end, highlight_start, l, languages, parse, path, showdown, sources, spawn, template, _ref;
- var __hasProp = Object.prototype.hasOwnProperty;
generate_documentation = function(source, callback) {
return fs.readFile(source, "utf-8", function(error, code) {
var sections;
@@ -28,14 +27,12 @@
};
for (_i = 0, _len = lines.length; _i < _len; _i++) {
line = lines[_i];
- if (line.match(language.comment_matcher)) {
- if (!(line.match(language.comment_filter))) {
- if (has_code) {
- save(docs_text, code_text);
- has_code = docs_text = code_text = '';
- }
- docs_text += line.replace(language.comment_matcher, '') + '\n';
+ if (line.match(language.comment_matcher) && !line.match(language.comment_filter)) {
+ if (has_code) {
+ save(docs_text, code_text);
+ has_code = docs_text = code_text = '';
}
+ docs_text += line.replace(language.comment_matcher, '') + '\n';
} else {
has_code = true;
code_text += line + '\n';
@@ -60,25 +57,24 @@
}
});
pygments.addListener('exit', function() {
- var fragments, i, section, _len, _ref;
+ var fragments, i, section, _len;
output = output.replace(highlight_start, '').replace(highlight_end, '');
fragments = output.split(language.divider_html);
- _ref = sections;
- for (i = 0, _len = _ref.length; i < _len; i++) {
- section = _ref[i];
+ for (i = 0, _len = sections.length; i < _len; i++) {
+ section = sections[i];
section.code_html = highlight_start + fragments[i] + highlight_end;
section.docs_html = showdown.makeHtml(section.docs_text);
}
return callback();
});
- pygments.stdin.write(((function() {
+ pygments.stdin.write((function() {
_results = [];
for (_i = 0, _len = sections.length; _i < _len; _i++) {
section = sections[_i];
_results.push(section.code_text);
}
return _results;
- })()).join(language.divider_text));
+ }()).join(language.divider_text));
return pygments.stdin.end();
};
generate_html = function(source, sections) {
@@ -118,10 +114,9 @@
}
};
for (ext in languages) {
- if (!__hasProp.call(languages, ext)) continue;
l = languages[ext];
l.comment_matcher = new RegExp('^\\s*' + l.symbol + '\\s?');
- l.comment_filter = new RegExp('^#![/]');
+ l.comment_filter = new RegExp('(^#![/]|^\\s*#\\{)');
l.divider_text = '\n' + l.symbol + 'DIVIDER\n';
l.divider_html = new RegExp('\\n*<span class="c1?">' + l.symbol + 'DIVIDER<\\/span>\\n*');
}
View
14 src/docco.coffee
@@ -64,12 +64,11 @@ parse = (source, code) ->
sections.push docs_text: docs, code_text: code
for line in lines
- if line.match language.comment_matcher
- if not (line.match language.comment_filter)
- if has_code
- save docs_text, code_text
- has_code = docs_text = code_text = ''
- docs_text += line.replace(language.comment_matcher, '') + '\n'
+ if line.match(language.comment_matcher) and not line.match(language.comment_filter)
+ if has_code
+ save docs_text, code_text
+ has_code = docs_text = code_text = ''
+ docs_text += line.replace(language.comment_matcher, '') + '\n'
else
has_code = yes
code_text += line + '\n'
@@ -142,7 +141,8 @@ for ext, l of languages
l.comment_matcher = new RegExp('^\\s*' + l.symbol + '\\s?')
# Ignore [hashbangs](http://en.wikipedia.org/wiki/Shebang_(Unix))
- l.comment_filter = new RegExp('^#![/]')
+ # and interpolations...
+ l.comment_filter = new RegExp('(^#![/]|^\\s*#\\{)')
# The dividing token we feed into Pygments, to delimit the boundaries between
# sections.
Please sign in to comment.
Something went wrong with that request. Please try again.