-
Notifications
You must be signed in to change notification settings - Fork 6
/
markdown.api.js
99 lines (75 loc) · 2.28 KB
/
markdown.api.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
var markdown_apis_new = function() {
function _get_dingus( api_url, api_params, handle_html )
{
var api_params_str = $.param( api_params );
api_params_str += '&callback=?' // NB: add callback for jquery jsonp; NB: need to append as string to avoid encoding of =?
$.getJSON( api_url, api_params_str, function( data ) {
handle_html( data.html ); // NB: assumes response { 'html': 'markup here' }
});
}
function _get_dingus_via_proxy( api_url, api_params, handle_html )
{
api_params.url = api_url; // add url to params
var api_proxy_url = 'http://note.herokuapp.com/proxy'
_get_dingus( api_proxy_url, api_params, handle_html );
}
function _ruby_w_lib( text, lib, handle_html )
{
var api_params = {
text: text,
lib: lib
}
var api_url = 'http://note.herokuapp.com/markdown/dingus';
_get_dingus( api_url, api_params, handle_html );
}
function ruby( text, handle_html )
{
var api_params = {
text: text
}
var api_url = 'http://note.herokuapp.com/markdown/dingus';
_get_dingus( api_url, api_params, handle_html );
}
function pandoc( text, handle_html )
{
// NB: note jsonp enabled - no cross domain request possible; use proxy server or similar
// todo: find other service
var api_params = {
text: text
}
var api_url = 'http://johnmacfarlane.net/cgi-bin/pandoc-dingus'
_get_dingus_via_proxy( api_url, api_params, handle_html );
}
function kramdown( text, handle_html )
{
_ruby_w_lib( text, 'kramdown', handle_html );
}
function maruku( text, handle_html )
{
_ruby_w_lib( text, 'maruku', handle_html );
}
function redcarpet( text, handle_html )
{
_ruby_w_lib( text, 'redcarpet', handle_html );
}
function bluecloth( text, handle_html )
{
_ruby_w_lib( text, 'bluecloth', handle_html );
}
return {
ruby: ruby,
ruby_kramdown: kramdown,
ruby_maruku: maruku,
ruby_redcarpet: redcarpet,
ruby_bluecloth: bluecloth,
pandoc: pandoc
}
} // fn makrdown_apis_new
var markdown_apis = markdown_apis_new();
////////////////
// use like
//
// markdown_apis.ruby( text, success );
// markdown_apis.ruby_kramdown( text, success );
// mardkown_apis.pandoc( text, success );
// etc.