admin管理员组文章数量:1417414
I'm using stand-alone highlighting (not the editor), something like this: .html
How can I auto-detect the language to use when running the highlighter?
There's a mode-autochanging demo here: .html
But I don't know how could I adapt this to work with Codemirror.runMode(). I wish to highlight the entire code block using the auto-detected scheme.
I'm using stand-alone highlighting (not the editor), something like this: http://codemirror/demo/runmode.html
How can I auto-detect the language to use when running the highlighter?
There's a mode-autochanging demo here: http://codemirror/demo/changemode.html
But I don't know how could I adapt this to work with Codemirror.runMode(). I wish to highlight the entire code block using the auto-detected scheme.
Share Improve this question asked Jan 20, 2012 at 15:32 AlexAlex 66.2k185 gold badges460 silver badges651 bronze badges1 Answer
Reset to default 4The "changemode" demo can only distinguish between the "Scheme" programming language and "everything else", see the implementation of
function looksLikeScheme(code) {
return !/^\s*\(\s*function\b/.test(code) && /^\s*[;\(]/.test(code);
}
So this won't work to auto-detect other programming languages, and as the demo pages says, even for detecting Scheme it's very crude.
Unfortunately, it's not easy to auto-detect a large range of programming languages from a source code snippet (for small snippets, different programming languages might even use the exact same syntax). However, a reasonable approach is suggested in Detecting programming language from a snippet.
本文标签: javascriptCodeMirrorlanguage autodetectionStack Overflow
版权声明:本文标题:javascript - CodeMirror - language auto-detection - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745257565a2650191.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论