codeFlask
是一个在线代码编辑器:
官方文档:https://kazzkiq.github.io/CodeFlask/
github
:https://github.com/kazzkiq/CodeFlask
代码也很简单:
代码语言:javascript复制<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script type="text/javascript" src="https://unpkg.com/codeflask/build/codeflask.min.js"></script>
</head>
<body>
<div id="editor"></div>
<script type="application/javascript">
const editorElem = document.getElementById('editor');
const flask = new CodeFlask(editorElem, {
language: 'js',
lineNumbers: true,
styleParent: this.shadowRoot
});
flask.addLanguage('JavaScript', Prism.languages['JavaScript']);
flask.onUpdate((code) => {
// do something with code here.
// this will trigger whenever the code
// in the editor changes.
console.log(code)
});
// flask.updateCode('哈哈');
// This will also trigger .onUpdate()
flask.updateCode(`<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<page>
</page>
</html>`);
const currentCode = flask.getCode();
console.log({
currentCode
})
</script>
</body>
</html>
这里page
本来应该是body
,但由于HbuilderX
自带的LiveReload
会把我的</body>
替换掉,所以我就换成page
了,如果不是用HbuilderX
运行自动刷新,则不用担心这个问题