Skip to content

Commit eed48f7

Browse files
committed
Support github links in markdown output
1 parent 8a2ec3e commit eed48f7

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

lib/output/markdown_ast.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var mdast = require('mdast'),
55

66
/**
77
* Given a hierarchy-nested set of comments, generate an mdast-compatible
8-
* Abstract Syntax Usable for generating Markdown output
8+
* Abstract Syntax Tree usable for generating Markdown output
99
*
1010
* @param {Array<Object>} comments nested comment
1111
* @param {Object} opts currently none accepted
@@ -93,7 +93,19 @@ function commentsToAST(comments, opts, callback) {
9393
});
9494
}
9595

96+
function githubLink(comment) {
97+
return comment.context.github && u('paragraph', [
98+
u('link', {
99+
title: 'Source code on GitHub',
100+
href: comment.context.github
101+
}, [u('text', comment.context.path + ':' +
102+
comment.context.loc.start.line + '-' +
103+
comment.context.loc.end.line)])
104+
]);
105+
}
106+
96107
return [u('heading', { depth: depth }, [u('text', comment.name)])]
108+
.concat(githubLink(comment))
97109
.concat(mdast.parse(formatInlineTags(comment.description)).children)
98110
.concat(paramSection(comment))
99111
.concat(propertySection(comment))

test/fixture/simple.output.github.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# simple.input
2+
3+
[test/fixture/simple.input.js:5-8]([github] "Source code on GitHub")
4+
5+
This function returns the number one.
6+
7+
Returns **Number** numberone

test/test.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,17 @@ if (fs.existsSync(path.join(__dirname, '../.git'))) {
2929
}
3030
var expect = require(outputfile);
3131
t.deepEqual(result, expect);
32-
t.end();
32+
33+
outputMarkdown(result, null, function (err, result) {
34+
t.ifError(err);
35+
var outputfile = file.replace('.input.js', '.output.github.md');
36+
if (UPDATE) {
37+
fs.writeFileSync(outputfile, result, 'utf8');
38+
}
39+
var expect = fs.readFileSync(outputfile, 'utf8');
40+
t.equal(result.toString(), expect, 'markdown output correct');
41+
t.end();
42+
});
3343
});
3444
});
3545
}

0 commit comments

Comments
 (0)