table.ts 814 B

1234567891011121314151617181920
  1. import { Plugin } from 'unified';
  2. import { visit } from 'unist-util-visit';
  3. export const remarkPlugin: Plugin = function() {
  4. return (tree) => {
  5. visit(tree, (node) => {
  6. if (node.type === 'table' || node.type === 'tableCell' || node.type === 'tableRow') {
  7. // omit position to fix the key regardless of its position
  8. // see:
  9. // https://github.com/remarkjs/react-markdown/issues/703
  10. // https://github.com/remarkjs/react-markdown/issues/466
  11. //
  12. // https://github.com/remarkjs/react-markdown/blob/a80dfdee2703d84ac2120d28b0e4998a5b417c85/lib/ast-to-react.js#L201-L204
  13. // https://github.com/remarkjs/react-markdown/blob/a80dfdee2703d84ac2120d28b0e4998a5b417c85/lib/ast-to-react.js#L217-L222
  14. delete node.position;
  15. }
  16. });
  17. };
  18. };