Skip to content

Commit

Permalink
Refactor code-style
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Dec 27, 2020
1 parent 67732d5 commit 39d5178
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@ var tableCellStyle = require('@mapbox/hast-util-table-cell-style')

module.exports = rehypeReact

var has = {}.hasOwnProperty
var own = {}.hasOwnProperty

// Add a React compiler.
function rehypeReact(options) {
var settings = options || {}
var createElement = settings.createElement
var Fragment = settings.Fragment
var components = settings.components || {}
var passNode = settings.passNode

this.Compiler = compiler

Expand All @@ -28,7 +25,7 @@ function rehypeReact(options) {
? result.props.children
: [result]

return createElement(Fragment || 'div', {}, result)
return createElement(settings.Fragment || 'div', {}, result)
}

return result
Expand All @@ -37,9 +34,11 @@ function rehypeReact(options) {
// Wrap `createElement` to pass components in.
function h(name, props, children) {
var component = name
if (has.call(components, name)) {
component = components[name]
if (passNode) {

if (settings.components && own.call(settings.components, name)) {
component = settings.components[name]

if (settings.passNode) {
props.node = this
}
}
Expand Down

0 comments on commit 39d5178

Please sign in to comment.