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

Fix react newline issues #29

Merged
merged 4 commits into from
Jun 23, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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