forked from ionic-team/ionic-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.js
More file actions
25 lines (19 loc) · 609 Bytes
/
Copy pathcode.js
File metadata and controls
25 lines (19 loc) · 609 Bytes
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
var encoder = new require('node-html-encoder').Encoder();
function code(str, inline, lang) {
// Encode any HTML entities in the code string
str = encoder.htmlEncode(str, true);
// If a language is provided then attach a CSS class to the code element
lang = lang ? ' class="lang-' + lang + '"' : '';
str = '<code' + lang + '>' + str + '</code>';
// If not inline then wrap the code element in a pre element
if ( !inline ) {
str = '<pre>' + str + '</pre>';
}
return str;
};
module.exports = {
name: 'code',
process: function(str, lang) {
return code(str, true, lang);
}
};