https://github.com/menci/markdown-it-merge-cells
A markdown-it plugin to merge adjacent cells with same content in tables
https://github.com/menci/markdown-it-merge-cells
Last synced: about 1 year ago
JSON representation
A markdown-it plugin to merge adjacent cells with same content in tables
- Host: GitHub
- URL: https://github.com/menci/markdown-it-merge-cells
- Owner: Menci
- License: mit
- Created: 2019-03-22T17:09:03.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-10-27T00:28:21.000Z (over 2 years ago)
- Last Synced: 2025-04-21T19:38:05.039Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 202 KB
- Stars: 15
- Watchers: 2
- Forks: 20
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# markdown-it-merge-cells
A markdown-it plugin to merge adjacent cells with same content.
It will first merge cells with same content in every *column* and then merge cells with same content (and height, if ones are merged in first step) in every *row*. This is by design because usually a column is a field and a row is a record -- it's more reasonable that multi records have same value in a field than in a record multi fields' have same value.
# Usage
```js
// Node.js
let MarkdownIt = require('markdown-it'),
MarkdownItMergeCells = require('markdown-it-merge-cells'),
md = new MarkdownIt();
md.use(MarkdownItMergeCells);
// Browser (use dist/bundle.min.js)
let md = new window.markdownit();
md.use(window.markdownitMergeCells);
let result = md.render(`
|1|1|3|4|5|
|-|-|-|-|-|
|1|1|2|2|6|
|1|1|2|2|7|
|1|4|3|5|5|
`)
```
The result is:
1
3
4
5
1
1
2
6
7
4
3
5
The rendered HTML is:
```html
1
3
4
5
1
1
2
6
7
4
3
5
```
# Notice
It's done by wrap markdown-it's table parser and modify the generated tokens (which will be rendered to HTML). If in later versions markdown-it change the tokens' generated by table parser, this plugin may not able to work anymore.
File a issue if you find this plugin can't work with latest version of markdown-it.
# License
[MIT](LICENSE)