代码镜像只能取消注释代码

时间:2013-08-13 06:01:57

标签: c# javascript codemirror jshint

我在asp.net应用程序中实现了最新的代码镜像。编辑器允许输入带有注释代码和未注释代码的javascript。

我想知道编辑器中编写的所有代码是否都已注释。

任何人都可以提供建议。

1 个答案:

答案 0 :(得分:0)

您可以获取文档文本,而不是通过regex, filtering out all the comments

传递文档文本
var editor = CodeMirror.fromTextArea(document.getElementById('code'), {
    lineNumbers: true
});

var out = document.getElementById('out');
out.textContent = editor.getValue()
        .replace(/(?:\/\*(?:[\s\S]*?)\*\/)|(?:[\s;]+\/\/(?:.*)$)/gm, '');

jsfiddle icon Demo

相关问题