Skip to content

Commit

Permalink
Support github links in markdown output
Browse files Browse the repository at this point in the history
  • Loading branch information
tmcw committed Nov 9, 2015
1 parent 8a2ec3e commit eed48f7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
14 changes: 13 additions & 1 deletion lib/output/markdown_ast.js
Expand Up @@ -5,7 +5,7 @@ var mdast = require('mdast'),

/**
* Given a hierarchy-nested set of comments, generate an mdast-compatible
* Abstract Syntax Usable for generating Markdown output
* Abstract Syntax Tree usable for generating Markdown output
*
* @param {Array<Object>} comments nested comment
* @param {Object} opts currently none accepted
Expand Down Expand Up @@ -93,7 +93,19 @@ function commentsToAST(comments, opts, callback) {
});
}

function githubLink(comment) {
return comment.context.github && u('paragraph', [
u('link', {
title: 'Source code on GitHub',
href: comment.context.github
}, [u('text', comment.context.path + ':' +
comment.context.loc.start.line + '-' +
comment.context.loc.end.line)])
]);
}

return [u('heading', { depth: depth }, [u('text', comment.name)])]
.concat(githubLink(comment))
.concat(mdast.parse(formatInlineTags(comment.description)).children)
.concat(paramSection(comment))
.concat(propertySection(comment))
Expand Down
7 changes: 7 additions & 0 deletions test/fixture/simple.output.github.md
@@ -0,0 +1,7 @@
# simple.input

[test/fixture/simple.input.js:5-8]([github] "Source code on GitHub")

This function returns the number one.

Returns **Number** numberone
12 changes: 11 additions & 1 deletion test/test.js
Expand Up @@ -29,7 +29,17 @@ if (fs.existsSync(path.join(__dirname, '../.git'))) {
}
var expect = require(outputfile);
t.deepEqual(result, expect);
t.end();

outputMarkdown(result, null, function (err, result) {
t.ifError(err);
var outputfile = file.replace('.input.js', '.output.github.md');
if (UPDATE) {
fs.writeFileSync(outputfile, result, 'utf8');
}
var expect = fs.readFileSync(outputfile, 'utf8');
t.equal(result.toString(), expect, 'markdown output correct');
t.end();
});
});
});
}
Expand Down

0 comments on commit eed48f7

Please sign in to comment.