开发者

Implementing CodeMirror Syntax Highlighter

开发者 https://www.devze.com 2022-12-28 00:07 出处:网络
I am trying to make use of this Syntax highlighter. I have tried to implement their example and I always seem to get this error in firebug:

I am trying to make use of this Syntax highlighter. I have tried to implement their example and I always seem to get this error in firebug:

place is not a function else place(div);

Here is my code, I thought it was开发者_运维百科 a path issue, but everything looks right:

<textarea id="code1" rows="20" cols="20">
select * from where this = done
</textarea>

<script type="text/javascript" src="codemirror/js/codemirror.js"></script>

<script type="text/javascript">

var editor = new CodeMirror('code1', {
  height: "150px",
  parserfile: "codemirror/contrib/sql/js/parsesql.js",
  stylesheet: "css/sqlcolors.css",
  textWrapping: true
});

</script>

If you look at the source code of that example page, its similar to mine yet, the text in the text area doesn't get highlighted and I always get that error.

Thanks all for any help


Change the code that initializes CodeMirror to the following and I think it will work:

var editor = CodeMirror.fromTextArea('code1', {
  height: "150px",
  parserfile: "codemirror/contrib/sql/js/parsesql.js",
  path: "codemirror/js/",
  stylesheet: "css/sqlcolors.css",
  textWrapping: true
});

The important parts are using CodeMirror.fromTextArea rather than new CodeMirror and providing a value for path in the object passed into CodeMirror.fromTextArea.

0

精彩评论

暂无评论...
验证码 换一张
取 消