简体   繁体   English

是否可以同时混合CodeMirror:Velocity模式和CodeMirror:HTML混合模式?

[英]Is it possible to mix both the CodeMirror: Velocity mode and the CodeMirror: HTML mixed mode?

Does anyone have made a 'htmlmixed' + 'Velocity' mode for codemirror? 是否有人为codemirror制作了“ htmlmixed” +“ Velocity”模式? Or anyone can advice how to achieve that? 或者任何人都可以建议如何实现?

I was able to achieve this easily with the overlay.js addon: 我能够使用overlay.js插件轻松实现此目标:

CodeMirror.defineMode("velocityOverlay", function(config, parserConfig) {
  return CodeMirror.overlayMode(CodeMirror.getMode(config, "htmlmixed"), CodeMirror.getMode(config, "velocity"));
});

Then in the editor set the mode option to be "velocityOverlay" and you are done. 然后在编辑器中将mode选项设置为“ velocityOverlay”,即可完成操作。

However, the velocity mode highlights characters like <,>, etc as velocity operators which you may not want as it will make your html higlighting look ugly. 但是,速度模式会突出显示诸如<,>等字符,这是您可能不希望使用的速度运算符,因为它会使html高亮显示难看。 To deal with this I changed the following line of code in velocity.js: 为了解决这个问题,我在Velocity.js中更改了以下代码行:

var isOperatorChar = /[+\-*&%=<>!?:\/|]/;

to

var isOperatorChar = /[+\*&%=?:|]/;

You might be able to get somewhere using the mode-multiplexer , if there are specific strings that you want to use to switch mode on. 如果要使用某些特定的字符串来打开模式,则可以使用mode-multiplexer到达某个地方。 But it looks like Velocity would require something more advanced. 但是看来Velocity需要更高级的东西。 So you'd have to write your own super-mode, similar to what the htmlmixed mode does, which intelligently switches between modes. 因此,您必须编写自己的超级模式,类似于htmlmixed模式所做的,它可以在模式之间进行智能切换。

I don't think that you can mix both the CodeMirror: Velocity mode and the CodeMirror: HTML mixed mode. 我认为您不能混合使用CodeMirror:Velocity模式CodeMirror:HTML混合模式。 A mode is the way of doing things in a specific way. 模式是一种以特定方式做事的方式。 How could you mix up two modes? 您如何混合两种模式? I don't think that there is a possibility. 我认为没有可能性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM