1.0.0 • Published 6 years ago

markdown-to-code v1.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

markdown-to-code

Install

npm install markdown-to-code

Usage

//import { mdToCode } from 'markdown-to-code';
//import fs from 'fs';
const { mdToCode } = require('markdown-to-code');
const fs = require('fs');

mdToCode({
    //The markdown file name
    filename:'test.md',
    //Filter by type
    type: 'javascript',
    //map is optional, gets each block of code,
    //and must return a string if you set it
    map(code){
        return code;
    }
})
//Write to a file
.write('out.js')
.then(({code, filename})=>{
    //Prove the new code file exists
    console.log(fs.readFileSync(filename, 'utf8'));
})
.catch(err=>console.log(err));

A markdown file like this:

Title
===

```javascript
let me = 'exist';
```

```javascript

let that = me;
```

Will be turned into this:

let me = 'exist';

let that = me;

About

markdown-to-code gets code from github style code blocks in markdown, and writes that code to a file.