# md-code-stream

> Collect code blocks from Markdown streams

Latest version **0.1.0** (published 2014-07-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install md-code-stream
pnpm add md-code-stream
yarn add md-code-stream
bun add md-code-stream
```

Provides the command `markdown_code`.

## 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.1.0 |
| Published | 2014-07-11 |
| First published | 2014-05-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 (+3 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 2 |
| Maintainers | jpommerening |
| Keywords | markdown, md, code, stream |

## Links

- npm: https://www.npmjs.com/package/md-code-stream
- Repository: https://github.com/jpommerening/node-md-code-stream
- Issues: https://github.com/jpommerening/node-md-code-stream/issues
- npm.io page: https://npm.io/package/md-code-stream

## Dependencies (3)

- [marked](https://npm.io/package/marked.md) ~0.3.2
- [inherits](https://npm.io/package/inherits.md) ~2.0.1
- [readable-stream](https://npm.io/package/readable-stream.md) ~1.1.13

## Alternatives

- [@mdxeditor/editor](https://npm.io/package/@mdxeditor/editor.md) — 962.4K weekly downloads
- [mmdb-lib](https://npm.io/package/mmdb-lib.md) — 680.9K weekly downloads
- [playcanvas](https://npm.io/package/playcanvas.md) — 36.2K weekly downloads
- [@glw907/cairn-cms](https://npm.io/package/@glw907/cairn-cms.md) — 967 weekly downloads
- [markdown-to-confluence](https://npm.io/package/markdown-to-confluence.md) — 103 weekly downloads

## Recent versions

- 0.1.0 (latest) — 2014-07-11
- 0.1.0-rc3 — 2014-05-23
- 0.1.0-rc2 — 2014-05-23
- 0.1.0-rc1 — 2014-05-23

## README

# md-code-stream

> Extract code blocks from Markdown streams, so you can test them

## Examples

In this example, we parse *this* `README.md` file and extract the first code
block:

```js
var fs = require('fs');
var assert = require('assert');

var mdCodeStream = require('md-code-stream');

var readme = fs.createReadStream('README.md')
               .pipe(mdCodeStream());

readme.once('entry', function(entry) {
  assert.equal(entry.section[0], 'md-code-stream');
  assert.equal(entry.section[1], 'Examples');
  assert.equal(entry.num, 0);
  assert.equal(entry.language, 'js');
  assert.equal(entry.props.path, 'md-code-stream/examples.js');

  // At this point we could also pipe it to stdout:
  // entry.pipe(process.stdout);
});
```

When given a filename as the first argument, the file will be opened
and piped into the stream. The stream also collects all it's entries in
the `entries` property:

```js
var assert = require('assert');
var mdCodeStream = require('md-code-stream');
var readme = mdCodeStream('README.md');

readme.on('end', function() {
  assert.equal(readme.entries.length, 3);
});
```

The stream is compatible with [`fstream`](https://npmjs.org/package/fstream),
so you can pipe it to a directory:

```js
var fs = require('fs');
var fstream = require('fstream');
var assert = require('assert');

var mdCodeStream = require('md-code-stream');

fs.createReadStream('README.md')
  .pipe(mdCodeStream())
  .pipe(fstream.Writer({path: 'tmp', type: 'Directory'}))
  .on('close', function() {
    assert(fs.existsSync('tmp/md-code-stream/examples.js'));
    assert(fs.existsSync('tmp/md-code-stream/examples-1.js'));
    assert(fs.existsSync('tmp/md-code-stream/examples-2.js'));
  });
```

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