Giter Club home page Giter Club logo

klipse's Introduction

Klipse

Klipse is a JavaScript plugin for embedding interactive code snippets in tech blogs. See examples at https://blog.klipse.tech/

Technically, Klipse is a small piece of JavaScript code that evaluates code snippets in the browser and it is pluggable on any web page.

If you like this stuff, please consider a (small donation) on Patreon.

Plugin

The klipse plugin is a JavaScript tag (see details below) that transforms static code snippets of an html page into live and interactive snippets:

  1. Live: The code is executed in your browser
  2. Interactive: You can modify the code and it is evaluated as you type

The code evaluation is done in the browser: no server is involved at all!

Live demo

With the klipse plugin, the code is evaluated as you type...

Here is a live demo of the embedding of klipse in a web page.

JavaScript Ruby
abc abc
PHP Clojure
abc abc

Supported languages

The code editing inside the interactive snippets is powered by CodeMirror.

How does it work?

Integration

In order to integrate the klipse plugin on a blog, library documentation or any other web page, you have to follow 3 simple steps.

  1. Make sure you have <!DOCTYPE html> at the top of your html file and <meta charset="utf-8"> right after your <head> (It is required in order to display properly the CodeMirror elements used by Klipse.)

  2. Add css and custom configuration somewhere in the page (it could be in the <head> or in the <body>) before the <script> element of step #3. The selector keys are per language (see below for a list of supported languages) and the value are the CSS selector of the elements that you want to klipsify.

<link rel="stylesheet" type="text/css" href="https://storage.googleapis.com/app.klipse.tech/css/codemirror.css">

<script>
    window.klipse_settings = {
        selector_eval_js: '.language-klipse-eval-js', // css selector for the html elements you want to klipsify
    };
</script>
  1. Add the JavaScript tag at the end of the body tag :

For Clojure:

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

For other languages:

    <script src="https://storage.googleapis.com/app.klipse.tech/plugin_prod/js/klipse_plugin.min.js"></script>
</body>

Here is an interactive guide of the klipse snippets.

If you want to host Klipse JavaScript tag from your own server, see Host Klipse Locally.

If you want to use an older version of Klipse, see Use Older Versions.

JavaScript

Here is the full interactive guide of the klipse JavaScript snippets.

<link rel="stylesheet" type="text/css" href="https://storage.googleapis.com/app.klipse.tech/css/codemirror.css">

<script>
    window.klipse_settings = {
        selector_eval_js: '.language-klipse-eval-js', // css selector for the html elements you want to klipsify
    };
</script>
<script src="https://storage.googleapis.com/app.klipse.tech/plugin_prod/js/klipse_plugin.min.js"></script>

Here is a jsfiddle with Klipse plugin for JavaScript. And here are detailed explanations about a JavaScript live code editor in a blog post.

Clojure and ClojureScript in a web page

Pay attention: for Clojure interactive snippets, you must use the non-minified version of klipse as for the moment, self-host cljs doesn't support advanced compilation!

Here is the full interactive guide of the klipse clojure snippets.

You can manipulate the DOM inside KLIPSE: here is a tutorial.

<link rel="stylesheet" type="text/css" href="https://storage.googleapis.com/app.klipse.tech/css/codemirror.css">

<script>
    window.klipse_settings = {
        selector: '.language-klipse'// css selector for the html elements you want to klipsify
    };
</script>
<script src="https://storage.googleapis.com/app.klipse.tech/plugin/js/klipse_plugin.js"></script>

ClojureScript project

If you want to integrate Klipse inside a Clojurescript project, it is recommended to consume Klipse as a Clojurescript library like any other Clojurescript lib, just like this Clojars.

Inside your code you have to require two namespaces and call a function:

(ns my.project
  (:require [klipse.run.plugin.plugin] ;; this namespace initializes Klipse. We require it for its side effects
            [klipse.plugin :as klipse-plugin]))

(klipse-plugin/init #js {:selector ".language-klipse"
                         :selector_reagent ".language-reagent"})

Here is an example of a tiny reagent demo project that integrates Klipse as a Clojurescript library.

Python

<link rel="stylesheet" type="text/css" href="https://storage.googleapis.com/app.klipse.tech/css/codemirror.css">

