-
Notifications
You must be signed in to change notification settings - Fork 3
/
showdown-icon.js
54 lines (48 loc) · 1.63 KB
/
showdown-icon.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
/**
* Showdown Icon Extension, Glyphicon and FontAwesome support for showdown
* http://github.com/dbtek/showdown-icon
* 2014, Ismail Demirbilek
* License: MIT
*/
(function (extension) {
'use strict';
// UML - Universal Module Loader
// This enables the extension to be loaded in different environments
if (typeof showdown !== 'undefined') {
// global (browser or nodejs global)
extension(showdown);
} else if (typeof define === 'function' && define.amd) {
// AMD
define(['showdown'], extension);
} else if (typeof exports === 'object') {
// Node, CommonJS-like
module.exports = extension(require('showdown'));
} else {
// showdown was not found so we throw
throw Error('Could not find showdown library');
}
}(function (showdown) {
'use strict';
//This is the extension code per se
// Here you have a safe sandboxed environment where you can use "static code"
// that is, code and data that is used accros instances of the extension itself
// If you have regexes or some piece of calculation that is immutable
// this is the best place to put them.
// The following method will register the extension with showdown
showdown.extension('icon', function() {
'use strict';
return [{
type: "lang",
regex: "\\B(\\\\)?@glyphicon-([\\S]+)\\b",
replace: function(a, b, c) {
return b === "\\" ? a : '<span class="glyphicon glyphicon-' + c + '">' + "</span>"
}
}, {
type: "lang",
regex: "\\B(\\\\)?@fa-([\\S]+)\\b",
replace: function(a, b, c) {
return b === "\\" ? a : '<i class="fa fa-' + c + '">' + "</i>"
}
}];
});
}));