mdown.js
1.9 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
/** @license
* RequireJS plugin for loading Markdown files and converting them into HTML.
* Author: Miller Medeiros
* Version: 0.1.1 (2012/02/17)
* Released under the MIT license
*/
// NOTE :: if you don't need to load markdown files in production outside of
// the build, precompile them into modules and set
// `pragmasOnSave.excludeMdown=true`
define(
[
//>>excludeStart('excludeMdown', pragmas.excludeMdown)
'text',
'markdownConverter'
//>>excludeEnd('excludeMdown')
],
function (
//>>excludeStart('excludeMdown', pragmas.excludeMdown)
text, markdownConverter
//>>excludeEnd('excludeMdown')
) {
//>>excludeStart('excludeMdown', pragmas.excludeMdown)
var buildMap = {};
//>>excludeEnd('excludeMdown')
//API
return {
load : function(name, req, onLoad, config) {
//>>excludeStart('excludeMdown', pragmas.excludeMdown)
text.get(req.toUrl(name), function(data){
data = markdownConverter.makeHtml(data);
if (config.isBuild) {
buildMap[name] = data;
onLoad(data);
} else {
onLoad(data);
}
});
},
//write method based on RequireJS official text plugin by James Burke
//https://github.com/jrburke/requirejs/blob/master/text.js
write : function(pluginName, moduleName, write){
if(moduleName in buildMap){
var content = text.jsEscape(buildMap[moduleName]);
write.asModule(pluginName + "!" + moduleName,
"define(function () { return '" +
content +
"';});\n");
}
//>>excludeEnd('excludeMdown')
}
};
});