<script>
    window.klipse_settings = {
        selector_eval_python_client: '.language-klipse-python', // css selector for the html elements you want to klipsify
    };
</script>
<script src="https://storage.googleapis.com/app.klipse.tech/plugin_prod/js/klipse_plugin.min.js"></script>

Python3 (numpy, pandas)

<link rel="stylesheet" type="text/css" href="https://storage.googleapis.com/app.klipse.tech/css/codemirror.css">

<script>
    window.klipse_settings = {
        selector_pyodide: '.language-klipse-pyodide', // css selector for the html elements you want to klipsify
    };
</script>
<script src="https://storage.googleapis.com/app.klipse.tech/plugin_prod/js/klipse_plugin.min.js"></script>

Ruby

<link rel="stylesheet" type="text/css" href="https://storage.googleapis.com/app.klipse.tech/css/codemirror.css">

<script>
    window.klipse_settings = {
        selector_eval_ruby: '.language-klipse-eval-ruby', // css selector for the html elements you want to klipsify
    };
</script>
<script src="https://storage.googleapis.com/app.klipse.tech/plugin_prod/js/klipse_plugin.min.js"></script>

Lua

<link rel="stylesheet" type="text/css" href="https://storage.googleapis.com/app.klipse.tech/css/codemirror.css">
<link rel="stylesheet" type="text/css" href="https://storage.googleapis.com/app.klipse.tech/css/lua.css">

<script>
    window.klipse_settings = {
        selector_lua: '.language-klipse-lua', // css selector for the html elements you want to klipsify
    };
</script>
<script src="https://storage.googleapis.com/app.klipse.tech/plugin_prod/js/klipse_plugin.min.js"></script>

Go

<link rel="stylesheet" type="text/css" href="https://storage.googleapis.com/app.klipse.tech/css/codemirror.css">

<script>
    window.klipse_settings = {
        selector_golang: '.language-klipse-go, // css selector for the html elements you want to klipsify
    };
</script>
<script src="https://storage.googleapis.com/app.klipse.tech/plugin_prod/js/klipse_plugin.min.js"></script>

Scheme

<link rel="stylesheet" type="text/css" href="https://storage.googleapis.com/app.klipse.tech/css/codemirror.css">

<script>
    window.klipse_settings = {
        selector_eval_scheme: '.language-klipse-eval-scheme', // css selector for the html elements you want to klipsify
    };
</script>
<script src="https://storage.googleapis.com/app.klipse.tech/plugin_prod/js/klipse_plugin.min.js"></script>

Prolog

Prolog code snippets are separated into two kinds:

  • Rules
  • Queries

In the query, you must omit the ?- characters.

See A new way of blogging about Prolog for a full example and guide.

<link rel="stylesheet" type="text/css" href="https://storage.googleapis.com/app.klipse.tech/css/codemirror.css">
<link rel="stylesheet" type="text/css" href="https://storage.googleapis.com/app.klipse.tech/css/prolog.css">

<script>
    window.klipse_settings = {
        selector_prolog_rules: '.language-prolog-rules', // css selector for the html elements that contain prolog rules
        selector_prolog_query: '.language-prolog-query', // css selector for the html elements that contain prolog queries
    };
</script>
<script src="https://storage.googleapis.com/app.klipse.tech/plugin_prod/js/klipse_plugin.min.js?v=7.7.1-a"></script>

Common Lisp

<link rel="stylesheet" type="text/css" href="https://storage.googleapis.com/app.klipse.tech/css/codemirror.css">

<script>
    window.klipse_settings = {
        selector_eval_clisp: '.language-klipse-eval-clisp', // css selector for the html elements you want to klipsify
    };
</script>
<script src="https://storage.googleapis.com/app.klipse.tech/plugin_prod/js/klipse_plugin.min.js"></script>

OCaml

<link rel="stylesheet" type="text/css" href="https://storage.googleapis.com/app.klipse.tech/css/codemirror.css">

<script>
    window.klipse_settings = {
 	    selector_eval_ocaml: '.language-klipse-ocaml', // selector for ocaml evaluation snippets
	    selector_transpile_ocaml: '.language-transpile-ocaml' // selector for ocaml transpilation snippets
    };
</script>
<script src="https://storage.googleapis.com/app.klipse.tech/plugin_prod/js/klipse_plugin.min.js"></script>

ReasonML version 3

