From e47817f00fce05cbed588e9124faef8d367648dc Mon Sep 17 00:00:00 2001 From: Stephen Eckels Date: Wed, 23 Jun 2021 10:33:41 -0400 Subject: [PATCH] Fix react newline issues Closes GH-28. Closes GH-29. Reviewed-by: Titus Wormer --- index.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/index.js b/index.js index bdfa149..10e5965 100644 --- a/index.js +++ b/index.js @@ -6,6 +6,15 @@ var tableCellStyle = require('@mapbox/hast-util-table-cell-style') module.exports = rehypeReact var own = {}.hasOwnProperty +var tableElements = new Set([ + 'table', + 'thead', + 'tbody', + 'tfoot', + 'tr', + 'th', + 'td' +]) // Add a React compiler. function rehypeReact(options) { @@ -35,6 +44,18 @@ function rehypeReact(options) { function h(name, props, children) { var component = name + // Currently, a warning is triggered by react for *any* white space in + // tables. + // So we remove the pretty lines for now. + // See: . + // See: . + // See: . + if (children && tableElements.has(name)) { + children = children.filter(function (child) { + return child !== '\n' + }) + } + if (settings.components && own.call(settings.components, name)) { component = settings.components[name]