mirror of
https://github.com/Tygs/0bin.git
synced 2023-08-10 21:13:00 +03:00
Improved comments handling in code detection
This commit is contained in:
parent
8e318c768b
commit
451a282684
@ -329,15 +329,22 @@ window.zerobin = {
|
|||||||
isCode: function(text){
|
isCode: function(text){
|
||||||
|
|
||||||
var code_chars = /[A-Z]{3}[A-Z]+|\.[a-z]|[=:<>{}\[\]$_'"&]| {2}|\t/g;
|
var code_chars = /[A-Z]{3}[A-Z]+|\.[a-z]|[=:<>{}\[\]$_'"&]| {2}|\t/g;
|
||||||
var comment = /(\/\*|\/\/|#|;).*$/g;
|
var comments = /(:?\/\*|<!--)(:?.|\n)*?(:?\*\/|-->)|(\/\/|#)(.*?)\n/g;
|
||||||
|
var formating = /[-*=_+]{4,}/;
|
||||||
|
|
||||||
var total = 0;
|
var total = 0;
|
||||||
var size = 0;
|
var size = 0;
|
||||||
|
var m = text.match(comments);
|
||||||
|
if (m){
|
||||||
|
total += text.match(comments).length;
|
||||||
|
}
|
||||||
|
text = text.replace(comments, '');
|
||||||
|
text.replace(formating, '');
|
||||||
text = text.split('\n');
|
text = text.split('\n');
|
||||||
for (var i = 0; i < text.length; i++) {
|
for (var i = 0; i < text.length; i++) {
|
||||||
var line = text[i];
|
var line = text[i];
|
||||||
size += line.length;
|
size += line.length;
|
||||||
var match = line.replace(comment, '').match(code_chars);
|
var match = line.replace(formating, '').match(code_chars);
|
||||||
if (match) {
|
if (match) {
|
||||||
total += match.length;
|
total += match.length;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user