Last active
July 29, 2019 18:18
-
-
Save caasi/2c172bacb31f884709f1 to your computer and use it in GitHub Desktop.
literate livescript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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