1
0
Fork 0
mirror of https://github.com/SunRed/haste-server.git synced 2024-11-01 09:40:21 +01:00

Allow forcing of highlight type

This commit is contained in:
John Crepezzi 2011-11-22 20:29:46 -05:00
parent 56bf98daac
commit ec0d419c61
3 changed files with 22 additions and 7 deletions

2
TODO
View file

@ -3,7 +3,7 @@ tests
add feedback for errors to UI - esp. too long add feedback for errors to UI - esp. too long
fix that chrome bug where it loads the doc twice fix that chrome bug where it loads the doc twice
add link to about page add link to about page
allow power users to force highlight lang - by supplying an extension!!!!!! expand extension map
maybe start serving highlighting on the other end to save transfer on highlight.js maybe start serving highlighting on the other end to save transfer on highlight.js
start using CDNs for most assets start using CDNs for most assets
kick expiration back by increment on each view kick expiration back by increment on each view

View file

@ -80,7 +80,7 @@ DocumentHandler.prototype.chooseKey = function(callback) {
// Return a boolean indicating whether or not something can be a key // Return a boolean indicating whether or not something can be a key
DocumentHandler.potentialKey = function(key) { DocumentHandler.potentialKey = function(key) {
return key.match(/^[a-zA-Z0-9]+$/); return key.match(/^[a-zA-Z0-9]+(\.[a-zA-Z]+?)$/);
}; };
// Generate a random key // Generate a random key

View file

@ -5,7 +5,7 @@ var haste_document = function() {
}; };
// Get this document from the server and lock it here // Get this document from the server and lock it here
haste_document.prototype.load = function(key, callback) { haste_document.prototype.load = function(key, callback, lang) {
var _this = this; var _this = this;
$.ajax('/documents/' + key, { $.ajax('/documents/' + key, {
type: 'get', type: 'get',
@ -14,11 +14,11 @@ haste_document.prototype.load = function(key, callback) {
_this.locked = true; _this.locked = true;
_this.key = key; _this.key = key;
_this.data = res.data; _this.data = res.data;
var high = hljs.highlightAuto(res.data); var high = lang ? hljs.highlight(lang, res.data) : hljs.highlightAuto(res.data);
callback({ callback({
value: high.value, value: high.value,
key: key, key: key,
language: high.language language: lang || high.language
}); });
}, },
error: function(err) { error: function(err) {
@ -105,11 +105,26 @@ haste.prototype.newDocument = function(hideHistory) {
}); });
}; };
// Map of common extensions
haste.extensionMap = {
'rb': 'ruby',
'py': 'python'
};
// Map an extension to a language
haste.prototype.lookupExtension = function(ext) {
var match = haste.extensionMap[ext];
return match; // if not found, will auto-detect
};
// Load a document and show it // Load a document and show it
haste.prototype.loadDocument = function(key) { haste.prototype.loadDocument = function(key) {
// Split the key up
var parts = key.split('.', 2);
// Ask for what we want
var _this = this; var _this = this;
_this.doc = new haste_document(); _this.doc = new haste_document();
_this.doc.load(key, function(ret) { _this.doc.load(parts[0], function(ret) {
if (ret) { if (ret) {
_this.$code.html(ret.value); _this.$code.html(ret.value);
var title = ret.key; var title = ret.key;
@ -124,7 +139,7 @@ haste.prototype.loadDocument = function(key) {
else { else {
_this.newDocument(); _this.newDocument();
} }
}); }, this.lookupExtension(parts[1]));
}; };
// Duplicate the current document - only if locked // Duplicate the current document - only if locked