ace-editor-web-component
Web component for printing code with syntax highlighting using ace editor.
安装与使用
请根据来源仓库和你的 AI 工具说明安装此技能。先阅读技能文件和依赖要求,再添加到工作流。
查看来源 ↗使用指南技能说明
documentation
Documentation can be found https://stopsopa.github.io/ace-editor-webcomponent/learning/008_ace_async_loader/dynamic.html
generally this is web component which can be used like
<ace-editor lang="javascript" id="unique-id">
<script type="ace">
function greet(name) {
console.log("Hello, " + name + "!");
}
greet("World");
</script>
</ace-editor>
between tagx <script type="ace"> and </script> you just place your code and pick the language in the lang attribute.
For full list of languages go to: https://github.com/ajaxorg/ace/blob/v1.43.4/src/ext/modelist.js#L72
Installation
Normally before we will be able to use this web component we will have to run
<script
type="module"
src="https://stopsopa.github.io/ace-editor-webcomponent/ace-web-component.js"
data-main-ace="https://stopsopa.github.io/ace-editor-webcomponent/noprettier/ace/ace-builds-1.43.4/src-min-noconflict/ace.js"
></script>
There is not npm package for this project. Because the only thing specific to this project is file https://stopsopa.github.io/ace-editor-webcomponent/ace-web-component.js
which can be just downloaded to this project we are building from there. So installation is not needed. Just downloading this file.
data-main-ace on the other hand can point to any publicly available ace editor version. We just have to point it to ace.min.js in particular place.
theme
By default don't override theme="..." argument in web component. Leave default theme.
For the purpose of AI usage just stick to the example above. User will change path to ace.min.js manually.
editing content in ace editor web component
Ace editor web component can be updated live by just finding editor in the DOM tree by id and updating it's content like so:
const editor = document.getElementById('programmatic-demo');
editor.setAttribute('lang', 'python');
editor.setAttribute('value', `# Python Example
def bubble_sort(arr):
n = len(arr)
for i in range(n):
for j in range(0, n - i - 1):
if arr[j] > arr[j + 1]:
arr[j], arr[j + 1] = arr[j + 1], arr[j]
return arr`);
example above also demonstrate how we can change language of the editor programatically
waiting to be able to interact with editor
if there is need to interact programatically with ace editor then below will not work.
The reason is that this is web component and it have to by hydrated -> some scripts have to be loaded and logic aplied to "dress" the components to build them in the browser dom and make them ready to interact.
Therefore we have to have way to wait for it to happen, so this is how it can be done using onLoad event:
使用示例
查看来源仓库中的使用示例与配置说明。
查看来源 ↗来源历史
- 收录时间
- 2026-03-11
- 索引更新时间
- 2026-03-11
- Branch
- main
收录与同步日期属于本站记录。源码修改历史请查看来源仓库。
GitHub ↗chat Comments (0)
Sign in to join the discussion and leave a comment.
No comments yet. Be the first to share your thoughts!