在我的网络应用程序中,我正在使用 ace 编辑器和 python 模式,如下所示:
var editor = ace.edit('aceEditor');
editor.setTheme("ace/theme/monokai");
editor.getSession().setMode("ace/mode/python");
editor.getSession().setUseWorker(false);
editor.setHighlightActiveLine(false);
editor.setShowPrintMargin(false);
ace.require("ace/ext/language_tools");
editor.setOptions({
enableBasicAutocompletion: true,
enableSnippets: true
});
editor.setBehavioursEnabled(true);
editor.setValue(`n=int(input("Enter the number of elements to be inserted: "))
a=[]
for i in range(0,n):
elem=int(input("Enter element: "))
a.append(elem)
avg=sum(a)/n
prin("Average of elements in the list",round(avg,2))`, -1);
#aceEditor {
width: 100%;
height: 260px;
border: "1px solid #ddd";
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.2/ace.js"></script>
<div id="aceEditor"></div>
如果 print
被用户输入错误,我需要像下面这样显示验证:
ace 编辑器对 HTML、JavaScript 进行语法验证/检查。但就我而言,我需要显示 python 的错误并且我愿意使用支持我的要求的其他编辑器并且我愿意使用 react-ace另外,在 react-ace 中,无法在 react-ace 上找到解决方案演示
我遇到了这个Issue ,其中指出 Cloud9 使用 pylint 来显示语法错误。如果是这样,如何在网络应用程序中启用它,我猜 ace 没有内置支持?关于这方面的任何帮助/指南都非常有帮助
最佳答案
我可以想到几个选项:
- 您可以找到用 Javascript 编写的 Python 解析器。快速谷歌搜索发现 filbert为我。我希望还有其他人。
- 使用在浏览器中运行的完整 Python 实现,然后使用 Python 工具进行验证。我用了Pyodide project构建我的 Live Coding in Python 的浏览器版本.
关于javascript - 在 ace 编辑器中启用 Python 语法验证/检查器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54664848/