Skip to content

xiupos/markdown-it-merge-cells

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

markdown-it-merge-cells

A markdown-it plugin to merge adjacent cells with same content.

Usage

// 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|6|
|^|^|^|^|7|
|^|4|3|>|5|
`)

The result is:

1 1 3 4 5
1 1 2 6
7
4 3 5

The rendered HTML is:

<table>
  <thead>
    <tr>
      <th>1</th>
      <th>1</th>
      <th>3</th>
      <th>4</th>
      <th>5</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td rowspan="3">1</td>
      <td rowspan="2">1</td>
      <td rowspan="2" colspan="2">2</td>
      <td>6</td>
    </tr>
    <tr>
      <td>7</td>
    </tr>
    <tr>
      <td>4</td>
      <td>3</td>
      <td colspan="2">5</td>
    </tr>
  </tbody>
</table>

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

About

A markdown-it plugin to merge adjacent cells

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%