Note: Code Snippets in Reason version 3 will automagically be upgraded to latest Reason version once a new version of Reason is released.

We have 4 kinds of ReasonML snippets:

  1. Code Evaluation
  2. Transpilation to JavaScript
  3. Transpilation to Ocaml
  4. Transpilation from Ocaml

Here is the JavaScript tag that you need to setup for embedding ReasonML snippets on your page:

<link rel="stylesheet" type="text/css" href="https://storage.googleapis.com/app.klipse.tech/css/codemirror.css">

<script>
    window.klipse_settings = {
 	     selector_transpile_reason_3: '.language-transpile-reason', // selector for reason transpilation snippets
         selector_transpile_reason_3_to_ocaml: '.language-transpile-reason-to-ocaml', // selector for reason transpilation into ocaml snippets
         selector_eval_reason_3: '.language-klipse-reason',  // selector for reason evaluation snippets
         selector_ocaml_to_reason: '.language-klipse-ocaml-to-reason' // selector for ocaml to reason snippets
   };
</script>
<script src="https://storage.googleapis.com/app.klipse.tech/plugin_prod/js/klipse_plugin.min.js"></script>

ReasonML - Old Syntax(deprecated)

<link rel="stylesheet" type="text/css" href="https://storage.googleapis.com/app.klipse.tech/css/codemirror.css">

<script>
    window.klipse_settings = {
    	 selector_transpile_reason: '.language-transpile-reason', // selector for reason transpilation snippets
         selector_transpile_reason_to_ocaml: '.language-transpile-reason-to-ocaml', // selector for reason transpilation into ocaml snippets
         selector_eval_reason: '.language-klipse-reason' // selector for reason evaluation snippets
   };
</script>
<script src="https://storage.googleapis.com/app.klipse.tech/plugin_prod/js/klipse_plugin.min.js"></script>

SQL

<link rel="stylesheet" type="text/css" href="https://storage.googleapis.com/app.klipse.tech/css/codemirror.css">
<link rel="stylesheet" type="text/css" href="https://storage.googleapis.com/app.klipse.tech/css/sql.css">

<script>
    window.klipse_settings = {
     selector_sql: '.sql',
    };
</script>
<script src="https://storage.googleapis.com/app.klipse.tech/plugin_prod/js/klipse_plugin.min.js"></script>

PHP

<link rel="stylesheet" type="text/css" href="https://storage.googleapis.com/app.klipse.tech/css/codemirror.css">

<script>
    window.klipse_settings = {
        selector_eval_php: '.language-klipse-eval-php', // css selector for the html elements you want to klipsify
    };
</script>
<script src="https://storage.googleapis.com/app.klipse.tech/plugin_prod/js/klipse_plugin.min.js"></script>

https

If your site runs under https, you need to load the klipse plugin from https://storage.googleapis.com/app.klipse.tech instead of http://app.klipse.tech.

The reason is that the klipse plugin is hosted on Google Cloud Storage and for the moment SSL is not supported for custom domains.

Configuration

The klipse plugin is configurable both at the level of the page and at the level of the snippet.

Page level configuration

Here are the settings for the klipse plugin a page level:

