https://github.com/jverneaut/markdown-table-loader
Given a markdown source representing a table, returns an array containing said table data.
https://github.com/jverneaut/markdown-table-loader
Last synced: 2 months ago
JSON representation
Given a markdown source representing a table, returns an array containing said table data.
- Host: GitHub
- URL: https://github.com/jverneaut/markdown-table-loader
- Owner: jverneaut
- Created: 2020-08-25T12:02:33.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-09-24T11:09:11.000Z (over 4 years ago)
- Last Synced: 2025-03-12T01:01:44.305Z (3 months ago)
- Language: JavaScript
- Homepage: https://github.com/jverneaut/markdown-table-loader
- Size: 216 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# markdown-table-loader
Given a markdown source representing a table, returns an array containing said table data.
## Setup
```bash
npm install markdown-table-loader
``````javascript
// webpack.config.js
module.exports = {
// ...
module: {
rules: [
{
test: /\.table\.md$/,
use: 'markdown-table-loader',
},
],
},
// ...
};
``````markdown
| foo | bar |
| --- | --- |
| baz | bim |
``````javascript
// index.js
import table from './data.table.md';console.log(table);
// [
// {
// foo: 'baz',
// bar: 'bim',
// },
// ]
```## Examples
Implementing specifications from [github.com Tables](https://github.github.com/gfm/#tables-extension-).
```javascript
// test/fixtures/tables.md.js
const table1 = {
value: `
| foo | bar |
| --- | --- |
| baz | bim |
`,
expected: [
{
foo: 'baz',
bar: 'bim',
},
],
};const table2 = {
value: `
| abc | defghi |
:-: | -----------:
bar | baz
`,
expected: [
{
abc: 'bar',
defghi: 'baz',
},
],
};const table3 = {
value: `
| f|oo |
| ------ |
| b|az |
| b|im |
`,
expected: [
{
'f|oo': 'b|az',
},
{
'f|oo': 'b|im',
},
],
};const table4 = {
value: `
| abc | def |
| --- | --- |
| bar | baz |
> bar
`,
expected: [
{
abc: 'bar',
def: 'baz',
},
],
};const table5 = {
value: `
| abc | def |
| --- | --- |
| bar | baz |
barbar
`,
expected: [
{
abc: 'bar',
def: 'baz',
},
{
abc: 'bar',
def: null,
},
],
};const table6 = {
value: `
| abc | def |
| --- |
| bar |
`,
expected: [],
};const table7 = {
value: `
| abc | def |
| --- | --- |
| bar |
| bar | baz | boo |
`,
expected: [
{
abc: 'bar',
def: null,
},
{
abc: 'bar',
def: 'baz',
},
],
};
```