From 44a42bdd1e0a627b6ca3ee48b4876592c35d0ca4 Mon Sep 17 00:00:00 2001 From: Leopere Date: Sat, 7 Mar 2026 16:08:10 -0500 Subject: [PATCH] Syntax highlighting: .coffee URL for CoffeeScript, extension only when relevance >= 5 - Map coffee extension to hljs language 'coffeescript' so URLs use .coffee not .coffeescript - Add minRelevanceForExtension (5); only append extension to URL when auto-detect is confident - Avoids misleading extensions for logs/plain text misclassified by highlightAuto Made-with: Cursor --- static/application.js | 11 +++++++++-- static/application.min.js | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/static/application.js b/static/application.js index 66567c0..cbf4466 100644 --- a/static/application.js +++ b/static/application.js @@ -69,10 +69,12 @@ haste_document.prototype.save = function(data, callback) { _this.locked = true; _this.key = res.key; var high = hljs.highlightAuto(data); + var relevance = high.relevance != null ? high.relevance : high.re; callback(null, { value: high.value, key: res.key, language: high.language, + relevance: relevance, lineCount: data.split('\n').length }); }, @@ -160,6 +162,10 @@ haste.prototype.newDocument = function(hideHistory) { this.removeLineNumbers(); }; +// Only add a URL extension when auto-detect relevance is at least this (avoids +// misleading extensions for log files / plain text that get misclassified) +haste.minRelevanceForExtension = 5; + // Map of common extensions // Note: this list does not need to include anything that IS its extension, // due to the behavior of lookupTypeByExtension and lookupExtensionByType @@ -170,7 +176,7 @@ haste.extensionMap = { lua: 'lua', pas: 'delphi', java: 'java', cpp: 'cpp', cc: 'cpp', m: 'objectivec', vala: 'vala', sql: 'sql', sm: 'smalltalk', lisp: 'lisp', ini: 'ini', diff: 'diff', bash: 'bash', sh: 'bash', tex: 'tex', erl: 'erlang', hs: 'haskell', - md: 'markdown', txt: '', coffee: 'coffee', json: 'javascript', + md: 'markdown', txt: '', coffee: 'coffeescript', json: 'javascript', swift: 'swift' }; @@ -246,7 +252,8 @@ haste.prototype.lockDocument = function() { _this.$code.html(ret.value); _this.setTitle(ret.key); var file = '/' + ret.key; - if (ret.language) { + var relevance = ret.relevance != null ? ret.relevance : 0; + if (ret.language && relevance >= haste.minRelevanceForExtension) { file += '.' + _this.lookupExtensionByType(ret.language); } window.history.pushState(null, _this.appName + '-' + ret.key, file); diff --git a/static/application.min.js b/static/application.min.js index a92f287..df7da5e 100644 --- a/static/application.min.js +++ b/static/application.min.js @@ -1 +1 @@ -var haste_document=function(){this.locked=!1},haste=(haste_document.prototype.htmlEscape=function(t){return t.replace(/&/g,"&").replace(/>/g,">").replace(/'+t+"");$("#messages").prepend(o),setTimeout(function(){o.slideUp("fast",function(){$(this).remove()})},3e3)},haste.prototype.lightKey=function(){this.configureKey(["new","save"])},haste.prototype.fullKey=function(){this.configureKey(["new","save","duplicate","raw"])},haste.prototype.configureKey=function(t){var e,o=0;$("#box2 .function").each(function(){for(e=$(this),o=0;o";$("#linenos").html(e)},haste.prototype.removeLineNumbers=function(){$("#linenos").html(">")},haste.prototype.loadDocument=function(t){var t=t.split(".",2),e=this;e.doc=new haste_document,e.doc.load(t[0],function(t){t?(e.$code.html(t.value),e.setTitle(t.key),e.fullKey(),e.$textarea.val("").hide(),e.$box.show().focus(),e.addLineNumbers(t.lineCount)):e.newDocument()},this.lookupTypeByExtension(t[1]))},haste.prototype.duplicateDocument=function(){var t;this.doc.locked&&(t=this.doc.data,this.newDocument(),this.$textarea.val(t))},haste.prototype.lockDocument=function(){var o=this;this.doc.save(this.$textarea.val(),function(t,e){t?o.showMessage(t.message,"error"):e&&(o.$code.html(e.value),o.setTitle(e.key),t="/"+e.key,e.language&&(t+="."+o.lookupExtensionByType(e.language)),window.history.pushState(null,o.appName+"-"+e.key,t),o.fullKey(),o.$textarea.val("").hide(),o.$box.show().focus(),o.addLineNumbers(e.lineCount))})},haste.prototype.configureButtons=function(){var e=this;this.buttons=[{$where:$("#box2 .save"),label:"Save",shortcut:function(t){return t.ctrlKey&&83===t.keyCode},shortcutDescription:"control + s",action:function(){e.doc.locked?e.duplicateDocument():e.lockDocument()}},{$where:$("#box2 .new"),label:"New",shortcut:function(t){return t.ctrlKey&&78===t.keyCode},shortcutDescription:"control + n",action:function(){e.newDocument(!e.doc.key)}},{$where:$("#box2 .duplicate"),label:"Duplicate & Edit",shortcut:function(t){return e.doc.locked&&t.ctrlKey&&68===t.keyCode},shortcutDescription:"control + d",action:function(){e.duplicateDocument()}},{$where:$("#box2 .raw"),label:"Just Text",shortcut:function(t){return t.ctrlKey&&t.shiftKey&&82===t.keyCode},shortcutDescription:"control + shift + r",action:function(){window.location.href="/raw/"+e.doc.key}}];for(var t=0;t/g,">").replace(/'+t+"");$("#messages").prepend(o),setTimeout(function(){o.slideUp("fast",function(){$(this).remove()})},3e3)},haste.prototype.lightKey=function(){this.configureKey(["new","save"])},haste.prototype.fullKey=function(){this.configureKey(["new","save","duplicate","raw"])},haste.prototype.configureKey=function(t){var e,o=0;$("#box2 .function").each(function(){for(e=$(this),o=0;o";$("#linenos").html(e)},haste.prototype.removeLineNumbers=function(){$("#linenos").html(">")},haste.prototype.loadDocument=function(t){var t=t.split(".",2),e=this;e.doc=new haste_document,e.doc.load(t[0],function(t){t?(e.$code.html(t.value),e.setTitle(t.key),e.fullKey(),e.$textarea.val("").hide(),e.$box.show().focus(),e.addLineNumbers(t.lineCount)):e.newDocument()},this.lookupTypeByExtension(t[1]))},haste.prototype.duplicateDocument=function(){var t;this.doc.locked&&(t=this.doc.data,this.newDocument(),this.$textarea.val(t))},haste.prototype.lockDocument=function(){var o=this;this.doc.save(this.$textarea.val(),function(t,e){t?o.showMessage(t.message,"error"):e&&(o.$code.html(e.value),o.setTitle(e.key),t="/"+e.key,(e.relevance!=null?e.relevance:0)>=haste.minRelevanceForExtension&&e.language&&(t+="."+o.lookupExtensionByType(e.language)),window.history.pushState(null,o.appName+"-"+e.key,t),o.fullKey(),o.$textarea.val("").hide(),o.$box.show().focus(),o.addLineNumbers(e.lineCount))})},haste.prototype.configureButtons=function(){var e=this;this.buttons=[{$where:$("#box2 .save"),label:"Save",shortcut:function(t){return t.ctrlKey&&83===t.keyCode},shortcutDescription:"control + s",action:function(){e.doc.locked?e.duplicateDocument():e.lockDocument()}},{$where:$("#box2 .new"),label:"New",shortcut:function(t){return t.ctrlKey&&78===t.keyCode},shortcutDescription:"control + n",action:function(){e.newDocument(!e.doc.key)}},{$where:$("#box2 .duplicate"),label:"Duplicate & Edit",shortcut:function(t){return e.doc.locked&&t.ctrlKey&&68===t.keyCode},shortcutDescription:"control + d",action:function(){e.duplicateDocument()}},{$where:$("#box2 .raw"),label:"Just Text",shortcut:function(t){return t.ctrlKey&&t.shiftKey&&82===t.keyCode},shortcutDescription:"control + shift + r",action:function(){window.location.href="/raw/"+e.doc.key}}];for(var t=0;t