forked from GitbookIO/plugin-hints
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
52 lines (47 loc) · 1.34 KB
/
index.js
File metadata and controls
52 lines (47 loc) · 1.34 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
var ALERT_STYLES = {
info:'info',
tip:'success',
danger:'danger',
working:'warning'
};
/**
* @param {String} style
* @param {Object} pluginConfig
* @return {String} HTML for an alert icon
*/
function makeIcon(style, pluginConfig) {
var id = pluginConfig[style];
return '<div class="hints-icon"><i class="'+id+'"></i></div>';
}
/**
* @param {String} html
* @return {String} HTML wrapped in a hint container
*/
function wrapInContainer(html) {
return '<div class="hints-container">'+html+'</div>';
}
module.exports = {
book: {
assets: './assets',
css: [
'plugin-hints.css'
]
},
blocks: {
hint: {
process: function (block) {
// Available styles: info, danger, tip, working
var style = block.kwargs.style || 'info';
var pluginConfig = this.config.get('pluginsConfig.hints');
return this
.renderBlock('markdown', block.body)
.then(function(renderedBody) {
return '<div class="alert alert-'+ALERT_STYLES[style]+' hints-alert">'
+ makeIcon(style, pluginConfig)
+ wrapInContainer(renderedBody)
+ '</div>';
});
}
}
}
};