Feature #30429
open
Automatic language detection in syntax highlighting
Added by Go MAEDA almost 6 years ago.
Updated almost 6 years ago.
Description
As of Redmine 4.0, you can use >100 languages in syntax highlighter (#24681). However, as you can use so many languages, it is difficult to memorize which languages you can highlight and what language name you should describe highlighting the snippet.
To resolve the problem, I propose a language name "auto". When you use the language name "auto" like the following, Redmine automatically detects the language and highlight the code snippet.
Probably we can use Rouge::Lexer.guess_by_source to implement this feature.
Files
Go MAEDA wrote:
Probably we can use Rouge::Lexer.guess_by_source to implement this feature.
Unfortunately, I found that guess_by_source is not so useful because it checks only a shebang line for most languages. It means that the following snippet that obviously looks like C language is not detected as C but plain text.
#include <stdio.h>
int main()
{
printf("Hello, world!\n");
return 0;
}
2.6.0 :012 > text
=> "#include <stdio.h>\n\nint main()\n{\n printf(\"Hello, world!\n\");\n return 0;\n}\n"
2.6.0 :013 > Rouge::Lexer.guess_by_source(text)
=> Rouge::Lexers::PlainText
+1 I am thinking it would probably be better to have the syntax highlighter guess the language only in case a user forgot to define what language it is, else the manual definition to always override the automatic detection. :)
It's for sure a nice improvement for Redmine.
+1
Max Johansson wrote:
I am thinking it would probably be better to have the syntax highlighter guess the language only in case a user forgot to define what language it is, else the manual definition to always override the automatic detection. :)
I would also prefer to have auto detection enabled by default as it would be more convenient and less error prone.
Also available in: Atom
PDF