window.klipse_settings = {
     eval_idle_msec: 20, // idle time in msec before the snippet is evaluated
     selector: '.language-klipse', // selector for Clojure evaluation snippets
     selector_js: '.language-klipse-js', // selector for Clojure transpilation snippets
     selector_reagent: '.language-reagent', // selector for reagent snippets
     selector_google_charts: '.language-google-charts' // selector for Google charts snippets
     selector_oblivion: '.language-oblivion' // selector for oblivion snippets
     selector_eval_js: '.language-klipse-eval-js', // selector for JavaScript evaluation snippets
     selector_eval_ruby: '.language-klipse-eval-ruby', // selector for Ruby evaluation snippets
     selector_lua: '.language-klipse-lua', // selector for lua evaluation snippets
     selector_es2017: '.language-klipse-es2017', // selector for EcmaScript 2017 evaluation snippets
     selector_jsx: '.language-klipse-jsx', // selector for JSX evaluation snippets
     selector_transpile_jsx: '.language-transpile-jsx', // selector for JSX transpilation snippets
     selector_render_jsx: '.language-render-jsx', // selector for JSX rendering snippets
     selector_react: '.language-react', // selector for React snippets
     selector_eval_php: '.language-klipse-eval-php', // selector for PHP evaluation snippets
     selector_eval_markdown: '.language-klipse-markdown', // selector for Markdown transpilation snippets
     selector_render_hiccup: '.render-hiccup', // selector for Hiccup rendering snippets
     selector_transpile_hiccup: '.transpile-hiccup', // selector for Hiccup transpiling snippets
     selector_eval_lambdaway: '.language-klipse-lambdaway', // selector for lambdaway transpilation snippets
     selector_eval_python_client: '.language-klipse-python', // selector for Python evaluation snippets
     selector_eval_cpp: '.language-klipse-cpp', // selector for cpp evaluation
     selector_eval_html: '.language-klipse-html', // selector for Html evaluation snippets
     selector_sql: '.language-klipse-sql', // selector for sqlite evaluation snippets
     selector_eval_scheme: '.language-klipse-scheme', // selector for Scheme evaluation snippets
     selector_brainfuck: '.language-klipse-brainfuck', // selector for Brainfuck snippets
     selector_eval_ocaml: '.language-klipse-ocaml', // selector for Ocaml evaluation snippets
     selector_transpile_ocaml: '.language-transpile-ocaml', // selector for Ocaml transpilation snippets
     selector_transpile_reason_3: '.language-transpile-reason', // selector for Reason transpilation snippets
     selector_transpile_reason_3_to_ocaml: '.language-transpile-reason-to-ocaml', // selector for Reason transpilation into ocaml snippets
     selector_eval_reason_3: '.language-klipse-reason', // selector for Reason evaluation snippets
     selector_ocaml_to_reason: '.language-klipse-ocaml-to-reason' // selector for Ocaml to reason snippets
     cached_ns_root: '/my-root', // the root of Clojure cached namespace, default: https://viebel.github.io/cljs-analysis-cache/cache/
     clojure_cached_macro_ns_regexp: /reagent.*/, // the regexp for Clojure macro namespaces that are cached
     clojure_cached_ns_regexp: /reagent.*/, // the regexp for clojure namespaces that are cached
     codemirror_root: '/my-codemirror-root', // the root of Codemirror files
     scripts_root: '/my-scripts-root', // the root of scripts files (e.g pretty_format.js, opal.js ...)
     re_evaluate_all_snippets_on_change: false, // Whether all snippets should be reevaluated when any one snippet is edited, since snippets might depend on each other
     editor_type: 'code-mirror', //the type of the editor for Klipse results (the element where the evaluation of the snippet is displayed). Allowed values:
                                 // "code-mirror": The input editor is codemirror. The output editor is codemirror
                                 // "html": The input editor is codemirror. The output editor is html
                                 // "dom": The input editor is plain text. The output editor is plain text


};

Additionally, you can configure CodeMirror input (snippet source code) and output (snippet evaluation) by setting codemirror_options_in and codemirror_options_out:

Currently, we support all the settings CodeMirror Configuration settings and part of the Addons settings: matchBrackets and autoCloseBrackets.

For instance, you can modify the indentUnit, lineWrapping, lineNumbers and autoCloseBrackets like this:

window.klipse_settings = {
    codemirror_options_in: {
        indentUnit: 8,
        lineWrapping: true,
        lineNumbers: true,
        autoCloseBrackets: true
    },
    codemirror_options_out: {
        lineWrapping: true,
        lineNumbers: true
    }
}

Clojure only

  • print_length: (default 1000) max number of items in collections to display - useful to prevent browser stuck when evaluating infinite sequences like (range)
  • beautify_strings: (default false) when evaluation result is a string - display the "interior" of the string without escaping the quotes.

Snippet level configuration

The following attributes can be added to the DOM element of the snippet:

  • data-eval-idle-msec: (default 20) idle time in msec before the snippet is evaluated
  • data-loop-msec: (default undefined) the code is run in a loop every data-loop-msec msec
  • data-preamble: (default "") A string containing Clojurescript source code that should be run before the contents of this snippet, eg "(reset! canvas-id :canvas-2)". Useful for hiding implementation details from readers in blog posts, like e.g. setting a canvas-id atom to :canvas-2, or for performing any other setup operations that need to be done on a per-snippet basis
  • data-editor-type: (default "code-mirror") the type of the editor for the klipse result (the element where the evaluation of the snippet is displayed). Allowed values: ** "code-mirror": The input editor is codemirror. The output editor is codemirror ** "html": The input editor is codemirror. The output editor is html ** "dom": The input editor is plain text. The output editor is plain text

