Skip to content
This repository has been archived by the owner on Oct 1, 2024. It is now read-only.

Commit

Permalink
Add back table white space stripping
Browse files Browse the repository at this point in the history
Reverts 780b4cd.

Closes GH-64.
  • Loading branch information
wooorm committed Jun 18, 2019
1 parent fa3d3ac commit 228fd8e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 42 deletions.
14 changes: 14 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ try {

var own = {}.hasOwnProperty

var tableElements = ['table', 'thead', 'tbody', 'tfoot', 'tr']

function react(options) {
var settings = options || {}
var createElement = settings.createElement || globalCreateElement
Expand All @@ -34,6 +36,18 @@ function react(options) {

// Wrapper around `createElement` to pass components in.
function h(name, props, children) {
// 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.indexOf(name) !== -1) {
children = children.filter(function(child) {
return child !== '\n'
})
}

return createElement(
own.call(components, name) ? components[name] : name,
props,
Expand Down
43 changes: 1 addition & 42 deletions test/react/v16/fixtures/tables/output.html
Original file line number Diff line number Diff line change
@@ -1,42 +1 @@
<table>
<thead>
<tr>
<th>Alpha</th>
<th style="text-align:left">Bravo</th>
<th style="text-align:right">Charlie</th>
<th style="text-align:center">Delta</th>
</tr>
</thead>
<tbody>
<tr>
<td>Echo</td>
<td style="text-align:left">Foxtrot</td>
<td style="text-align:right"><strong>Golf</strong></td>
<td style="text-align:center"></td>
</tr>
<tr>
<td>India</td>
<td style="text-align:left">Juliett</td>
<td style="text-align:right">Kilo</td>
<td style="text-align:center">Lima</td>
</tr>
<tr>
<td>Mike</td>
<td style="text-align:left">November</td>
<td style="text-align:right">Oscar</td>
<td style="text-align:center"><del>Papa</del></td>
</tr>
<tr>
<td>Quebec</td>
<td style="text-align:left"><em>Romeo</em></td>
<td style="text-align:right">Sierra</td>
<td style="text-align:center">Tango</td>
</tr>
<tr>
<td>Uniform</td>
<td style="text-align:left">Victor</td>
<td style="text-align:right">Whiskey</td>
<td style="text-align:center"></td>
</tr>
</tbody>
</table>
<table><thead><tr><th>Alpha</th><th style="text-align:left">Bravo</th><th style="text-align:right">Charlie</th><th style="text-align:center">Delta</th></tr></thead><tbody><tr><td>Echo</td><td style="text-align:left">Foxtrot</td><td style="text-align:right"><strong>Golf</strong></td><td style="text-align:center"></td></tr><tr><td>India</td><td style="text-align:left">Juliett</td><td style="text-align:right">Kilo</td><td style="text-align:center">Lima</td></tr><tr><td>Mike</td><td style="text-align:left">November</td><td style="text-align:right">Oscar</td><td style="text-align:center"><del>Papa</del></td></tr><tr><td>Quebec</td><td style="text-align:left"><em>Romeo</em></td><td style="text-align:right">Sierra</td><td style="text-align:center">Tango</td></tr><tr><td>Uniform</td><td style="text-align:left">Victor</td><td style="text-align:right">Whiskey</td><td style="text-align:center"></td></tr></tbody></table>

0 comments on commit 228fd8e

Please sign in to comment.