Giter Site home page Giter Site logo

markdown-it-merge-cells's Introduction

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

// 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:

<table>
  <thead>
    <tr>
      <th colspan="2">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

markdown-it-merge-cells's People

Contributors

menci avatar undefined-moe avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

markdown-it-merge-cells's Issues

Render ordering issues

Is there a way to run my custom render function before this plugin's pass? Since there no option to selectively disable it and the "comments"-solution (#15) also doesn't work in my case.

Context

I'm using VitePress. I've written a custom rendering function using markdown-it-container which basically takes a table inside certain container and parses it to get 2d string array from the contents of its cells. Unfortunately my pass happens after the cells were merged, hence I'm receive distorted matrix.

I've tried reordering md.use calls: it had no difference.

I've also tried directly using md.renderer.rules.table_open to register my parser to eliminate possible interference from markdown-it-container, but I was still getting table after merging,

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.