Codemirror, defineMode在双引号内
Codemirror, defineMode inside doublequotes
本文关键字:defineMode Codemirror 更新时间:2023-09-26
我正在编写一个自定义覆盖来创建类型为engage
的令牌,用于一些自定义功能/样式。
我现在在双引号创建令牌,如"EXP=SOMETHING"
我需要虽然只有在双引号之间:EXP=SOMETHING
,我可以轻松地跳过第一个报价并得到类似EXP=SOMETHING"
但我似乎无法找到一个可行的方法,跳过最后一个引用,在这个问题上我一直敲我的头这么久我开始认为这是不可能的,备份的字符返回EXCEPTION: Uncaught (in promise): Error: Mode engage failed to advance stream.
这是有意义的。我肯定我遗漏了一些东西,我想要一些输入。
跟随产生EXP=SOMETHING"
的代码谢谢你的帮助:-)
CodeMirror.defineMode("engage", function(config, parserConfig) {
var engageOverlay = {
startState: function() {return {inString: false};},
token: function(stream, state) {
// If we are not inside the engage token and we are peeking a "
if (!state.inString && stream.peek() == '"') {
// We move the stream to the next char
// Then mark the start of the string
// Then return null to avoid including the first " as part of the token
stream.next();
state.inString = true;
return null;
}
// We are inside the target token
if (state.inString)
{
if (stream.skipTo('"'))
{
stream.next();
state.inString = false;
}
else
{
stream.skipToEnd();
}
return "engage";
}
else
{
stream.skipTo('"') || stream.skipToEnd();
return null;
}
}
};
return CodeMirror.overlayMode(CodeMirror.getMode(config, parserConfig.backdrop || "xml"), engageOverlay);
});
如果有人无意中发现了这个问题,下面是上述问题的解决方案:
// If we are not inside the engage token and we are peeking a "
if ( !state.inString && stream.match(/="/, true) ) {
state.inString = true;
return null;
}
// We are inside the target token
if (state.inString)
{
if (stream.skipTo('"'))
{
state.inString = false;
return "engage";
}
else
{
stream.skipToEnd();
return null;
}
}
stream.next();
return null;
我们基本上只是区分双引号的开始和结束,在我的特殊情况下,我总是在第一个"之前有一个=,如果不是这种情况,你可以很容易地设置另一个标志
相关文章:
- http://oauth.googlecode.com/svn/code/javascript/oauth.js已关闭,
- 如何从键Code;中获取字符串/字符值;
- jQUery Code没有'我不在IE工作
- 将angular javascript文件包装为“;(function(){..[js-code here]…})()&
- Javascript code to struts2
- Javascript 计时器只调用一次 Code 隐藏方法
- 将 2D 数组从 Code Behind 传递给 JavaScript
- Joomla javascript var with HTML code
- 从Dart Code调用匿名Javascript函数
- this.form.elements.code引用了什么
- 通过将按钮id从Code-behind传递给Jquery Function,Set buttons display no
- Execution of code in <script>
- $(document).ready(function(){code});没有接到电话
- Missing ) with JavaScript Code
- 谷歌脚本从code.gs返回到index.html
- 使用Just My Code在Visual Studio 2013中调试Javascript
- 更改Facebook Like Code中的URL
- Javascript,SublimeCodeIntel和hinting Code Intelligence自动完成
- 为什么当我使用JQuery DatePicker时,Google Code Prettifier停止工作(反之亦然)
- GWT Code Generation, MVC & Support