Skip to content

Support github links in markdown output #238

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

Merged
merged 1 commit into from
Nov 9, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion lib/output/markdown_ast.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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