# extract-gfm

> Utilities for extracting and replacing GitHub Flavored Markdown code blocks. For example, you could easily find code blocks for a specific language and run the code through a linter.

Latest version **0.1.0** (published 2014-09-24) · 0 weekly downloads

## Install

```sh
npm install extract-gfm
pnpm add extract-gfm
yarn add extract-gfm
bun add extract-gfm
```

## 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-09-24 |
| First published | 2014-09-24 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.10.0 |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | Jon Schlinkert |
| Maintainers | jonschlinkert |
| Keywords | docs, documentation, generate, generator, markdown, templates, verb |

## Links

- npm: https://www.npmjs.com/package/extract-gfm
- Repository: https://github.com/jonschlinkert/extract-gfm
- Issues: https://github.com/jonschlinkert/extract-gfm/issues
- npm.io page: https://npm.io/package/extract-gfm

## Dependencies (2)

- [gfm-code-blocks](https://npm.io/package/gfm-code-blocks.md) ^0.2.0
- [gfm-code-block-regex](https://npm.io/package/gfm-code-block-regex.md) ^0.2.1

## Alternatives

- [@cantoo/pdf-lib](https://npm.io/package/@cantoo/pdf-lib.md) — 297.9K weekly downloads
- [datatables.net-buttons](https://npm.io/package/datatables.net-buttons.md) — 200.1K weekly downloads
- [@ckeditor/ckeditor5-export-pdf](https://npm.io/package/@ckeditor/ckeditor5-export-pdf.md) — 167.0K weekly downloads
- [scanbot-web-sdk](https://npm.io/package/scanbot-web-sdk.md) — 15.0K weekly downloads
- [@syncfusion/ej2-angular-pdfviewer](https://npm.io/package/@syncfusion/ej2-angular-pdfviewer.md) — 8.8K weekly downloads

## Recent versions

- 0.1.0 (latest) — 2014-09-24

## README

# extract-gfm [![NPM version](https://badge.fury.io/js/extract-gfm.svg)](http://badge.fury.io/js/extract-gfm)


> Utilities for extracting and replacing GitHub Flavored Markdown code blocks. For example, you could easily find code blocks for a specific language and run the code through a linter.

See the [example](./example.js) for ideas.

## Install
#### Install with [npm](npmjs.org):

```bash
npm i extract-gfm --save-dev
```

## Run tests

```bash
npm test
```

## Usage

```js
var extract = require('extract-gfm');
extract.parseBlocks('abc\n```js\nvar foo = "bar";\n```\nxyz');
```
**Returns:**

```js
{ text: 'abc\n__CODE_BLOCK0__\nxyz',
  blocks:
   [ { lang: 'js',
       code: 'var foo = "bar";',
       block: '```js\nvar foo = "bar";\n```' } ],
  markers: [ '__CODE_BLOCK0__' ] }
```

## API
### [.stripBlocks](index.js#L24)

* `str` **{String}**: Original string with gfm code blocks.    
* `returns`: {String}  

Strip code blocks from a string and replaced them with
heuristic markers.

### [.extractBlocks](index.js#L41)

* `str` **{String}**: The string to parse.    
* `returns`: {Array}  

Return an array of all **gfm code blocks** found.
See [gfm-code-blocks] for more detail.

### [.parseBlocks](index.js#L70)

Convenience method to make it easy to replace code blocks.

* `str` **{String}**: The string to parse.    
* `returns`: {Object}  

Returns an object with:

   - `text`: the string stripped of code blocks, where each block
     is replaced with a heuristic marker.
   - `blocks`: An array of code blocks, using the [.extractBlocks()](#extractBlocks) method.
   - `markers`: An array of heuristic markers to be used for adding code blocks back.

**Example**

```js
var code = require('extract-gfm');
var fs = require('fs');
var str = fs.readFileSync('README.md', 'utf8');
console.log(code.parseBlocks(str));
```

### [.injectBlocks](index.js#L93)

Used for adding code blocks back into the string after they have been modified somehow.

* `str` **{String}**: A string with heuristic markers to replace.    
* `object` **{String}**: Object created by [.parseBlocks()](#parseBlocks)    
* `returns` **{String}**: Updated string, with shiny new code blocks.  

To customize how this is done, just look at the `injectBlocks`
method and create your own based on this. [.parseBlocks()](#parseBlocks)
really does all of the hard work.

## Author

**Jon Schlinkert**
 
+ [github/jonschlinkert](https://github.com/jonschlinkert)
+ [twitter/jonschlinkert](http://twitter.com/jonschlinkert) 

## License
Copyright (c) 2014 Jon Schlinkert, contributors.  
Released under the MIT license

***

_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on September 23, 2014._

[gfm-code-blocks]: https://github.com/jonschlinkert/gfm-code-blocks

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