forked from ovns/ovns.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgithub-wiki.js
63 lines (50 loc) · 1.77 KB
/
github-wiki.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
//The name of the page in github
var github_page = "ovns"
//Find the title of the article to be shown
var title;
if (document.URL.match("=")) {
title = document.URL.split("=")[1];
} else {
title = "Open_Value_Networks";
}
//transforms double brackets links into markdown links
function link_converter(md) {
return md.replace(/\[\[([\w\s\-]+)\]\]/g, function(match, p1, offset, string) {
return "[" + p1 + "](/" + p1.replace(/\s/g, "_") + ")";
});
}
//Initialize sanitizing converter.
var converter = Markdown.getSanitizingConverter();
//Load Markdown document, convert it and add it to the DOM.
function load_article(title) {
$.ajax({
url: "wiki/" + title + ".md",
success: function(data) {
var lmd = link_converter("# "+title.replace(/_/g," ")+"\n\n"+data);
console.log(lmd);
var html = converter.makeHtml(lmd);
$("#article").empty();
$("#article").append(html);
//Catch all links and redirect them to the correct url if they are local.
$("a").on("click", function(e) {
var link = $(e.target).attr("href");
if (link[0] == "/" && link[1] != "/" && link.match(".html") == null) {
window.location.href = "/wiki.html?article=" + link.substr(1);
return false;
}
});
},
error: function() {
load_article("Meta:404");
}
});
}
$(function() {
//Add event to the edit link
$("#edit_link").click(function(e) {
console.log("this");
window.location.href = "https://github.com/" + github_page + "/" + github_page + ".github.io/blob/master/wiki/" + title + ".md";
return false;
});
load_article(title);
})