nw-playground
Usage
Quick experiments with NW.js :
document;
This will turn all code that looks like this :
console.log('hello');
Into this :
console.log('hello'); Run
User will be able to edit the content of the <pre>
tag.
Clicking the Run
button will create a <script>
tag containing the code currently inside the <pre>
tag nested inside a closure, and append it at the end of the <body>
:
<!-- ... -->
Clicking again will remove previous <script>
tag before creating a new one
(this will not stop the code !).
Advanced usage
Convert custom elements
document;
Callback
You can pass a callback that will be called after a playground has been created :
// here the callback is called after the given element has been turned into a// playgrounddocument; // here the callback is called once for each converted elementdocument;
The element
argument is the original element that has been converted (class nw-playground-editor
) and container
is the top level wrapper element of the corresponding playground (class nw-playground
).
You can use this to customize the generated HTML to suit your needs.
Syntax highlighting with Highlight.js
You can pass the main Highlight.js object to color the code inside the playgrounds :
<!-- ... --> <!-- load Highlight.js --> <!-- ... -->
Code inside each playground will be highlighted on load and when the element looses focus.
Reference
init(document[, hljs])
var init = ;;
document
: the DOM document (required)hljs
: main Highlight.js object (optional)
convertAll([callback])
Convert all pre
tags to a playground.
callback
: function called once for each element that has been converted. Receives following parameters :element
: the original element that has been converted (classnw-playground-editor
)container
: the top level wrapper element of the corresponding playground (classnw-playground
)
convertOne(element[, callback])
Convert given element to a playground.
callback
: function called after the element has been converted. Receives following parameters :element
: the original element that has been converted (classnw-playground-editor
)container
: the top level wrapper element of the corresponding playground (classnw-playground
)
License
The MIT License (MIT) - Copyright (c) 2015 Alexandre Bintz alexandre@bintz.io
See LICENSE file for full text.