-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
57 lines (45 loc) · 1.32 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
45
46
47
48
49
50
51
52
53
54
55
56
57
/* jshint node: true */
'use strict';
var Filter = require('broccoli-filter');
var marked = require('marked');
marked.setOptions({
gfm: true,
sanitize: true
});
function TemplateCompiler(inputNode, options) {
if (!(this instanceof TemplateCompiler)) {
return new TemplateCompiler(inputNode, options);
}
options = options || {};
Filter.call(this, inputNode, options);
this.compile = marked;
}
TemplateCompiler.prototype = Object.create(Filter.prototype);
TemplateCompiler.prototype.constructor = TemplateCompiler;
TemplateCompiler.prototype.extensions = ['md'];
TemplateCompiler.prototype.targetExtension = 'hbs';
TemplateCompiler.prototype.processString = function(string, relativePath) {
return this.compile(string).replace(/{/g, '{');
};
module.exports = {
name: 'ember-cli-markdown-compiler',
isDevelopingAddon: function() {
return true;
},
setupPreprocessorRegistry: function(type, registry) {
registry.add('template', {
name: 'ember-cli-markdown-compiler',
ext: ['md'],
toTree: function(tree) {
return TemplateCompiler(tree);
}
});
if (type === 'parent') {
this.parentRegistry = registry;
}
},
included: function(app) {
this._super.included.apply(this, arguments);
this.setupPreprocessorRegistry('parent', app.registry);
}
};