3.0.2 • Published 5 years ago

gulp-markdown-table-to-json v3.0.2

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

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

nameagegrade
John113
Bob134

Girls Table

nameagegrade
Petra158
Olivia147

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:([^ -]+) *-->/.

3.0.2

5 years ago

3.0.1

5 years ago

2.0.7

5 years ago

2.0.6

5 years ago

2.0.5

5 years ago

1.2.7

5 years ago

1.1.6

5 years ago

1.0.5

9 years ago

1.0.4

9 years ago

1.0.3

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago