@@ -228,8 +228,13 @@ export function emojify(s: string): string {
228
228
return emojified ;
229
229
}
230
230
231
+ const HashLinkContext = React . createContext < ?StatelessFunctionalComponent < {
232
+ hash : string ,
233
+ children ?: Node ,
234
+ } >> ( null ) ;
235
+
231
236
function Link ( props ) {
232
- const { HashLink} = props ;
237
+ const HashLink = React . useContext ( HashLinkContext ) ;
233
238
if ( props . href && props . href . startsWith ( '#' ) && HashLink ) {
234
239
return < HashLink hash = { props . href } > { props . children } </ HashLink > ;
235
240
}
@@ -251,7 +256,6 @@ function headingSlug(props) {
251
256
const defaultRenderers = ( {
252
257
isRss,
253
258
addHeadingIds,
254
- HashLink,
255
259
} : {
256
260
isRss ?: ?boolean ,
257
261
addHeadingIds ?: ?boolean ,
@@ -302,9 +306,7 @@ const defaultRenderers = ({
302
306
/>
303
307
) ;
304
308
} ,
305
- link ( props ) {
306
- return < Link { ...props } HashLink = { HashLink } /> ;
307
- } ,
309
+ link : Link ,
308
310
linkReference ( props ) {
309
311
return < div { ...props } /> ;
310
312
} ,
@@ -390,17 +392,18 @@ const parseHtml = htmlParser({
390
392
export default class MarkdownRenderer extends React . PureComponent < Props > {
391
393
render ( ) {
392
394
return (
393
- < ReactMarkdown
394
- escapeHtml = { this . props . trustedInput ? false : true }
395
- source = { this . props . source }
396
- renderers = { defaultRenderers ( {
397
- isRss : false ,
398
- addHeadingIds : this . props . addHeadingIds ,
399
- HashLink : this . props . HashLink ,
400
- } ) }
401
- astPlugins = { this . props . trustedInput ? [ parseHtml ] : [ ] }
402
- parserOptions = { { footnotes : true } }
403
- />
395
+ < HashLinkContext . Provider value = { this . props . HashLink } >
396
+ < ReactMarkdown
397
+ escapeHtml = { this . props . trustedInput ? false : true }
398
+ source = { this . props . source }
399
+ renderers = { defaultRenderers ( {
400
+ isRss : false ,
401
+ addHeadingIds : this . props . addHeadingIds ,
402
+ } ) }
403
+ astPlugins = { this . props . trustedInput ? [ parseHtml ] : [ ] }
404
+ parserOptions = { { footnotes : true } }
405
+ />
406
+ </ HashLinkContext . Provider >
404
407
) ;
405
408
}
406
409
}
0 commit comments