This repository was archived by the owner on Mar 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathrender.js
More file actions
147 lines (137 loc) · 5.12 KB
/
render.js
File metadata and controls
147 lines (137 loc) · 5.12 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
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
(function(d){
/*!
* License http://www.apache.org/licenses/LICENSE-2.0
*/
var cel = function(tag,prop,ap){
var c=document.createElement(tag);
for(p in prop){
if(typeof prop[p] == 'object'){
for(q in prop[p])
c[p][q] = prop[p][q];
}
else c[p] = prop[p];
}
if(ap) ap.appendChild(c);
return c;
}
var gitHtml = {
decode: (function(el,str){
if(str && typeof str === 'string'){
str = str.replace(/<script[^>]*>([\S\s]*?)<\/script>/gmi, '');
str = str.replace(/<\/?\w(?:[^"'>]|"[^"]*"|'[^']*')*>/gmi, '');
el.innerHTML = str;
str = el.textContent;
el.textContent = '';
}
return str;
}),
open: (function(c,d) {
var ifr = cel('iframe',{
src: 'about:blank',
style: {
width: '100%',
height: '100%',
position: 'absolute',
top: '0px',
zIndex: '9999',
background: '#fff'
},
id: 'iframe'
}, false);
var close = cel('a',{
innerHTML: 'x',
style: {
position: 'absolute',
top: '5px',
left: '5px',
zIndex: '99999'
},
className: 'minibutton',
href: 'javascript:;',
onclick: (function(){
location.reload();
return false;
})
},false);
var allow = cel('a',{
innerHTML: '[links]',
style:{
position: 'absolute',
top: '5px',
left: '5px',
zIndex: '99999'
},
className: 'minibutton',
href: 'javascript:;',
onclick: (function(){
this.style.cssText = this.style.cssText+';'+
"color:#fff;"+
"text-decoration:none;"+
"text-shadow:0 -1px 0 rgba(0,0,0,0.3);"+
"border-color:#518cc6;"+
"border-bottom-color:#2a65a0;"+
"background:#599bdc;"+
"background:-moz-linear-gradient(#599bdc,#3072b3);"+
"background:-webkit-linear-gradient(#599bdc,#3072b3);";
var ifrm = d.getElementById('iframe');
ifrm = (ifrm.contentDocument.document)
? ifrm.contentDocument.document
: ifrm.contentDocument;
var all = ifrm.getElementsByTagName('a');
for(var i = 0; i<all.length; i++){
all[i].onclick = function(){
location.href = this.href;
return false;
}
}
return false;
})
},false);
if(location.href.indexOf('#gitHtml')==-1){
allow.style.left = '40px';
d.body.appendChild(close);
}
else {
cel('link',{
type: 'text/css',
rel: 'stylesheet',
href: 'https://a248.e.akamai.net/assets.github.com/assets/github-496f7426a679ea2d607d7e535f79e4be5f2a5352.css'
},d.body);
}
d.body.appendChild(allow);
d.body.appendChild(ifr);
d.body.style.padding = '0px';
d.body.style.margin = '0px';
var ifrm = d.getElementById('iframe');
ifrm = (ifrm.contentWindow)
? ifrm.contentWindow
: (ifrm.contentDocument.document)
? ifrm.contentDocument.document
: ifrm.contentDocument;
ifrm.document.open();
if ( c.indexOf('render.js') !=-1 ) {
c = '---> click the [x] on the left and try "github-renderer" again';
}
ifrm.document.write(c);
ifrm.document.close();
}),
start: (function(d){
var el = d.createElement('div');
var hp = (typeof jQuery === "undefined")
? d.getElementsByTagName('pre')[0].innerHTML
: $(".highlight pre").html();
var lo = location.href.replace(/\/blob\//,'/raw/');
var bh = lo.replace(/\/[a-zA-Z0-9-_\.]+$/,'');
var pr = hp.replace(/<div class=[\'|\"]line/g,'\n<div class="line').replace(/(<([^>]+)>)/ig,'');
pr = escape(gitHtml.decode(el,pr));
if ( location.href.indexOf('#gitHtml') ==-1 )
pr = pr.replace(/http/g,'https');
pr = pr.replace(/\.htm(l?)/g,'.htm$1#gitHtml');
pr = unescape(pr).replace(/\n/g,'--githtml-newline--').replace(/\s/g,' ').replace(/--githtml-newline--/g,'\n');
gitHtml.open(
unescape("%3Cbase%20href%3D%22"+escape(lo)+"%22%3E")+pr,d
);
})
}
gitHtml.start(d);
})(document);