mirror of
https://github.com/Tygs/0bin.git
synced 2023-08-10 21:13:00 +03:00
Syntax coloration
This commit is contained in:
parent
d09e0feb1e
commit
f91bcbf977
31
src/paste.py
31
src/paste.py
@ -126,25 +126,24 @@ class Paste(object):
|
|||||||
# each worker. If the dir is not in cache, we check the FS, and
|
# each worker. If the dir is not in cache, we check the FS, and
|
||||||
# if the dir is not in there, we create the dir
|
# if the dir is not in there, we create the dir
|
||||||
if head not in self.DIR_CACHE:
|
if head not in self.DIR_CACHE:
|
||||||
first_dir = self.build_path(head)
|
|
||||||
if not os.path.isdir(first_dir):
|
self.DIR_CACHE.add(head)
|
||||||
|
|
||||||
|
if not os.path.isdir(self.build_path(head)):
|
||||||
os.makedirs(self.build_path(head, tail))
|
os.makedirs(self.build_path(head, tail))
|
||||||
self.DIR_CACHE.update((head, (head, tail)))
|
self.DIR_CACHE.add((head, tail))
|
||||||
|
|
||||||
elif (head, tail) not in self.DIR_CACHE:
|
elif (head, tail) not in self.DIR_CACHE:
|
||||||
path = self.build_path(head, tail)
|
path = self.build_path(head, tail)
|
||||||
if not os.path.isdir(path):
|
self.DIR_CACHE.add((head, tail))
|
||||||
os.mkdir(path)
|
if not os.path.isdir(path):
|
||||||
self.DIR_CACHE.add((head, tail))
|
os.mkdir(path)
|
||||||
|
|
||||||
try:
|
with open(self.path, 'w') as f:
|
||||||
with open(self.path, 'w') as f:
|
f.write(unicode(self.expiration) + '\n')
|
||||||
f.write(unicode(self.expiration) + '\n')
|
f.write(self.content + '\n')
|
||||||
f.write(self.content + '\n')
|
if self.comments:
|
||||||
if self.comments:
|
f.write(comments)
|
||||||
f.write(comments)
|
|
||||||
except:
|
|
||||||
import ipdb; ipdb.set_trace()
|
|
||||||
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
4
start.py
4
start.py
@ -61,6 +61,6 @@ def server_static(filename):
|
|||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
if settings.DEBUG:
|
if settings.DEBUG:
|
||||||
debug(True)
|
debug(True)
|
||||||
run(app, host='localhost', port=8080, reloader=True)
|
run(app, host='localhost', port=8080, reloader=True, server="cherrypy")
|
||||||
else:
|
else:
|
||||||
run(app, host='localhost', port=8080)
|
run(app, host='localhost', port=8080, server="cherrypy")
|
@ -42,6 +42,10 @@ padding: 9px 0;
|
|||||||
float:right;
|
float:right;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#paste-content {
|
||||||
|
background-color:white;
|
||||||
|
}
|
||||||
|
|
||||||
select {
|
select {
|
||||||
width: 135px;
|
width: 135px;
|
||||||
}
|
}
|
||||||
|
84
static/css/vs.css
Normal file
84
static/css/vs.css
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
Visual Studio-like style based on original C# coloring by Jason Diamond <jason@diamond.name>
|
||||||
|
|
||||||
|
*/
|
||||||
|
pre code {
|
||||||
|
display: block; padding: 0.5em;
|
||||||
|
}
|
||||||
|
|
||||||
|
pre .comment,
|
||||||
|
pre .annotation,
|
||||||
|
pre .template_comment,
|
||||||
|
pre .diff .header,
|
||||||
|
pre .chunk,
|
||||||
|
pre .apache .cbracket {
|
||||||
|
color: rgb(0, 128, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
pre .keyword,
|
||||||
|
pre .id,
|
||||||
|
pre .title,
|
||||||
|
pre .built_in,
|
||||||
|
pre .aggregate,
|
||||||
|
pre .smalltalk .class,
|
||||||
|
pre .winutils,
|
||||||
|
pre .bash .variable,
|
||||||
|
pre .tex .command {
|
||||||
|
color: rgb(0, 0, 255);
|
||||||
|
}
|
||||||
|
|
||||||
|
pre .string,
|
||||||
|
pre .title,
|
||||||
|
pre .parent,
|
||||||
|
pre .tag .value,
|
||||||
|
pre .rules .value,
|
||||||
|
pre .rules .value .number,
|
||||||
|
pre .ruby .symbol,
|
||||||
|
pre .ruby .symbol .string,
|
||||||
|
pre .ruby .symbol .keyword,
|
||||||
|
pre .ruby .symbol .keymethods,
|
||||||
|
pre .instancevar,
|
||||||
|
pre .aggregate,
|
||||||
|
pre .template_tag,
|
||||||
|
pre .django .variable,
|
||||||
|
pre .addition,
|
||||||
|
pre .flow,
|
||||||
|
pre .stream,
|
||||||
|
pre .apache .tag,
|
||||||
|
pre .date,
|
||||||
|
pre .tex .formula {
|
||||||
|
color: rgb(163, 21, 21);
|
||||||
|
}
|
||||||
|
|
||||||
|
pre .ruby .string,
|
||||||
|
pre .decorator,
|
||||||
|
pre .filter .argument,
|
||||||
|
pre .localvars,
|
||||||
|
pre .array,
|
||||||
|
pre .attr_selector,
|
||||||
|
pre .pseudo,
|
||||||
|
pre .pi,
|
||||||
|
pre .doctype,
|
||||||
|
pre .deletion,
|
||||||
|
pre .envvar,
|
||||||
|
pre .shebang,
|
||||||
|
pre .preprocessor,
|
||||||
|
pre .userType,
|
||||||
|
pre .apache .sqbracket,
|
||||||
|
pre .nginx .built_in,
|
||||||
|
pre .tex .special,
|
||||||
|
pre .input_number {
|
||||||
|
color: rgb(43, 145, 175);
|
||||||
|
}
|
||||||
|
|
||||||
|
pre .phpdoc,
|
||||||
|
pre .javadoc,
|
||||||
|
pre .xmlDocTag {
|
||||||
|
color: rgb(128, 128, 128);
|
||||||
|
}
|
||||||
|
|
||||||
|
pre .vhdl .type { font-weight: bold; }
|
||||||
|
pre .vhdl .string { color: #666666; }
|
||||||
|
pre .vhdl .literal { color: rgb(163, 21, 21); }
|
||||||
|
|
@ -1,30 +1,19 @@
|
|||||||
;
|
;
|
||||||
|
|
||||||
// Start random number generator seeding ASAP
|
// Start random number generator seeding ASAP
|
||||||
sjcl.random.startCollectors();
|
sjcl.random.startCollectors();
|
||||||
|
|
||||||
var zerobin = function() {
|
var zerobin = {
|
||||||
that = {};
|
encrypt: function(key, content) {
|
||||||
that.base64 = {
|
return sjcl.encrypt(key, lzw.compress(content));
|
||||||
decode: function(content) {
|
},
|
||||||
return sjcl.codec.utf8String.fromBits(sjcl.codec.base64.toBits(content));
|
decrypt: function(key, content) {
|
||||||
},
|
return lzw.decompress(sjcl.decrypt(key, content));
|
||||||
encode: function(content) {
|
},
|
||||||
return sjcl.codec.base64.fromBits(sjcl.codec.utf8String.toBits(content));
|
make_key: function() {
|
||||||
}
|
|
||||||
};
|
|
||||||
that.encrypt = function(key, content) {
|
|
||||||
var encrypted = sjcl.encrypt(key, content);
|
|
||||||
return lzw.compress(encrypted);
|
|
||||||
};
|
|
||||||
that.decrypt = function(key, content) {
|
|
||||||
var uncompressed = lzw.decompress(content)
|
|
||||||
return sjcl.decrypt(key, uncompressed);
|
|
||||||
};
|
|
||||||
that.make_key = function() {
|
|
||||||
return sjcl.codec.base64.fromBits(sjcl.random.randomWords(8, 0), 0);
|
return sjcl.codec.base64.fromBits(sjcl.random.randomWords(8, 0), 0);
|
||||||
};
|
}
|
||||||
return that;
|
};
|
||||||
}();
|
|
||||||
|
|
||||||
$(function(){
|
$(function(){
|
||||||
|
|
||||||
@ -43,7 +32,6 @@ $('button[type=submit]').click(function(e){
|
|||||||
alert('Paste could not be saved. Please try again later.');
|
alert('Paste could not be saved. Please try again later.');
|
||||||
})
|
})
|
||||||
.success(function(data) {
|
.success(function(data) {
|
||||||
alert('success');
|
|
||||||
window.location = '/paste/' + data + '#' + key;
|
window.location = '/paste/' + data + '#' + key;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -55,6 +43,7 @@ var key = window.location.hash.substring(1);
|
|||||||
if (content && key) {
|
if (content && key) {
|
||||||
try {
|
try {
|
||||||
$('#paste-content').text(zerobin.decrypt(key, content));
|
$('#paste-content').text(zerobin.decrypt(key, content));
|
||||||
|
hljs.highlightBlock($('#paste-content')[0]);
|
||||||
} catch(err) {
|
} catch(err) {
|
||||||
alert('Could not decrypt data (Wrong key ?)');
|
alert('Could not decrypt data (Wrong key ?)');
|
||||||
}
|
}
|
||||||
|
1
static/js/highlight.pack.js
Normal file
1
static/js/highlight.pack.js
Normal file
File diff suppressed because one or more lines are too long
125
static/js/lzw.js
125
static/js/lzw.js
@ -3,7 +3,6 @@
|
|||||||
// Note: modifed to javascript from orginal as2 found below
|
// Note: modifed to javascript from orginal as2 found below
|
||||||
// basically identical actual to as2
|
// basically identical actual to as2
|
||||||
//
|
//
|
||||||
//
|
|
||||||
// http://www.razorberry.com/blog/archives/2004/08/22/lzw-compression-methods-in-as2/
|
// http://www.razorberry.com/blog/archives/2004/08/22/lzw-compression-methods-in-as2/
|
||||||
//
|
//
|
||||||
// A class for LZW compression modified from code posted at the following URL's
|
// A class for LZW compression modified from code posted at the following URL's
|
||||||
@ -110,127 +109,3 @@ var lzw = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// LZW-compress a string
|
|
||||||
function lzw_encode(s) {
|
|
||||||
var dict = {};
|
|
||||||
var data = (s + "").split("");
|
|
||||||
var out = [];
|
|
||||||
var currChar;
|
|
||||||
var phrase = data[0];
|
|
||||||
var code = 256;
|
|
||||||
for (var i=1; i<data.length; i++) {
|
|
||||||
currChar=data[i];
|
|
||||||
if (dict[phrase + currChar] != null) {
|
|
||||||
phrase += currChar;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
out.push(phrase.length > 1 ? dict[phrase] : phrase.charCodeAt(0));
|
|
||||||
dict[phrase + currChar] = code;
|
|
||||||
code++;
|
|
||||||
phrase=currChar;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
out.push(phrase.length > 1 ? dict[phrase] : phrase.charCodeAt(0));
|
|
||||||
for (var i=0; i<out.length; i++) {
|
|
||||||
out[i] = String.fromCharCode(out[i]);
|
|
||||||
}
|
|
||||||
return out.join("");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Decompress an LZW-encoded string
|
|
||||||
function lzw_decode(s) {
|
|
||||||
var dict = {};
|
|
||||||
var data = (s + "").split("");
|
|
||||||
var currChar = data[0];
|
|
||||||
var oldPhrase = currChar;
|
|
||||||
var out = [currChar];
|
|
||||||
var code = 256;
|
|
||||||
var phrase;
|
|
||||||
for (var i=1; i<data.length; i++) {
|
|
||||||
var currCode = data[i].charCodeAt(0);
|
|
||||||
if (currCode < 256) {
|
|
||||||
phrase = data[i];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
phrase = dict[currCode] ? dict[currCode] : (oldPhrase + currChar);
|
|
||||||
}
|
|
||||||
out.push(phrase);
|
|
||||||
currChar = phrase.charAt(0);
|
|
||||||
dict[code] = oldPhrase + currChar;
|
|
||||||
code++;
|
|
||||||
oldPhrase = phrase;
|
|
||||||
}
|
|
||||||
return out.join("");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* utf.js - UTF-8 <=> UTF-16 convertion
|
|
||||||
*
|
|
||||||
* Copyright (C) 1999 Masanao Izumo <iz@onicos.co.jp>
|
|
||||||
* Version: 1.0
|
|
||||||
* LastModified: Dec 25 1999
|
|
||||||
* This library is free. You can redistribute it and/or modify it.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Interfaces:
|
|
||||||
* utf8 = utf16to8(utf16);
|
|
||||||
* utf16 = utf16to8(utf8);
|
|
||||||
*/
|
|
||||||
|
|
||||||
function utf16to8(str) {
|
|
||||||
var out, i, len, c;
|
|
||||||
|
|
||||||
out = "";
|
|
||||||
len = str.length;
|
|
||||||
for(i = 0; i < len; i++) {
|
|
||||||
c = str.charCodeAt(i);
|
|
||||||
if ((c >= 0x0001) && (c <= 0x007F)) {
|
|
||||||
out += str.charAt(i);
|
|
||||||
} else if (c > 0x07FF) {
|
|
||||||
out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));
|
|
||||||
out += String.fromCharCode(0x80 | ((c >> 6) & 0x3F));
|
|
||||||
out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
|
|
||||||
} else {
|
|
||||||
out += String.fromCharCode(0xC0 | ((c >> 6) & 0x1F));
|
|
||||||
out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
function utf8to16(str) {
|
|
||||||
var out, i, len, c;
|
|
||||||
var char2, char3;
|
|
||||||
|
|
||||||
out = "";
|
|
||||||
len = str.length;
|
|
||||||
i = 0;
|
|
||||||
while(i < len) {
|
|
||||||
c = str.charCodeAt(i++);
|
|
||||||
switch(c >> 4)
|
|
||||||
{
|
|
||||||
case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
|
|
||||||
// 0xxxxxxx
|
|
||||||
out += str.charAt(i-1);
|
|
||||||
break;
|
|
||||||
case 12: case 13:
|
|
||||||
// 110x xxxx 10xx xxxx
|
|
||||||
char2 = str.charCodeAt(i++);
|
|
||||||
out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F));
|
|
||||||
break;
|
|
||||||
case 14:
|
|
||||||
// 1110 xxxx 10xx xxxx 10xx xxxx
|
|
||||||
char2 = str.charCodeAt(i++);
|
|
||||||
char3 = str.charCodeAt(i++);
|
|
||||||
out += String.fromCharCode(((c & 0x0F) << 12) |
|
|
||||||
((char2 & 0x3F) << 6) |
|
|
||||||
((char3 & 0x3F) << 0));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return out;
|
|
||||||
}
|
|
@ -9,6 +9,7 @@
|
|||||||
pastebin with a burn after reading feature">
|
pastebin with a burn after reading feature">
|
||||||
|
|
||||||
<link rel="shortcut icon" href="/static/ico/favicon.ico">
|
<link rel="shortcut icon" href="/static/ico/favicon.ico">
|
||||||
|
<link href="/static/css/vs.css" rel="stylesheet" />
|
||||||
<link href="/static/css/bootstrap.css" rel="stylesheet">
|
<link href="/static/css/bootstrap.css" rel="stylesheet">
|
||||||
<link href="/static/css/style.css" rel="stylesheet">
|
<link href="/static/css/style.css" rel="stylesheet">
|
||||||
|
|
||||||
@ -85,7 +86,7 @@
|
|||||||
</div><!--/.fluid-container-->
|
</div><!--/.fluid-container-->
|
||||||
|
|
||||||
<script src="/static/js/lzw.js"></script>
|
<script src="/static/js/lzw.js"></script>
|
||||||
|
<script src="/static/js/highlight.pack.js"></script>
|
||||||
<!--
|
<!--
|
||||||
<script src="/static/js/jquery.js"></script>
|
<script src="/static/js/jquery.js"></script>
|
||||||
<script src="/static/js/bootstrap-transition.js"></script>
|
<script src="/static/js/bootstrap-transition.js"></script>
|
||||||
|
@ -8,9 +8,13 @@
|
|||||||
<p>
|
<p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
<pre id="paste-content">
|
|
||||||
|
<pre id="paste-content" class="prettyprint">
|
||||||
|
<code>
|
||||||
{{ paste.content }}
|
{{ paste.content }}
|
||||||
|
</code>
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p class="paste-option btn-group">
|
<p class="paste-option btn-group">
|
||||||
|
Loading…
Reference in New Issue
Block a user