react-markdown
Advanced tools
Comparing version 4.3.1 to 5.0.0
172
index.d.ts
@@ -1,137 +0,93 @@ | ||
// Type definitions for react-markdown > v3.3.0 | ||
// Project: https://github.com/rexxars/react-markdown | ||
// Definitions by: | ||
// - Ruslan Ibragimov <https://github.com/IRus> | ||
// - Kohei Asai <me@axross.io> | ||
// - ClassicDarkChocolate <https://github.com/ClassicDarkChocolate> | ||
// - Espen Hovlandsdal <https://espen.codes/> | ||
// - Ted Piotrowski <https://github.com/ted-piotrowski> | ||
// TypeScript Version: 3.4 | ||
import {Component, ReactElement, ReactNode, ReactType} from 'react' | ||
import {ElementType, ReactNode, ReactElement} from 'react' | ||
import {PluggableList} from 'unified' | ||
import * as unist from 'unist' | ||
import * as mdast from 'mdast' | ||
declare class ReactMarkdown extends Component<ReactMarkdown.ReactMarkdownProps, {}> {} | ||
type Not<T> = { | ||
[key in keyof T]?: never | ||
} | ||
type MutuallyExclusive<T, U> = (T & Not<U>) | (U & Not<T>) | ||
declare namespace ReactMarkdown { | ||
interface Point { | ||
readonly line: number | ||
readonly column: number | ||
readonly offset?: number | ||
} | ||
type Point = unist.Point | ||
interface Position { | ||
readonly start: Point | ||
readonly end: Point | ||
readonly indent?: number[] | ||
} | ||
type Position = unist.Position | ||
interface RemarkParseOptions { | ||
gfm: boolean | ||
commonmark: boolean | ||
footnotes: boolean | ||
blocks: string[] | ||
pedantic: boolean | ||
} | ||
type NodeType = mdast.Content['type'] | ||
export type NodeType = | ||
| 'root' | ||
| 'text' | ||
| 'break' | ||
| 'paragraph' | ||
| 'emphasis' | ||
| 'strong' | ||
| 'thematicBreak' | ||
| 'blockquote' | ||
| 'delete' | ||
| 'link' | ||
| 'image' | ||
| 'linkReference' | ||
| 'imageReference' | ||
| 'table' | ||
| 'tableHead' | ||
| 'tableBody' | ||
| 'tableRow' | ||
| 'tableCell' | ||
| 'list' | ||
| 'listItem' | ||
| 'definition' | ||
| 'heading' | ||
| 'inlineCode' | ||
| 'code' | ||
| 'html' | ||
| 'virtualHtml' | ||
type AlignType = mdast.AlignType | ||
export type AlignType = | ||
| "left" | ||
| "right" | ||
| "center" | ||
| null | ||
type ReferenceType = mdast.ReferenceType | ||
export type ReferenceType = | ||
| "shortcut" | ||
| "collapsed" | ||
| "full" | ||
type LinkTargetResolver = (uri: string, text: string, title?: string) => string | ||
export type LinkTargetResolver = (uri: string, text: string, title?: string) => string | ||
type Renderer<T> = (props: T) => ElementType<T> | ||
interface Renderers { | ||
[key: string]: string | Renderer<any> | ||
} | ||
export interface ReactMarkdownProps { | ||
interface ReactMarkdownPropsBase { | ||
readonly className?: string | ||
readonly source?: string | ||
readonly sourcePos?: boolean | ||
readonly includeNodeIndex?: boolean | ||
readonly rawSourcePos?: boolean | ||
readonly escapeHtml?: boolean | ||
readonly skipHtml?: boolean | ||
readonly allowNode?: (node: MarkdownAbstractSyntaxTree, index: number, parent: NodeType) => boolean | ||
readonly allowNode?: (node: mdast.Content, index: number, parent: NodeType) => boolean | ||
readonly linkTarget?: string | LinkTargetResolver | ||
readonly transformLinkUri?: | ||
| ((uri: string, children?: ReactNode, title?: string) => string) | ||
| null | ||
readonly transformImageUri?: | ||
| ((uri: string, children?: ReactNode, title?: string, alt?: string) => string) | ||
| null | ||
readonly renderers?: {[nodeType: string]: ElementType} | ||
readonly astPlugins?: PluggableList | ||
readonly plugins?: PluggableList | ||
} | ||
interface SourceProp { | ||
/** @deprecated use children */ | ||
readonly source: string | ||
} | ||
interface ChildrenProp { | ||
readonly children: string | ||
} | ||
interface AllowedTypesProp { | ||
readonly allowedTypes?: NodeType[] | ||
readonly disallowedTypes?: NodeType[] | ||
readonly linkTarget?: string | LinkTargetResolver | ||
readonly transformLinkUri?: ((uri: string, children?: ReactNode, title?: string) => string) | null | ||
readonly transformImageUri?: ((uri: string, children?: ReactNode, title?: string, alt?: string) => string) | null | ||
} | ||
interface DisallowedTypesProp { | ||
readonly disallowedTypes: NodeType[] | ||
readonly unwrapDisallowed?: boolean | ||
readonly renderers?: {[nodeType: string]: ReactType} | ||
readonly astPlugins?: MdastPlugin[] | ||
readonly plugins?: any[] | (() => void) | ||
readonly parserOptions?: Partial<RemarkParseOptions> | ||
} | ||
interface RenderProps extends ReactMarkdownProps { | ||
readonly definitions?: object | ||
interface AllowDangerousHtmlProp { | ||
readonly allowDangerousHtml?: boolean | ||
} | ||
type Renderer<T> = (props: T) => ReactElement<T> | ||
interface Renderers { | ||
[key: string]: string | Renderer<any> | ||
interface EscapeHtmlProp { | ||
/** @deprecated use allowDangerousHtml */ | ||
readonly escapeHtml?: boolean | ||
} | ||
interface MarkdownAbstractSyntaxTree { | ||
align?: AlignType[] | ||
alt?: string | null | ||
checked?: boolean | null | ||
children?: MarkdownAbstractSyntaxTree[] | ||
data?: {[key: string]: any} | ||
index?: number | ||
depth?: number | ||
height?: number | ||
identifier?: string | ||
lang?: string | null | ||
loose?: boolean | ||
ordered?: boolean | ||
position?: Position | ||
referenceType?: ReferenceType | ||
start?: number | null | ||
title?: string | null | ||
type: string | ||
url?: string | ||
value?: string | ||
width?: number | ||
interface SkipHtmlProp { | ||
readonly skipHtml?: boolean | ||
} | ||
type MdastPlugin = (node: MarkdownAbstractSyntaxTree, renderProps?: RenderProps) => MarkdownAbstractSyntaxTree | ||
type ReactMarkdownProps = ReactMarkdownPropsBase & | ||
MutuallyExclusive<ChildrenProp, SourceProp> & | ||
MutuallyExclusive<AllowedTypesProp, DisallowedTypesProp> & | ||
MutuallyExclusive<EscapeHtmlProp, MutuallyExclusive<SkipHtmlProp, AllowDangerousHtmlProp>> | ||
export var types: NodeType[] | ||
export var renderers: Renderers | ||
export var uriTransformer: (uri: string) => string | ||
const types: NodeType[] | ||
const renderers: Renderers | ||
function uriTransformer(uri: string): string | ||
} | ||
declare function ReactMarkdown(props: ReactMarkdown.ReactMarkdownProps): ReactElement | ||
export = ReactMarkdown | ||
@@ -9,24 +9,21 @@ 'use strict'; | ||
var defaultNodePosition = { | ||
start: { | ||
line: 1, | ||
column: 1, | ||
offset: 0 | ||
}, | ||
end: { | ||
line: 1, | ||
column: 1, | ||
offset: 0 | ||
} | ||
}; | ||
function astToReact(node, options) { | ||
var parent = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
var index = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0; | ||
var renderer = options.renderers[node.type]; // nodes generated by plugins may not have position data | ||
// much of the code after this point will attempt to access properties of the node.position | ||
// this will set the node position to the parent node's position to prevent errors | ||
var renderer = options.renderers[node.type]; // Nodes created by plugins do not have positional info, in which case we set | ||
// an object that matches the positon interface. | ||
if (node.position === undefined) { | ||
node.position = parent.node && parent.node.position || defaultNodePosition; | ||
if (!node.position) { | ||
node.position = { | ||
start: { | ||
line: null, | ||
column: null, | ||
offset: null | ||
}, | ||
end: { | ||
line: null, | ||
column: null, | ||
offset: null | ||
} | ||
}; | ||
} | ||
@@ -59,3 +56,3 @@ | ||
}; | ||
var isTagRenderer = typeof renderer === 'string'; // `sourcePos` is true if the user wants source information (line/column info from markdown source) | ||
var isSimpleRenderer = typeof renderer === 'string' || renderer === React.Fragment; // `sourcePos` is true if the user wants source information (line/column info from markdown source) | ||
@@ -66,3 +63,3 @@ if (opts.sourcePos && node.position) { | ||
if (opts.rawSourcePos && !isTagRenderer) { | ||
if (opts.rawSourcePos && !isSimpleRenderer) { | ||
props.sourcePosition = node.position; | ||
@@ -72,3 +69,3 @@ } // If `includeNodeIndex` is true, pass node index info to all non-tag renderers | ||
if (opts.includeNodeIndex && parent.node && parent.node.children && !isTagRenderer) { | ||
if (opts.includeNodeIndex && parent.node && parent.node.children && !isSimpleRenderer) { | ||
props.index = parent.node.children.indexOf(node); | ||
@@ -78,3 +75,5 @@ props.parentChildCount = parent.node.children.length; | ||
var ref = node.identifier !== null && node.identifier !== undefined ? opts.definitions[node.identifier] || {} : null; | ||
var ref = node.identifier !== null && node.identifier !== undefined ? | ||
/* istanbul ignore next - plugins could inject an undefined reference. */ | ||
opts.definitions[node.identifier.toUpperCase()] || {} : null; | ||
@@ -100,3 +99,3 @@ switch (node.type) { | ||
props.ordered = node.ordered; | ||
props.tight = !node.loose; | ||
props.spread = node.spread; | ||
props.depth = node.depth; | ||
@@ -107,3 +106,3 @@ break; | ||
props.checked = node.checked; | ||
props.tight = !node.loose; | ||
props.spread = node.spread; | ||
props.ordered = node.ordered; | ||
@@ -148,5 +147,5 @@ props.index = node.index; | ||
assignDefined(props, { | ||
alt: node.alt || undefined, | ||
title: node.title || undefined, | ||
src: opts.transformImageUri ? opts.transformImageUri(node.url, node.children, node.title, node.alt) : node.url | ||
src: opts.transformImageUri ? opts.transformImageUri(node.url, node.children, node.title, node.alt) : node.url, | ||
alt: node.alt || '', | ||
title: node.title || undefined | ||
}); | ||
@@ -164,4 +163,4 @@ break; | ||
src: opts.transformImageUri && ref.href ? opts.transformImageUri(ref.href, node.children, ref.title, node.alt) : ref.href, | ||
title: ref.title || undefined, | ||
alt: node.alt || undefined | ||
alt: node.alt || '', | ||
title: ref.title || undefined | ||
}); | ||
@@ -195,2 +194,3 @@ break; | ||
props.isBlock = node.position.start.line !== node.position.end.line; | ||
props.allowDangerousHtml = opts.allowDangerousHtml; | ||
props.escapeHtml = opts.escapeHtml; | ||
@@ -213,2 +213,3 @@ props.skipHtml = opts.skipHtml; | ||
props.allowDangerousHtml = opts.allowDangerousHtml; | ||
props.escapeHtml = opts.escapeHtml; | ||
@@ -228,6 +229,10 @@ props.skipHtml = opts.skipHtml; | ||
if (!isTagRenderer && node.value) { | ||
if (!isSimpleRenderer && node.value) { | ||
props.value = node.value; | ||
} | ||
if (!isSimpleRenderer) { | ||
props.node = node; | ||
} | ||
return props; | ||
@@ -248,2 +253,3 @@ } | ||
if (Array.isArray(el)) { | ||
/* istanbul ignore next - `div` fallback for old React. */ | ||
var Fragment = React.Fragment || 'div'; | ||
@@ -266,11 +272,5 @@ return React.createElement(Fragment, null, el); | ||
function getListItemChildren(node, parent) { | ||
if (node.loose) { | ||
return node.children; | ||
} | ||
if (parent.node && node.index > 0 && parent.node.children[node.index - 1].loose) { | ||
return node.children; | ||
} | ||
return unwrapParagraphs(node); | ||
/* istanbul ignore next - list items are always in a list, but best to be sure. */ | ||
var loose = parent && parent.node ? listLoose(parent.node) : listItemLoose(node); | ||
return loose ? node.children : unwrapParagraphs(node); | ||
} | ||
@@ -280,6 +280,25 @@ | ||
return node.children.reduce(function (array, child) { | ||
return array.concat(child.type === 'paragraph' ? child.children || [] : [child]); | ||
return array.concat(child.type === 'paragraph' ? child.children : [child]); | ||
}, []); | ||
} | ||
function listLoose(node) { | ||
var children = node.children; | ||
var loose = node.spread; | ||
var index = -1; | ||
while (!loose && ++index < children.length) { | ||
loose = listItemLoose(children[index]); | ||
} | ||
return loose; | ||
} | ||
function listItemLoose(node) { | ||
var spread = node.spread; | ||
/* istanbul ignore next - spread is present from remark-parse, but maybe plugins don’t set it. */ | ||
return spread === undefined || spread === null ? node.children.length > 1 : spread; | ||
} | ||
module.exports = astToReact; |
'use strict'; | ||
module.exports = function getDefinitions(node) { | ||
var defs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
return (node.children || []).reduce(function (definitions, child) { | ||
if (child.type === 'definition') { | ||
definitions[child.identifier] = { | ||
href: child.url, | ||
title: child.title | ||
}; | ||
} | ||
var visit = require('unist-util-visit'); | ||
return getDefinitions(child, definitions); | ||
}, defs); | ||
module.exports = function getDefinitions(tree) { | ||
var definitions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
visit(tree, 'definition', function (node) { | ||
var identifier = node.identifier.toUpperCase(); | ||
if (identifier in definitions) return; | ||
definitions[identifier] = { | ||
href: node.url, | ||
title: node.title | ||
}; | ||
}); | ||
return definitions; | ||
}; |
@@ -5,42 +5,35 @@ "use strict"; | ||
var splice = [].splice; | ||
exports.ofType = function (types, mode) { | ||
return function (node) { | ||
types.forEach(function (type) { | ||
return visit(node, type, disallow, true); | ||
}); | ||
return node; | ||
}; | ||
return ifNotMatch(allow, mode); | ||
function disallow(node, index, parent) { | ||
if (parent) { | ||
untangle(node, index, parent, mode); | ||
} | ||
function allow(node, index, parent) { | ||
return !types.includes(node.type); | ||
} | ||
}; | ||
exports.ifNotMatch = function (allowNode, mode) { | ||
return function (node) { | ||
visit(node, disallow, true); | ||
return node; | ||
}; | ||
exports.ifNotMatch = ifNotMatch; | ||
function disallow(node, index, parent) { | ||
if (parent && !allowNode(node, index, parent)) { | ||
untangle(node, index, parent, mode); | ||
} | ||
} | ||
}; | ||
function ifNotMatch(allow, mode) { | ||
return transform; | ||
function untangle(node, index, parent, mode) { | ||
if (mode === 'remove') { | ||
parent.children.splice(index, 1); | ||
} else if (mode === 'unwrap') { | ||
var args = [index, 1]; | ||
function transform(tree) { | ||
visit(tree, filter); | ||
return tree; | ||
} // eslint-disable-next-line consistent-return | ||
if (node.children) { | ||
args = args.concat(node.children); | ||
function filter(node, index, parent) { | ||
if (parent && !allow(node, index, parent)) { | ||
var parameters = [index, 1]; | ||
if (mode === 'unwrap' && node.children) { | ||
parameters = parameters.concat(node.children); | ||
} | ||
splice.apply(parent.children, parameters); | ||
return index; | ||
} | ||
Array.prototype.splice.apply(parent.children, args); | ||
} | ||
} |
@@ -40,3 +40,3 @@ "use strict"; | ||
visit(tree, 'html', function (node, index, parent) { | ||
if (props.escapeHtml) { | ||
if (!props.allowDangerousHtml && props.escapeHtml !== false) { | ||
parent.children.splice(index, 1, { | ||
@@ -132,2 +132,4 @@ type: 'text', | ||
var el = parser.parseWithInstructions(node.value, config.isValidNode, config.processingInstructions); | ||
/* istanbul ignore if - seems to never happen. Hiding it because we plan on | ||
* moving to rehype. */ | ||
@@ -150,2 +152,5 @@ if (!el) { | ||
var startTagMatch = node.value.trim().match(startTagRe); | ||
/* istanbul ignore next - seems it’s always a start tag, hiding it because we | ||
* plan on moving to rehype. */ | ||
var tag = startTagMatch ? startTagMatch[1] : el.type; | ||
@@ -186,3 +191,3 @@ return { | ||
if (props && (typeof config.source !== 'undefined' || typeof config.children !== 'undefined')) { | ||
throw new Error('react-markdown: `html-parser` must be called before use - see https://github.com/rexxars/react-markdown#parsing-html'); | ||
throw new Error('react-markdown: `html-parser` must be called before use - see https://github.com/remarkjs/react-markdown#parsing-html'); | ||
} | ||
@@ -189,0 +194,0 @@ |
'use strict'; | ||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); } | ||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); } | ||
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); } | ||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } } | ||
var xtend = require('xtend'); | ||
@@ -40,4 +32,4 @@ | ||
var ReactMarkdown = function ReactMarkdown(props) { | ||
// To do in next major: remove `source`. | ||
var src = props.source || props.children || ''; | ||
var parserOptions = props.parserOptions; | ||
@@ -49,24 +41,17 @@ if (props.allowedTypes && props.disallowedTypes) { | ||
var renderers = xtend(defaultRenderers, props.renderers); | ||
var plugins = [[parse, parserOptions]].concat(props.plugins || []); | ||
var parser = plugins.reduce(applyParserPlugin, unified()); | ||
var rawAst = parser.parse(src); | ||
var processor = unified().use(parse).use(props.plugins || []); // eslint-disable-next-line no-sync | ||
var tree = processor.runSync(processor.parse(src)); | ||
var renderProps = xtend(props, { | ||
renderers: renderers, | ||
definitions: getDefinitions(rawAst) | ||
definitions: getDefinitions(tree) | ||
}); | ||
var astPlugins = determineAstPlugins(props); // eslint-disable-next-line no-sync | ||
var transformedAst = parser.runSync(rawAst); | ||
var ast = astPlugins.reduce(function (node, plugin) { | ||
return plugin(node, renderProps); | ||
}, transformedAst); | ||
return astToReact(ast, renderProps); | ||
determineAstToReactTransforms(props).forEach(function (transform) { | ||
tree = transform(tree, renderProps); | ||
}); | ||
return tree; | ||
}; | ||
function applyParserPlugin(parser, plugin) { | ||
return Array.isArray(plugin) ? parser.use.apply(parser, _toConsumableArray(plugin)) : parser.use(plugin); | ||
} | ||
function determineAstPlugins(props) { | ||
var plugins = [wrapTableRows, addListMetadata()]; | ||
function determineAstToReactTransforms(props) { | ||
var transforms = [wrapTableRows, addListMetadata()]; | ||
var disallowedTypes = props.disallowedTypes; | ||
@@ -83,32 +68,30 @@ | ||
if (disallowedTypes && disallowedTypes.length > 0) { | ||
plugins.push(disallowNode.ofType(disallowedTypes, removalMethod)); | ||
transforms.push(disallowNode.ofType(disallowedTypes, removalMethod)); | ||
} | ||
if (props.allowNode) { | ||
plugins.push(disallowNode.ifNotMatch(props.allowNode, removalMethod)); | ||
} | ||
transforms.push(disallowNode.ifNotMatch(props.allowNode, removalMethod)); | ||
} // To do in next major: remove `escapeHtml`. | ||
var renderHtml = !props.escapeHtml && !props.skipHtml; | ||
var hasHtmlParser = (props.astPlugins || []).some(function (item) { | ||
var plugin = Array.isArray(item) ? item[0] : item; | ||
return plugin.identity === symbols.HtmlParser; | ||
var renderHtml = (props.allowDangerousHtml || props.escapeHtml === false) && !props.skipHtml; | ||
var hasHtmlParser = (props.astPlugins || []).some(function (transform) { | ||
return transform.identity === symbols.HtmlParser; | ||
}); | ||
if (renderHtml && !hasHtmlParser) { | ||
plugins.push(naiveHtml); | ||
transforms.push(naiveHtml); | ||
} | ||
return props.astPlugins ? plugins.concat(props.astPlugins) : plugins; | ||
if (props.astPlugins) { | ||
transforms = transforms.concat(props.astPlugins); | ||
} // Add the final transform to turn everything into React. | ||
transforms.push(astToReact); | ||
return transforms; | ||
} | ||
ReactMarkdown.defaultProps = { | ||
renderers: {}, | ||
escapeHtml: true, | ||
skipHtml: false, | ||
sourcePos: false, | ||
rawSourcePos: false, | ||
transformLinkUri: uriTransformer, | ||
astPlugins: [], | ||
plugins: [], | ||
parserOptions: {} | ||
transformLinkUri: uriTransformer | ||
}; | ||
@@ -122,2 +105,3 @@ ReactMarkdown.propTypes = { | ||
escapeHtml: PropTypes.bool, | ||
allowDangerousHtml: PropTypes.bool, | ||
skipHtml: PropTypes.bool, | ||
@@ -133,4 +117,3 @@ allowNode: PropTypes.func, | ||
renderers: PropTypes.object, | ||
plugins: PropTypes.array, | ||
parserOptions: PropTypes.object | ||
plugins: PropTypes.array | ||
}; | ||
@@ -137,0 +120,0 @@ ReactMarkdown.types = allTypes; |
@@ -7,3 +7,5 @@ /* eslint-disable react/prop-types, react/no-multi-comp */ | ||
var React = require('react'); | ||
/* istanbul ignore next - Don’t crash on old React. */ | ||
var supportsStringRender = parseInt((React.version || '16').slice(0, 2), 10) >= 16; | ||
@@ -42,2 +44,3 @@ var createElement = React.createElement; | ||
function TextRenderer(props) { | ||
/* istanbul ignore next - `span` is a fallback for old React. */ | ||
return supportsStringRender ? props.children : createElement('span', null, props.children); | ||
@@ -47,5 +50,7 @@ } | ||
function Root(props) { | ||
var useFragment = !props.className; | ||
var root = useFragment ? React.Fragment || 'div' : 'div'; | ||
return createElement(root, useFragment ? null : props, props.children); | ||
var className = props.className; | ||
var root = !className && React.Fragment || 'div'; | ||
return createElement(root, className ? { | ||
className: className | ||
} : null, props.children); | ||
} | ||
@@ -113,7 +118,8 @@ | ||
var dangerous = props.allowDangerousHtml || props.escapeHtml === false; | ||
var tag = props.isBlock ? 'div' : 'span'; | ||
if (props.escapeHtml) { | ||
var comp = React.Fragment || tag; | ||
return createElement(comp, null, props.value); | ||
if (!dangerous) { | ||
/* istanbul ignore next - `tag` is a fallback for old React. */ | ||
return createElement(React.Fragment || tag, null, props.value); | ||
} | ||
@@ -130,2 +136,3 @@ | ||
function ParsedHtml(props) { | ||
/* To do: `React.cloneElement` is slow, is it really needed? */ | ||
return props['data-sourcepos'] ? React.cloneElement(props.element, { | ||
@@ -145,5 +152,8 @@ 'data-sourcepos': props['data-sourcepos'] | ||
function getCoreProps(props) { | ||
return props['data-sourcepos'] ? { | ||
'data-sourcepos': props['data-sourcepos'] | ||
var source = props['data-sourcepos']; | ||
/* istanbul ignore next - nodes from plugins w/o position */ | ||
return source ? { | ||
'data-sourcepos': source | ||
} : {}; | ||
} |
"use strict"; | ||
var HtmlParser = '__RMD_HTML_PARSER__'; | ||
/* istanbul ignore next - Fallback for `Symbol`. */ | ||
exports.HtmlParser = typeof Symbol === 'undefined' ? HtmlParser : Symbol(HtmlParser); |
212
package.json
{ | ||
"name": "react-markdown", | ||
"description": "Renders Markdown as React components", | ||
"version": "4.3.1", | ||
"version": "5.0.0", | ||
"description": "Render Markdown as React components", | ||
"license": "MIT", | ||
"keywords": [ | ||
"remark", | ||
"unified", | ||
"markdown", | ||
"commonmark", | ||
"gfm", | ||
"ast", | ||
"react", | ||
"react-component" | ||
"react-component", | ||
"component" | ||
], | ||
"main": "lib/react-markdown.js", | ||
"unpkg": "umd/react-markdown.js", | ||
"scripts": { | ||
"analyze": "npm run clean && npm run compile && NODE_ENV=production ANALYZE_BUNDLE=1 webpack -p", | ||
"build": "npm run clean && npm run compile && NODE_ENV=production webpack -p && npm run build:demo", | ||
"build:demo": "NODE_ENV=production webpack -p --config webpack.config.demo.js", | ||
"postbuild": "echo 'Ensuring ES5 compatibility...' && uglifyjs umd/react-markdown.js > /dev/null && echo 'Yep!'", | ||
"clean": "rimraf lib/", | ||
"compile": "babel --copy-files -d lib/ src/", | ||
"deploy": "gh-pages-deploy", | ||
"posttest": "eslint .", | ||
"prepublishOnly": "npm run qa", | ||
"qa": "npm test && npm run build", | ||
"test": "jest --coverage --env=jsdom", | ||
"watch": "webpack --watch", | ||
"watch:demo": "webpack --watch --config webpack.config.demo.js" | ||
"repository": "remarkjs/react-markdown", | ||
"bugs": "https://github.com/remarkjs/react-markdown/issues", | ||
"funding": { | ||
"type": "opencollective", | ||
"url": "https://opencollective.com/unified" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git@github.com:rexxars/react-markdown.git" | ||
}, | ||
"author": "Espen Hovlandsdal <espen@hovlandsdal.com>", | ||
"license": "MIT", | ||
"gh-pages-deploy": { | ||
"noprompt": true, | ||
"prep": [ | ||
"build" | ||
], | ||
"staticpath": "demo/dist" | ||
}, | ||
"contributors": [ | ||
"Espen Hovlandsdal <espen@hovlandsdal.com>", | ||
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)" | ||
], | ||
"types": "index.d.ts", | ||
"main": "lib/react-markdown.js", | ||
"unpkg": "react-markdown.min.js", | ||
"files": [ | ||
"lib/", | ||
"plugins/", | ||
"index.d.ts", | ||
"react-markdown.min.js", | ||
"with-html.d.ts", | ||
"with-html.js" | ||
], | ||
"dependencies": { | ||
"@types/mdast": "^3.0.3", | ||
"@types/unist": "^2.0.3", | ||
"html-to-react": "^1.3.4", | ||
@@ -45,49 +46,122 @@ "mdast-add-list-metadata": "1.0.1", | ||
"react-is": "^16.8.6", | ||
"remark-parse": "^5.0.0", | ||
"unified": "^6.1.5", | ||
"unist-util-visit": "^1.3.0", | ||
"remark-parse": "^9.0.0", | ||
"unified": "^9.0.0", | ||
"unist-util-visit": "^2.0.0", | ||
"xtend": "^4.0.1" | ||
}, | ||
"peerDependencies": { | ||
"@types/react": "^15.0.0 || ^16.0.0", | ||
"react": "^15.0.0 || ^16.0.0" | ||
}, | ||
"devDependencies": { | ||
"@babel/cli": "^7.4.3", | ||
"@babel/core": "^7.4.3", | ||
"@babel/preset-env": "^7.4.3", | ||
"@babel/cli": "^7.0.0", | ||
"@babel/core": "^7.0.0", | ||
"@babel/preset-env": "^7.0.0", | ||
"@babel/preset-react": "^7.0.0", | ||
"babel-core": "^7.0.0-bridge.0", | ||
"babel-jest": "^24.7.1", | ||
"babel-loader": "^8.0.5", | ||
"@rollup/plugin-babel": "^5.0.0", | ||
"@rollup/plugin-commonjs": "^15.0.0", | ||
"@rollup/plugin-json": "^4.0.0", | ||
"@rollup/plugin-node-resolve": "^9.0.0", | ||
"@rollup/plugin-replace": "^2.0.0", | ||
"@types/react": "^16.0.0", | ||
"@types/react-dom": "^16.0.0", | ||
"babel-plugin-transform-react-remove-prop-types": "^0.4.24", | ||
"enzyme": "^3.9.0", | ||
"enzyme-adapter-react-16": "^1.12.1", | ||
"eslint": "^5.16.0", | ||
"eslint-config-prettier": "^4.1.0", | ||
"eslint-config-sanity": "^4.0.2", | ||
"eslint-plugin-react": "^7.12.4", | ||
"gh-pages-deploy": "^0.5.1", | ||
"jest": "^24.7.1", | ||
"prettier": "^1.17.0", | ||
"react": "^16.8.6", | ||
"react-addons-test-utils": "^15.6.2", | ||
"react-dom": "^16.8.6", | ||
"react-test-renderer": "^16.8.6", | ||
"remark-breaks": "^1.0.2", | ||
"remark-shortcodes": "^0.2.1", | ||
"remark-toc": "^5.1.1", | ||
"rimraf": "^2.6.3", | ||
"uglify-js": "^3.5.4", | ||
"webpack": "^4.30.0", | ||
"webpack-bundle-analyzer": "^3.3.2", | ||
"webpack-cli": "^3.3.0" | ||
"dtslint": "^4.0.0", | ||
"enzyme": "^3.10.0", | ||
"enzyme-adapter-react-16": "^1.0.0", | ||
"eslint": "^7.0.0", | ||
"eslint-config-prettier": "^6.0.0", | ||
"eslint-config-sanity": "^4.0.0", | ||
"eslint-plugin-react": "^7.0.0", | ||
"jest": "^26.0.0", | ||
"npm-run-all": "^4.0.0", | ||
"prettier": "^2.0.0", | ||
"react": "^16.0.0", | ||
"react-dom": "^16.0.0", | ||
"react-katex": "^2.0.0", | ||
"react-test-renderer": "^16.0.0", | ||
"remark-cli": "^9.0.0", | ||
"remark-gfm": "^1.0.0", | ||
"remark-math": "^4.0.0", | ||
"remark-preset-wooorm": "^8.0.0", | ||
"remark-toc": "^7.0.0", | ||
"rimraf": "^3.0.0", | ||
"rollup": "^2.0.0", | ||
"rollup-plugin-node-polyfills": "^0.2.0", | ||
"rollup-plugin-terser": "^7.0.0", | ||
"typescript": "^4.0.0", | ||
"uglify-js": "^3.0.0" | ||
}, | ||
"peerDependencies": { | ||
"react": "^15.0.0 || ^16.0.0" | ||
"scripts": { | ||
"build:lib": "rimraf lib/ && babel src/ --quiet --copy-files -d lib/", | ||
"build:umd": "rollup --silent -c", | ||
"build:umdcheck": "printf 'ES5? ' && uglifyjs react-markdown.min.js > /dev/null && echo 'Yes'", | ||
"build": "run-s build:*", | ||
"format": "remark . -qfo --ignore-pattern test/ && prettier . -w --loglevel warn && eslint . --fix", | ||
"test": "run-s build format test:*", | ||
"test:unit": "jest --coverage", | ||
"test:types": "dtslint ." | ||
}, | ||
"browserslist": "> 0.25%, not dead", | ||
"remarkConfig": { | ||
"plugins": [ | ||
"preset-wooorm", | ||
[ | ||
"lint-no-html", | ||
false | ||
] | ||
] | ||
}, | ||
"jest": { | ||
"verbose": true, | ||
"testEnvironment": "node", | ||
"coverageDirectory": "coverage", | ||
"collectCoverageFrom": [ | ||
"src/**.js" | ||
] | ||
"coverageThreshold": { | ||
"global": { | ||
"branches": 90, | ||
"functions": 90, | ||
"lines": 90, | ||
"statements": 90 | ||
} | ||
} | ||
}, | ||
"prettier": { | ||
"bracketSpacing": false, | ||
"printWidth": 100, | ||
"semi": false, | ||
"singleQuote": true, | ||
"tabWidth": 2, | ||
"trailingComma": "none", | ||
"useTabs": false | ||
}, | ||
"eslintConfig": { | ||
"extends": [ | ||
"sanity", | ||
"prettier", | ||
"plugin:react/recommended" | ||
], | ||
"plugins": [ | ||
"react" | ||
], | ||
"env": { | ||
"node": true, | ||
"browser": true | ||
}, | ||
"parserOptions": { | ||
"ecmaVersion": 2018, | ||
"ecmaFeatures": { | ||
"jsx": true | ||
} | ||
}, | ||
"rules": { | ||
"react/no-children-prop": 0, | ||
"strict": 0, | ||
"complexity": [ | ||
"warn", | ||
15 | ||
] | ||
}, | ||
"settings": { | ||
"react": { | ||
"version": "15.0" | ||
} | ||
} | ||
} | ||
} |
@@ -1,5 +0,9 @@ | ||
import {Component} from 'react' | ||
import ReactMarkdownRoot = require('react-markdown') | ||
// TypeScript Version: 3.4 | ||
declare class ReactMarkdown extends Component<ReactMarkdownRoot.ReactMarkdownProps, {}> {} | ||
import {ReactElement} from 'react' | ||
import {ReactMarkdownProps} from 'react-markdown' | ||
declare namespace ReactMarkdown {} | ||
declare function ReactMarkdown(props: ReactMarkdownProps): ReactElement | ||
export = ReactMarkdown |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
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
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
176103
1315
1
509
12
37
20
1
2
+ Added@types/mdast@^3.0.3
+ Added@types/unist@^2.0.3
+ Added@types/mdast@3.0.15(transitive)
+ Added@types/prop-types@15.7.13(transitive)
+ Added@types/react@16.14.62(transitive)
+ Added@types/scheduler@0.16.8(transitive)
+ Added@types/unist@2.0.11(transitive)
+ Addedcsstype@3.1.3(transitive)
+ Addeddebug@4.3.7(transitive)
+ Addedis-buffer@2.0.5(transitive)
+ Addedis-plain-obj@2.1.0(transitive)
+ Addedmdast-util-from-markdown@0.8.5(transitive)
+ Addedmdast-util-to-string@2.0.0(transitive)
+ Addedmicromark@2.11.4(transitive)
+ Addedms@2.1.3(transitive)
+ Addedparse-entities@2.0.0(transitive)
+ Addedremark-parse@9.0.0(transitive)
+ Addedunified@9.2.2(transitive)
+ Addedunist-util-is@4.1.0(transitive)
+ Addedunist-util-stringify-position@2.0.3(transitive)
+ Addedunist-util-visit@2.0.3(transitive)
+ Addedunist-util-visit-parents@3.1.1(transitive)
+ Addedvfile@4.2.1(transitive)
+ Addedvfile-message@2.0.4(transitive)
- Removedcollapse-white-space@1.0.6(transitive)
- Removedinherits@2.0.4(transitive)
- Removedis-buffer@1.1.6(transitive)
- Removedis-plain-obj@1.1.0(transitive)
- Removedis-whitespace-character@1.0.4(transitive)
- Removedis-word-character@1.0.4(transitive)
- Removedmarkdown-escapes@1.0.4(transitive)
- Removedparse-entities@1.2.2(transitive)
- Removedremark-parse@5.0.0(transitive)
- Removedrepeat-string@1.6.1(transitive)
- Removedreplace-ext@1.0.0(transitive)
- Removedstate-toggle@1.0.3(transitive)
- Removedtrim@0.0.1(transitive)
- Removedtrim-trailing-lines@1.1.4(transitive)
- Removedunherit@1.1.3(transitive)
- Removedunified@6.2.0(transitive)
- Removedunist-util-is@3.0.0(transitive)
- Removedunist-util-remove-position@1.1.4(transitive)
- Removedunist-util-stringify-position@1.1.2(transitive)
- Removedunist-util-visit@1.4.1(transitive)
- Removedunist-util-visit-parents@2.1.2(transitive)
- Removedvfile@2.3.0(transitive)
- Removedvfile-location@2.0.6(transitive)
- Removedvfile-message@1.1.1(transitive)
- Removedx-is-string@0.1.0(transitive)
Updatedremark-parse@^9.0.0
Updatedunified@^9.0.0
Updatedunist-util-visit@^2.0.0