JavaScript only

  • data-external-libs: comma separated list of JavaScript libraries to load before snippet evaluation
  • data-async-code: (default false) when true, asynchronous calls to console.log append their result to the result cell

Clojure only

Here is a live demo of the different snippet level configuration options.

The following data attributes are supported on a klipse snippet DOM element:

  • data-static-fns: (default false) set to true for using static dispatch
  • data-external-libs: comma separated list of github repositories to resolve dependencies: you need to provide the full list of dependencies (including the dependencies of dependencies recursively). See for instance Lambda Calculus with clojure and Klipse
  • data-print-length: (default 1000) max number of items in collections to display - useful to prevent browser stuck when evaluating infinite sequences like (range)
  • data-beautify-strings: (default false) when evaluation result is a string - display the "interior" of the string without escaping the quotes.
  • data-verbose: (default false) passed to bootstrapped eval and compile :verbose opts
  • data-max-eval-duration: (default 1000) max number of milliseconds the snippet code is allowed to run synchronously before being interrupted.
  • data-compile-display-guard: (default false) when true, display the anti-starvation code inside result of compilation

Styling

The Klipse plugin can be easily styled with CSS, which can be applied both to the Klipse plugin's own elements, and to the CodeMirror editor's elements. Much of the styling you'll apply will be to CodeMirror, as it contains all the CSS classes to style the code itself. Surrounding CodeMirror is the Klipse plugin, the styles of which control the plugin's borders, and the executed code's output.

DOM elements

Each klipse snippet is associated with 4 HTML elements:

  1. The klipse snippet itself: it has the class klipse-snippet.
  2. The result: it has the class klipse-result.
  3. A container: it has the class klipse-container and is accessible inside the klipse snippet through the global variable klipse_container (the global variable is dynamically bound to the correct klipse container).
  4. A separator: it has the class klipse-separator.

Changing the style of CodeMirror

You can change the theme of the CodeMirror editor simply by modifying its CSS. If you don't want to create your own theme, Farhad Gayour has an awesome list of ready-made themes you can select from. Have a look at the different themes by selecting them from the drop-down. Once you've found one you like, head to the theme repo to copy the CSS, paste it into a CSS file, and link to it from the HTML page containing your Klipse plugin.

Changing the style of the Klipse plugin

To change the style of the Klipse plugin's borders and the console output, you'll need to add a few extra style rules to your CSS file. These are:

  • .CodeMirror - modify the plugin's borders and CodeMirror's containing div
  • .CodeMirror:last-child::before - modify the console's title (i.e. the bit that says Output:)
  • .CodeMirror:last-child - modify the console area (i.e. the area beneath Output:)

You can see an example of styling Klipse in demos/styling. And here is a live demo

Interactive slides with Klipse

You can build interactive slides by integrating Klipse with Reveal.js using this template for reveal.js and Klipse.

Klipse Community

Here are a couple of examples of blogs using the klipse plugin:

Ask us any question about the klipse plugin (integration, feature requests...) on Join the chat at https://gitter.im/viebel/klipse

Access the CodeMirror editors programmatically

Each code snippet is wrapped into a CodeMirror editor.

The CodeMirror editors are accessible via the JavaScript global variable: klipse_editors. This is an array that contains the CodeMirror editors wrapping the original code snippets. For instance, you can modify the content of the code snippet i by calling: klipse_editors[i].setValue('let a = 1');

Here is a jsfiddle that shows it in action.

The evaluation of each snippet is also wrapped into a CodeMirror editor. The CodeMirror editors that wrapped results are accessible via the JavaScript global variable: klipse_results. This is an array that contains the CodeMirror editors wrapping the results of the evaluation of the code snippets. For instance, you can read the content of the code snippet i by calling: klipse_results[i].getValue();

Here is a jsfiddle that shows it in action.

Use older versions

Since version 6.8.0, Klipse is published on npm. Therefore you can access the klipse files of a specific version from unpkg - a cdn for stuff that is published to npm.

