zmarkdown icon indicating copy to clipboard operation
zmarkdown copied to clipboard

remark-grid-tables does not work with latest version of remark

Open dwjohnston opened this issue 2 years ago • 8 comments

I suspect that a later release of remark has broken remark-grid-table.

You can see here on Remark's list of plugins that remark-grid-tables is showing as broken:

https://github.com/remarkjs/remark/blob/main/doc/plugins.md#list-of-plugins

I have a repro attempting basic usage of the plugin here:

https://github.com/dwjohnston/remark-play/tree/851e343e3bf969b371c7737a9a93ea3751384962

When we run this we get:

/Users/davidjohnston/git/remark-play/node_modules/remark-grid-tables/dist/index.js:869
  var blockTokenizers = Parser.prototype.blockTokenizers;
                                         ^

TypeError: Cannot read properties of undefined (reading 'blockTokenizers')

That is - I believe that the Parser object is no longer attached.

dwjohnston avatar Jul 04 '22 06:07 dwjohnston

Can confirm this works for older version of unified, remark etc.

https://github.com/dwjohnston/remark-play/tree/d6de4d8cde062e767a0d19b84675b50c9f88ca90

Can I suggest adding those values as peer deps?

dwjohnston avatar Jul 04 '22 06:07 dwjohnston

By upgrading the dependencies one at a time, I'm able to ascertain that it is the upgrade of 8.x.x to 10.x.x of remark-parse that causes the breaking issue.

https://github.com/dwjohnston/remark-play/commit/8825694aef083dd544e9a1387045e510aa86644f

dwjohnston avatar Jul 04 '22 06:07 dwjohnston

I'm having a little bit of trouble reading the remark change log, but for remark-parse 9 and 10:

https://github.com/remarkjs/remark/releases/tag/remark-parse%409.0.0

refers to major release 13 of remark:

https://github.com/remarkjs/remark/releases/tag/13.0.0

And remark-parse 10 refers to major release 14 of remark

https://github.com/remarkjs/remark/releases/tag/14.0.2 https://github.com/remarkjs/remark/compare/14.0.1...14.0.2

however 14 seems like it is just documentation fixes?

dwjohnston avatar Jul 04 '22 07:07 dwjohnston

Some related issues:

https://github.com/remarkjs/remark/issues/499 ~~https://github.com/remarkjs/remark/issues/357~~ Issue from before remark@13 ~~https://github.com/remarkjs/remark/issues/453~~ Issue from before remark@13

Is it that blockTokenizers hasn't been removed, but that another plugin removes it?

dwjohnston avatar Jul 04 '22 07:07 dwjohnston

Related issue here: https://github.com/zestedesavoir/zmarkdown/issues/416

dwjohnston avatar Jul 05 '22 07:07 dwjohnston

Hello :wave:

this issue is known, as you have noticed. Especially, the README states:

Currently, all the plugins provided only work for remark versions lesser than 13.0.0 (i.e. previous to micromark).

To make it short, migration of the plugins is planned, but without any milestone. I have very little time to work on it so it is unlikely to be done anytime soon, especillay for remark-grid-tables which is a big package.

At first sight, it seems to me to be a good idea adding remark <13 as peer dependency. I need to think about it but I will see what can be done. I'm keeping this issue open as a reminder, but further questions about the migration to micromark should go on #416 .

StaloneLab avatar Jul 05 '22 13:07 StaloneLab

@StaloneLab No worries, thanks for replying.

For anyone who needs it, my current workaround is to convert the grid table into a gfm style table.

function transformGridTableToGfmFn(input) {
  // TIL - JavaScript needs the multiline flag
  // To work over for end of line matching
  // https://javascript.info/regexp-multiline-mode

  // Note - distinction between $ and \n in the regex.
  // If you want to get replace the linebreak itself, then use \n

  // Remove +---+ lines 
  const mdValue2 = input.replace(/^\+[-+]*\+\s*\n/gm, '');
  
  // Convert +===+ lines to |---| lines (this is the line between the table header and the table body)
  const mdValue3 = mdValue2.replace(/=+\+\s*$/gm, '=|');
  const mdValue4 = mdValue3.replace(/\+=+/gm, '|---');

  return mdValue4;
}

dwjohnston avatar Jul 07 '22 01:07 dwjohnston

Thanks for this workaround. It only works for simple tables unfortunately, I think, so the scope seems limited, but it might be helpful if someone is interested in the syntax.

StaloneLab avatar Jul 07 '22 12:07 StaloneLab