forked from thlorenz/jsdoc-githubify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
44 lines (32 loc) · 1.05 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
'use strict';
var stream = require('stream');
var util = require('util');
var adaptLinks = require('./lib/adapt-links');
var Transform = stream.Transform || require('readable-stream').Transform;
module.exports = function (file /* not used */) {
return new GitifyTransform();
}
util.inherits(GitifyTransform, Transform);
function GitifyTransform (opts) {
if (!(this instanceof GitifyTransform)) return new GitifyTransform(opts);
opts = opts || {};
Transform.call(this, opts);
this.original = '';
}
GitifyTransform.prototype._transform = function (chunk, encoding, cb) {
this.original += encoding === 'utf8' ? chunk : chunk.toString();
cb();
};
GitifyTransform.prototype._flush = function (cb) {
var self = this;
var lines = this.original.split('\n');
// trim lines and remove empties
var transformedLines = lines
.map(function (x) { return x.trim() })
.filter(function (x) { return x.length })
adaptLinks(transformedLines.join('\n'), function (err, html) {
if (err) return cb(err);
self.push(html);
cb();
});
};