Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

remark-react

Package Overview
Dependencies
Maintainers
2
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

remark-react - npm Package Compare versions

Comparing version 8.0.0 to 9.0.0

index.d.ts

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
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc