Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rehypejs/rehype-react
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 7.1.1
Choose a base ref
...
head repository: rehypejs/rehype-react
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 7.1.2
Choose a head ref
  • 8 commits
  • 6 files changed
  • 2 contributors

Commits on Oct 12, 2022

  1. Update dev-dependencies

    wooorm committed Oct 12, 2022

    Verified

    This commit was signed with the committer’s verified signature.
    dtolnay David Tolnay
    Copy the full SHA
    c969afd View commit details
  2. Add some docs to types

    wooorm committed Oct 12, 2022
    Copy the full SHA
    951a17d View commit details

Commits on Jan 18, 2023

  1. Update dev-dependencies

    wooorm committed Jan 18, 2023
    Copy the full SHA
    6612299 View commit details
  2. Fix types for TS 4.9

    wooorm committed Jan 18, 2023
    Copy the full SHA
    32b5e83 View commit details
  3. Fix to not strip whitespace in th, td

    Related-to GH-32.
    Closes GH-45.
    
    Reviewed-by: Titus Wormer <tituswormer@gmail.com>
    chitoku-k authored Jan 18, 2023
    Copy the full SHA
    33e3489 View commit details
  4. Refactor code-style

    wooorm committed Jan 18, 2023
    Copy the full SHA
    532e059 View commit details
  5. Add more notes

    wooorm committed Jan 18, 2023
    Copy the full SHA
    820014f View commit details
  6. 7.1.2

    wooorm committed Jan 18, 2023
    Copy the full SHA
    497de53 View commit details
Showing with 37 additions and 23 deletions.
  1. +1 −1 .github/workflows/main.yml
  2. +1 −1 index.d.ts
  3. +3 −3 lib/complex-types.ts
  4. +17 −12 lib/index.js
  5. +4 −4 package.json
  6. +11 −2 test.js
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -17,5 +17,5 @@ jobs:
strategy:
matrix:
node:
- lts/erbium
- lts/fermium
- node
2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
@@ -13,4 +13,4 @@ import type {Options} from './lib/index.js'
declare const rehypeReact: Plugin<[Options], Root, ReactElement<unknown>>
export default rehypeReact

export {Options} from './lib/index.js'
export type {Options} from './lib/index.js'
6 changes: 3 additions & 3 deletions lib/complex-types.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type {ComponentType} from 'react'
import type {Element} from 'hast'

interface WithNode {
type WithNode = {
node: Element
}

export interface ComponentsWithNodeOptions {
export type ComponentsWithNodeOptions = {
/**
* Expose hast elements as a `node` field in components
*/
@@ -21,7 +21,7 @@ export interface ComponentsWithNodeOptions {
}>
}

export interface ComponentsWithoutNodeOptions {
export type ComponentsWithoutNodeOptions = {
/**
* Expose hast elements as a `node` field in components.
*/
29 changes: 17 additions & 12 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/**
* @typedef {import('hast').Root} Root
* @typedef {import('hast').Element} Element
* @typedef {import('react').ReactNode} ReactNode
* @typedef {import('react').ReactElement<unknown>} ReactElement
*
@@ -11,16 +10,18 @@
* @returns {ReactNode}
*
* @typedef SharedOptions
* Base configuration (without `components`).
* @property {CreateElementLike} createElement
* How to create elements or components.
* You should typically pass `React.createElement`.
* @property {((props: any) => ReactNode)|undefined} [Fragment]
* Create fragments instead of an outer `<div>` if available.
* You should typically pass `React.Fragment`.
* @property {string|undefined} [prefix='h-']
* React key prefix
* React key prefix.
*
* @typedef {SharedOptions & (import("./complex-types").ComponentsWithNodeOptions|import("./complex-types").ComponentsWithoutNodeOptions)} Options
* @typedef {SharedOptions & (import('./complex-types').ComponentsWithNodeOptions|import('./complex-types').ComponentsWithoutNodeOptions)} Options
* Configuration.
*/

import {toH} from 'hast-to-hyperscript'
@@ -29,17 +30,18 @@ import tableCellStyle from '@mapbox/hast-util-table-cell-style'
import {whitespace} from 'hast-util-whitespace'

const own = {}.hasOwnProperty
const tableElements = new Set([
'table',
'thead',
'tbody',
'tfoot',
'tr',
'th',
'td'
])
const tableElements = new Set(['table', 'thead', 'tbody', 'tfoot', 'tr'])

/**
* Compile HTML to React nodes.
*
* > 👉 **Note**: this compiler returns a React node where compilers typically
* > return `string`.
* > When using `.stringify`, the result is such a React node.
* > When using `.process` (or `.processSync`), the result is available at
* > `file.result`.
*
* @this {import('unified').Processor}
* @type {import('unified').Plugin<[Options], Root, ReactElement>}
*/
export default function rehypeReact(options) {
@@ -90,6 +92,9 @@ export default function rehypeReact(options) {
// 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>.
// See: <https://github.com/rehypejs/rehype-react/pull/29>.
// See: <https://github.com/rehypejs/rehype-react/pull/32>.
// See: <https://github.com/rehypejs/rehype-react/pull/45>.
if (children && tableElements.has(name)) {
children = children.filter((child) => !whitespace(child))
}
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "rehype-react",
"description": "rehype plugin to transform to React",
"version": "7.1.1",
"version": "7.1.2",
"license": "MIT",
"keywords": [
"unified",
@@ -63,14 +63,14 @@
"react": "^18.0.0",
"react-dom": "^18.0.0",
"remark": "^14.0.0",
"remark-cli": "^10.0.0",
"remark-cli": "^11.0.0",
"remark-preset-wooorm": "^9.0.0",
"rimraf": "^3.0.0",
"tape": "^5.0.0",
"type-coverage": "^2.0.0",
"typescript": "^4.0.0",
"unist-builder": "^3.0.0",
"xo": "^0.48.0"
"xo": "^0.53.0"
},
"scripts": {
"build": "rimraf \"lib/*.d.ts\" \"test.d.ts\" && tsc && type-coverage",
@@ -91,7 +91,7 @@
"prettier": true,
"": "`xo` is wrong about file extensions",
"rules": {
"node/file-extension-in-import": "off"
"n/file-extension-in-import": "off"
}
},
"remarkConfig": {
13 changes: 11 additions & 2 deletions test.js
Original file line number Diff line number Diff line change
@@ -171,13 +171,22 @@ test('React ' + React.version, (t) => {
t.deepEqual(
processor.stringify(
u('root', [
h('table', {}, ['\n ', h('tbody', {}, ['\n ', h('tr', {})])])
h('table', {}, [
'\n ',
h('tbody', {}, [
'\n ',
h('tr', {}, ['\n ', h('th', {}, ['\n ']), h('td', {}, ['\n '])])
])
])
])
),
React.createElement('div', {}, [
React.createElement('table', {key: 'h-1'}, [
React.createElement('tbody', {key: 'h-2'}, [
React.createElement('tr', {key: 'h-3'}, undefined)
React.createElement('tr', {key: 'h-3'}, [
React.createElement('th', {key: 'h-4'}, ['\n ']),
React.createElement('td', {key: 'h-5'}, ['\n '])
])
])
])
]),