Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Headless tables break extension #161

Open
arjangeertsema opened this issue Dec 18, 2024 · 9 comments · May be fixed by #162
Open

Headless tables break extension #161

arjangeertsema opened this issue Dec 18, 2024 · 9 comments · May be fixed by #162

Comments

@arjangeertsema
Copy link

With this version the code breaks when headless tables are used:

cannot read properties of null (reading 'colsnum') in patterns.js line 175:

const calc = tokens[idx].meta.colsnum >> 0;

proposed fix:

Add null check.

const calc = tokens[idx].meta?.colsnum >> 0;

Markdown-it versions: 4.3.0

Example input:

| - | - |
| a | b |
| c | d |

Current output:

cannot read properties of null (reading 'colsnum') in patterns.js line 175:

Expected output:

<tbody>
<tr>
<td>a</td>
<td>b</td>
</tr>
<tr>
<td>c</td>
<td>d</td>
</tr>
</tbody>
@arjangeertsema arjangeertsema linked a pull request Dec 18, 2024 that will close this issue
@TheNorthMemory
Copy link
Contributor

The headerless tables feature looks like from markdown-it-multimd-table package, isn't it? This case wasn't tests covered. Anothers, multiple thead and multiple tbody may also have troubles.

@yiiman-dev
Copy link

this is very useful contribute
we have this problem too, and this library used as dependency on some other packages.
please accept this PR.
@arve0

@arve0
Copy link
Owner

arve0 commented Dec 23, 2024

Hi @arjangeertsema 👋 Thanks for reporting and fix. I'll try to reproduce and create a regression test.

Until then, @yiiman-dev, version v4.1.6 should probably be fine.

@arve0
Copy link
Owner

arve0 commented Dec 23, 2024

Hi again. I'm unable to reproduce. Maybe you can supply a minimum reproducible example?

Here is what I tried:

/* eslint-env es6 */
const md = require('markdown-it')();
const markdownItAttrs = require('./');

md.use(markdownItAttrs)
  .use(require('markdown-it-multimd-table'));

const src = `| - | - |
| a | b |
| c | d |`;


const res = md.render(src);

console.log(res);  // eslint-disable-line

which does not crash.

Edit: Use example input for issue.

@TheNorthMemory
Copy link
Contributor

This cames from markdown-it-multimd-table integration, which is supported headerless md-table rendering.

Hi again. I'm unable to reproduce. Maybe you can supply a minimum reproducible example?

Here is what I tried:

/* eslint-env es6 */
const md = require('markdown-it')();
const markdownItAttrs = require('./');

md.use(markdownItAttrs)
  .use(require('markdown-it-multimd-table'));

const src = `| - | - |
| a | b |
| c | d |`;


const res = md.render(src);

console.log(res);  // eslint-disable-line

which does not crash.

Edit: Use example input for issue.

@arve0
Copy link
Owner

arve0 commented Dec 23, 2024

This cames from markdown-it-multimd-table integration, which is supported headerless md-table rendering.

OK, I believe I included it:

  .use(require('markdown-it-multimd-table'));

Anyhow, I added general error handling in v4.3.1, which might solve the issue until I can reproduce the error.

@TheNorthMemory
Copy link
Contributor

Sorry for this, I'm also trying reproduce and thinking about how to improve the multiple header and tbody potential problems.

@TheNorthMemory
Copy link
Contributor

  .use(require('markdown-it-multimd-table'));

try notation {headerless:true} like this can reproduced.

    .use(require('markdown-it-multimd-table'), { headerless: true });

@yiiman-dev
Copy link

@arve0 thanks for new update.
My problem is now fully resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants