fix(remark-extend): support importing of tables
This commit is contained in:
parent
921545081c
commit
bffd6db9df
5 changed files with 52 additions and 0 deletions
5
.changeset/strong-icons-argue.md
Normal file
5
.changeset/strong-icons-argue.md
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'remark-extend': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Support GitHub Flavored Markdown (gfm) tables when importing markdown
|
||||||
|
|
@ -25,6 +25,7 @@
|
||||||
"test:watch": "mocha test-node --watch"
|
"test:watch": "mocha test-node --watch"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"remark-gfm": "^1.0.0",
|
||||||
"remark-parse": "^9.0.0",
|
"remark-parse": "^9.0.0",
|
||||||
"unified": "^9.2.0",
|
"unified": "^9.2.0",
|
||||||
"unist-util-is": "^4.0.2",
|
"unist-util-is": "^4.0.2",
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ const visit = require('unist-util-visit');
|
||||||
const { select } = require('unist-util-select');
|
const { select } = require('unist-util-select');
|
||||||
const unified = require('unified');
|
const unified = require('unified');
|
||||||
const markdown = require('remark-parse');
|
const markdown = require('remark-parse');
|
||||||
|
const gfm = require('remark-gfm');
|
||||||
const is = require('unist-util-is');
|
const is = require('unist-util-is');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
@ -172,6 +173,7 @@ function remarkExtend({ rootDir = process.cwd(), page } = {}) {
|
||||||
toInsertNodes = [];
|
toInsertNodes = [];
|
||||||
const parser = unified()
|
const parser = unified()
|
||||||
.use(markdown)
|
.use(markdown)
|
||||||
|
.use(gfm)
|
||||||
.use(handleImportedFile, {
|
.use(handleImportedFile, {
|
||||||
startSelector,
|
startSelector,
|
||||||
endSelector,
|
endSelector,
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
## Currencies
|
||||||
|
|
||||||
|
| Sign | Name |
|
||||||
|
| ---- | ------ |
|
||||||
|
| $ | Dollar |
|
||||||
|
| € | Euro |
|
||||||
|
|
@ -329,4 +329,42 @@ describe('remarkExtend', () => {
|
||||||
].join('\n'),
|
].join('\n'),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('can import files with a table', async () => {
|
||||||
|
const result = await execute(
|
||||||
|
[
|
||||||
|
//
|
||||||
|
'### Static Headline',
|
||||||
|
"```js ::importBlock('./fixtures/import-table.md', '## Currencies')",
|
||||||
|
'```',
|
||||||
|
].join('\n'),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(result).to.equal(
|
||||||
|
[
|
||||||
|
//
|
||||||
|
'<h3>Static Headline</h3>',
|
||||||
|
'<h2>Currencies</h2>',
|
||||||
|
'<table>',
|
||||||
|
'<thead>',
|
||||||
|
'<tr>',
|
||||||
|
'<th>Sign</th>',
|
||||||
|
'<th>Name</th>',
|
||||||
|
'</tr>',
|
||||||
|
'</thead>',
|
||||||
|
'<tbody>',
|
||||||
|
'<tr>',
|
||||||
|
'<td>$</td>',
|
||||||
|
'<td>Dollar</td>',
|
||||||
|
'</tr>',
|
||||||
|
'<tr>',
|
||||||
|
'<td>€</td>',
|
||||||
|
'<td>Euro</td>',
|
||||||
|
'</tr>',
|
||||||
|
'</tbody>',
|
||||||
|
'</table>',
|
||||||
|
'',
|
||||||
|
].join('\n'),
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue