remark-react
Advanced tools
Comparing version 8.0.0 to 9.0.0
78
index.js
@@ -1,77 +0,3 @@ | ||
'use strict' | ||
import remarkReact from './lib/index.js' | ||
module.exports = react | ||
var toHast = require('mdast-util-to-hast') | ||
var sanitize = require('hast-util-sanitize') | ||
var toH = require('hast-to-hyperscript') | ||
var tableCellStyle = require('@mapbox/hast-util-table-cell-style') | ||
var globalReact | ||
var globalCreateElement | ||
var globalFragment | ||
/* istanbul ignore next - Hard to test */ | ||
try { | ||
globalReact = require('react') | ||
globalCreateElement = globalReact.createElement | ||
globalFragment = globalReact.Fragment | ||
} catch (_) {} | ||
var own = {}.hasOwnProperty | ||
var tableElements = ['table', 'thead', 'tbody', 'tfoot', 'tr'] | ||
function react(options) { | ||
var settings = options || {} | ||
var createElement = settings.createElement || globalCreateElement | ||
var Fragment = settings.fragment || globalFragment | ||
var clean = settings.sanitize !== false | ||
var scheme = | ||
clean && typeof settings.sanitize !== 'boolean' ? settings.sanitize : null | ||
var toHastOptions = settings.toHast || {} | ||
var components = settings.remarkReactComponents || {} | ||
this.Compiler = compile | ||
// Wrapper around `createElement` to pass components in. | ||
function h(name, props, children) { | ||
// Currently, React issues a warning 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>. | ||
/* istanbul ignore next - still works but need to publish `remark-gfm` | ||
* first. */ | ||
if (children && tableElements.indexOf(name) !== -1) { | ||
children = children.filter(function (child) { | ||
return child !== '\n' | ||
}) | ||
} | ||
return createElement( | ||
own.call(components, name) ? components[name] : name, | ||
props, | ||
children | ||
) | ||
} | ||
// Compile mdast to React. | ||
function compile(node) { | ||
var tree = toHast(node, toHastOptions) | ||
var root | ||
if (clean) { | ||
tree = sanitize(tree, scheme) | ||
} | ||
root = toH(h, tableCellStyle(tree), settings.prefix) | ||
// If this compiled to a `<div>`, but fragment are possible, use those. | ||
if (root.type === 'div' && Fragment) { | ||
root = createElement(Fragment, {}, root.props.children) | ||
} | ||
return root | ||
} | ||
} | ||
export default remarkReact |
{ | ||
"name": "remark-react", | ||
"version": "8.0.0", | ||
"version": "9.0.0", | ||
"description": "remark plugin to transform to React", | ||
@@ -40,38 +40,47 @@ "license": "MIT", | ||
], | ||
"sideEffects": false, | ||
"type": "module", | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"files": [ | ||
"lib/", | ||
"index.d.ts", | ||
"index.js" | ||
], | ||
"dependencies": { | ||
"@mapbox/hast-util-table-cell-style": "^0.1.3", | ||
"hast-to-hyperscript": "^9.0.0", | ||
"hast-util-sanitize": "^3.0.0", | ||
"mdast-util-to-hast": "^10.0.0" | ||
"@mapbox/hast-util-table-cell-style": "^0.2.0", | ||
"@types/mdast": "^3.0.0", | ||
"@types/react": "^17.0.0", | ||
"hast-to-hyperscript": "^10.0.0", | ||
"hast-util-sanitize": "^4.0.0", | ||
"mdast-util-to-hast": "^11.0.0", | ||
"unified": "^10.0.0" | ||
}, | ||
"devDependencies": { | ||
"is-hidden": "^1.0.0", | ||
"negate": "^1.0.0", | ||
"nyc": "^15.0.0", | ||
"@types/react-dom": "^17.0.0", | ||
"@types/tape": "^4.0.0", | ||
"c8": "^7.0.0", | ||
"is-hidden": "^2.0.0", | ||
"prettier": "^2.0.0", | ||
"remark": "^13.0.0-alpha.0", | ||
"remark-cli": "^8.0.0", | ||
"remark-footnotes": "^2.0.0", | ||
"remark-frontmatter": "^2.0.0", | ||
"remark-preset-wooorm": "^7.0.0", | ||
"react": "^17.0.0", | ||
"react-dom": "^17.0.0", | ||
"remark": "^14.0.0", | ||
"remark-cli": "^10.0.0", | ||
"remark-footnotes": "^4.0.0", | ||
"remark-frontmatter": "^4.0.0", | ||
"remark-preset-wooorm": "^8.0.0", | ||
"rimraf": "^3.0.0", | ||
"tape": "^5.0.0", | ||
"vfile": "^4.0.0", | ||
"xo": "^0.33.0" | ||
"type-coverage": "^2.0.0", | ||
"typescript": "^4.0.0", | ||
"vfile": "^5.0.0", | ||
"xo": "^0.44.0" | ||
}, | ||
"scripts": { | ||
"sub-install": "cd test/react/v16 && npm install && cd ../..", | ||
"format": "remark . -qfo && prettier . --write && xo --fix", | ||
"test-api": "node test", | ||
"test-coverage": "nyc --reporter lcov tape test/index.js", | ||
"test": "npm run sub-install && npm run format && npm run test-coverage" | ||
"build": "rimraf \"lib/**/*.d.ts\" \"test/**/*.d.ts\" && tsc && type-coverage", | ||
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix", | ||
"test-api": "node --conditions development test/index.js", | ||
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov npm run test-api", | ||
"test": "npm run build && npm run format && npm run test-coverage" | ||
}, | ||
"nyc": { | ||
"check-coverage": true, | ||
"lines": 100, | ||
"functions": 100, | ||
"branches": 100 | ||
}, | ||
"prettier": { | ||
@@ -86,17 +95,3 @@ "tabWidth": 2, | ||
"xo": { | ||
"prettier": true, | ||
"esnext": false, | ||
"rules": { | ||
"unicorn/no-fn-reference-in-iterator": "off", | ||
"unicorn/prefer-includes": "off", | ||
"unicorn/prefer-optional-catch-binding": "off", | ||
"no-eq-null": "off", | ||
"eqeqeq": [ | ||
"error", | ||
"always", | ||
{ | ||
"null": "ignore" | ||
} | ||
] | ||
} | ||
"prettier": true | ||
}, | ||
@@ -107,3 +102,13 @@ "remarkConfig": { | ||
] | ||
}, | ||
"typeCoverage": { | ||
"atLeast": 100, | ||
"detail": true, | ||
"strict": true, | ||
"ignoreCatch": true, | ||
"#": "needed `any`s", | ||
"ignoreFiles": [ | ||
"lib/index.d.ts" | ||
] | ||
} | ||
} |
@@ -35,2 +35,5 @@ # remark-react | ||
This package is [ESM only](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c): | ||
Node 12+ is needed to use it and it must be `import`ed instead of `require`d. | ||
[npm][]: | ||
@@ -47,5 +50,5 @@ | ||
import ReactDom from 'react-dom' | ||
import unified from 'unified' | ||
import parse from 'remark-parse' | ||
import remark2react from 'remark-react' | ||
import {unified} from 'unified' | ||
import remarkParse from 'remark-parse' | ||
import remarkReact from 'remark-react' | ||
@@ -55,8 +58,10 @@ class App extends React.Component { | ||
super() | ||
this.state = { text: '# hello world' } | ||
this.state = {text: '# hello world'} | ||
this.onChange = this.onChange.bind(this) | ||
} | ||
onChange(e) { | ||
this.setState({ text: e.target.value }) | ||
onChange(event) { | ||
this.setState({text: event.target.value}) | ||
} | ||
render() { | ||
@@ -69,4 +74,4 @@ return ( | ||
unified() | ||
.use(parse) | ||
.use(remark2react) | ||
.use(remarkParse) | ||
.use(remarkReact, React) | ||
.processSync(this.state.text).result | ||
@@ -80,3 +85,3 @@ } | ||
ReactDom.render(<App />, document.getElementById('root')) | ||
ReactDom.render(<App />, document.querySelector('#root')) | ||
``` | ||
@@ -86,4 +91,7 @@ | ||
### `remark().use(react[, options])` | ||
This package exports no identifiers. | ||
The default export is `remarkReact`. | ||
### `unified().use(remarkReact, options)` | ||
Transform Markdown to React. | ||
@@ -97,7 +105,12 @@ | ||
> ℹ️ In [`unified@9.0.0`][unified-9], the result of `.process` changed from | ||
> ~~`file.contents`~~ to `file.result`. | ||
##### `options` | ||
###### `options.createElement` | ||
How to create elements or components (`Function`, required). | ||
###### `options.Fragment` | ||
Create fragments instead of an outer `<div>` if available (`unknown`). | ||
###### `options.toHast` | ||
@@ -125,12 +138,2 @@ | ||
###### `options.createElement` | ||
How to create elements or components (`Function`). | ||
Default: `require('react').createElement` | ||
###### `options.fragment` | ||
Create fragments instead of an outer `<div>` if available (`Function`, default: | ||
`require('react').Fragment`). | ||
###### `options.remarkReactComponents` | ||
@@ -153,4 +156,7 @@ | ||
See how to integrate with other remark plugins in the [Integrations][] section | ||
of `remark-html`. | ||
`remark-react` is similar in configuration to its alternative `remark-html`. | ||
You’ll want to use one or the other but setting up plugins for either is done | ||
in the same way. | ||
As such, you can see how to integrate with other remark plugins in the | ||
[Integrations][] section of `remark-html`’s documentation. | ||
@@ -180,5 +186,5 @@ ## Security | ||
[build-badge]: https://img.shields.io/travis/remarkjs/remark-react/main.svg | ||
[build-badge]: https://github.com/remarkjs/remark-react/workflows/main/badge.svg | ||
[build]: https://travis-ci.org/remarkjs/remark-react | ||
[build]: https://github.com/remarkjs/remark-react/actions | ||
@@ -252,3 +258,1 @@ [coverage-badge]: https://img.shields.io/codecov/c/github/remarkjs/remark-react.svg | ||
[unified]: https://github.com/unifiedjs/unified | ||
[unified-9]: https://github.com/unifiedjs/unified/releases/tag/9.0.0 |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
53389
7
1315
248
Yes
7
18
1
+ Added@types/mdast@^3.0.0
+ Added@types/react@^17.0.0
+ Addedunified@^10.0.0
+ Added@mapbox/hast-util-table-cell-style@0.2.1(transitive)
+ Added@types/hast@2.3.10(transitive)
+ Added@types/mdurl@1.0.5(transitive)
+ Added@types/prop-types@15.7.13(transitive)
+ Added@types/react@17.0.83(transitive)
+ Added@types/scheduler@0.16.8(transitive)
+ Addedbail@2.0.2(transitive)
+ Addedcomma-separated-tokens@2.0.3(transitive)
+ Addedcsstype@3.1.3(transitive)
+ Addedextend@3.0.2(transitive)
+ Addedhast-to-hyperscript@10.0.3(transitive)
+ Addedhast-util-sanitize@4.1.0(transitive)
+ Addedis-buffer@2.0.5(transitive)
+ Addedis-plain-obj@4.1.0(transitive)
+ Addedmdast-util-definitions@5.1.2(transitive)
+ Addedmdast-util-to-hast@11.3.0(transitive)
+ Addedproperty-information@6.5.0(transitive)
+ Addedspace-separated-tokens@2.0.2(transitive)
+ Addedstyle-to-object@0.4.4(transitive)
+ Addedtrough@2.2.0(transitive)
+ Addedunified@10.1.2(transitive)
+ Addedunist-builder@3.0.1(transitive)
+ Addedunist-util-generated@2.0.1(transitive)
+ Addedunist-util-is@5.2.1(transitive)
+ Addedunist-util-position@4.0.4(transitive)
+ Addedunist-util-stringify-position@3.0.3(transitive)
+ Addedunist-util-visit@4.1.2(transitive)
+ Addedunist-util-visit-parents@5.1.3(transitive)
+ Addedvfile@5.3.7(transitive)
+ Addedvfile-message@3.1.4(transitive)
+ Addedweb-namespaces@2.0.1(transitive)
- Removed@mapbox/hast-util-table-cell-style@0.1.3(transitive)
- Removedcomma-separated-tokens@1.0.8(transitive)
- Removedhast-to-hyperscript@9.0.1(transitive)
- Removedhast-util-sanitize@3.0.2(transitive)
- Removedmdast-util-definitions@4.0.0(transitive)
- Removedmdast-util-to-hast@10.2.0(transitive)
- Removedproperty-information@5.6.0(transitive)
- Removedspace-separated-tokens@1.1.5(transitive)
- Removedstyle-to-object@0.3.0(transitive)
- Removedunist-builder@2.0.3(transitive)
- Removedunist-util-generated@1.1.6(transitive)
- Removedunist-util-is@4.1.0(transitive)
- Removedunist-util-position@3.1.0(transitive)
- Removedunist-util-visit@2.0.3(transitive)
- Removedunist-util-visit-parents@3.1.1(transitive)
- Removedweb-namespaces@1.1.4(transitive)
- Removedxtend@4.0.2(transitive)
Updatedhast-to-hyperscript@^10.0.0
Updatedhast-util-sanitize@^4.0.0
Updatedmdast-util-to-hast@^11.0.0