Skip to content

Commit

Permalink
Fix react newline issues
Browse files Browse the repository at this point in the history
Closes GH-28.
Closes GH-29.

Reviewed-by: Titus Wormer <tituswormer@gmail.com>
  • Loading branch information
stevemk14ebr authored Jun 23, 2021
1 parent 7c60ebe commit e47817f
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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: <https://github.com/facebook/react/pull/7081>.
// See: <https://github.com/facebook/react/pull/7515>.
// See: <https://github.com/remarkjs/remark-react/issues/64>.
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]

Expand Down

0 comments on commit e47817f

Please sign in to comment.