https://github.com/jamen/markdown-to-code
https://github.com/jamen/markdown-to-code
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/jamen/markdown-to-code
- Owner: jamen
- License: mit
- Created: 2019-05-17T09:55:22.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2019-05-17T09:55:35.000Z (about 7 years ago)
- Last Synced: 2025-02-08T01:49:13.280Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# @jamen/markdown-to-code
A [literate programming][1] tool using markdown and codeblocks. It turns codeblocks into source code and the rest of the content into comments, allowing you to execute or analyze only the code.
## Install
```
npm i @jamen/markdown-to-code
```
Or quickly use command-line utility:
```sh
npx @jamen/markdown-to-code foo.md foo.js
```
## Usage
### `markdownCode(options?)`
Compiles an `input` stream with the given options, returns a readable stream.
```js
let compileMarkdown = markdownCode({
language: 'js',
mode: {
opener: '/**',
normal: ' * ',
closer: ' **/'
}
})
createReadStream('input.md')
.pipe(compileMarkdown)
.pipe(createWriteStream('output.js'))
```
### `markdown-to-code `
Command-line tool that compiles the input file to the output file. Uses stdio without files.
Use `--mode` or `-m` to set the commenting mode (see [lib/modes.json](lib/modes.json)).
To opt-in or opt-out of codeblocks turning into code, you use HTML comments above them containing the word "export". By default this is an opt-in behavior, but you can use the `--all` or `-a` flag to make it opt-out (everything is exported)
[1]: https://en.wikipedia.org/wiki/Literate_programming