Skip to content

Commit

Permalink
Add a binary interface
Browse files Browse the repository at this point in the history
It reads markdown content from stdin and output only a section of it
  • Loading branch information
maboiteaspam committed Jul 16, 2015
1 parent 7c3fb33 commit aab6662
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
18 changes: 13 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
# markdown-extract

A module on top of [chjj/marked](https://github.com/chjj/marked) to extract a paragraph from your markdown.
A command line tool to extract a paragraph from a markdown content.

## Usage

```sh
cat README.md | md-extract <what>
```

## Installation
Run the following commands to download and install the application:

```sh
npm i markdown-extract --save
npm i markdown-extract -g
```

## Usage
## API

It also provide an api which provides more options than the binnary interface.

```js
var mdExtract = require('markdown-extract')

mdExtract ({type: /heading/, text: /Usage/, gnp: true}).join('\n')
```

See more in the [test suite](https://github.com/maboiteaspam/markdown-extract/blob/master/test/index.js) a
nd it s [markdown version](https://github.com/maboiteaspam/markdown-extract/blob/master/mocha.md).
See more in the [test suite](https://github.com/maboiteaspam/markdown-extract/blob/master/test/index.js)
and it s [markdown version](https://github.com/maboiteaspam/markdown-extract/blob/master/mocha.md).

## Documentation

Expand Down
16 changes: 16 additions & 0 deletions bin/md-extract.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env node

var byline = require('byline')
var mdExtract = require('../index.js')

var search = process.argv[2]

var display = false
byline(process.stdin).on('data', function (d){
if (display && !('' + d).match(/^[#]+/)) {
process.stdout.write(d + '\n')
}
if (('' + d).match(/^[#]+/)) {
display = !!('' + d).match(search)
}
})
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"scripts": {
"test": "mocha"
},
"bin": {},
"bin": {
"md-extract": "./bin/md-extract.js"
},
"keywords": [
"To",
"be",
Expand All @@ -22,7 +24,7 @@
"url": "https://github.com/maboiteaspam/markdown-extract/issues"
},
"dependencies": {
"commander": "^2.8.1",
"byline": "^4.2.1",
"marked": "^0.3.3",
"underscore": "^1.8.3"
},
Expand Down

0 comments on commit aab6662

Please sign in to comment.