Skip to content

Commit 3c09355

Browse files
committed
fix embeds
1 parent 85b957c commit 3c09355

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

src/MarkdownRenderer.js

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,13 @@ export function emojify(s: string): string {
228228
return emojified;
229229
}
230230

231+
const HashLinkContext = React.createContext<?StatelessFunctionalComponent<{
232+
hash: string,
233+
children?: Node,
234+
}>>(null);
235+
231236
function Link(props) {
232-
const {HashLink} = props;
237+
const HashLink = React.useContext(HashLinkContext);
233238
if (props.href && props.href.startsWith('#') && HashLink) {
234239
return <HashLink hash={props.href}>{props.children}</HashLink>;
235240
}
@@ -251,7 +256,6 @@ function headingSlug(props) {
251256
const defaultRenderers = ({
252257
isRss,
253258
addHeadingIds,
254-
HashLink,
255259
}: {
256260
isRss?: ?boolean,
257261
addHeadingIds?: ?boolean,
@@ -302,9 +306,7 @@ const defaultRenderers = ({
302306
/>
303307
);
304308
},
305-
link(props) {
306-
return <Link {...props} HashLink={HashLink} />;
307-
},
309+
link: Link,
308310
linkReference(props) {
309311
return <div {...props} />;
310312
},
@@ -390,17 +392,18 @@ const parseHtml = htmlParser({
390392
export default class MarkdownRenderer extends React.PureComponent<Props> {
391393
render() {
392394
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>
404407
);
405408
}
406409
}

0 commit comments

Comments
 (0)