3. Semi-literate programming
Here we explain the simplest use of litpro: elevating comments to readable paragraphs.
The idea here is quite simple. Write paragraphs for comments. Then use either indented blocks or code fences to write code blocks.
Here is a simple example:
# Saying Hi
We want to write a little javascript command that says hi, waits one second,
and then says bye. We will save it in [teens.js](# "save:")
Greetings are great, right?
console.log("hi");
Timer is in milliseconds, so 1000. We'll call the function `bye` defined
elsewhere
setTimeout(bye, 1000);
And now let's define the bye function. For no apparent reason, we use a named
fence block. Hey, maybe we'll get some syntax highlighting!
```js
function bye () {
console.log("bye");
}
```
Hey, we're all done!
With that text saved in a file, we can run litpro on it and it should produce
the file teens.js consisting of
console.log("hi");
setTimeout(bye, 1000);
function bye () {
console.log("bye");
}
This uses the save directive which is, at its simplest, [filename](# "save:")
where filename is where to save the file. The hash symbol says to use the current section; we’ll see later how to reference other sections.