Repository navigation
Expand file tree
/
Copy pathhelpers.js
More file actions
72 lines (67 loc) · 1.98 KB
/
Copy pathhelpers.js
File metadata and controls
72 lines (67 loc) · 1.98 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/**
* Original work Copyright (c) 2016 Philippe FERDINAND
* Modified work Copyright (c) 2016 Kam Low
*
* @license MIT
**/
'use strict';
var fs = require('fs');
var path = require('path');
var util = require('util');
var log = require('winston');
var handlebars = require('handlebars');
module.exports = {
inline: function(code) {
if (Array.isArray(code)) {
var refs, s = '', isInline = false;
code.forEach(function (e) {
refs = e.split(/(\[.*\]\(.*\)|\n|\s{2}\n)/g);
refs.forEach(function (f) {
if (f.charAt(0) == '[') {
// link
var link = f.match(/\[(.*)\]\((.*)\)/);
if (link) {
isInline ? (s += '`') && (isInline = false) : null;
s += '[`' + link[1] + '`](' + link[2] + ')';
}
}
else if (f == '\n' || f == ' \n') {
// line break
isInline ? (s += '`') && (isInline = false) : null;
s += f;
}
else if (f) {
!isInline ? (s += '`') && (isInline = true) : null;
s += f;
}
});
});
return s + (isInline ? '`' : '');
}
else {
return '`' + code + '`';
}
},
// Replace group and class links to point to correct output file if needed
resolveRef: function(options, compound, references) {
return function(refid) {
if ((options.groups || options.classes) && compound.refid !== refid && references[refid]) {
return util.format(options.output, options.groups ? references[refid].groupname : references[refid].name) + '#' + refid;
} else {
return '#' + refid;
}
};
},
// Write the output file
writeFile: function (filepath, contents) {
log.verbose('Writing', filepath);
var stream = fs.createWriteStream(filepath);
stream.once('open', function(fd) {
contents.forEach(function (content) {
if (content)
stream.write(content);
});
stream.end();
});
}
};