For instance, The urls are for the version 6.8.0 are:

Host Klipse locally

You can download klipse with npm or bower.

In order to serve Klipse from your own server, you have to:

  1. Include in your page all the assets that you need from the dist folder: codemirror.css, klipse_plugin.js or klipse_plugin.min.js, javascript.inc.js (CodeMirror JavaScript addon), pretty_format.js (JavaScript beautifier)
  2. set klipse_settings.no_dynamic_scripts=true;

If you need more assets that are usually dynamically loaded by klipse, please download them manually.

Klipse App - Clojure Web Repl

Here is the information about the Klipse app

The Web REPL is live at http://app.klipse.tech

Here is the manual for the KLIPSE web repl.

Languages supported in the REPL: Clojure and ClojureScript.

License

If you like this stuff, please consider a (small donation) on Patreon.

See the LICENSE file for license rights and limitations (GNU General Public License v3.0).

klipse's People

Contributors

alanbernstein avatar alysbrooks avatar anmonteiro avatar benhalpern avatar bundance avatar burkeb avatar bzg avatar dijonkitchen avatar dupuchba avatar dvberkel avatar elyahou avatar ericnormand avatar flyjwayur avatar gitter-badger avatar jrheard avatar jsdelivrbot avatar jsoref avatar lechten avatar lucaskuhn avatar moxaj avatar olymk2 avatar polytypic avatar raphaelboukara avatar rodmoioliveira avatar settinghead avatar sobolevn avatar sroller avatar timothypratley avatar viebel avatar xrmx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

klipse's Issues

Missing: How it Works

hi,

I love this kind of tool. I wouldn't want to make websites that depend on services though. It's not clear by the project's description if it uses a backend of some sort. Does it? If so or not, I'd recommended pointing that out as it's a selling point if it's backend free.

Thanks,
Francois

Feature request: Support HTML as a language

It would be great to be able to show life HTML snippets :)

Example:

<pre><code class="klipse-html">
&lt;h1&gt;Hi&lt;/h1&gt;
</code></pre>

Should render:

<h1>Hi</h1>

Then if the user changes the box to Hello, it updates :)

eval/print primitives

Try the following values in klipse:

  • :foo
  • "foo"
  • 123

Neither of them seem to print a result.

data-external-libs could use an example in the README

The is currently a reference to a site that used data-external-libs, but by the time you inspect the html on that page, the div that had the data-external-libs="" has already been replaced by CodeMirror. It would be nice to have a simple example showing what the html element should look like.

<div class="klipse code-block" data-external-libs="https://raw.githubusercontent.com/diminishedprime/anagrams/master/src/">
    (ns your-namespace
    (:require [anagrams.core :as anagrams]))
</div>

Usable from reveal.js (and org-reveal) presentations ?

I think it would be great to have Klipse snippets in presentations. Reveal.js is a pretty popular way to make online presentations, and I use it from emacs org mode thanks to org-reveal that let me add raw HTML.

I tried some simple test but the result is unconvincing (watch out for httpS automatic redirect, one must use the http because of the reveal.js http source).

A way to embed Klipse in reveal.js presentations would be great !

Best Regards.

No error message when using undeclared variable

When evaluating (map inc 1234) I get the message 1234 is not ISeqable.
But when evaluating (str hello world) no error message is displayed in the cljs panel, Instead
;; Press Ctrl-Enter or wait for 3 sec to eval in clojure... is written.

oCaml support for klipse

With this issue I would like to gauge the interest to support oCaml in klipse.

BuckleScript is an excellent oCaml to JavaScript compiler, that also runs in the browser.

If there is interest, I am willing and hopefully able to provide a pull request integrating oCaml in klipse

Error when using & as a function name

I can define a function that is called &, but when I try to call it klipse gives an error.

(def & identity)

;; Evaling just this returns what I'd expect
& ;=> #object[Function "function (a){return a}"]

;; But calling it doesn't work

(& 42) ;=>
 #error {:message "Could not eval my.klipse",
         :data {:tag :cljs/analysis-error},
         :cause #error {:message "No method in multimethod 'cljs.analyzer/parse' for dispatch value: & at line 1 ",
         :data {:file nil, :line 1, :column 1, :tag :cljs/analysis-error},
         :cause #object[Error Error: No method in multimethod 'cljs.analyzer/parse' for dispatch value: &]}}

