From 895485e410a42487de5984ca6b388a0b10eb1ad8 Mon Sep 17 00:00:00 2001 From: John Crepezzi Date: Mon, 28 Nov 2011 00:54:24 -0500 Subject: [PATCH] Fix highlighting bug --- TODO.md | 1 - static/application.js | 3 ++- static/application.min.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/TODO.md b/TODO.md index b7ca5fc..3032e05 100644 --- a/TODO.md +++ b/TODO.md @@ -5,4 +5,3 @@ * Add file extensions ourselves to push state * Better about page text * add feedback for errors to UI - esp. too long -* html escape everything diff --git a/static/application.js b/static/application.js index f0e5732..eadbdc3 100644 --- a/static/application.js +++ b/static/application.js @@ -17,7 +17,8 @@ haste_document.prototype.load = function(key, callback, lang) { try { var high = lang ? hljs.highlight(lang, res.data) : hljs.highlightAuto(res.data); } catch(err) { - high = { value: res.data, language: null }; + // failed highlight, fall back on auto + high = hljs.highlightAuto(res.data); } callback({ value: high.value, diff --git a/static/application.min.js b/static/application.min.js index 9ea2954..f0a96ec 100644 --- a/static/application.min.js +++ b/static/application.min.js @@ -1 +1 @@ -var haste_document=function(){this.locked=!1};haste_document.prototype.load=function(a,b,c){var d=this;$.ajax("/documents/"+a,{type:"get",dataType:"json",success:function(e){d.locked=!0,d.key=a,d.data=e.data;try{var f=c?hljs.highlight(c,e.data):hljs.highlightAuto(e.data)}catch(g){f={value:e.data,language:null}}b({value:f.value,key:a,language:f.language||c})},error:function(a){b(!1)}})},haste_document.prototype.save=function(a,b){if(this.locked)return!1;this.data=a;var c=this;$.ajax("/documents",{type:"post",data:a,dataType:"json",success:function(d){c.locked=!0,c.key=d.key;var e=hljs.highlightAuto(a);b({value:e.value,key:d.key,language:e.language})}})};var haste=function(a,b){this.appName=a,this.baseUrl=window.location.href,this.$textarea=$("textarea"),this.$box=$("#box"),this.$code=$("#box code"),this.options=b,this.configureShortcuts(),this.configureButtons(),b.twitter||$("#key .box2 .twitter").hide()};haste.prototype.setTitle=function(a){var b=a?this.appName+" - "+a:this.appName;document.title=b},haste.prototype.lightKey=function(){this.configureKey(["new","save"]),this.removeClip()},haste.prototype.fullKey=function(){this.configureKey(["new","duplicate","twitter","link"]),this.configureClip()},haste.prototype.configureKey=function(a){var b,c=0;$("#key .box2 .function").each(function(){b=$(this);for(c=0;c