-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjquery.markdown.js
More file actions
61 lines (42 loc) · 1.76 KB
/
jquery.markdown.js
File metadata and controls
61 lines (42 loc) · 1.76 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
60
61
(function( $ ){
$.fn.loadMarkdown = function(options) {
var settings = jQuery.extend({
preAdd: function(content){ return content },
postAdd: function(element){ },
replaceWith: false
}, options);
var currentElement = this;
var successFunction = function(data) {
var converter = new Markdown.Converter();
converter.hooks.chain("postConversion", function (text) {
return settings.preAdd(text);
});
//alert(data.val();
var result = converter.makeHtml(data);
if (settings.replaceWith) {
currentElement.replaceWith(result);
} else {
currentElement.append(result);
}
settings.postAdd();
};
$.ajax({
url: options.url,
success: successFunction,
dataType: 'html'
});
};
$(document).ready(function () {
$('[data-markdown-url]').each(function(index) {
var item = $(this);
var options = {url: item.attr('data-markdown-url')};
if (item.attr('data-markdown-replaceWith') !== undefined)
options.replaceWith = (item.attr('data-markdown-replaceWith') == 'true');
if (item.attr('data-markdown-preAdd') !== undefined)
eval('options.preAdd = ' + item.attr('data-markdown-preAdd'));
if (item.attr('data-markdown-postAdd') !== undefined)
eval('options.postAdd = ' + item.attr('data-markdown-postAdd'));
item.loadMarkdown(options);
});
});
})( jQuery );