Syntax highlighting: .coffee URL for CoffeeScript, extension only when relevance >= 5
ci/woodpecker/push/woodpecker Pipeline failed
Details
ci/woodpecker/push/woodpecker Pipeline failed
Details
- 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
This commit is contained in:
parent
820a17e40b
commit
44a42bdd1e
|
|
@ -69,10 +69,12 @@ haste_document.prototype.save = function(data, callback) {
|
||||||
_this.locked = true;
|
_this.locked = true;
|
||||||
_this.key = res.key;
|
_this.key = res.key;
|
||||||
var high = hljs.highlightAuto(data);
|
var high = hljs.highlightAuto(data);
|
||||||
|
var relevance = high.relevance != null ? high.relevance : high.re;
|
||||||
callback(null, {
|
callback(null, {
|
||||||
value: high.value,
|
value: high.value,
|
||||||
key: res.key,
|
key: res.key,
|
||||||
language: high.language,
|
language: high.language,
|
||||||
|
relevance: relevance,
|
||||||
lineCount: data.split('\n').length
|
lineCount: data.split('\n').length
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
@ -160,6 +162,10 @@ haste.prototype.newDocument = function(hideHistory) {
|
||||||
this.removeLineNumbers();
|
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
|
// Map of common extensions
|
||||||
// Note: this list does not need to include anything that IS its extension,
|
// Note: this list does not need to include anything that IS its extension,
|
||||||
// due to the behavior of lookupTypeByExtension and lookupExtensionByType
|
// 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',
|
lua: 'lua', pas: 'delphi', java: 'java', cpp: 'cpp', cc: 'cpp', m: 'objectivec',
|
||||||
vala: 'vala', sql: 'sql', sm: 'smalltalk', lisp: 'lisp', ini: 'ini',
|
vala: 'vala', sql: 'sql', sm: 'smalltalk', lisp: 'lisp', ini: 'ini',
|
||||||
diff: 'diff', bash: 'bash', sh: 'bash', tex: 'tex', erl: 'erlang', hs: 'haskell',
|
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'
|
swift: 'swift'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -246,7 +252,8 @@ haste.prototype.lockDocument = function() {
|
||||||
_this.$code.html(ret.value);
|
_this.$code.html(ret.value);
|
||||||
_this.setTitle(ret.key);
|
_this.setTitle(ret.key);
|
||||||
var file = '/' + 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);
|
file += '.' + _this.lookupExtensionByType(ret.language);
|
||||||
}
|
}
|
||||||
window.history.pushState(null, _this.appName + '-' + ret.key, file);
|
window.history.pushState(null, _this.appName + '-' + ret.key, file);
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue