1
0
Fork 0
Plugin for Markdown-it to use non-GFM table. https://www.npmjs.com/package/@sup39/markdown-it-raw-table
This repository has been archived on 2024-02-06. You can view files and clone it, but cannot push or open issues or pull requests.
Find a file
2021-01-13 01:12:03 +09:00
lib init: implement lib, test 2021-01-10 16:52:37 +09:00
test init: implement lib, test 2021-01-10 16:52:37 +09:00
.eslintrc.js init: implement lib, test 2021-01-10 16:52:37 +09:00
.gitignore init: implement lib, test 2021-01-10 16:52:37 +09:00
LICENSE init: implement lib, test 2021-01-10 16:52:37 +09:00
package.json add files field to package.json 2021-01-13 01:12:03 +09:00
README.md fix README.md 2021-01-10 17:09:23 +09:00
yarn.lock init: implement lib, test 2021-01-10 16:52:37 +09:00

markdown-it-raw-table

Usage

const md = require('markdown-it')();
const mrt = require('@sup39/markdown-it-raw-table');
md.use(mrt);

md.render(`
| abc | def |
| --- | --- |
| bar |
| bar | baz | boo |
`);

Feature

td count is NOT adjusted to th count when using this plugin.

For example,

| abc | def |
| --- | --- |
| bar |
| bar | baz | boo |

is rendered as

abc def
bar
bar baz boo
<table>
  <thead>
    <tr>
      <th>abc</th>
      <th>def</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>bar</td>
    </tr>
    <tr>
      <td>bar</td>
      <td>baz</td>
      <td>boo</td>
    </tr>
  </tbody>
</table>

instead of

abc def
bar
bar baz

Advantage of this version

This version works well with markdown-it-attrs plugin.

rowspan and colspan

This version works well with rowspan and colspan because it does not append extraneous td.

For example,

| h1 | h2 | h3 | h4 |
| --- | --- | --- | --- |
| x11 | x12 | x13 {rowspan=2} | x14 |
| x21 {colspan=2} | x24 |

is rendered as

h1 h2 h3 h4
x11 x12 x13 x14
x21 x24
<table>
  <thead>
    <tr>
      <th>h1</th>
      <th>h2</th>
      <th>h3</th>
      <th>h4</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>x11</td>
      <td>x12</td>
      <td rowspan="2">x13</td>
      <td>x14</td>
    </tr>
    <tr>
      <td colspan="2">x21</td>
      <td>x24</td>
    </tr>
  </tbody>
</table>

which is intended,

instead of

h1 h2 h3 h4
x11 x12 x13 x14
x21 x24
<table>
  <thead>
    <tr>
      <th>h1</th>
      <th>h2</th>
      <th>h3</th>
      <th>h4</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>x11</td>
      <td>x12</td>
      <td rowspan="2">x13</td>
      <td>x14</td>
    </tr>
    <tr>
      <td colspan="2">x21</td>
      <td>x24</td>
      <td></td>
      <td></td>
    </tr>
  </tbody>
</table>

which produces extraneous td because it tries to make th count (=4) equal to td count in the second tr in tbody.

markdown-it-attrs for tr

This version prevents extra tokens like {.class} being eliminating, which makes markdown-it-attrs for tr possible.

For example,

| h1 | h2 |
| -- | -- |
| x1 {.c3} | x2 | {.c1}
| x3 | x4 {.c4} | {.c2}

is rendered as

<table>
  <thead>
    <tr>
      <th>h1</th>
      <th>h2</th>
    </tr>
  </thead>
  <tbody>
    <tr class="c1">
      <td class="c3">x1</td>
      <td>x2</td>
    </tr>
    <tr class="c2">
      <td>x3</td>
      <td class="c4">x4</td>
    </tr>
  </tbody>
</table>