# markdown-code-blocks

> Extract fenced code blocks from Markdown streams

Latest version **0.0.1** (published 2013-12-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install markdown-code-blocks
pnpm add markdown-code-blocks
yarn add markdown-code-blocks
bun add markdown-code-blocks
```

Provides the command `markdown-code-blocks`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2013-12-24 |
| First published | 2013-12-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Stephen Sugden |
| Maintainers | grncdr |
| Keywords | markdown, code-block, code |

## Links

- npm: https://www.npmjs.com/package/markdown-code-blocks
- Repository: https://github.com/substack/markdown-code-blocks
- Issues: https://github.com/substack/markdown-code-blocks/issues
- npm.io page: https://npm.io/package/markdown-code-blocks

## Dependencies (4)

- [split](https://npm.io/package/split.md) ~0.2.10
- [arrayify](https://npm.io/package/arrayify.md) ~1.0.0
- [duplexer](https://npm.io/package/duplexer.md) ~0.1.1
- [through2](https://npm.io/package/through2.md) ~0.2.3

## Alternatives

- [flatbuffers](https://npm.io/package/flatbuffers.md) — 6.0M weekly downloads
- [jwt-simple](https://npm.io/package/jwt-simple.md) — 259.5K weekly downloads
- [@exodus/patch-broken-hermes-typed-arrays](https://npm.io/package/@exodus/patch-broken-hermes-typed-arrays.md) — 28.5K weekly downloads
- [@native-to-anchor/buffer-layout](https://npm.io/package/@native-to-anchor/buffer-layout.md) — 12.2K weekly downloads
- [binary-parser-encoder](https://npm.io/package/binary-parser-encoder.md) — 5.3K weekly downloads

## Recent versions

- 0.0.1 (latest) — 2013-12-24
- 0.0.0 — 2013-12-24

## README

# markdown-code-blocks

A through stream that extracts code from Markdown content, optionally selecting
only code blocks of a selected type.

Currently this only works with GFM-style fenced code blocks, I don't have a need
for indentation based blocks (yet). This README file makes a nice example:

```
$ markdown-code-blocks -t javascript < ./README.md
```

Will output:

```javascript
var fs = require('fs')
var assert = require('assert')
var concat = require('concat-stream')
var markdownCodeBlocks = require('./')

var readme = fs.createReadStream(__dirname + '/README.md', 'utf8')

readme.pipe(markdownCodeBlocks('javascript')).pipe(concat(function (code) {
  // Writing code that asserts it's own contents is kind of tricky...
  assert.deepEqual(code.toString().split('\n').slice(0, 10), [
    "var fs = require('fs')",
    "var assert = require('assert')",
    "var concat = require('concat-stream')",
    "var markdownCodeBlocks = require('./')",
    "",
    "var readme = fs.createReadStream(__dirname + '/README.md', 'utf8')",
    "",
    "readme.pipe(markdownCodeBlocks('javascript')).pipe(concat(function (code) {",
    "  // Writing code that asserts it's own contents is kind of tricky...",
    "  assert.deepEqual(code.toString().split('\\n').slice(0, 10), ["
  ])
}))
```

Which you can pipe into `node` to verify that this module is working:

```
$ markdown-code-blocks -t javascript < README.md | node
```

## API

```ocaml
module.exports = (types: String|Array<String>) => Transform<String, String>
```

## License

MIT

---
_Source: https://npm.io/package/markdown-code-blocks · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
