A plugin for live coding CSS, HTML, SVG in Reveal.js.
You can try it here (slide 16): The Future of CSS (masks)
Just add the plugin as a dependency of Reveal:
Reveal.initialize({
dependencies: [
// others dependencies
// ...
// liveCoding plugin
{ src: 'plugin/live-coding/live-coding.js', async: true, condition: function() { return !!document.body.classList; }}
]
});
Reveal.js uses <pre>
and <code>
tags for code.
Follow these steps on the <code>
tag you want to use for live coding:
contenteditable
attribute (to make it editable).liveCoding
class..css
(if CSS) or .xml
(if HTML, SVG...) class (see below).data-livecoding-id
attribute: the value is the id
you want to target.Here is a full example:
<pre><code class="liveCoding css" data-livecoding-id="myElement" contenteditable>
.title{
color: red;
}
</code></pre>
<div id="myElement">
<p class="title">Hello</p>
</div>
In Reveal, by default, code is highlighted with highlight.js (by detecting the language) and a class is added (eg.
css, xml) on <code>
. This class is used by LiveCoding to update the code properly. BUT, if you disable highlight.js,
or use another highlighter, please use the HTML5 recommended syntax:
.language-*
class on the <code>
tag. (eg .language-css
, .language-markup
, ...)The value of the data-livecoding-id
attribute is an identifier that is the scope of the live-coding CSS. Thus, it is
possible to target all descendants of this identifier.
Associated styles are added in a <style>
tag, at the end of the <body>
.
The value of the data-livecoding-id
attribute is an identifier that is the parent of the live-coding code. The content
of this identifier is replaced by the code you write.