Skip to content

Instantly share code, notes, and snippets.

@caasi
Last active July 29, 2019 18:18
Show Gist options
  • Save caasi/2c172bacb31f884709f1 to your computer and use it in GitHub Desktop.
Save caasi/2c172bacb31f884709f1 to your computer and use it in GitHub Desktop.
literate livescript
# Literate LiveScript
This is an example for literate livescript. Although I can just wrap comments in
`/**/`, I think a markdown is more beautiful.
request = require 'superagent'
triple-ip = ->
{ body: { origin: a } } <- request.get 'http://httpbin.org/ip'
{ body: { origin: b } } <- request.get 'http://httpbin.org/ip'
{ body: { origin: c } } <- request.get 'http://httpbin.org/ip'
console.log "#a, #b, #c"
Inline code will not be executed `console.log "hello"`.
```livescript
triple-ip!
```
Have fun.
#!/usr/bin/env lsc
require! {
'fs'
'markdown-to-ast'
'prelude-ls': { concat-map, filter, id, join }
'livescript': LiveScript
}
[,, ...files] = process.argv
const extract = ({ type, children = [], value = '' }) ->
result = children |> concat-map extract |> filter id |> join "\n"
switch
| type is 'CodeBlock' => value + result
| otherwise => result
for filepath in files
err, data <- fs.readFile filepath, encoding: \utf-8
LiveScript.run extract markdown-to-ast.parse data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment