在ace edi中启用Python语法验证/检查器

2024-09-29 07:19:56 发布

您现在位置:Python中文网/ 问答频道 /正文

在我的web应用程序中,我使用的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); ^{pr2}$

<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.2/ace.js"></script>
<div id="aceEditor"></div>

如果用户错误地键入了print,我需要显示如下验证:

HTML Syntax validation

ace编辑器对HTML、JavaScript进行语法验证/检查。但在我的例子中,我需要显示python的错误,并且我愿意使用支持我的需求的其他编辑器,我也愿意使用react-ace而且,在react ace中,在react-ace上找不到解决方案演示

我遇到了这个Issue,其中声明Cloud9使用pylint来显示语法错误。如果是这样的话,如何在web应用中启用它,我猜ace没有内置的支持?这方面有什么帮助/指南吗


Tags: ofthewebfalsetrueinputelements编辑器
1条回答
网友
1楼 · 发布于 2024-09-29 07:19:56

我可以想出几个选择:

  1. 你可以找到一个用Javascript编写的Python解析器。谷歌快速搜索找到了filbert。我想还有其他人。在
  2. 使用在浏览器中运行的完整Python实现,然后使用Python工具进行验证。我使用Pyodide project来构建我的Live Coding in Python的浏览器版本。在

相关问题 更多 >