CodeMirror - 语言自动检测
我正在使用独立的突出显示(不是编辑器),如下所示: http://codemirror.net/demo/runmode.html
如何自动检测语言运行荧光笔时使用?
这里有一个模式自动更改演示: http://codemirror.net/demo/changemode.html
但我不知道怎么可能我对其进行了调整以与 Codemirror.runMode() 一起使用。我希望使用自动检测方案突出显示整个代码块。
I'm using stand-alone highlighting (not the editor), something like this:
http://codemirror.net/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.net/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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
“changemode”演示只能区分“Scheme”编程语言和“其他所有语言”,请参阅实现
因此这无法自动检测其他编程语言,正如演示页面所说,即使用于检测Scheme这是非常粗糙的。
不幸的是,从源代码片段中自动检测大量编程语言并不容易(对于小片段,不同的编程语言甚至可能使用完全相同的语法)。不过,从代码片段检测编程语言中建议了一种合理的方法。
The "changemode" demo can only distinguish between the "Scheme" programming language and "everything else", see the implementation of
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.