gulp-markdown-table-to-json

3.0.2 • Public • Published

gulp-markdown-table-to-json

NPM version

A github-style-markdown table parse plugin for gulp 3/4

Special thanks to noraj

Usage

First, install gulp-markdown-table-to-json as a development dependency:

npm install --save-dev gulp-markdown-table-to-json

Then, add it to your gulpfile.js:

Write Some Tables in Markdown File

Boys Table

name age grade
John 11 3
Bob 13 4

Girls Table

name age grade
Petra 15 8
Olivia 14 7

source code

### Boys Table
<!-- table2json:boys -->
name | age| grade 
-----|----|-----
John|11|3
Bob|13|4
 
### Girls Table
<!-- table2json:girls -->
name | age| grade | 
-----|----|-----
Petra|15|8
Olivia|14|7

Get Json

Gulp 3:

const md2json = require('gulp-markdown-table-to-json');
 
gulp.task('md2json', function(){
  gulp.src('README.md')
    .pipe(md2json())
    .pipe(gulp.dest('.'));
});

Gulp 4:

const { src, dest, task} = require('gulp');
const md2json = require('gulp-markdown-table-to-json');
 
task(m2j);
m2j.description = 'Markdown table to JSON';
function m2j() {
  return src('index.md')
    .pipe(md2json())
    .pipe(dest('.'));
};

Then you will get a json file named README.json with the following content:

{"boys":[{"name":"John","age":"11","grade":"3"},{"name":"Bob","age":"13","grade":"4"}],"girls":[{"name":"Petra","age":"15","grade":"8"},{"name":"Olivia","age":"14","grade":"7"}]}

You can also use "gulp-beautify" to beautify it:

{
    "boys": [{
        "name": "John",
        "age": "11",
        "grade": "3"
    }, {
        "name": "Bob",
        "age": "13",
        "grade": "4"
    }],
    "girls": [{
        "name": "Petra",
        "age": "15",
        "grade": "8"
    }, {
        "name": "Olivia",
        "age": "14",
        "grade": "7"
    }]
}

API

md2json(tableMarker)

tableMarker

Type: RegExp

The RegExp to search for table title. Default is /<!-- *table2json:([^ -]+) *-->/.

Package Sidebar

Install

npm i gulp-markdown-table-to-json

Weekly Downloads

3

Version

3.0.2

License

MIT

Unpacked Size

7.49 kB

Total Files

6

Last publish

Collaborators

  • blackmiaool