shorter urls for app.klipse.tech

Integrate klipse with reveal

reveal.js is a HTML presentation framework. Multiple persons have mentioned in interest in integrating klipse into reveal, notably @viebel, @titaniumbones and myself. There are probably others as well.

Integrating klipse into reveal is hard because of the way that reveal uses CSS. It is very opinionated and has liberal use of !important, which often does not play nice with other frameworks and libraries. See for example CSS conflict with reveal.js.

This issue is created to keep track of the progress of and interest in integrating klipse into reveal

Cursor rendering issue

Hey, awesome tool! I'm trying to use this for some online code documentation, but there seems to be an issue with how the cursor renders. I have reproduced this in latest Chrome, Safari, and Firefox, and then, thinking it may be an issue with my template, copied the demo from https://jsfiddle.net/viebel/50oLnykk/ and ran it locally and the same issues occur.

Not sure if this is a browser quirk or something with klipse, but hopefully you can help me narrow this down. For some reason, the demo seems to work just fine in the jsfiddle, but I can't figure out for the life of me what could possibly be different. Note that there are not any additional stylesheets at play, just purely the css recommended by klipse.

screen shot 2016-12-22 at 7 38 55 am

screen shot 2016-12-22 at 7 38 08 am

Here is the minimal code that reproduces this issue locally:

<!doctype html>
<html>
<body>
<div class="klipse">
 function foo(name) {
 return "Hello " + name;
 }
 foo("Klipse");
</div>
<link rel="stylesheet" type="text/css" href="https://storage.googleapis.com/app.klipse.tech/css/codemirror.css">
<script>
    window.klipse_settings = {
        selector_eval_js: '.klipse', // css selector for the html elements you want to klipsify
    };
</script>
<script src="https://storage.googleapis.com/app.klipse.tech/plugin_prod/js/klipse_plugin.min.js"></script>
</body>
</html>

Thank you for your help!

Credits

It would be nice to see credits for what libraries have been used, for instance, the replit library used for C++.

Newly opened articles scroll down

I couldn't come up with a better title. Sorry.

When opening a new article on the Klipse blog the site starts out scrolled to the top, but the more content gets loaded in, the more the page scrolls down. On the defprotocol article for instance, a fully loaded page ends up opened 85% through (see attached screenshot).
2016-04-10 at 3 02 pm
This happens on both Safari / OS X.10.3 and on the latest Firefox (same OS)

Minmum html to try klipse

I'm trying to use klipse for clojure. I save the following html locally and open with Chrome but the evaluation is not happening.

<html>
    <head>
        <meta charset="utf-8">
        <title>Foo</title>
        <link rel="stylesheet" type="text/css" href="http://app.klipse.tech/css/codemirror.css">

        <script>
            window.klipse_settings = {
                selector: '.language-klipse'// css selector for the html elements you want to klipsify
            };
        </script>
        <script src="http://app.klipse.tech/plugin/js/klipse_plugin.js"></script>
   </head>

   <body>
        <p>And now, we are going to <strong>klipsify</strong> this code snippet:</p>

        <pre><code class="language-klipse">(map inc [1 2 3])
        </code></pre>
    </body>
</html>

Is this supposed to work? Or am I missing anything?

I'm using Chrome 51.0.2704.103 (64-bit) on OSX and I can see the following logs in developer console. I don't see any errors.

KLIPSE version: 1.0.1
klipse_plugin.js:12959 register-mode:  eval-clojure selector
klipse_plugin.js:12959 register-mode:  transpile-clojurescript selector_js
klipse_plugin.js:12959 register-mode:  eval-ruby selector_eval_ruby
klipse_plugin.js:12959 register-mode:  eval-javascript selector_eval_js
klipse_plugin.js:12959 settings:  #js {:selector .language-klipse}
klipse_plugin.js:12959 (settings): [object Object]
klipse_plugin.js:12959 settings: {"selector" ".language-klipse"}
klipse_plugin.js:12959 (keys (clojure.core/deref selector->mode)): ("selector" "selector_js" "selector_eval_ruby" "selector_eval_js")
klipse_plugin.js:12959 (array-seq (js/document.querySelectorAll selector)): 
klipse_plugin.js:12959 klipsify-elements:  nil eval-clojure
klipse_plugin.js:12959 "Elapsed time: 0.055000 msecs"

