22 * Base Markdown component
33 * @author Mient-jan Stelling
44 */
5- import { useMemo } from 'react' ;
5+ import { useMemo } from 'react' ;
66import PropTypes from 'prop-types' ;
77import parser from './lib/parser' ;
88import applyStyle from './lib/util/applyStyle' ;
@@ -15,8 +15,8 @@ import AstRenderer from './lib/AstRenderer';
1515import MarkdownIt from 'markdown-it' ;
1616import PluginContainer from './lib/plugin/PluginContainer' ;
1717import blockPlugin from './lib/plugin/blockPlugin' ;
18- import { styles } from './lib/styles' ;
19- import { stringToTokens } from './lib/util/stringToTokens' ;
18+ import { styles } from './lib/styles' ;
19+ import { stringToTokens } from './lib/util/stringToTokens' ;
2020/**
2121 *
2222 */
@@ -48,13 +48,13 @@ const getCopyFromChildren = children => {
4848const getRenderer = ( renderer , rules , style , onLinkPress ) => {
4949 if ( renderer && rules ) {
5050 console . warn (
51- 'react-native-markdown-display you are using renderer and rules at the same time. This is not possible, props.rules is ignored'
51+ 'react-native-markdown-display you are using renderer and rules at the same time. This is not possible, props.rules is ignored' ,
5252 ) ;
5353 }
5454
5555 if ( renderer && style ) {
5656 console . warn (
57- 'react-native-markdown-display you are using renderer and style at the same time. This is not possible, props.style is ignored'
57+ 'react-native-markdown-display you are using renderer and style at the same time. This is not possible, props.style is ignored' ,
5858 ) ;
5959 }
6060
@@ -63,7 +63,9 @@ const getRenderer = (renderer, rules, style, onLinkPress) => {
6363 if ( ! ( typeof renderer === 'function' ) || renderer instanceof AstRenderer ) {
6464 return renderer ;
6565 } else {
66- throw new Error ( 'Provided renderer is not compatible with function or AstRenderer. please change' ) ;
66+ throw new Error (
67+ 'Provided renderer is not compatible with function or AstRenderer. please change' ,
68+ ) ;
6769 }
6870 } else {
6971 return new AstRenderer (
@@ -75,7 +77,7 @@ const getRenderer = (renderer, rules, style, onLinkPress) => {
7577 ...styles ,
7678 ...style ,
7779 } ,
78- onLinkPress
80+ onLinkPress ,
7981 ) ;
8082 }
8183} ;
@@ -105,8 +107,14 @@ const Markdown = ({
105107 } ) ,
106108 onLinkPress = ( ) => { } ,
107109} ) => {
108- const momoizedRenderer = useMemo ( ( ) => getRenderer ( renderer , rules , style , onLinkPress ) , [ renderer , rules , style ] ) ;
109- const markdownParser = useMemo ( ( ) => getMarkdownParser ( markdownit , plugins ) , [ markdownit , plugins ] ) ;
110+ const momoizedRenderer = useMemo (
111+ ( ) => getRenderer ( renderer , rules , style , onLinkPress ) ,
112+ [ onLinkPress , renderer , rules , style ] ,
113+ ) ;
114+ const markdownParser = useMemo ( ( ) => getMarkdownParser ( markdownit , plugins ) , [
115+ markdownit ,
116+ plugins ,
117+ ] ) ;
110118
111119 const copy = ( this . copy = getCopyFromChildren ( children ) ) ;
112120 return parser ( copy , momoizedRenderer . render , markdownParser ) ;
@@ -117,7 +125,10 @@ const Markdown = ({
117125 */
118126Markdown . propTypes = {
119127 children : PropTypes . node . isRequired ,
120- renderer : PropTypes . oneOfType ( [ PropTypes . func , PropTypes . instanceOf ( AstRenderer ) ] ) ,
128+ renderer : PropTypes . oneOfType ( [
129+ PropTypes . func ,
130+ PropTypes . instanceOf ( AstRenderer ) ,
131+ ] ) ,
121132 onLinkPress : PropTypes . func ,
122133 rules : ( props , propName , componentName ) => {
123134 let invalidProps = [ ] ;
@@ -128,17 +139,19 @@ Markdown.propTypes = {
128139 }
129140
130141 if ( typeof prop === 'object' ) {
131- invalidProps = Object . keys ( prop ) . filter ( key => typeof prop [ key ] !== 'function' ) ;
142+ invalidProps = Object . keys ( prop ) . filter (
143+ key => typeof prop [ key ] !== 'function' ,
144+ ) ;
132145 }
133146
134147 if ( typeof prop !== 'object' ) {
135148 return new Error (
136- `Invalid prop \`${ propName } \` supplied to \`${ componentName } \`. Must be of shape {[index:string]:function} `
149+ `Invalid prop \`${ propName } \` supplied to \`${ componentName } \`. Must be of shape {[index:string]:function} ` ,
137150 ) ;
138151 } else if ( invalidProps . length > 0 ) {
139152 return new Error (
140153 `Invalid prop \`${ propName } \` supplied to \`${ componentName } \`. These ` +
141- `props are not of type function \`${ invalidProps . join ( ', ' ) } \` `
154+ `props are not of type function \`${ invalidProps . join ( ', ' ) } \` ` ,
142155 ) ;
143156 }
144157 } ,
0 commit comments