viebel / klipse

Klipse is a JavaScript plugin for embedding interactive code snippets in tech blogs.
http://blog.klipse.tech/
GNU General Public License v3.0
3.1k stars 153 forks source link

Question about accessing klipse programmatically #367

Closed rdbeach closed 4 years ago

rdbeach commented 4 years ago

Hi, I have a couple of questions.

First, can I just send the code as a string to the compiler and have it return a result as a string, bypassing the DOM elements.

I saw something like this in the examples:

<script>
    window.klipse_settings = {

        selector: '.clojure'

    };

</script>

<script src="https://storage.googleapis.com/app.klipse.tech/plugin/js/klipse_plugin.js">`

</script>

<script>
console.log(window.cljs);

console.log(window.klipse);

 eval_clj = window.klipse.compiler.str_eval;

console.log("(map inc [1 2 3]):" , eval_clj("(map inc [1 2 3])"));

</script>

But I tried it and it didn't seem to work. Maybe there have been changes?

Second, are all the complilers/interpreters bundled in the one js file? How do I assemble only the compilers I want?

BTW I'm a javascript guy. I'm not that familiar with clojure.

viebel commented 4 years ago

Hello @rdbeach What language are you interested to eval?

rdbeach commented 4 years ago

I think Python and javascript would be my first priority. However, I was asking if there is a general way to do it, as well. The thing is, I have my own codemirror editor. I would like to be able to grab the contents from it, send it to the compiler and put the output in a place of my choosing. I saw that this project handled multiple languages, which is something I found desirable.

rdbeach commented 4 years ago

So I figured out a way to do this. It's a hack, but I guess I'll go with it for now.