Embeding Code Editor

Hi, I would like to know i could embed a code editor like Ace in Anvil. I softly tried but couldn’t seem to get it to work.

I created a little Flask server to test it out and it turns out it’s painless. One HTML file, a couple JS files (depending on the desired functionality) and that’s it.

In this case loaded the 3 JS files i wanted from a cdn, using Flask’s “render_template” to load the HTML file: https://pastebin.com/pm08J85Z

Thanks!

Hi @bLeDy and welcome to the forum.

This is certainly possible.
You can achieve this in the following way:

move your cdn scripts to native libraries
Create a custom HTML Form and paste some of the html/css/js…


<pre id="editor">def foo(items):
    for i in len(items):
        print("Ace Rocks", items[i])
</pre>

<script>
    var editor = ace.edit("editor");
    editor.setTheme("ace/theme/twilight");
    editor.session.setMode("ace/mode/python");
</script>

<style>
    #editor {
        margin: 0;
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
    }
  </style>

Clone Link:
https://anvil.works/build#clone:3BELTE4C6AI7T3RD=WLNFPDS4JGPHL6GKSLOOIPCS

5 Likes

That is it, placing the scripts in native libraries was the major thing i was missing!

Thank you so much

1 Like