attaching output (DOM fragments/ SVG) to current DOM from Klipse ?

I think that it would be awesome if it was possible for some Klipse snippets that return DOM fragments / SVG to have the result not displayed as text in a console output, but attached to the current DOM (the root could be a parameter ?).
It would allow to have interactive graphic code with Klipse, a nice thing imo.

Best Regards !

In the Javascript interpreter, 1/0 does not return Infinity

I used a very basic setup, and tested with Chrome:

<div class="klipse">
1/0
</div>
<link rel="stylesheet" type="text/css" href="http://app.klipse.tech/css/codemirror.css">
<script>
window.klipse_settings = {selector_eval_js: '.klipse'};
</script>
<script src="http://app.klipse.tech/plugin/js/klipse_plugin.min.js"></script>

Live evaluatino is not working on 2016/05/30/spec.html on chrome

Live evaluation is not working when I open http://blog.klipse.tech/clojure/2016/05/30/spec.html.

When evaluating the followings

(ns my.spec
  (:require [cljs.spec :as s]))
(ns my.spec
  (:require [cljs.spec :as s]))

I got the following error.

#error {:message "No such namespace: goog.object, could not locate goog/object.cljs, goog/object.cljc, or Closure namespace \"goog.object\"", :data {:tag :cljs/analysis-error}}

I'm getting the same error for all evaluations in the article. Live evaluation seems working on other articles: i.g. http://blog.klipse.tech/clojure/2016/06/07/klipse-plugin-tuto.html

I'm using Chrome 51.0.2704.103 on OSX 10.11.4 (15E65). The page works on Safari.

render HTML

How hard would it be to get klipse to render html?

Return strings like REPL

The typical behavior I expect from a REPL is to render string values as by pr or pr-str rather than print.

This is most obvious when using strings with escaped characters.

In a ClojureScript REPL:

cljs.user=> (str \" "Hello" \")
"\"Hello\""

From Klipse I see:

screen shot 2016-07-29 at 12 21 07 pm

hardcoded urls

Noticed that there are externally hosted libraries hardcoded into the dist/ plugin files. For example:

...sistentVector.EMPTY_NODE,["https://viebel.github.io/klipse/repo/js/pretty_format.js"],null),cljs.core.cst$kw$comment_DASH_str,"//"],null);
klipse.common.registry.register_mode("eval-...

I seem to be missing information on how to change those. Is there a build argument or something I can use? I don't want to depend on those external files, or even the responsibility to ensure a network connection for this code to run.

Great tool!

klipse freezes far too easily

When you're editing code it's good practice to keep it syntactically correct as much as possible.
Certain editors make it difficult; for example "Intellisense" is really dumb about this grabbing various keys and generally behaving like a headless chicken.

OTOH, various editors try to be helpful, inserting the closing structure automatically when you enter the start of a loop or condition. This doesn't always work very well either.

Currently, klipse is probably one of the least helpful I've come across. You basically have to force a syntax error at the top of the code to keep it from crashing and if you (for example) decrement the wrong variable within a loop you lose what you've typed.

The solution is simple in concept; the code should only run until the next keypress ... no more.

Would you be interested in publishing klipse to bower

First of all: I really love what you created. Great idea very well executed!

Unless I am mistaken, if you want to use klipse, you fetch it from http://app.klipse.tech/plugin_prod/js/. This means you always need a internet connection if you want to use it. Sometimes I do not want to rely on internet.

Obviously I could manually download klipse and store it locally and reference it from there. I would rather do this in an automated fashion. I personally would like to use bower for that.

Bower calls itself a package manager for the web. It allows to specify which dependencies your project has and fetch them with the bower command line interface.

Would you be interested in publishing your artifacts to bower?

To have a feel for what you get yourself into below your find a series of steps

  1. Keep the build artifacts in the repository.
  2. Create a bower.json describing the project and what to serve.
  3. Register klipse to bower. This needs to be done only once.
  4. Tag each new release.

I am willing and able to put in the work of creating bower.json in a pull-request.

On macs, eval on Cmd-Enter

It would be great if, on a mac, cmd-enter would work as well as ctrl-enter as the shortcut to reevaluate the snippet. cmd is more idiomatic on macs.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.